empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r885154 - in /incubator/empire-db/trunk/empire-db-codegen: ./ src/main/java/org/apache/empire/db/codegen/ src/test/java/org/apache/empire/db/codegen/
Date Sat, 28 Nov 2009 22:07:16 GMT
Author: doebele
Date: Sat Nov 28 22:07:15 2009
New Revision: 885154

URL: http://svn.apache.org/viewvc?rev=885154&view=rev
Log:
EMPIREDB-52 - Renamed CodeGen to CodeGenWriter. Error handling etc.

Added:
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
      - copied, changed from r885142, incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
Removed:
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
Modified:
    incubator/empire-db/trunk/empire-db-codegen/config.xml
    incubator/empire-db/trunk/empire-db-codegen/pom.xml
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
    incubator/empire-db/trunk/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenTest.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=885154&r1=885153&r2=885154&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/config.xml (original)
+++ incubator/empire-db/trunk/empire-db-codegen/config.xml Sat Nov 28 22:07:15 2009
@@ -25,6 +25,12 @@
 		<jdbcURL>jdbc:oracle:thin:@192.168.0.2:1521:ora10</jdbcURL>
 		<jdbcUser>DBSAMPLE</jdbcUser>
 		<jdbcPwd>DBSAMPLE</jdbcPwd>
+		<!-- 
+		<jdbcClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbcClass>
+		<jdbcURL>jdbc:sqlserver://localhost:1433</jdbcURL>
+		<jdbcUser>empire-db</jdbcUser>
+		<jdbcPwd>empire-db</jdbcPwd>
+		-->
 
 		<!-- Schema options -->
 		<dbCatalog></dbCatalog>

Modified: incubator/empire-db/trunk/empire-db-codegen/pom.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/pom.xml?rev=885154&r1=885153&r2=885154&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/pom.xml (original)
+++ incubator/empire-db/trunk/empire-db-codegen/pom.xml Sat Nov 28 22:07:15 2009
@@ -47,13 +47,21 @@
 		    <!-- <scope>runtime</scope> -->
 		</dependency>
 
-		<!-- 
+		<!-- ojdbc 
 		<dependency>
 		    <groupId>ojdbc</groupId>
 		    <artifactId>ojdbc</artifactId>
 		    <version>14</version>
 		</dependency>
 		-->
+
+		<!-- msssql 
+		<dependency>
+		    <groupId>microsoft</groupId>
+		    <artifactId>sqljdbc</artifactId>
+		    <version>1.0</version>
+		</dependency>
+		-->
 		
 	</dependencies>
 </project>
\ No newline at end of file

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java?rev=885154&r1=885153&r2=885154&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
Sat Nov 28 22:07:15 2009
@@ -42,6 +42,8 @@
 	 *            arguments
 	 */
 	public static void main(String[] args) {
+	    ErrorObject.setExceptionsEnabled(true);
+	    // Start code generator
 		CodeGenApp app = new CodeGenApp();
 		app.start((args.length > 0 ? args[0] : DEFAULT_CONFIG_FILE));
 	}	
@@ -61,7 +63,7 @@
 		DBDatabase db = parser.loadDbModel();
 		
 		// create the source-code for that database
-		CodeGen codeGen = new CodeGen(config);
+		CodeGenWriter codeGen = new CodeGenWriter(config);
 		codeGen.generateCodeFiles(db);
 		
 		log.info("Code generation completed sucessfully!");

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java?rev=885154&r1=885153&r2=885154&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
Sat Nov 28 22:07:15 2009
@@ -29,6 +29,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.empire.commons.ErrorObject;
+import org.apache.empire.commons.Errors;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBDatabase;
@@ -42,7 +44,7 @@
  * 
  * @author Benjamin Venditti
  */
