empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r886936 - in /incubator/empire-db/trunk/empire-db-codegen/src/main: java/org/apache/empire/db/codegen/CodeGenWriter.java resources/templates/Database.vm resources/templates/Table.vm
Date Thu, 03 Dec 2009 21:55:24 GMT
Author: francisdb
Date: Thu Dec  3 21:55:24 2009
New Revision: 886936

URL: http://svn.apache.org/viewvc?rev=886936&view=rev
Log:
EMPIREDB-52 - code submitted by Benjamin (CODEGEN-0.5.patch of Dec.1)

Modified:
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Database.vm
    incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java?rev=886936&r1=886935&r2=886936&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
Thu Dec  3 21:55:24 2009
@@ -52,13 +52,13 @@
  * <p>
  * NOTE: THIS VERSION HAS SEVERE RESTRICTIONS:
  * <ol>
- * <li> Only tables are currently modeled (we'll add views to a later version).</li>

- * <li> Table indexes are not yet modeled (exception is primary key). Again, 
- * this will be added to later editions.</li>  
- * <li> It is assumed that each table has a single INTEGER auto-generated primary
- * key column that has the same name for all tables. </li> 
- * <li> It is assumed that each table has a single TIMESTAMP optimistic locking
- * column that has the same name for all tables.</li> 
+ * <li>Only tables are currently modeled (we'll add views to a later version).</li>
+ * <li>Table indexes are not yet modeled (exception is primary key). Again, this
+ * will be added to later editions.</li>
+ * <li>It is assumed that each table has a single INTEGER auto-generated primary
+ * key column that has the same name for all tables.</li>
+ * <li>It is assumed that each table has a single TIMESTAMP optimistic locking
+ * column that has the same name for all tables.</li>
  * </ol>
  */
 
@@ -75,7 +75,7 @@
 
 	// Services
 	private final ParserUtil pUtil;
-	
+
 	// Properties
 	private final CodeGenConfig config;
 	private File baseDir;
@@ -88,7 +88,8 @@
 	public CodeGenWriter(CodeGenConfig config) {
 		// we have to keep this in sync with our logging system
 		// http://velocity.apache.org/engine/releases/velocity-1.5/developer-guide.html#simpleexampleofacustomlogger
-		Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute() );
+		Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,
+				new CommonsLogLogChute());
 		try {
 			Velocity.init();
 		} catch (Exception e) {
@@ -101,10 +102,12 @@
 
 	/**
 	 * Generates the java code files for the database
-	 * @param db the DBDatabase to generate files for
+	 * 
+	 * @param db
+	 *            the DBDatabase to generate files for
 	 */
 	public List<File> generateCodeFiles(DBDatabase db) {
-	    List<File> generatedFiles = new ArrayList<File>();
+		List<File> generatedFiles = new ArrayList<File>();
 
 		// Prepare directories for generated source files
 		this.initDirectories(config.getTargetFolder(), config.getPackageName());
@@ -118,10 +121,12 @@
 		// Create base record class
 		generatedFiles.add(this.createBaseRecordClass(db));
 		// Create table classes, record interfaces and record classes
-		for (DBTable table : db.getTables()) 
-		{
-		    generatedFiles.add(this.createTableClass(db, table));
-		    generatedFiles.add(this.createRecordClass(db, table));
+		for (DBTable table : db.getTables()) {
+			if (!config.isNestTables()) {
+				// if table nesting is disabled, create separate table classes 
+				generatedFiles.add(this.createTableClass(db, table));
+			}
+			generatedFiles.add(this.createRecordClass(db, table));
 		}
 		return generatedFiles;
 	}
@@ -161,6 +166,9 @@
 		context.put("dbClassName", config.getDbClassName());
 		context.put("tableSubPackage", "tables");
 		context.put("database", db);
+		context.put("nestTables", config.isNestTables());
+		context.put("baseTableClassName", config.getTableBaseName());
+
 		writeFile(file, TEMPLATE_PATH + "/" + DATABASE_TEMPLATE, context);
 		return file;
 	}
@@ -183,6 +191,7 @@
 		context.put("tablePackageName", config.getPackageName() + ".tables");
 		context.put("baseTableClassName", config.getTableBaseName());
 		context.put("dbClassName", config.getDbClassName());
+		context.put("nestTables", config.isNestTables());
 		context.put("table", table);
 		writeFile(file, TEMPLATE_PATH + "/" + TABLE_TEMPLATE, context);
 		return file;
@@ -201,13 +210,15 @@
 	}
 
 	private File createRecordClass(DBDatabase db, DBTable table) {
-		File file = new File(recordDir, pUtil.getRecordClassName(table
-				.getName())
-				+ ".java");
+		File file = new File(recordDir, pUtil.getRecordClassName(table.getName()) + ".java");
 		VelocityContext context = new VelocityContext();
 		context.put("parser", pUtil);
 		context.put("basePackageName", config.getPackageName());
-		context.put("tablePackageName", config.getPackageName() + ".tables");
+		// If the tables shall be nested within the database classe, their include path for the
records needs to be changed
+		if (config.isNestTables())
+			context.put("tablePackageName", config.getPackageName() + "." + config.getDbClassName());
+		else
+			context.put("tablePackageName", config.getPackageName() + ".tables");
 		context.put("recordPackageName", config.getPackageName() + ".records");
 		context.put("baseRecordClassName", config.getRecordBaseName());
 		context.put("dbClassName", config.getDbClassName());

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Database.vm
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Database.vm?rev=886936&r1=886935&r2=886936&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Database.vm (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Database.vm Thu
Dec  3 21:55:24 2009
@@ -27,6 +27,10 @@
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBReader;
 import org.apache.empire.db.DBRecord;
+#if($nestTables == true)
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBTableColumn;
+#end
 
 import $basePackageName.$tableSubPackage.*;
 
@@ -115,4 +119,11 @@
 		}
 		return records;
 	}
+	
+	#if($nestTables == true)
+		#foreach ($table in $database.tables)
+			#parse( "src/main/resources/templates/Table.vm" )
+		#end
+	#end
+	
 }

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm?rev=886936&r1=886935&r2=886936&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm Thu
Dec  3 21:55:24 2009
@@ -16,6 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  *#
+
+#if($nestTables == false)
 package $tablePackageName;
 
 import java.util.ArrayList;
@@ -23,10 +25,10 @@
 
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBTableColumn;
-
 import $basePackageName.${dbClassName};
+#end
 
-public class $parser.getTableClassName($table.name) extends ${baseTableClassName} {
+public #if($nestTables == true)static#end  class $parser.getTableClassName($table.name) extends
${baseTableClassName} {
 	// Primary key column
 	private List<DBTableColumn> keyColumns= new ArrayList<DBTableColumn>();
 	



Mime
View raw message