package org.apache.maven.hibernate.beans;

/* ====================================================================
 *   Copyright 2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

import java.io.FileInputStream;
import java.util.Properties;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaUpdate;

/**
 * 
 * The Bean which serves as Proxy To Hibernate SchemaUpdate 
 * <br/>
 *   
 * @author <a href="maven@felipeal.net">Felipe Leme</a> 
 * @version $Id$
 */
public class SchemaUpdateBean extends SchemaBeanBase
{
   
   protected void executeSchema(Configuration cfg) throws Exception {
      SchemaUpdate schemaUpdate = null;
      if (getProperties() == null)
      {
         schemaUpdate = new SchemaUpdate(cfg);
      }
      else
      {
         Properties properties = new Properties();
         properties.load(new FileInputStream(getProperties()));
         schemaUpdate = new SchemaUpdate(cfg, properties);
      }
      schemaUpdate.execute( !getQuiet(), !getText() );
    }
   
}
