View Javadoc

1   package org.apache.maven.hibernate.beans;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import java.io.FileInputStream;
21  import java.util.Properties;
22  
23  import net.sf.hibernate.cfg.Configuration;
24  import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
25  
26  /**
27   * 
28   * The Bean which serves as Proxy To Hibernate API
29   * <br/>
30   *   
31   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
32   * @version $Id: SchemaExportBean.java 170200 2005-05-15 06:24:19Z brett $
33   */
34  public class SchemaExportBean extends SchemaBeanBase
35  {
36  
37     private boolean drop = false;
38     
39     /**
40      * @return
41      */
42     public boolean isDrop()
43     {
44        return drop;
45     }
46  
47     /**
48      * @param b
49      */
50     public void setDrop(boolean b)
51     {
52        drop = b;
53     }
54     
55     protected void executeSchema(Configuration cfg) throws Exception {
56        SchemaExport schemaExport = null;
57        if (getProperties() == null)
58        {
59           schemaExport = new SchemaExport(cfg);
60        }
61        else
62        {
63           Properties properties = new Properties();
64           properties.load(new FileInputStream(getProperties()));
65           schemaExport = new SchemaExport(cfg, properties);
66        }
67        LOG.debug("Output file:" + getOutputFile());
68        schemaExport.setOutputFile(getOutputFile());
69        schemaExport.setDelimiter(getDelimiter());
70        if (isDrop())
71        {
72            schemaExport.drop(!getQuiet(), !getText());
73        } 
74        else
75        {
76            schemaExport.create(!getQuiet(), !getText());
77        }
78      }
79     
80  }