cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r813134 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/types/IntegerType.java dba/JdbcAdapter.java
Date Wed, 09 Sep 2009 21:59:02 GMT
Author: aadamchik
Date: Wed Sep  9 21:59:02 2009
New Revision: 813134

URL: http://svn.apache.org/viewvc?rev=813134&view=rev
Log:
CAY-1273 Replace DefaultType with dedicated types

adding IntegerType

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/IntegerType.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/IntegerType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/IntegerType.java?rev=813134&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/IntegerType.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/IntegerType.java
Wed Sep  9 21:59:02 2009
@@ -0,0 +1,83 @@
+/*****************************************************************
+ *   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.access.types;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.validation.BeanValidationFailure;
+import org.apache.cayenne.validation.ValidationResult;
+
+/**
+ * @since 3.0
+ */
+public class IntegerType implements ExtendedType {
+
+    public String getClassName() {
+        return Integer.class.getName();
+    }
+
+    public Object materializeObject(ResultSet rs, int index, int type) throws Exception {
+        int value = rs.getInt(index);
+        return (rs.wasNull()) ? null : value;
+    }
+
+    public Object materializeObject(CallableStatement rs, int index, int type)
+            throws Exception {
+        int value = rs.getInt(index);
+        return (rs.wasNull()) ? null : value;
+    }
+
+    public void setJdbcObject(
+            PreparedStatement statement,
+            Object value,
+            int pos,
+            int type,
+            int scale) throws Exception {
+
+        if (value == null) {
+            statement.setNull(pos, type);
+        }
+        else {
+            statement.setInt(pos, ((Integer) value).intValue());
+        }
+    }
+
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
+    public boolean validateProperty(
+            Object source,
+            String property,
+            Object value,
+            DbAttribute dbAttribute,
+            ValidationResult validationResult) {
+        if (dbAttribute.isMandatory() && value == null) {
+            validationResult.addFailure(new BeanValidationFailure(source, property, "'"
+                    + property
+                    + "' must be not null"));
+            return false;
+        }
+
+        return true;
+    }
+
+}

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=813134&r1=813133&r2=813134&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
Wed Sep  9 21:59:02 2009
@@ -41,6 +41,7 @@
 import org.apache.cayenne.access.types.CharType;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.access.types.IntegerType;
 import org.apache.cayenne.access.types.UtilDateType;
 import org.apache.cayenne.conf.ClasspathResourceFinder;
 import org.apache.cayenne.map.DbAttribute;
@@ -163,6 +164,9 @@
      * and Java layers. Called from default constructor.
      */
     protected void configureExtendedTypes(ExtendedTypeMap map) {
+
+        map.registerType(new IntegerType());
+
         // use BooleanType to ensure that returned booleans are an enum of Boolean.TRUE
         // and Boolean.FALSE
         map.registerType(new BooleanType());
@@ -266,7 +270,9 @@
      * @since 3.0
      */
     public Collection<String> dropTableStatements(DbEntity table) {
-        QuotingStrategy context =  getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());
+        QuotingStrategy context = getQuotingStrategy(table
+                .getDataMap()
+                .isQuotingSQLIdentifiers());
 
         StringBuffer buf = new StringBuffer("DROP TABLE ");
         buf.append(context.quoteFullyQualifiedName(table));
@@ -280,12 +286,13 @@
      */
     public String createTable(DbEntity entity) {
         boolean status;
-        if(entity.getDataMap()!=null && entity.getDataMap().isQuotingSQLIdentifiers()){

-            status= true;
-        } else {
+        if (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
             status = false;
         }
-        QuotingStrategy context =  getQuotingStrategy(status);
+        QuotingStrategy context = getQuotingStrategy(status);
         StringBuffer sqlBuffer = new StringBuffer();
         sqlBuffer.append("CREATE TABLE ");
         sqlBuffer.append(context.quoteFullyQualifiedName(entity));
@@ -329,12 +336,13 @@
      */
     protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
         boolean status;
-        if(entity.getDataMap()!=null && entity.getDataMap().isQuotingSQLIdentifiers()){

-            status= true;
-        } else {
+        if (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
             status = false;
         }
-        QuotingStrategy context =  getQuotingStrategy(status);
+        QuotingStrategy context = getQuotingStrategy(status);
         Iterator<DbAttribute> pkit = entity.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             sqlBuffer.append(", PRIMARY KEY (");
@@ -360,12 +368,14 @@
      */
     public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
         boolean status;
-        if((column.getEntity().getDataMap() != null) && column.getEntity().getDataMap().isQuotingSQLIdentifiers())
{ 
-            status= true;
-        } else {
+        if ((column.getEntity().getDataMap() != null)
+                && column.getEntity().getDataMap().isQuotingSQLIdentifiers()) {
+            status = true;
+        }
+        else {
             status = false;
         }
-        QuotingStrategy context =  getQuotingStrategy(status);
+        QuotingStrategy context = getQuotingStrategy(status);
         String[] types = externalTypesForJdbcType(column.getType());
         if (types == null || types.length == 0) {
             String entityName = column.getEntity() != null ? ((DbEntity) column
@@ -413,12 +423,13 @@
      */
     public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)
{
         boolean status;
-        if(source.getDataMap()!=null && source.getDataMap().isQuotingSQLIdentifiers()){

-            status= true;
-        } else {
+        if (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
             status = false;
         }
-        QuotingStrategy context =  getQuotingStrategy(status);
+        QuotingStrategy context = getQuotingStrategy(status);
 
         if (columns == null || columns.isEmpty()) {
             throw new CayenneRuntimeException(
@@ -454,12 +465,13 @@
 
         DbEntity source = (DbEntity) rel.getSourceEntity();
         boolean status;
-        if(source.getDataMap()!=null && source.getDataMap().isQuotingSQLIdentifiers()){

-            status= true;
-        } else {
+        if (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
             status = false;
         }
-        QuotingStrategy context =  getQuotingStrategy(status);
+        QuotingStrategy context = getQuotingStrategy(status);
         StringBuilder buf = new StringBuilder();
         StringBuilder refBuf = new StringBuilder();
 
@@ -627,11 +639,10 @@
     /**
      * @since 3.0
      */
-    public QuotingStrategy  getQuotingStrategy(boolean needQuotes) {
+    public QuotingStrategy getQuotingStrategy(boolean needQuotes) {
         if (needQuotes) {
-            return new QuoteStrategy(
-                    this.getIdentifiersStartQuote(),
-                    this.getIdentifiersEndQuote());
+            return new QuoteStrategy(this.getIdentifiersStartQuote(), this
+                    .getIdentifiersEndQuote());
         }
         else {
             return new NoQuoteStrategy();



Mime
View raw message