empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1184937 - in /incubator/empire-db/trunk/empire-db-codegen: ./ src/main/java/org/apache/empire/db/codegen/ src/main/resources/templates/
Date Sun, 16 Oct 2011 21:33:25 GMT
Author: doebele
Date: Sun Oct 16 21:33:25 2011
New Revision: 1184937

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

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/CodeGenConfig.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/WriterService.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/Record.vm
    incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Table.vm
    incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/View.vm

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=1184937&r1=1184936&r2=1184937&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/config.xml (original)
+++ incubator/empire-db/trunk/empire-db-codegen/config.xml Sun Oct 16 21:33:25 2011
@@ -48,10 +48,13 @@
 		<tableBaseName>SampleTable</tableBaseName>
 		<viewBaseName>SampleView</viewBaseName>
 		<recordBaseName>SampleRecord</recordBaseName>
+		<tableNamePrefix></tableNamePrefix>
 		<tableClassPrefix>T_</tableClassPrefix>
 		<tableClassSuffix></tableClassSuffix>
+		<viewNamePrefix></viewNamePrefix>
 		<viewClassPrefix>V_</viewClassPrefix>
 		<viewClassSuffix></viewClassSuffix>
+		<columnNamePrefix></columnNamePrefix>
 		<nestTables>true</nestTables>
 		<nestViews>false</nestViews>
 		<createRecordProperties>true</createRecordProperties>

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=1184937&r1=1184936&r2=1184937&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 Oct 16 21:33:25 2011
@@ -123,6 +123,21 @@ public class CodeGenConfig extends XMLCo
 	private String recordBaseName = "BaseRecord";
 	
 	/**
+	 * Prefix used for table member declarations
+	 */
+	private String tableNamePrefix = "";
+	
+	/**
+	 * Prefix used for view member declarations
+	 */
+	private String viewNamePrefix = "";
+	
+	/**
+	 * Prefix used for column member declarations
+	 */
+	private String columnNamePrefix = "";
+	
+	/**
 	 * 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/>
@@ -388,6 +403,14 @@ public class CodeGenConfig extends XMLCo
 	public void setRecordBaseName(String recordBaseName) {
 		this.recordBaseName = recordBaseName;
 	}
+	
+	public String getTableNamePrefix() {
+		return tableNamePrefix;
+	}
+
+	public void setTableNamePrefix(String tableNamePrefix) {
+		this.tableNamePrefix = tableNamePrefix;
+	}
 
 	public String getTableClassPrefix() {
 		return tableClassPrefix;
@@ -405,6 +428,14 @@ public class CodeGenConfig extends XMLCo
 		this.tableClassSuffix = tableClassSuffix;
 	}
 
+	public String getViewNamePrefix() {
+		return viewNamePrefix;
+	}
+
+	public void setViewNamePrefix(String viewNamePrefix) {
+		this.viewNamePrefix = viewNamePrefix;
+	}
+
 	public String getViewClassPrefix() {
 		return viewClassPrefix;
 	}
@@ -421,6 +452,14 @@ public class CodeGenConfig extends XMLCo
 		this.viewClassSuffix = viewClassSuffix;
 	}
 
+	public String getColumnNamePrefix() {
+		return columnNamePrefix;
+	}
+
+	public void setColumnNamePrefix(String columnNamePrefix) {
+		this.columnNamePrefix = columnNamePrefix;
+	}
+
 	public boolean isNestTables() {
 		return nestTables;
 	}

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/WriterService.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/WriterService.java?rev=1184937&r1=1184936&r2=1184937&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/WriterService.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/WriterService.java
Sun Oct 16 21:33:25 2011
@@ -24,14 +24,16 @@ import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRowSet;
 import org.apache.empire.db.DBTable;
 import org.apache.empire.db.DBTableColumn;
+import org.apache.empire.db.DBView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class is used by the velocity templates.
@@ -65,6 +67,39 @@ public class WriterService {
 		}
 		return names;
 	}
+	
+	/**
+	 * Returns the instance name of a table
+	 */
+	public String getTableName(DBTable t) {
+		return StringUtils.toString(config.getTableNamePrefix(), "")
+			 + deriveAttributeName(t.getName());
+	}
+	
+	/**
+	 * Returns the instance name of a view
+	 */
+	public String getViewName(DBView v) {
+		return StringUtils.toString(config.getViewNamePrefix(), "")
+			 + deriveAttributeName(v.getName());
+	}
+	
+	/**
+	 * Returns the instance name of a rowset
+	 */
+	public String getRowsetName(DBRowSet r) {
+		// use same as table
+		return StringUtils.toString(config.getTableNamePrefix(), "")
+		 	 + deriveAttributeName(r.getName());
+	}
+	
+	/**
+	 * Returns the instance name of a column
+	 */
+	public String getColumnName(DBColumn c) {
+		return StringUtils.toString(config.getColumnNamePrefix(), "")
+			 + deriveAttributeName(c.getName());
+	}
 
 	/**
 	 * Returns the java table class name for a given table name.
@@ -116,11 +151,11 @@ public class WriterService {
 	
 	/**
 	 * Returns the attribute name for a given DBColumn
-	 */
 	public String getAttributeName(DBColumn c)
 	{
 		return deriveAttributeName(c.getName());
 	}
