package org.apache.maven.hibernate.beans;

/* ====================================================================
 *   Copyright 2001-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.SchemaExport;

/**
 * 
 * The Bean which serves as Proxy To Hibernate API
 * <br/>
 *   
 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
 * @version $Id$
 */
public class SchemaExportBean extends SchemaBeanBase
{

   private boolean drop = false;
   
   /**
    * @return
    */
   public boolean isDrop()
   {
      return drop;
   }

   /**
    * @param b
    */
   public void setDrop(boolean b)
   {
      drop = b;
   }
   
   protected void executeSchema(Configuration cfg) throws Exception {
      SchemaExport schemaExport = null;
      if (getProperties() == null)
      {
         schemaExport = new SchemaExport(cfg);
      }
      else
      {
         Properties properties = new Properties();
         properties.load(new FileInputStream(getProperties()));
         schemaExport = new SchemaExport(cfg, properties);
      }
      LOG.debug("Output file:" + getOutputFile());
      schemaExport.setOutputFile(getOutputFile());
      schemaExport.setDelimiter(getDelimiter());
      if (isDrop())
      {
          schemaExport.drop(!getQuiet(), !getText());
      } 
      else
      {
          schemaExport.create(!getQuiet(), !getText());
      }
    }
   
}
