cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amania...@apache.org
Subject svn commit: r600176 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba: ./ db2/ frontbase/ hsqldb/ ingres/ mysql/ oracle/ postgres/ sqlite/ sqlserver/ sybase/
Date Sat, 01 Dec 2007 18:12:19 GMT
Author: amaniatis
Date: Sat Dec  1 10:12:18 2007
New Revision: 600176

URL: http://svn.apache.org/viewvc?rev=600176&view=rev
Log:
Generics and cleanup of dba package.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/TypesMapping.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.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/oracle/OracleAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteCalendarType.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerBatchAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/TypesMapping.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/TypesMapping.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/TypesMapping.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/TypesMapping.java
Sat Dec  1 10:12:18 2007
@@ -28,10 +28,8 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.cayenne.util.Util;
 
@@ -99,22 +97,22 @@
     /**
      * Keys: SQL string type names, Values: SQL int type definitions from java.sql.Types
      */
-    private static final Map sqlStringType = new HashMap();
+    private static final Map<String, Integer> sqlStringType = new HashMap<String,
Integer>();
 
     /**
      * Keys: SQL int type definitions from java.sql.Types, Values: SQL string type names
      */
-    private static final Map sqlEnumType = new HashMap();
+    private static final Map<Integer, String> sqlEnumType = new HashMap<Integer,
String>();
 
     /**
      * Keys: SQL int type definitions from java.sql.Types, Values: java class names
      */
-    private static final Map sqlEnumJava = new HashMap();
+    private static final Map<Integer, String> sqlEnumJava = new HashMap<Integer,
String>();
 
     /**
      * Keys: java class names, Values: SQL int type definitions from java.sql.Types
      */