-public class CodeGenParser {
+public class CodeGenParser extends ErrorObject {
 
 	public static class InMemoryDatabase extends DBDatabase {
 	}
@@ -131,9 +133,14 @@
 	private void populateDatabase() {
 		ResultSet tables = null;
 		try {
-			tables = dbMeta.getTables(config.getDbCatalog(), config
-					.getDbSchema(), config.getDbTablePattern(),
+		    // Get table metadata
+		    tables = dbMeta.getTables(
+		            config.getDbCatalog(), 
+		            config.getDbSchema(), 
+		            config.getDbTablePattern(),
 					new String[] { "TABLE" });
+		    // Add all tables
+            int count = 0;
 			while (tables.next()) {
 				String tableName = tables.getString("TABLE_NAME");
 				// Ignore system tables containing a '$' symbol (required for
@@ -145,9 +152,18 @@
 				// end system table exclusion
 				log.info("Adding table " + tableName);
 				addTable(tableName);
+				count++;
+			}
+			// Count added
+			if (count==0) {
+			    // getTables returned no result
+			    String info = "catalog="+config.getDbCatalog(); 
+                info += "/ schema="+config.getDbSchema(); 
+                info += "/ pattern="+config.getDbTablePattern(); 
+			    log.warn("DatabaseMetaData.getTables() returned no tables! Please check parameters:
"+info);
 			}
 		} catch (SQLException e) {
-			throw new RuntimeException(e);
+			error(e);
 		} finally {
 			DBUtil.close(tables, log);
 		}
@@ -162,26 +178,29 @@
 		List<String> pkCols = this.findPkColumns(name);
 		String lockColName = config.getTimestampColumn();
 		DBColumn[] keys = new DBColumn[pkCols.size()];
-		int i = 0;
 		ResultSet rs = null;
 		try {
 			rs = dbMeta.getColumns(config.getDbCatalog(), config.getDbSchema(),
 					name, null);
+	        int i=0;
 			while (rs.next()) {
 				DBTableColumn c = addColumn(t, rs);
 				// check if it is a KeyColumn
-				if (pkCols.contains(c.getName()))
+				if (pkCols.contains(c.getName().toUpperCase()))
 					keys[i++] = c;
 
 				// check if it is the Timestamp/Locking Column
-				if (lockColName != null
-						&& c.getName().toUpperCase().equals(
-								lockColName.toUpperCase()))
+				if (lockColName!=null && c.getName().equalsIgnoreCase(lockColName))
 					t.setTimestampColumn(c);
 			}
-			t.setPrimaryKey(keys);
+	        // Check whether all key columns have been set
+	        for (i=0; i<keys.length; i++)
+	            if (keys[i]==null)
+	                error(Errors.ItemNotFound, pkCols.get(i));
+			// Set Primary Key
+	        t.setPrimaryKey(keys);
 		} catch (SQLException e) {
-			throw new RuntimeException(e);
+			error(e);
 		} finally {
 			DBUtil.close(rs, log);
 		}

Copied: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
(from r885142, 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/CodeGenWriter.java?p2=incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java&p1=incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java&r1=885142&r2=885154&rev=885154&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/CodeGenWriter.java
Sat Nov 28 22:07:15 2009
@@ -36,6 +36,7 @@
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.log.CommonsLogLogChute;
 
 /**
@@ -61,8 +62,8 @@
  * </ol>
  */
 
-public class CodeGen {
-	private static final Log log = LogFactory.getLog(CodeGen.class);
+public class CodeGenWriter {
+	private static final Log log = LogFactory.getLog(CodeGenWriter.class);
 
 	// Templates
 	public static final String TEMPLATE_PATH = "src/main/resources/templates/";
@@ -84,10 +85,10 @@
 	/**
 	 * Constructor
 	 */
-	public CodeGen(CodeGenConfig config) {
+	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(Velocity.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute() );
+		Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute() );
 		try {
 			Velocity.init();
 		} catch (Exception e) {

Modified: incubator/empire-db/trunk/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenTest.java?rev=885154&r1=885153&r2=885154&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenTest.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenTest.java
Sat Nov 28 22:07:15 2009
@@ -41,7 +41,7 @@
     {
         CodeGenConfig config = new CodeGenConfig();
         config.init("testconfig.xml", true, false);
-        CodeGen codeGen = new CodeGen(config);
+        CodeGenWriter codeGen = new CodeGenWriter(config);
         
         DBDatabase db = new DBDatabase()
         {



Mime
View raw message