You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2009/09/27 23:52:16 UTC

svn commit: r819414 - in /incubator/empire-db/trunk/empire-db-codegen: config.xml src/main/java/org/apache/empire/db/codegen/CodeGen.java src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java

Author: doebele
Date: Sun Sep 27 21:52:16 2009
New Revision: 819414

URL: http://svn.apache.org/viewvc?rev=819414&view=rev
Log:
EMPIREDB-52

Modified:
    incubator/empire-db/trunk/empire-db-codegen/config.xml
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java

Modified: incubator/empire-db/trunk/empire-db-codegen/config.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/config.xml?rev=819414&r1=819413&r2=819414&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/config.xml (original)
+++ incubator/empire-db/trunk/empire-db-codegen/config.xml Sun Sep 27 21:52:16 2009
@@ -27,6 +27,18 @@
 		<jdbcURL>jdbc:oracle:thin:@192.168.0.2:1521:ora10</jdbcURL>
 		<jdbcUser>DBSAMPLE</jdbcUser>
 		<jdbcPwd>DBSAMPLE</jdbcPwd>
+		
+		<!-- generation options -->
+		<packageName>org.foo.db</packageName>
+		<dbClassName>MyDB</dbClassName>
+		<tableBaseName>MyTable</tableBaseName>
+		<viewBaseName>MyView</viewBaseName>
+		<recordBaseName>MyRecord</recordBaseName>
+		<tableClassPrefix>T</tableClassPrefix>
+		<viewClassPrefix>V</viewClassPrefix>
+		<nestTables>True</nestTables>
+		<nestViews>False</nestViews>
+		<createRecordProperties>True</createRecordProperties>
 	</properties>
 	
 	<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java?rev=819414&r1=819413&r2=819414&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java Sun Sep 27 21:52:16 2009
@@ -24,11 +24,14 @@
 import java.sql.ResultSet;
 import java.util.logging.Logger;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.empire.commons.ErrorObject;
