empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r906385 - in /incubator/empire-db/trunk: empire-db-codegen/src/main/java/org/apache/empire/db/codegen/ empire-db-codegen/src/main/resources/templates/ empire-db-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/...
Date Thu, 04 Feb 2010 07:26:53 GMT
Author: francisdb
Date: Thu Feb  4 07:26:53 2010
New Revision: 906385

URL: http://svn.apache.org/viewvc?rev=906385&view=rev
Log:
EMPIREDB-64
Get rid of the convenience methods in the generated Database class
Make sure the generated code looks like the examples

Modified:
    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/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-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/codegen/ValidatePluginRunTest.java

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=906385&r1=906384&r2=906385&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
Thu Feb  4 07:26:53 2010
@@ -108,7 +108,7 @@
 	 * 
 	 * <br/>
 	 */
-	private String recordBaseName = "MyRecord";
+	private String recordBaseName = "BaseRecord";
 	
 	/**
 	 * Prefix used for generating table class names.<br/>
@@ -123,7 +123,7 @@
 	 * </ul>
 	 * Where XX is the prefix.
 	 */
-	private String tableClassPrefix = "T";
+	private String tableClassPrefix = "";
 
 	/**
 	 * Suffix used for generating table class names.<br/>
@@ -138,7 +138,7 @@
 	 * </ul>
 	 * Where "Table" is the suffix.
 	 */
-	private String tableClassSuffix = "Table";
+	private String tableClassSuffix = "";
 	
 	/**
 	 * Prefix used for generating view class names.<br/>
@@ -148,7 +148,7 @@
 	 * with a capital letter.<br/>
 	 * See naming of table classes above.
 	 */
-	private String viewClassPrefix = "V";
+	private String viewClassPrefix = "";
 	
 	/**
 	 * Suffix used for generating view class names.<br/>
@@ -163,7 +163,7 @@
 	 * </ul>
 	 * Where "View" is the suffix.
 	 */
-	private String viewClassSuffix = "Table";
+	private String viewClassSuffix = "";
 
 	/**
 	 * if TRUE table classes should be declared as inner classes of DBDatabase.<br/>

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=906385&r1=906384&r2=906385&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
Feb  4 07:26:53 2010
@@ -45,12 +45,12 @@
 
 #foreach($table in $database.tables)
 	#set($tblClass=$parser.getTableClassName($table.name))
-	public final $tblClass T_${table.name} = new $tblClass(this);
+	public final $tblClass ${table.name} = new $tblClass(this);
 #end
 
 #foreach($view in $database.views)
 	#set($viewClass=$parser.getViewClassName($view.name))
-	public final $viewClass V_${view.name} = new $viewClass(this);
+	public final $viewClass ${view.name} = new $viewClass(this);
 #end
 	
 	/**
@@ -70,65 +70,6 @@
 	private ${dbClassName}() {
 	}
 	
-	/**
-	 * Convenience method that returns a single DB record based on a given 
-	 * command (i.e. query).  Only use this method for queries that should only
-	 * return a single value. 
-	 * @param <T> The DB record type.
-	 * @param recordType The DB record class.
-	 * @param command The command (or query) to execute.
-	 * @return 
-	 */
-	public <T extends DBRecord> T findRecord(Class<T> recordType, 
-			DBCommand command, Connection conn) {
-		DBReader reader = new DBReader();
-		T record = null;
-		try {
-			if (reader.getRecordData(command, conn)) {
-				record = recordType.newInstance();
-				reader.initRecord(record.getRowSet(), record);
-			}
-		} catch (InstantiationException e) {
-			throw new RuntimeException(e);
-		} catch (IllegalAccessException e) {
-			throw new RuntimeException(e);
-		}
-		finally {
-			reader.close();
-		}	
-		return record;
-	}
-	
-	/**
-	 * Convenience method that returns a list of DB records based on a given 
-	 * command (i.e. query).
-	 * @param <T> The DB record type.
-	 * @param recordType The DB record class.
-	 * @param command The command (or query) to execute.
-	 * @return 
-	 */
-	public <T extends DBRecord> List<T> findRecords(Class<T> recordType, 
-			DBCommand command, Connection conn) {
-		List<T> records = new ArrayList<T>();
-		DBReader reader = new DBReader();
-		try {
-			reader.open(command, conn);
-			while (reader.moveNext()) {
-				T record = recordType.newInstance();
-				reader.initRecord(record.getRowSet(), record);
-				records.add(record);
-			}
-		} catch (InstantiationException e) {
-			throw new RuntimeException(e);
-		} catch (IllegalAccessException e) {
-			throw new RuntimeException(e);
-		}
-		finally {
-			reader.close();
-		}
-		return records;
-	}
-	
 	#if($nestTables == true)
 		#foreach ($table in $database.tables)
 			#parse( "$templateFolder/Table.vm" )

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=906385&r1=906384&r2=906385&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 Thu
Feb  4 07:26:53 2010
@@ -43,7 +43,7 @@
  */
 public class $parser.getRecordClassName($table.name) extends ${baseRecordClassName}<$parser.getTableClassName($table.name)>
{
 	public $parser.getRecordClassName($table.name)() {
-		super(${dbClassName}.get().T_${table.name});
+		super(${dbClassName}.get().${table.name});
 	}
 	