-    private static final Map javaSqlEnum = new HashMap();
+    private static final Map<String, Integer> javaSqlEnum = new HashMap<String,
Integer>();
 
     static {
         sqlStringType.put(SQL_ARRAY, new Integer(Types.ARRAY));
@@ -261,16 +259,7 @@
 
     /** Returns an array of string names of the default JDBC data types. */
     public static String[] getDatabaseTypes() {
-        Set keys = sqlStringType.keySet();
-        int len = keys.size();
-        String[] types = new String[len];
-
-        Iterator it = keys.iterator();
-        for (int i = 0; i < len; i++) {
-            types[i] = (String) it.next();
-        }
-
-        return types;
+        return sqlStringType.keySet().toArray(new String[0]);
     }
 
     /**
@@ -304,7 +293,7 @@
             }
         }
 
-        List list = new ArrayList();
+        List<TypeInfo> list = new ArrayList<TypeInfo>();
         for (int i = 0; i < len; i++) {
             if (maxPrec == alts[i].precision) {
                 list.add(alts[i]);
@@ -314,32 +303,32 @@
         // work with smaller list now.....
         int slen = list.size();
         if (slen == 1)
-            return ((TypeInfo) list.get(0)).name;
+            return (list.get(0)).name;
 
         // start/end match
         for (int i = 0; i < slen; i++) {
-            String uppercase = ((TypeInfo) list.get(i)).name.toUpperCase();
+            String uppercase = (list.get(i)).name.toUpperCase();
             if (uppercase.startsWith(jdbcName) || uppercase.endsWith(jdbcName))
-                return ((TypeInfo) list.get(i)).name;
+                return (list.get(i)).name;
         }
 
         // in the middle match
         for (int i = 0; i < slen; i++) {
-            String uppercase = ((TypeInfo) list.get(i)).name.toUpperCase();
+            String uppercase = (list.get(i)).name.toUpperCase();
 
             if (uppercase.indexOf(jdbcName) >= 0)
-                return ((TypeInfo) list.get(i)).name;
+                return (list.get(i)).name;
         }
 
         // out of ideas... return the first one
-        return ((TypeInfo) list.get(0)).name;
+        return (list.get(0)).name;
     }
 
     /**
      * Returns a JDBC int type for SQL typem name.
      */
     public static int getSqlTypeByName(String typeName) {
-        Integer tmp = (Integer) sqlStringType.get(typeName);
+        Integer tmp = sqlStringType.get(typeName);
         return (null == tmp) ? NOT_DEFINED : tmp.intValue();
     }
 
@@ -347,7 +336,7 @@
      * Returns a String representation of the SQL type from its JDBC code.
      */
     public static String getSqlNameByType(int type) {
-        return (String) sqlEnumType.get(new Integer(type));
+        return sqlEnumType.get(new Integer(type));
     }
 
     /**
@@ -361,14 +350,14 @@
             return NOT_DEFINED;
         }
 
-        Integer type = (Integer) javaSqlEnum.get(className);
+        Integer type = javaSqlEnum.get(className);
         if (type != null) {
             return type.intValue();
         }
 
         // try to load a Java class - some nonstandard mappings may work
 
-        Class aClass;
+        Class<?> aClass;
         try {
             aClass = Util.getJavaClass(className);
         }
@@ -384,13 +373,13 @@
      * 
      * @since 1.1
      */
-    public static int getSqlTypeByJava(Class javaClass) {
+    public static int getSqlTypeByJava(Class<?> javaClass) {
         if (javaClass == null) {
             return NOT_DEFINED;
         }
 
         // check standard mapping of class and superclasses
-        Class aClass = javaClass;
+        Class<?> aClass = javaClass;
         while (aClass != null) {
 
             String name;
@@ -413,7 +402,7 @@
         // check non-standard JDBC types that are still supported by JPA
         if (javaClass.isArray()) {
 
-            Class elementType = javaClass.getComponentType();
+            Class<?> elementType = javaClass.getComponentType();
             if (Character.class.isAssignableFrom(elementType)
                     || Character.TYPE.isAssignableFrom(elementType)) {
                 return Types.VARCHAR;
@@ -445,7 +434,7 @@
      * @return Fully qualified Java type name or null if not found.
      */
     public static String getJavaBySqlType(int type) {
-        return (String) sqlEnumJava.get(new Integer(type));
+        return sqlEnumJava.get(new Integer(type));
     }
 
     /**
@@ -458,14 +447,14 @@
         if (type == Types.NUMERIC && precision == 0) {
             type = Types.INTEGER;
         }
-        return (String) sqlEnumJava.get(new Integer(type));
+        return sqlEnumJava.get(new Integer(type));
     }
 
     // *************************************************************
     // non-static code
     // *************************************************************
 
-    protected Map databaseTypes = new HashMap();
+    protected Map<Integer, List<TypeInfo>> databaseTypes = new HashMap<Integer,
List<TypeInfo>>();
 
     public TypesMapping(DatabaseMetaData metaData) throws SQLException {
         // map database types to standard JDBC types
@@ -479,10 +468,10 @@
                 info.precision = rs.getLong("PRECISION");
 
                 Integer key = new Integer(info.jdbcType);
-                List infos = (List) databaseTypes.get(key);
+                List<TypeInfo> infos = databaseTypes.get(key);
 
                 if (infos == null) {
-                    infos = new ArrayList();
+                    infos = new ArrayList<TypeInfo>();
                     databaseTypes.put(key, infos);
                 }
 
@@ -498,8 +487,8 @@
         // 1. swap TIMESTAMP - DATE
         Integer ts = new Integer(Types.TIMESTAMP);
         Integer dt = new Integer(Types.DATE);
-        List tsInfo = (List) databaseTypes.get(ts);
-        List dtInfo = (List) databaseTypes.get(dt);
+        List<TypeInfo> tsInfo = databaseTypes.get(ts);
+        List<TypeInfo> dtInfo = databaseTypes.get(dt);
 
         if (tsInfo != null && dtInfo == null)
             databaseTypes.put(dt, tsInfo);
@@ -510,8 +499,8 @@
         // 2. Swap CLOB - LONGVARCHAR
         Integer clob = new Integer(Types.CLOB);
         Integer lvc = new Integer(Types.LONGVARCHAR);
-        List clobInfo = (List) databaseTypes.get(clob);
-        List lvcInfo = (List) databaseTypes.get(lvc);
+        List<TypeInfo> clobInfo = databaseTypes.get(clob);
+        List<TypeInfo> lvcInfo = databaseTypes.get(lvc);
 
         if (clobInfo != null && lvcInfo == null)
             databaseTypes.put(lvc, clobInfo);
@@ -522,8 +511,8 @@
         // 2. Swap BLOB - LONGVARBINARY
         Integer blob = new Integer(Types.BLOB);
         Integer lvb = new Integer(Types.LONGVARBINARY);
-        List blobInfo = (List) databaseTypes.get(blob);
-        List lvbInfo = (List) databaseTypes.get(lvb);
+        List<TypeInfo> blobInfo = databaseTypes.get(blob);
+        List<TypeInfo> lvbInfo = databaseTypes.get(lvb);
 
         if (blobInfo != null && lvbInfo == null)
             databaseTypes.put(lvb, blobInfo);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
Sat Dec  1 10:12:18 2007
@@ -32,6 +32,7 @@
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
@@ -82,7 +83,7 @@
         buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
 
         // columns
-        Iterator it = ent.getAttributes().iterator();
+        Iterator<Attribute> it = ent.getAttributes().iterator();
         boolean first = true;
         while (it.hasNext()) {
             if (first) {
@@ -143,7 +144,7 @@
         }
 
         // primary key clause
-        Iterator pkit = ent.getPrimaryKeys().iterator();
+        Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             if (first)
                 first = false;
@@ -158,7 +159,7 @@
                 else
                     buf.append(", ");
 
-                DbAttribute at = (DbAttribute) pkit.next();
+                DbAttribute at = pkit.next();
                 buf.append(at.getName());
             }
             buf.append(')');

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
Sat Dec  1 10:12:18 2007
@@ -25,7 +25,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -82,12 +81,9 @@
         }
     }
 
-    public void createAutoPk(DataNode node, List dbEntities) throws Exception {
-        Collection sequences = getExistingSequences(node);
-        Iterator it = dbEntities.iterator();
-
-        while (it.hasNext()) {
-            DbEntity entity = (DbEntity) it.next();
+    public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
+        Collection<String> sequences = getExistingSequences(node);
+       for (DbEntity entity : dbEntities) {
             if (!sequences.contains(sequenceName(entity))) {
                 this.runUpdate(node, createSequenceString(entity));
             }
@@ -97,27 +93,21 @@
     /**
      * Creates a list of CREATE SEQUENCE statements for the list of DbEntities.
      */
-    public List createAutoPkStatements(List dbEntities) {
-        List list = new ArrayList(dbEntities.size());
-        Iterator it = dbEntities.iterator();
-
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
-            list.add(createSequenceString(ent));
+    public List<String> createAutoPkStatements(List<DbEntity> dbEntities) {
+        List<String> list = new ArrayList<String>(dbEntities.size());
+        for (DbEntity entity : dbEntities) {
+            list.add(createSequenceString(entity));
         }
-
         return list;
     }
 
     /**
      * Drops PK sequences for all specified DbEntities.
      */
-    public void dropAutoPk(DataNode node, List dbEntities) throws Exception {
-        Collection sequences = getExistingSequences(node);
+    public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
+        Collection<String> sequences = getExistingSequences(node);
 
-        Iterator it = dbEntities.iterator();
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
+        for (DbEntity ent : dbEntities) {
             if (sequences.contains(sequenceName(ent))) {
                 runUpdate(node, dropSequenceString(ent));
             }
@@ -127,23 +117,18 @@
     /**
      * Creates a list of DROP SEQUENCE statements for the list of DbEntities.
      */
-    public List dropAutoPkStatements(List dbEntities) {
-
-        List list = new ArrayList(dbEntities.size());
-        Iterator it = dbEntities.iterator();
-
-        while (it.hasNext()) {
-            DbEntity entity = (DbEntity) it.next();
+    public List<String> dropAutoPkStatements(List<DbEntity> dbEntities) {
+        List<String> list = new ArrayList<String>(dbEntities.size());
+        for (DbEntity entity : dbEntities) {
             list.add(dropSequenceString(entity));
         }
-
         return list;
     }
 
     /**
      * Fetches a list of existing sequences that might match Cayenne generated ones.
      */
-    protected List getExistingSequences(DataNode node) throws SQLException {
+    protected List<String> getExistingSequences(DataNode node) throws SQLException
{
 
         // check existing sequences
         Connection con = node.getDataSource().getConnection();
@@ -159,7 +144,7 @@
                 QueryLogger.logQuery(sql, Collections.EMPTY_LIST);
                 ResultSet rs = sel.executeQuery(sql);
                 try {
-                    List sequenceList = new ArrayList();
+                    List<String> sequenceList = new ArrayList<String>();
                     while (rs.next()) {
                         sequenceList.add(rs.getString(1));
                     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
Sat Dec  1 10:12:18 2007
@@ -28,6 +28,7 @@
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.Query;
@@ -89,7 +90,7 @@
         buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
 
         // columns
-        Iterator it = ent.getAttributes().iterator();
+        Iterator<Attribute> it = ent.getAttributes().iterator();
         boolean first = true;
         while (it.hasNext()) {
             if (first) {
@@ -165,7 +166,7 @@
         }
 
         // primary key clause
-        Iterator pkit = ent.getPrimaryKeys().iterator();
+        Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             if (first)
                 first = false;
@@ -180,7 +181,7 @@
                 else
                     buf.append(", ");
 
-                DbAttribute at = (DbAttribute) pkit.next();
+                DbAttribute at = pkit.next();
                 buf.append(at.getName());
             }
             buf.append(')');

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
Sat Dec  1 10:12:18 2007
@@ -21,7 +21,6 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -50,35 +49,29 @@
         return 0;
     }
 
-    public void createAutoPk(DataNode node, List dbEntities) throws Exception {
+    public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
         // For each entity (re)set the unique counter
-        Iterator it = dbEntities.iterator();
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
-            runUpdate(node, pkCreateString(ent.getName()));
+        for (DbEntity entity : dbEntities) {
+            runUpdate(node, pkCreateString(entity.getName()));
         }
     }
 
-    public List createAutoPkStatements(List dbEntities) {
-        List list = new ArrayList();
-
-        Iterator it = dbEntities.iterator();
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
-            list.add(pkCreateString(ent.getName()));
+    public List<String> createAutoPkStatements(List<DbEntity> dbEntities) {
+        List<String> list = new ArrayList<String>();
+        for (DbEntity entity : dbEntities) {
+            list.add(pkCreateString(entity.getName()));
         }
-
         return list;
     }
 
-    public void dropAutoPk(DataNode node, List dbEntities) throws Exception {
+    public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
     }
 
     protected String pkTableCreateString() {
         return "";
     }
 
-    protected String pkDeleteString(List dbEntities) {
+    protected String pkDeleteString(List<DbEntity> dbEntities) {
         return "-- The 'Drop Primary Key Support' option is unavailable";
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
Sat Dec  1 10:12:18 2007
@@ -47,7 +47,6 @@
  *        test-hsqldb.jdbc.password = secret
  *        test-hsqldb.jdbc.url = jdbc:hsqldb:hsql://serverhostname
  *        test-hsqldb.jdbc.driver = org.hsqldb.jdbcDriver
- *        
  * </pre>
  * 
  * @author Holger Hoffstaette
@@ -97,7 +96,7 @@
      * 
      * @since 1.1
      */
-    public String createUniqueConstraint(DbEntity source, Collection columns) {
+    public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)
{
         if (columns == null || columns.isEmpty()) {
             throw new CayenneRuntimeException(
                     "Can't create UNIQUE constraint - no columns specified.");
@@ -117,12 +116,12 @@
         buf.append((long) (System.currentTimeMillis() / (Math.random() * 100000)));
         buf.append(" UNIQUE (");
 
-        Iterator it = columns.iterator();
-        DbAttribute first = (DbAttribute) it.next();
+        Iterator<DbAttribute> it = columns.iterator();
+        DbAttribute first = it.next();
         buf.append(first.getName());
 
         while (it.hasNext()) {
-            DbAttribute next = (DbAttribute) it.next();
+            DbAttribute next = it.next();
             buf.append(", ");
             buf.append(next.getName());
         }
@@ -157,10 +156,8 @@
 
         buf.append(" FOREIGN KEY (");
 
-        Iterator jit = rel.getJoins().iterator();
         boolean first = true;
-        while (jit.hasNext()) {
-            DbJoin join = (DbJoin) jit.next();
+        for (DbJoin join : rel.getJoins()) {
             if (!first) {
                 buf.append(", ");
                 refBuf.append(", ");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
Sat Dec  1 10:12:18 2007
@@ -29,6 +29,7 @@
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
@@ -61,7 +62,7 @@
         buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
 
         // columns
-        Iterator it = ent.getAttributes().iterator();
+        Iterator<Attribute> it = ent.getAttributes().iterator();
         boolean first = true;
         while (it.hasNext()) {
             if (first) {
@@ -123,7 +124,7 @@
         }
 
         // primary key clause
-        Iterator pkit = ent.getPrimaryKeys().iterator();
+        Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             if (first)
                 first = false;
@@ -138,7 +139,7 @@
                 else
                     buf.append(", ");
 
-                DbAttribute at = (DbAttribute) pkit.next();
+                DbAttribute at = pkit.next();
                 buf.append(at.getName());
             }
             buf.append(')');

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java
Sat Dec  1 10:12:18 2007
@@ -88,7 +88,7 @@
         }
     }
 
-    protected List getExistingSequences(DataNode node) throws SQLException {
+    protected List<String> getExistingSequences(DataNode node) throws SQLException
{
 
         // check existing sequences
         Connection connection = node.getDataSource().getConnection();
@@ -100,7 +100,7 @@
                 QueryLogger.logQuery(sql, Collections.EMPTY_LIST);
                 ResultSet rs = select.executeQuery(sql);
                 try {
-                    List sequenceList = new ArrayList();
+                    List<String> sequenceList = new ArrayList<String>();
                     while (rs.next()) {
                         String name = rs.getString(1);
                         if(name != null) {

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=600176&r1=600175&r2=600176&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
Sat Dec  1 10:12:18 2007
@@ -36,6 +36,7 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.Relationship;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLAction;
 
@@ -200,10 +201,10 @@
     protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
 
         // must move generated to the front...
-        List pkList = new ArrayList(entity.getPrimaryKeys());
+        List<DbAttribute> pkList = new ArrayList<DbAttribute>(entity.getPrimaryKeys());
         Collections.sort(pkList, new PKComparator());
 
-        Iterator pkit = pkList.iterator();
+        Iterator<DbAttribute> pkit = pkList.iterator();
         if (pkit.hasNext()) {
 
             sqlBuffer.append(", PRIMARY KEY (");
@@ -214,7 +215,7 @@
                 else
                     sqlBuffer.append(", ");
 
-                DbAttribute at = (DbAttribute) pkit.next();
+                DbAttribute at = pkit.next();
                 sqlBuffer.append(at.getName());
             }
             sqlBuffer.append(')');
@@ -224,21 +225,20 @@
         // Note that according to MySQL docs, FK indexes are created automatically when
         // constraint is defined, starting at MySQL 4.1.2
         if (supportsFkConstraints()) {
-            Iterator relationships = entity.getRelationships().iterator();
-            while (relationships.hasNext()) {
-                DbRelationship relationship = (DbRelationship) relationships.next();
+            for (Relationship r :  entity.getRelationships()) {
+                DbRelationship relationship = (DbRelationship) r;
                 if (relationship.getJoins().size() > 0
                         && relationship.isToPK()
                         && !relationship.isToDependentPK()) {
 
                     sqlBuffer.append(", KEY (");
 
-                    Iterator columns = relationship.getSourceAttributes().iterator();
-                    DbAttribute column = (DbAttribute) columns.next();
+                    Iterator<DbAttribute> columns = relationship.getSourceAttributes().iterator();
+                    DbAttribute column = columns.next();
                     sqlBuffer.append(column.getName());
 
                     while (columns.hasNext()) {
-                        column = (DbAttribute) columns.next();
+                        column = columns.next();
                         sqlBuffer.append(", ").append(column.getName());
                     }
 
@@ -259,11 +259,9 @@
         }
     }
 
-    final class PKComparator implements Comparator {
+    final class PKComparator implements Comparator<DbAttribute> {
 
-        public int compare(Object o1, Object o2) {
-            DbAttribute a1 = (DbAttribute) o1;
-            DbAttribute a2 = (DbAttribute) o2;
+        public int compare(DbAttribute a1, DbAttribute a2) {
             if (a1.isGenerated() != a2.isGenerated()) {
                 return a1.isGenerated() ? -1 : 1;
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
Sat Dec  1 10:12:18 2007
@@ -23,7 +23,6 @@
 import java.lang.reflect.Method;
 import java.sql.PreparedStatement;
 import java.sql.Types;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -53,15 +52,11 @@
  * settings to use with Oracle are shown below:
  * 
  * <pre>
- *        
- *         
  *          test-oracle.cayenne.adapter = org.apache.cayenne.dba.oracle.OracleAdapter
  *          test-oracle.jdbc.username = test
  *          test-oracle.jdbc.password = secret
  *          test-oracle.jdbc.url = jdbc:oracle:thin:@//192.168.0.20:1521/ora1 
- *          test-oracle.jdbc.driver = oracle.jdbc.driver.OracleDriver
- *          
- *         
+ *          test-oracle.jdbc.driver = oracle.jdbc.driver.OracleDriver   
  * </pre>
  * 
  * @author Andrus Adamchik
@@ -94,7 +89,7 @@
 
         // configure static information
         try {
-            Class oraTypes = Class.forName("oracle.jdbc.driver.OracleTypes");
+            Class<?> oraTypes = Class.forName("oracle.jdbc.driver.OracleTypes");
             Field cursorField = oraTypes.getField("CURSOR");
             oracleCursorType = cursorField.getInt(null);
 
@@ -136,13 +131,12 @@
             return false;
         }
 
-        List updatedAttributes = (isInsert)
+        List<DbAttribute> updatedAttributes = (isInsert)
                 ? query.getDbAttributes()
                 : ((UpdateBatchQuery) query).getUpdatedAttributes();
 
-        Iterator it = updatedAttributes.iterator();
-        while (it.hasNext()) {
-            int type = ((DbAttribute) it.next()).getType();
+        for (DbAttribute attr : updatedAttributes) {
+            int type = attr.getType();
             if (type == Types.CLOB || type == Types.BLOB) {
                 return true;
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
Sat Dec  1 10:12:18 2007
@@ -31,6 +31,7 @@
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.merge.MergerFactory;
@@ -122,7 +123,7 @@
         buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
 
         // columns
-        Iterator it = ent.getAttributes().iterator();
+        Iterator<Attribute> it = ent.getAttributes().iterator();
         boolean first = true;
         while (it.hasNext()) {
             if (first) {
@@ -186,7 +187,7 @@
         }
 
         // primary key clause
-        Iterator pkit = ent.getPrimaryKeys().iterator();
+        Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             if (first)
                 first = false;
@@ -201,7 +202,7 @@
                 else
                     buf.append(", ");
 
-                DbAttribute at = (DbAttribute) pkit.next();
+                DbAttribute at = pkit.next();
                 buf.append(at.getName());
             }
             buf.append(')');

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
Sat Dec  1 10:12:18 2007
@@ -103,7 +103,7 @@
     /**
      * Fetches a list of existing sequences that might match Cayenne generated ones.
      */
-    protected List getExistingSequences(DataNode node) throws SQLException {
+    protected List<String> getExistingSequences(DataNode node) throws SQLException
{
 
         // check existing sequences
         Connection con = node.getDataSource().getConnection();
@@ -115,7 +115,7 @@
                 QueryLogger.logQuery(sql, Collections.EMPTY_LIST);
                 ResultSet rs = sel.executeQuery(sql);
                 try {
-                    List sequenceList = new ArrayList();
+                    List<String> sequenceList = new ArrayList<String>();
                     while (rs.next()) {
                         sequenceList.add(rs.getString(1));
                     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteCalendarType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteCalendarType.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteCalendarType.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteCalendarType.java
Sat Dec  1 10:12:18 2007
@@ -21,6 +21,7 @@
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 
@@ -38,8 +39,8 @@
     protected ExtendedType delegateCalendarType;
     protected ExtendedType delegateDateType;
 
-    public SQLiteCalendarType(Class calendarClass) {
-        this.delegateCalendarType = new CalendarType(calendarClass);
+    public <T extends Calendar> SQLiteCalendarType(Class<T> calendarClass) {
+        this.delegateCalendarType = new CalendarType<T>(calendarClass);
         this.delegateDateType = new SQLiteDateType();
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerBatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerBatchAction.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerBatchAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerBatchAction.java
Sat Dec  1 10:12:18 2007
@@ -23,12 +23,12 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collections;
-import java.util.Iterator;
 
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.jdbc.BatchAction;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.BatchQuery;
@@ -107,10 +107,8 @@
         }
 
         // find identity attributes
-        Iterator it = query.getDbEntity().getAttributes().iterator();
-        while (it.hasNext()) {
-            DbAttribute attribute = (DbAttribute) it.next();
-            if (attribute.isGenerated()) {
+        for (Attribute attribute : query.getDbEntity().getAttributes()) {
+            if (((DbAttribute)attribute).isGenerated()) {
                 return true;
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
Sat Dec  1 10:12:18 2007
@@ -24,9 +24,9 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.ResultIterator;
@@ -125,8 +125,8 @@
 
     class Observer implements OperationObserver {
 
-        List results;
-        List counts;
+        List<List<DataRow>> results;
+        List<Integer> counts;
         OperationObserver observer;
 
         Observer(OperationObserver observer) {
@@ -135,20 +135,16 @@
 
         void flushResults(Query query) {
             if (results != null) {
-                Iterator it = results.iterator();
-                while (it.hasNext()) {
-                    observer.nextDataRows(query, (List) it.next());
+                for (List<DataRow> result : results) {
+                    observer.nextDataRows(query, result);
                 }
-
                 results = null;
             }
 
             if (counts != null) {
-                Iterator it = counts.iterator();
-                while (it.hasNext()) {
-                    observer.nextCount(query, ((Number) it.next()).intValue());
+                for (Integer count : counts) {
+                    observer.nextCount(query, count);
                 }
-
                 counts = null;
             }
         }
@@ -161,17 +157,17 @@
             // does not delegate to wrapped observer
             // but instead caches results locally.
             if (counts == null) {
-                counts = new ArrayList();
+                counts = new ArrayList<Integer>();
             }
 
             counts.add(new Integer(resultCount));
         }
 
-        public void nextDataRows(Query query, List dataRows) {
+        public void nextDataRows(Query query, List<DataRow> dataRows) {
             // does not delegate to wrapped observer
             // but instead caches results locally.
             if (results == null) {
-                results = new ArrayList();
+                results = new ArrayList<List<DataRow>>();
             }
 
             results.add(dataRows);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java?rev=600176&r1=600175&r2=600176&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java
Sat Dec  1 10:12:18 2007
@@ -78,15 +78,15 @@
      *
      *  @param node node that provides access to a DataSource.
      */
-    public void createAutoPk(DataNode node, List dbEntities) throws Exception {
+    public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
     	super.createAutoPk(node, dbEntities);
     	super.runUpdate(node, safePkProcDrop());
         super.runUpdate(node, unsafePkProcCreate());
     }
     
     
-    public List createAutoPkStatements(List dbEntities) {
-		List list = super.createAutoPkStatements(dbEntities);
+    public List<String> createAutoPkStatements(List<DbEntity> dbEntities) {
+		List<String> list = super.createAutoPkStatements(dbEntities);
 		
 		// add stored procedure drop code
 		list.add(safePkProcDrop());
@@ -118,13 +118,13 @@
      *
      *  @param node node that provides access to a DataSource.
      */
-    public void dropAutoPk(DataNode node, List dbEntities) throws Exception {
+    public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
         super.runUpdate(node, safePkProcDrop());
         super.runUpdate(node, safePkTableDrop());
     }
     
-    public List dropAutoPkStatements(List dbEntities) {
-		List list = new ArrayList();
+    public List<String> dropAutoPkStatements(List<DbEntity> dbEntities) {
+		List<String> list = new ArrayList<String>();
 		list.add(safePkProcDrop());
 		list.add(safePkTableDrop());
 		return list;



Mime
View raw message