You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ol...@apache.org on 2010/01/12 15:59:36 UTC

svn commit: r898349 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba: JdbcAdapter.java mysql/MySQLAdapter.java sqlserver/SQLServerAdapter.java

Author: oltka
Date: Tue Jan 12 14:59:35 2010
New Revision: 898349

URL: http://svn.apache.org/viewvc?rev=898349&view=rev
Log:
CAY-1364 SQL server don't support notations float(a, b)

HSQLDB and oracle similarly don't support notations float(a, b). fixed it in hsqldb and oracle.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java?rev=898349&r1=898348&r2=898349&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java Tue Jan 12 14:59:35 2010
@@ -22,6 +22,7 @@
 import java.net.URL;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -321,8 +322,12 @@
         // append size and precision (if applicable)s
         if (TypesMapping.supportsLength(column.getType())) {
             int len = column.getMaxLength();
-            int scale = TypesMapping.isDecimal(column.getType()) ? column.getScale() : -1;
-
+            
+            int scale = (TypesMapping.isDecimal(column.getType()) 
+                    && column.getType() != Types.FLOAT
+                    ) 
+                    ? column.getScale() : -1;
+            
             // sanity check
             if (scale > len) {
                 scale = -1;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java?rev=898349&r1=898348&r2=898349&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java Tue Jan 12 14:59:35 2010
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.jdbc.EJBQLTranslatorFactory;
 import org.apache.cayenne.access.types.ByteArrayType;
@@ -36,6 +37,7 @@
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
@@ -301,7 +303,54 @@
      */
     @Override
     public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
-        super.createTableAppendColumn(sqlBuffer, column);
+        boolean status;
+        if ((column.getEntity().getDataMap() != null)
+                && column.getEntity().getDataMap().isQuotingSQLIdentifiers()) {
+            status = true;
+        }
+        else {
+            status = false;
+        }
+        QuotingStrategy context = getQuotingStrategy(status);
+        String[] types = externalTypesForJdbcType(column.getType());
+        if (types == null || types.length == 0) {
+            String entityName = column.getEntity() != null ? ((DbEntity) column
+                    .getEntity()).getFullyQualifiedName() : "<null>";
+            throw new CayenneRuntimeException("Undefined type for attribute '"
+                    + entityName
+                    + "."
+                    + column.getName()
+                    + "': "
+                    + column.getType());
+        }
+
+        String type = types[0];
+        sqlBuffer.append(context.quoteString(column.getName()));
+        sqlBuffer.append(' ').append(type);
+
+        // append size and precision (if applicable)s
+        if (TypesMapping.supportsLength(column.getType())) {
+            int len = column.getMaxLength();
+            
+            int scale = TypesMapping.isDecimal(column.getType())? column.getScale() : -1;
+            
+            // sanity check
+            if (scale > len) {
+                scale = -1;
+            }
+
+            if (len > 0) {
+                sqlBuffer.append('(').append(len);
+
+                if (scale >= 0) {
+                    sqlBuffer.append(", ").append(scale);
+                }
+
+                sqlBuffer.append(')');
+            }
+        }
+
+        sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL");
 
         if (column.isGenerated()) {
             sqlBuffer.append(" AUTO_INCREMENT");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java?rev=898349&r1=898348&r2=898349&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java Tue Jan 12 14:59:35 2010
@@ -121,56 +121,7 @@
     @Override
     public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
        
-        boolean status;
-        if ((column.getEntity().getDataMap() != null)
-                && column.getEntity().getDataMap().isQuotingSQLIdentifiers()) {
-            status = true;
-        }
-        else {
-            status = false;
-        }
-        QuotingStrategy context = getQuotingStrategy(status);
-        String[] types = externalTypesForJdbcType(column.getType());
-        if (types == null || types.length == 0) {
-            String entityName = column.getEntity() != null ? ((DbEntity) column
-                    .getEntity()).getFullyQualifiedName() : "<null>";
-            throw new CayenneRuntimeException("Undefined type for attribute '"
-                    + entityName
-                    + "."
-                    + column.getName()
-                    + "': "
-                    + column.getType());
-        }
-
-        String type = types[0];
-        sqlBuffer.append(context.quoteString(column.getName()));
-        sqlBuffer.append(' ').append(type);
-
-        // append size and precision (if applicable)s
-        if (TypesMapping.supportsLength(column.getType())) {
-            int len = column.getMaxLength();
-            
-            int scale = (TypesMapping.isDecimal(column.getType()) 
-                    && column.getType() != Types.FLOAT) // SQL server don't support notations float(a, b) 
-                    ? column.getScale() : -1;
-
-            // sanity check
-            if (scale > len) {
-                scale = -1;
-            }
-
-            if (len > 0) {
-                sqlBuffer.append('(').append(len);
-
-                if (scale >= 0) {
-                    sqlBuffer.append(", ").append(scale);
-                }
-
-                sqlBuffer.append(')');
-            }
-        }
-
-        sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL");
+        super.createTableAppendColumn(sqlBuffer, column);
         
         if(column.isGenerated()) {
             // current limitation - we don't allow to set identity parameters...