empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From der...@apache.org
Subject empire-db git commit: EMPIREDB-252
Date Fri, 02 Dec 2016 10:22:34 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 9a45804ce -> 1ff38e379


EMPIREDB-252

Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/1ff38e37
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/1ff38e37
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/1ff38e37

Branch: refs/heads/master
Commit: 1ff38e379c12f7fc103439eb76dc5c3d2bb683e7
Parents: 9a45804
Author: Jan Glaubitz <jan@glaubitz.org>
Authored: Fri Dec 2 11:20:16 2016 +0100
Committer: Jan Glaubitz <jan@glaubitz.org>
Committed: Fri Dec 2 11:20:16 2016 +0100

----------------------------------------------------------------------
 .../apache/empire/db/codegen/CodeGenParser.java |  6 ++-
 .../empire/db/codegen/CodeGenParserMySQL.java   | 43 ++++++++++++++++++++
 .../apache/empire/db/codegen/CodeGenerator.java |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/1ff38e37/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
----------------------------------------------------------------------
diff --git a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
index 28b9ca8..e34292c 100644
--- a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
+++ b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
@@ -365,8 +365,8 @@ public class CodeGenParser {
 			throws SQLException {
 		String name = rs.getString("COLUMN_NAME");
 		DataType empireType = getEmpireDataType(rs.getInt("DATA_TYPE"));
+		double colSize = getColumnSize(empireType, rs.getInt("DATA_TYPE"), rs.getInt("COLUMN_SIZE"));
 		
-		double colSize = rs.getInt("COLUMN_SIZE");
 		if (empireType==DataType.DECIMAL || empireType==DataType.FLOAT)
 		{	// decimal digits
 			int decimalDig = rs.getInt("DECIMAL_DIGITS");
@@ -434,6 +434,10 @@ public class CodeGenParser {
 		
 	}
 	
+	protected double getColumnSize(DataType empireType, int dataType, int columnSize) {
+		return columnSize;
+	}
+
 	/**
 	 * Adds DBColumn object to the given DBTable. The DBColumn is created from
 	 * the given ResultSet

http://git-wip-us.apache.org/repos/asf/empire-db/blob/1ff38e37/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParserMySQL.java
----------------------------------------------------------------------
diff --git a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParserMySQL.java
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParserMySQL.java
new file mode 100644
index 0000000..a4673ad
--- /dev/null
+++ b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParserMySQL.java
@@ -0,0 +1,43 @@
+package org.apache.empire.db.codegen;
+
+import java.sql.Types;
+
+import org.apache.empire.data.DataType;
+
+public class CodeGenParserMySQL extends CodeGenParser {
+
+	// private static final Logger log = LoggerFactory.getLogger(CodeGenParserMySQL.class);
+	
+	public CodeGenParserMySQL(CodeGenConfig config) {
+		super(config);
+	}
+
+	@Override
+	protected double getColumnSize(DataType empireType, int dataType, int columnSize) {
+		
+		switch (empireType) {
+			
+			case INTEGER: {
+				// return size in byte, depending on MySQL Integer Types
+				// see http://dev.mysql.com/doc/refman/5.7/en/integer-types.html
+				// ignore the "real" columnsize as its just a "format hint"
+				switch(dataType) {
+					case Types.TINYINT:
+						return 1; // TINYINT, 1 byte
+					case Types.SMALLINT:
+						return 2; // SMALLINT, 2 byte
+					case Types.BIGINT:
+						return 8; // BIGINT, 8 byte
+					default: 
+						return 4; // Types.INTEGER, INT, 4 byte
+				}
+			}
+			
+			default:
+				return super.getColumnSize(empireType, dataType, columnSize);
+			
+		}
+		
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/1ff38e37/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenerator.java
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenerator.java
index a936837..25325a6 100644
--- a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenerator.java
+++ b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenerator.java
@@ -54,6 +54,7 @@ public class CodeGenerator {
 		
 		// read the database model
 		CodeGenParser parser = new CodeGenParser(config);
+		// CodeGenParser parser = new CodeGenParserMySQL(config);
 		DBDatabase db = parser.loadDbModel();
 		
 		// create the source-code for that database


Mime
View raw message