empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r831666 - in /incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen: CodeGen.java types/Column.java types/Database.java types/Table.java util/DBUtil.java
Date Sun, 01 Nov 2009 10:43:08 GMT
Author: doebele
Date: Sun Nov  1 10:43:07 2009
New Revision: 831666

URL: http://svn.apache.org/viewvc?rev=831666&view=rev
Log:
EMPIREDB-52 - Minor improvements to Benjamin's code

Modified:
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Column.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Database.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Table.java
    incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java

Modified: 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/CodeGen.java?rev=831666&r1=831665&r2=831666&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/CodeGen.java
Sun Nov  1 10:43:07 2009
@@ -200,7 +200,7 @@
 		String dbTablePattern = config.getDbTablePattern();
 		dbTablePattern=dbTablePattern==""?dbTablePattern:null;
 
-		Database db = new Database(conn, log, dbSchema, dbCatalog, dbTablePattern);
+		Database db = new Database(conn, dbSchema, dbCatalog, dbTablePattern);
 		db.populateTableMetaData(dbLockingCol);
 		
 		// Prepare directories for generated source files

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Column.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Column.java?rev=831666&r1=831665&r2=831666&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Column.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Column.java
Sun Nov  1 10:43:07 2009
@@ -22,11 +22,15 @@
 import java.sql.SQLException;
 import java.sql.Types;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.codegen.util.StringUtils;
 
 public class Column {
-	private String name;
+    private static final Log log = LogFactory.getLog(Database.class);
+
+    private String name;
 	private int sqlType;
 	private int colSize; // max length if string, precision is numeric
 	private int decimalDigits; // max decimal digits allowed (real numbers)
@@ -145,76 +149,75 @@
 		this.javaName = StringUtils.deriveAttributeName(this.name);
 		DataType empireType = DataType.UNKNOWN;
 		switch (this.sqlType) {
-		case Types.INTEGER:
-		case Types.SMALLINT:
-		case Types.TINYINT:
-		case Types.BIGINT:
-			empireType = DataType.INTEGER;
-			empireTypeString = "DataType.INTEGER";
-			javaTypeString = "Long";
-			break;
-		case Types.VARCHAR:
-			empireType = DataType.TEXT;
-			empireTypeString = "DataType.TEXT";
-			javaTypeString = "String";
-			break;
-		case Types.DATE:
-			empireType = DataType.DATE;
-			empireTypeString = "DataType.DATE";
-			javaTypeString = "Date";
-			break;
-		case Types.TIMESTAMP:
-		case Types.TIME:
-			empireType = DataType.DATETIME;
-			empireTypeString = "DataType.DATETIME";
-			javaTypeString = "Date";
-			break;
-		case Types.CHAR:
-			empireType = DataType.CHAR;
-			empireTypeString = "DataType.CHAR";
-			javaTypeString = "String";
-			break;
-		case Types.DOUBLE:
-		case Types.FLOAT:
-		case Types.REAL:
-			empireType = DataType.DOUBLE;
-			empireTypeString = "DataType.DOUBLE";
-			javaTypeString = "Double";
-			break;
-		case Types.DECIMAL:
-		case Types.NUMERIC:
-			empireType = DataType.DECIMAL;
-			empireTypeString = "DataType.DECIMAL";
-			javaTypeString = "BigDecimal";
-			break;
-		case Types.BIT:
-		case Types.BOOLEAN:
-			empireType = DataType.BOOL;
-			empireTypeString = "DataType.BOOL";
-			javaTypeString = "Boolean";
-			break;
-		case Types.CLOB:
-		case Types.LONGVARCHAR:
-			empireType = DataType.CLOB;
-			empireTypeString = "DataType.CLOB";
-			javaTypeString = "String";
-			break;
-		case Types.BINARY:
-		case Types.VARBINARY:
-		case Types.LONGVARBINARY:
-		case Types.BLOB:
-			empireType = DataType.BLOB;
-			empireTypeString = "DataType.BLOB";
-			javaTypeString = "Byte[]";
-			break;
-		default:
-			empireType = DataType.UNKNOWN;
-			empireTypeString = "DataType.UNKNOWN";
-			javaTypeString = "Byte[]";
-			System.out.println("SQL column type " + this.sqlType
-					+ " not supported.");
+    		case Types.INTEGER:
+    		case Types.SMALLINT:
+    		case Types.TINYINT:
+    		case Types.BIGINT:
+    			empireType = DataType.INTEGER;
+    			empireTypeString = "DataType.INTEGER";
+    			javaTypeString = "Long";
+    			break;
+    		case Types.VARCHAR:
+    			empireType = DataType.TEXT;
+    			empireTypeString = "DataType.TEXT";
+    			javaTypeString = "String";
+    			break;
+    		case Types.DATE:
+    			empireType = DataType.DATE;
+    			empireTypeString = "DataType.DATE";
+    			javaTypeString = "Date";
+    			break;
+    		case Types.TIMESTAMP:
+    		case Types.TIME:
+    			empireType = DataType.DATETIME;
+    			empireTypeString = "DataType.DATETIME";
+    			javaTypeString = "Date";
+    			break;
+    		case Types.CHAR:
+    			empireType = DataType.CHAR;
+    			empireTypeString = "DataType.CHAR";
+    			javaTypeString = "String";
+    			break;
+    		case Types.DOUBLE:
+    		case Types.FLOAT:
+    		case Types.REAL:
+    			empireType = DataType.DOUBLE;
+    			empireTypeString = "DataType.DOUBLE";
+    			javaTypeString = "Double";
+    			break;
+    		case Types.DECIMAL:
+    		case Types.NUMERIC:
+    			empireType = DataType.DECIMAL;
+    			empireTypeString = "DataType.DECIMAL";
+    			javaTypeString = "BigDecimal";
+    			break;
+    		case Types.BIT:
+    		case Types.BOOLEAN:
+    			empireType = DataType.BOOL;
+    			empireTypeString = "DataType.BOOL";
+    			javaTypeString = "Boolean";
+    			break;
+    		case Types.CLOB:
+    		case Types.LONGVARCHAR:
+    			empireType = DataType.CLOB;
+    			empireTypeString = "DataType.CLOB";
+    			javaTypeString = "String";
+    			break;
+    		case Types.BINARY:
+    		case Types.VARBINARY:
+    		case Types.LONGVARBINARY:
+    		case Types.BLOB:
+    			empireType = DataType.BLOB;
+    			empireTypeString = "DataType.BLOB";
+    			javaTypeString = "Byte[]";
+    			break;
+    		default:
+    			empireType = DataType.UNKNOWN;
+    			empireTypeString = "DataType.UNKNOWN";
+    			javaTypeString = "Byte[]";
+    			log.warn("SQL column type " + this.sqlType + " not supported.");
 		}
-
+		log.info("Mapping date type " + String.valueOf(this.sqlType) + " to " + empireType);
 		return empireType;
 	}
 

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Database.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Database.java?rev=831666&r1=831665&r2=831666&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Database.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Database.java
Sun Nov  1 10:43:07 2009
@@ -27,22 +27,23 @@
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.empire.db.codegen.util.DBUtil;
 
 public class Database {
-	private DatabaseMetaData metaData;
+    private static final Log log = LogFactory.getLog(Database.class);
+
+    private DatabaseMetaData metaData;
 	private String catalogName;
 	private String schemaPattern;
 	private String tablePattern;
 	private Connection con;
-	private Log log;
 
 	private Map<String, Table> tableMap = new HashMap<String, Table>();
 
-	public Database(Connection con, Log log, String schemaPattern,
+	public Database(Connection con, String schemaPattern,
 			String catalogName, String tablePattern) {
 
-		this.log = log;
 		this.con = con;
 		this.schemaPattern = schemaPattern;
 		this.catalogName = catalogName;
@@ -69,9 +70,14 @@
 					new String[] { "TABLE" });
 			while (tables.next()) {
 				String tableName = tables.getString("TABLE_NAME");
-				System.out.println("TABLE:\t" + tableName);
-				Table table = new Table(tableName, lockColName, schemaPattern, catalogName,
-						dbMeta, log);
+				// Ignore system tables containing a '$' symbol (required for Oracle!)
+				if (tableName.indexOf('$')>=0) {
+	                log.info("Ignoring system table " + tableName);
+	                continue;
+				}
+				// end system table exclusion
+				log.info("Adding table " + tableName);
+				Table table = new Table(tableName, lockColName, schemaPattern, catalogName, dbMeta);
 				this.tableMap.put(tableName.toUpperCase(), table);
 			}
 		} catch (SQLException e) {

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Table.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Table.java?rev=831666&r1=831665&r2=831666&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Table.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/types/Table.java
Sun Nov  1 10:43:07 2009
@@ -27,24 +27,25 @@
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.codegen.util.DBUtil;
 import org.apache.empire.db.codegen.util.StringUtils;
 
 public class Table {
-	private String tableName;
+    private static final Log log = LogFactory.getLog(Database.class);
+
+    private String tableName;
 	private List<String> pkCols;
 	private List<Column> columns;
 	private Column lockCol;
-	private Log log;
 	private String lockColName;
 
 	private Map<String, Column> columnMap = new HashMap<String, Column>();
 
 	public Table(String tableName,String lockColName, String schemaPattern, String catalogName,
-			DatabaseMetaData dbMeta, Log log) {
+			DatabaseMetaData dbMeta) {
 		this.tableName = tableName.toUpperCase();
-		this.log = log;
 		this.lockColName=lockColName;
 		this.createColumns(dbMeta, schemaPattern, catalogName);
 	}

Modified: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java?rev=831666&r1=831665&r2=831666&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
(original)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
Sun Nov  1 10:43:07 2009
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.empire.db.codegen.util;
 
 import java.sql.ResultSet;



Mime
View raw message