+import org.apache.empire.db.DBDatabase;
 
 public class CodeGen
 {
-    public static Logger logger = Logger.getLogger(CodeGen.class.getName());
+    private static final Log log = LogFactory.getLog(CodeGen.class);
 
     private static CodeGenConfig config = new CodeGenConfig();
 
@@ -53,6 +56,19 @@
             // Get a JDBC Connection
             conn = getJDBCConnection();
             
+            // List options
+            log.info("Database connection successful. Config options are:");
+            log.info("PackageName="+config.getPackageName());
+            log.info("DbClassName="+config.getDbClassName());
+            log.info("TableBaseName="+config.getTableBaseName());
+            log.info("ViewBaseName="+config.getViewBaseName());
+            log.info("RecordBaseName="+config.getRecordBaseName());
+            log.info("TableClassPrefix="+config.getTableClassPrefix());
+            log.info("ViewClassPrefi="+config.getViewClassPrefix());
+            log.info("NestTable="+config.isNestTables());
+            log.info("NestViews="+config.isNestViews());
+            log.info("CreateRecordPropertie="+config.isCreateRecordProperties());
+            
             // Get Metadata
             DatabaseMetaData dmd = conn.getMetaData();
             
@@ -86,22 +102,21 @@
     {
         // Establish a new database connection
         Connection conn = null;
-        logger.info("Connecting to Database'" + config.getJdbcURL() + "' / User=" + config.getJdbcUser());
+        log.info("Connecting to Database'" + config.getJdbcURL() + "' / User=" + config.getJdbcUser());
         try
         {
             // Connect to the databse
             Class.forName(config.getJdbcClass()).newInstance();
             conn = DriverManager.getConnection(config.getJdbcURL(), config.getJdbcUser(), config.getJdbcPwd());
-            logger.info("Connected successfully");
+            log.info("Connected successfully");
             // set the AutoCommit to false this session. You must commit
             // explicitly now
             conn.setAutoCommit(true);
-            logger.info("AutoCommit is " + conn.getAutoCommit());
+            log.info("AutoCommit is " + conn.getAutoCommit());
 
         } catch (Exception e)
         {
-            logger.severe("Failed to connect directly to '" + config.getJdbcURL() + "' / User=" + config.getJdbcUser());
-            logger.severe(e.toString());
+            log.fatal("Failed to connect directly to '" + config.getJdbcURL() + "' / User=" + config.getJdbcUser(), e);
             throw new RuntimeException(e);
         }
         return conn;
@@ -112,12 +127,11 @@
      */
     private static void close(Connection conn)
     {
-        logger.info("Closing database connection");
+        log.info("Closing database connection");
         try {
             conn.close();
         } catch (Exception e) {
-            logger.severe("Error closing connection");
-            logger.severe(e.toString());
+            log.fatal("Error closing connection", e);
         }
     }
     

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java?rev=819414&r1=819413&r2=819414&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java Sun Sep 27 21:52:16 2009
@@ -29,6 +29,70 @@
     private String jdbcUser = "sa";
 
     private String jdbcPwd = "";
+    
+    // generation options
+    /**
+     * name of the target package
+     */
+    private String packageName = "org.foo.db";
+    
+    /**
+     * Target name of the generated database class.
+     * This class extends DBDatabase.
+     */
+    private String dbClassName    = "MyDB";
+    /**
+     * Target name of the generated table class.
+     * This class extends DBTable and is the base class for all generated individual table classes.
+     */
+    private String tableBaseName  = "MyTable";
+    /**
+     * Target name of the generated view class.
+     * This class extends DBView and is the base class for all generated individual view classes.
+     */
+    private String viewBaseName   = "MyView";
+    /**
+     * Target name of the generated record class.
+     * This is a template class that extends DBRecord as follows:<br/>
+     * <pre>XXRecord<T extends XXTable> extends DBRecord</pre><br/>
+     */
+    private String recordBaseName = "MyRecord";
+    /**
+     * Prefix used for generating table class names.<br/> 
+     * The Table name is appended after the prefix starting with captial letter followed by lower case letters.<br/>
+     * Occurrence an of underscore indicates a new word which will again start with a capital letter.<br/>
+     * e.g.<br/>
+     * <ul>
+     *  <li>Table "names" -> Class "XXNames"</li>
+     *  <li>Table "flight_bookings" -> Class "XXFlightBookings"</li>
+     * </ul>
+     * Where XX is the prefix.
+     */
+    private String tableClassPrefix = "T";
+    /**
+     * Prefix used for generating view class names.<br/> 
+     * The Table name is appended after the prefix starting with captial letter followed by lower case letters.<br/>
+     * Occurrence an of underscore indicates a new word which will again start with a capital letter.<br/>
+     * See naming of table classes above.
+     */
+    private String viewClassPrefix  = "V";
+    
+    /**
+     * if TRUE table classes should be declared as inner classes of DBDatabase.<br/>
+     * if FALSE table classes should be declared as top level classes.
+     */
+    private boolean nestTables;
+    /**
+     * if TRUE view classes should be declared as inner classes of DBDatabase.<br/>
+     * if FALSE view classes should be declared as top level classes.
+     */
+    private boolean nestViews;
+    /**
+     * if TRUE record classes should have a getter and setter for each field.<br/>
+     * Otherwiese getters / setters are omitted.
+     */
+    private boolean createRecordProperties;
+    
 
     /**
      * Initialize the configuration.
@@ -89,4 +153,107 @@
         this.jdbcPwd = jdbcPwd;
     }
     
+    // ------- generation options -------
+    
+    public String getPackageName()
+    {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName)
+    {
+        this.packageName = packageName;
+    }
+
+    public String getDbClassName()
+    {
+        return dbClassName;
+    }
+
+    public void setDbClassName(String dbClassName)
+    {
+        this.dbClassName = dbClassName;
+    }
+
+    public String getTableBaseName()
+    {
+        return tableBaseName;
+    }
+
+    public void setTableBaseName(String tableBaseName)
+    {
+        this.tableBaseName = tableBaseName;
+    }
+
+    public String getViewBaseName()
+    {
+        return viewBaseName;
+    }
+
+    public void setViewBaseName(String viewBaseName)
+    {
+        this.viewBaseName = viewBaseName;
+    }
+
+    public String getRecordBaseName()
+    {
+        return recordBaseName;
+    }
+
+    public void setRecordBaseName(String recordBaseName)
+    {
+        this.recordBaseName = recordBaseName;
+    }
+
+    public String getTableClassPrefix()
+    {
+        return tableClassPrefix;
+    }
+
+    public void setTableClassPrefix(String tableClassPrefix)
+    {
+        this.tableClassPrefix = tableClassPrefix;
+    }
+
+    public String getViewClassPrefix()
+    {
+        return viewClassPrefix;
+    }
+
+    public void setViewClassPrefix(String viewClassPrefix)
+    {
+        this.viewClassPrefix = viewClassPrefix;
+    }
+
+    public boolean isNestTables()
+    {
+        return nestTables;
+    }
+
+    public void setNestTables(boolean nestTables)
+    {
+        this.nestTables = nestTables;
+    }
+
+    public boolean isNestViews()
+    {
+        return nestViews;
+    }
+
+    public void setNestViews(boolean nestViews)
+    {
+        this.nestViews = nestViews;
+    }
+
+    public boolean isCreateRecordProperties()
+    {
+        return createRecordProperties;
+    }
+
+    public void setCreateRecordProperties(boolean createRecordProperties)
+    {
+        this.createRecordProperties = createRecordProperties;
+    }
+    
+    
 }