empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r1158253 - in /incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen: CodeGenApp.java CodeGenConfig.java CodeGenParser.java CodeGenWriter.java
Date Tue, 16 Aug 2011 12:59:42 GMT
Author: francisdb
Date: Tue Aug 16 12:59:41 2011
New Revision: 1158253

URL: http://svn.apache.org/viewvc?rev=1158253&view=rev
Log:
EMPIREDB 99 Refactor codegen for new error handling

Modified:
    incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java?rev=1158253&r1=1158252&r2=1158253&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
(original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenApp.java
Tue Aug 16 12:59:41 2011
@@ -18,10 +18,9 @@
  */
 package org.apache.empire.db.codegen;
 
+import org.apache.empire.db.DBDatabase;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.empire.commons.ErrorObject;
-import org.apache.empire.db.DBDatabase;
 
 /**
  * Console code generator application, takes the config file as first argument.
@@ -41,7 +40,6 @@ public class CodeGenApp {
 	 *            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));
@@ -78,9 +76,6 @@ public class CodeGenApp {
 		CodeGenConfig config = new CodeGenConfig();
 		config.init(configFile);
 
-		// Enable Exceptions
-		ErrorObject.setExceptionsEnabled(true);
-
 		if (config.getTableClassPrefix() == null)
 			config.setTableClassPrefix("");
 

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java?rev=1158253&r1=1158252&r2=1158253&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
(original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
Tue Aug 16 12:59:41 2011
@@ -18,7 +18,8 @@
  */
 package org.apache.empire.db.codegen;
 
-import org.apache.empire.commons.Errors;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.xml.XMLConfiguration;
 import org.apache.empire.xml.XMLUtil;
 import org.apache.log4j.xml.DOMConfigurator;
@@ -202,41 +203,41 @@ public class CodeGenConfig extends XMLCo
 	 * 
 	 * @return true on success
 	 */
-	public boolean init(String filename) {
+	public void init(String filename) {
 		// Read the properties file
-		if (super.init(filename, false) == false)
-			return false;
+		super.init(filename, false);
+
         // Init Logging
         initLogging();
-		// Done
-		if (readProperties(this, "properties") == false)
-			return false;
+
 		// Reader Provider Properties
-		return true;
+		readProperties(this, "properties");
 	}
 
     /**
      * Init logging using Log4J's DOMConfigurator 
      * @return
      */
-    private boolean initLogging()
+    private void initLogging()
     {
         // Get configuration root node
         Element rootNode = getRootNode();
         if (rootNode == null)
-            return error(Errors.ObjectNotValid, getClass().getName());
+        {
+        	// TODO throw proper exception
+        	throw new ObjectNotValidException(getClass().getName());
+        }
         // Find log configuration node
         Element loggingNode = XMLUtil.findFirstChild(rootNode, loggingNodeName);
         if (loggingNode == null)
         {   // log configuration node not found
             log.error("Log configuration node {} has not been found. Logging has not been
configured.", loggingNodeName);
-            return error(Errors.ItemNotFound, loggingNodeName);
+            throw new ItemNotFoundException(loggingNodeName);
         }
         // Init Log4J
         DOMConfigurator.configure(loggingNode);
         // done
         log.info("Logging sucessfully configured from node {}.", loggingNodeName);
-        return success();
     }
 
 	public String getJdbcClass() {

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java?rev=1158253&r1=1158252&r2=1158253&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
(original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
Tue Aug 16 12:59:41 2011
@@ -18,8 +18,16 @@
  */
 package org.apache.empire.db.codegen;
 
-import org.apache.empire.commons.ErrorObject;
-import org.apache.empire.commons.Errors;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBCommandExpr;
@@ -29,26 +37,17 @@ import org.apache.empire.db.DBTableColum
 import org.apache.empire.db.DBView;
 import org.apache.empire.db.DBView.DBViewColumn;
 import org.apache.empire.db.codegen.util.DBUtil;
+import org.apache.empire.exceptions.ItemNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * This class is used to create a in memory DBDatabase of a given SQLConnection
  * and Configuration
  * 
  * @author Benjamin Venditti
  */
-public class CodeGenParser extends ErrorObject {
+public class CodeGenParser {
 
 	public static class InMemoryDatabase extends DBDatabase {
         private static final long serialVersionUID = 1L;
@@ -288,8 +287,9 @@ public class CodeGenParser extends Error
 			}
 	        // 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));
+	            if (keys[i]==null){
+	            	throw new ItemNotFoundException(pkCols.get(i));
+	            }
 	        if(keys.length > 0){
 	        	t.setPrimaryKey(keys);
 	        }

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java?rev=1158253&r1=1158252&r2=1158253&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
(original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenWriter.java
Tue Aug 16 12:59:41 2011
@@ -25,8 +25,6 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBTable;
 import org.apache.empire.db.DBView;
@@ -39,6 +37,8 @@ import org.apache.velocity.exception.Res
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.log.CommonsLogLogChute;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This is the entry class for generating the java persistence model based on a



Mime
View raw message