+	 */
 
 	/**
 	 * Returns whether the given table uses BigDecimal class or not. Velocity

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=1184937&r1=1184936&r2=1184937&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 Sun
Oct 16 21:33:25 2011
@@ -55,12 +55,12 @@ public class $dbClassName extends DBData
 
 #foreach($table in $database.tables)
 	#set($tblClass=$parser.getTableClassName($table.name))
-	public final $tblClass ${table.name} = new $tblClass(this);
+	public final $tblClass $parser.getTableName($table) = new $tblClass(this);
 #end
 
 #foreach($view in $database.views)
 	#set($viewClass=$parser.getViewClassName($view.name))
-	public final $viewClass ${view.name} = new $viewClass(this);
+	public final $viewClass $parser.getViewName($view) = new $viewClass(this);
 #end
 	
 	/**
@@ -85,9 +85,9 @@ public class $dbClassName extends DBData
 		addRelation("$relation.name", new DBRelation.DBReference[] {
 #foreach ($reference in $relation.references)
 #if($foreach.isLast())
-        	${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)})
});
+        	${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.${parser.getColumnName($reference.targetColumn)})
});
 #else
-        	${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)}),
+        	${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.${parser.getColumnName($reference.targetColumn)}),
 #end
 #end
 #end
@@ -98,17 +98,17 @@ public class $dbClassName extends DBData
 #foreach ($relation in $database.relations)
 #if($relation.references.size()==1)
 #foreach ($reference in $relation.references)
-		addRelation( ${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)}));

+		addRelation( ${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.${parser.getColumnName($reference.targetColumn)}));
 #end
 #else
 #foreach ($reference in $relation.references)
 #if($foreach.isFirst())
-		addRelation( ${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)}),
+		addRelation( ${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.$parser.getColumnName($reference.targetColumn)),
 #else
 #if($foreach.isLast())
-        	         ${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)}));
+        	         ${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.$parser.getColumnName($reference.targetColumn)));
 #else
-            	     ${reference.sourceColumn.rowSet.name}.${parser.getAttributeName($reference.sourceColumn)}.referenceOn(${reference.targetColumn.rowSet.name}.${parser.getAttributeName($reference.targetColumn)}),
+            	     ${parser.getRowsetName($reference.sourceColumn.rowSet)}.${parser.getColumnName($reference.sourceColumn)}.referenceOn(${parser.getRowsetName($reference.targetColumn.rowSet)}.$parser.getColumnName($reference.targetColumn)),
 #end
 #end
 #end

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Record.vm
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Record.vm?rev=1184937&r1=1184936&r2=1184937&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Record.vm (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/Record.vm Sun
Oct 16 21:33:25 2011
@@ -46,18 +46,18 @@ public class $parser.getRecordClassName(
 	private static final long serialVersionUID = 1L;
 
 	public $parser.getRecordClassName($table.name)() {
-		super(${dbClassName}.get().${table.name});
+		super(${dbClassName}.get().$parser.getTableName($table));
 	}
 	
 #if($createRecordProperties == true)
-	// Access methods for all attributes
+	// Access methods for all columns
 #foreach($col in $table.columns)
 
 	public $parser.getJavaType($col).getName() $parser.getAccessorName($col)() {
-		return ($parser.getJavaType($col).getName())super.getValue(getTable().${parser.getAttributeName($col)});
+		return ($parser.getJavaType($col).getName())super.getValue(getTable().${parser.getColumnName($col)});
 	}
 	public void $parser.getMutatorName($col)($parser.getJavaType($col).getName() val) {
-		super.setValue(getTable().${parser.getAttributeName($col)}, val);
+		super.setValue(getTable().${parser.getColumnName($col)}, val);
 	}
 #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=1184937&r1=1184936&r2=1184937&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 Sun
Oct 16 21:33:25 2011
@@ -36,29 +36,28 @@ public class $parser.getTableClassName($
 	private static final long serialVersionUID = 1L;
 	private List<DBTableColumn> keyColumns = new ArrayList<DBTableColumn>();
 	
-	// Regular attributes
+	// define columns
 #foreach ($col in $table.columns)
-	public final DBTableColumn ${parser.getAttributeName($col)};
+	public final DBTableColumn ${parser.getColumnName($col)};
 #end
 	
 	public $parser.getTableClassName($table.name)(${dbClassName} db) {
 		super("$table.name", db);
 		
-		// all columns
+		// create columns
 #foreach ($col in $table.columns)
-		${parser.getAttributeName($col)} = addColumn("${col.name}", DataType.${parser.getDataType($col)},
${col.size}, ${col.isRequired()}, ${parser.getDefaultValue($col)});
+		${parser.getColumnName($col)} = addColumn("${col.name}", DataType.${parser.getDataType($col)},
${col.size}, ${col.isRequired()}, ${parser.getDefaultValue($col)});
 #end
 
-
-		// configure primary columns
+		// configure key columns (primary key)
 #foreach ($col in $table.keyColumns)
-    	keyColumns.add(${col.name});
+    	keyColumns.add(${parser.getColumnName($col)});
 #end
 		setPrimaryKey(keyColumns.toArray(new DBTableColumn[keyColumns.size()]));
 		
 		// Optimistic locking column
 #if($parser.hasLockingColumn($table) == true)
-		setTimestampColumn(${parser.getAttributeName($table.getTimestampColumn())});
+		setTimestampColumn(${parser.getColumnName($table.getTimestampColumn())});
 #else
 		/*no locking column specified*/
 #end

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/View.vm
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/View.vm?rev=1184937&r1=1184936&r2=1184937&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/View.vm (original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/resources/templates/View.vm Sun Oct
16 21:33:25 2011
@@ -36,17 +36,17 @@ public class $parser.getViewClassName($v
 	
 	private static final long serialVersionUID = 1L;
 
-	// Regular attributes
+	// define columns
 #foreach ($col in $view.columns)
-	public final DBViewColumn C_${parser.getAttributeName($col)};
+	public final DBViewColumn ${parser.getColumnName($col)};
 #end
 	
 	public $parser.getViewClassName($view.name)(${dbClassName} db) {
-		super("$parser.getViewClassName($view.name)", db);
+		super("$view.name", db);
 		
-		// all columns
+		// create all columns
 #foreach ($col in $view.columns)
-		C_${parser.getAttributeName($col)} = super.addColumn("${col.name}", DataType.${col.getDataType()});
+		${parser.getColumnName($col)} = super.addColumn("${col.name}", DataType.${col.getDataType()});
 #end		
 	}
 	
@@ -54,7 +54,8 @@ public class $parser.getViewClassName($v
     public DBCommandExpr createCommand()
     {
     	/*
-    	Supply a command for the creation of this view here.
+    	Supply a command for the creation of this view here 
+    	or return null to skip view creation
     	*/
         throw new NotImplementedException(this, "createCommand");
     }



Mime
View raw message