db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r379951 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java test/jdbc.properties.maxdb
Date Wed, 22 Feb 2006 22:41:36 GMT
Author: tomdz
Date: Wed Feb 22 14:41:33 2006
New Revision: 379951

URL: http://svn.apache.org/viewcvs?rev=379951&view=rev
Log:
Enhanced/fixed SapDB/MaxDB platform

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java
    db/ddlutils/trunk/src/test/jdbc.properties.maxdb
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java?rev=379951&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbModelReader.java Wed
Feb 22 14:41:33 2006
@@ -0,0 +1,83 @@
+package org.apache.ddlutils.platform.sapdb;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Map;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
+import org.apache.ddlutils.platform.JdbcModelReader;
+
+/**
+ * Reads a database model from a SapDb database.
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class SapDbModelReader extends JdbcModelReader
+{
+    /**
+     * Creates a new model reader for SapDb databases.
+     * 
+     * @param platformInfo The platform specific settings
+     */
+    public SapDbModelReader(PlatformInfo platformInfo)
+    {
+        super(platformInfo);
+        setDefaultCatalogPattern(null);
+        setDefaultSchemaPattern(null);
+        setDefaultTablePattern("%");
+    }
+
+	/**
+     * {@inheritDoc}
+     */
+    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+    {
+		Column column = super.readColumn(metaData, values);
+
+		if (column.getDefaultValue() != null)
+		{
+			// SapDb pads the default value with spaces
+			column.setDefaultValue(column.getDefaultValue().trim());
+			// SapDb uses the default value for the auto-increment specification
+			if (column.getDefaultValue().startsWith("DEFAULT SERIAL"))
+			{
+				column.setAutoIncrement(true);
+				column.setDefaultValue(null);
+			}
+		}
+		if (column.getTypeCode() == Types.DECIMAL)
+		{
+			// For some reason, the size will be reported with 2 byte more, e.g. 17 instead of 15
+			// So we have to adjust the size here
+			if (column.getSizeAsInt() > 2)
+			{
+				column.setSizeAndScale(column.getSizeAsInt() - 2, column.getScale());
+			}
+			// We also perform back-mapping to BIGINT
+			if ((column.getSizeAsInt() == 38) && (column.getScale() == 0))
+			{
+				column.setTypeCode(Types.BIGINT);
+			}
+		}
+		return column;
+	}
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java?rev=379951&r1=379950&r2=379951&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java Wed Feb
22 14:41:33 2006
@@ -51,32 +51,41 @@
         info.setCommentPrefix("/*");
         info.setCommentSuffix("*/");
 
-        info.addNativeTypeMapping(Types.ARRAY,         "LONG BYTE");
+        // BIGINT is also handled by the model reader
+        // Unfortunately there is no way to distinguish between REAL, and FLOAT/DOUBLE when
+        // reading back via JDBC, because they all have the same size of 8
+        info.addNativeTypeMapping(Types.ARRAY,         "LONG BYTE", Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.BIGINT,        "FIXED(38,0)");
-        info.addNativeTypeMapping(Types.BINARY,        "LONG BYTE");
+        info.addNativeTypeMapping(Types.BINARY,        "CHAR{0} BYTE");
         info.addNativeTypeMapping(Types.BIT,           "BOOLEAN");
-        info.addNativeTypeMapping(Types.BLOB,          "LONG BYTE");
-        info.addNativeTypeMapping(Types.CLOB,          "LONG");
-        info.addNativeTypeMapping(Types.DISTINCT,      "LONG BYTE");
-        info.addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
-        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
-        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "LONG BYTE");
+        info.addNativeTypeMapping(Types.BLOB,          "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.CLOB,          "LONG",      Types.LONGVARCHAR);
+        info.addNativeTypeMapping(Types.DECIMAL,       "FIXED");
+        info.addNativeTypeMapping(Types.DISTINCT,      "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.DOUBLE,        "FLOAT(38)", Types.FLOAT);
+        info.addNativeTypeMapping(Types.FLOAT,         "FLOAT(38)");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "LONG BYTE", Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.LONGVARBINARY, "LONG BYTE");
-        info.addNativeTypeMapping(Types.LONGVARCHAR,   "LONG VARCHAR");
-        info.addNativeTypeMapping(Types.NULL,          "LONG BYTE");
-        info.addNativeTypeMapping(Types.NUMERIC,       "DECIMAL");
-        info.addNativeTypeMapping(Types.OTHER,         "LONG BYTE");
-        info.addNativeTypeMapping(Types.REF,           "LONG BYTE");
-        info.addNativeTypeMapping(Types.STRUCT,        "LONG BYTE");
-        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
-        info.addNativeTypeMapping(Types.VARBINARY,     "LONG BYTE");
-        info.addNativeTypeMapping("DATALINK", "LONG BYTE");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "LONG");
+        info.addNativeTypeMapping(Types.NULL,          "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.NUMERIC,       "FIXED",     Types.DECIMAL);
+        info.addNativeTypeMapping(Types.OTHER,         "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.REAL,          "FLOAT(16)", Types.FLOAT);
+        info.addNativeTypeMapping(Types.REF,           "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.STRUCT,        "LONG BYTE", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT",  Types.SMALLINT);
+        info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR{0} BYTE");
 
-        // no support for specifying the size for these types
-        info.setHasSize(Types.BINARY, false);
-        info.setHasSize(Types.VARBINARY, false);
+        info.addNativeTypeMapping("BOOLEAN",  "BOOLEAN",   "BIT");
+        info.addNativeTypeMapping("DATALINK", "LONG BYTE", "LONGVARBINARY");
+
+        info.addDefaultSize(Types.CHAR,      254);
+        info.addDefaultSize(Types.VARCHAR,   254);
+        info.addDefaultSize(Types.BINARY,    254);
+        info.addDefaultSize(Types.VARBINARY, 254);
 
         setSqlBuilder(new SapDbBuilder(info));
+        setModelReader(new SapDbModelReader(info));
     }
 
     /**

Added: db/ddlutils/trunk/src/test/jdbc.properties.maxdb
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/jdbc.properties.maxdb?rev=379951&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.maxdb (added)
+++ db/ddlutils/trunk/src/test/jdbc.properties.maxdb Wed Feb 22 14:41:33 2006
@@ -0,0 +1,16 @@
+# JDBC properties for SapDB/MaxDB
+# Note: Properties starting with "datasource." will be fed into the datasource instance of
the
+# class configured via the datasource.class property
+
+# Use this property if ddlutils does not recognize the platform from the settings
+#ddlutils.platform=SapDB
+
+#
+# Using the plain DBCP datasource
+#
+
+datasource.class=org.apache.commons.dbcp.BasicDataSource
+datasource.driverClassName=com.sap.dbtech.jdbc.DriverSapDB
+datasource.url=jdbc:sapdb://localhost/ddlutils
+datasource.username=ddlutils
+datasource.password=ddlutils



Mime
View raw message