 #if($createRecordProperties == true)
@@ -51,10 +51,10 @@
 #foreach($col in $table.columns)
 
 	public $parser.getJavaType($col) $parser.getAccessorName($col)() {
-		return ($parser.getJavaType($col))super.getValue(getDbTable().C_${parser.getAttributeName($col)});
+		return ($parser.getJavaType($col))super.getValue(getDbTable().${parser.getAttributeName($col)});
 	}
 	public void $parser.getMutatorName($col)($parser.getJavaType($col) val) {
-		super.setValue(getDbTable().C_${parser.getAttributeName($col)}, val);
+		super.setValue(getDbTable().${parser.getAttributeName($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=906385&r1=906384&r2=906385&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
Feb  4 07:26:53 2010
@@ -33,7 +33,7 @@
 	
 	// Regular attributes
 #foreach ($col in $table.columns)
-	public final DBTableColumn C_${parser.getAttributeName($col)};
+	public final DBTableColumn ${parser.getAttributeName($col)};
 #end
 	
 	public $parser.getTableClassName($table.name)(${dbClassName} db) {
@@ -41,19 +41,19 @@
 		
 		// all columns
 #foreach ($col in $table.columns)
-		C_${parser.getAttributeName($col)} = addColumn("${col.name}", DataType.${parser.getDataType($col)},
${col.size}, ${col.isRequired()}, ${parser.getDefaultValue($col)});
+		${parser.getAttributeName($col)} = addColumn("${col.name}", DataType.${parser.getDataType($col)},
${col.size}, ${col.isRequired()}, ${parser.getDefaultValue($col)});
 #end
 
 
 		// configure primary columns
 #foreach ($col in $table.keyColumns)
-    	keyColumns.add(C_${col.name});
+    	keyColumns.add(${col.name});
 #end
 		setPrimaryKey(keyColumns.toArray(new DBTableColumn[keyColumns.size()]));
 		
 		// Optimistic locking column
 #if($parser.hasLockingColumn($table) == true)
-		setTimestampColumn(C_${parser.getAttributeName($table.getTimestampColumn())});
+		setTimestampColumn(${parser.getAttributeName($table.getTimestampColumn())});
 #else
 		/*no locking column specified*/
 #end

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/codegen/ValidatePluginRunTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/codegen/ValidatePluginRunTest.java?rev=906385&r1=906384&r2=906385&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/codegen/ValidatePluginRunTest.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-codegen/src/test/java/org/apache/empire/db/examples/codegen/ValidatePluginRunTest.java
Thu Feb  4 07:26:53 2010
@@ -32,7 +32,7 @@
 import org.apache.empire.db.DBDatabaseDriver;
 import org.apache.empire.db.DBReader;
 import org.apache.empire.db.example.MyDB;
-import org.apache.empire.db.example.tables.TEMPLOYEESTable;
+import org.apache.empire.db.example.tables.EMPLOYEES;
 import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -79,12 +79,12 @@
 	public void useGeneratedCode() throws Exception {
 
 		MyDB db = MyDB.get();
-		TEMPLOYEESTable EMP = db.T_EMPLOYEES;
+		EMPLOYEES EMP = db.EMPLOYEES;
 
 		DBDatabaseDriver driver = new DBDatabaseDriverHSql();
 		db.open(driver, conn);
 		DBCommand cmd = db.createCommand();
-		cmd.select(EMP.C_EMPLOYEE_ID, EMP.C_FIRSTNAME);
+		cmd.select(EMP.EMPLOYEE_ID, EMP.FIRSTNAME);
 
 		int rowCount = 0;
 		DBReader reader = new DBReader();
@@ -94,7 +94,7 @@
 			assertTrue(db.getErrorMessage(), succes);
 			while (reader.moveNext()) {
 				rowCount++;
-				System.out.println(reader.getString(EMP.C_EMPLOYEE_ID) + "\t" + reader.getString(EMP.C_FIRSTNAME));
+				System.out.println(reader.getString(EMP.EMPLOYEE_ID) + "\t" + reader.getString(EMP.FIRSTNAME));
 			}
 		} finally {
 			reader.close();



Mime
View raw message