cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r898287 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
Date Tue, 12 Jan 2010 11:40:40 GMT
Author: oltka
Date: Tue Jan 12 11:40:40 2010
New Revision: 898287

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

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
Modified:
    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/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=898287&r1=898286&r2=898287&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 11:40:40 2010
@@ -19,11 +19,17 @@
 
 package org.apache.cayenne.dba.sqlserver;
 
+import java.sql.Types;
+
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.trans.QualifierTranslator;
 import org.apache.cayenne.access.trans.QueryAssembler;
+import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.dba.sybase.SybaseAdapter;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.merge.MergerFactory;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLAction;
@@ -114,7 +120,57 @@
      */
     @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.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");
         
         if(column.isGenerated()) {
             // current limitation - we don't allow to set identity parameters...
@@ -126,4 +182,6 @@
     public MergerFactory mergerFactory() {
         return new SQLServerMergerFactory();
     }
+    
+    
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java?rev=898287&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
Tue Jan 12 11:40:40 2010
@@ -0,0 +1,48 @@
+/*****************************************************************
+ *   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.cayenne.dba.sqlserver;
+
+import java.sql.Types;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+
+
+public class SQLServerAdapterTest extends TestCase {
+    
+    public void testCreateTableWithFloatAttributeWithScale () {
+        SQLServerAdapter adapter = new SQLServerAdapter();
+        DbEntity e = new DbEntity("Test");
+        DbAttribute dblPrec = new DbAttribute("dbl1");
+        dblPrec.setType(Types.FLOAT);
+        dblPrec.setMaxLength(22);
+        dblPrec.setScale(12);
+        e.addAttribute(dblPrec);
+        
+        String sql = adapter.createTable(e);
+
+        // CAY-1363.
+        // Postgress don't support notations float(a, b) 
+        assertTrue(sql.indexOf("float(22)") > 0);
+        assertEquals(-1, sql.indexOf("float(22, 12)"));
+        assertEquals("CREATE TABLE Test (dbl1 float(22) NULL)", sql);
+    }
+}



Mime
View raw message