cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r606821 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/DbGenerator.java test/java/org/apache/cayenne/unit/AccessStackAdapter.java test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
Date Tue, 25 Dec 2007 22:11:41 GMT
Author: aadamchik
Date: Tue Dec 25 14:11:40 2007
New Revision: 606821

URL: http://svn.apache.org/viewvc?rev=606821&view=rev
Log:
generics, java5 for loop

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java?rev=606821&r1=606820&r2=606821&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
Tue Dec 25 14:11:40 2007
@@ -520,12 +520,10 @@
             excludedEntities = Collections.emptyList();
         }
 
-        // remove derived db entities
         List<DbEntity> tables = new ArrayList<DbEntity>();
         List<DbEntity> tablesWithAutoPk = new ArrayList<DbEntity>();
-        Iterator<DbEntity> it = map.getDbEntities().iterator();
-        while (it.hasNext()) {
-            DbEntity nextEntity = it.next();
+
+        for (DbEntity nextEntity : map.getDbEntities()) {
 
             // do sanity checks...
 
@@ -581,9 +579,7 @@
                 // supposedly all source attributes of the relationship
                 // to master entity must be a part of primary key,
                 // so
-                Iterator<DbJoin> joins = nextRelationship.getJoins().iterator();
-                while (joins.hasNext()) {
-                    DbJoin join = joins.next();
+                for (DbJoin join : nextRelationship.getJoins()) {
                     pkAttributes.remove(join.getSource());
                 }
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java?rev=606821&r1=606820&r2=606821&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
Tue Dec 25 14:11:40 2007
@@ -31,7 +31,6 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -52,7 +51,7 @@
  */
 public class AccessStackAdapter {
 
-    private static Log logObj = LogFactory.getLog(AccessStackAdapter.class);
+    private static Log logger = LogFactory.getLog(AccessStackAdapter.class);
 
     protected DbAdapter adapter;
 
@@ -74,29 +73,32 @@
     /**
      * Drops all table constraints.
      */
-    public void willDropTables(Connection conn, DataMap map, Collection tablesToDrop)
-            throws Exception {
+    public void willDropTables(
+            Connection conn,
+            DataMap map,
+            Collection<String> tablesToDrop) throws Exception {
         dropConstraints(conn, map, tablesToDrop);
     }
 
-    protected void dropConstraints(Connection conn, DataMap map, Collection tablesToDrop)
-            throws Exception {
-        Map constraintsMap = getConstraints(conn, map, tablesToDrop);
+    protected void dropConstraints(
+            Connection conn,
+            DataMap map,
+            Collection<String> tablesToDrop) throws Exception {
+        Map<String, Collection<String>> constraintsMap = getConstraints(
+                conn,
+                map,
+                tablesToDrop);
 
-        Iterator it = constraintsMap.entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+        for (Map.Entry<String, Collection<String>> entry : constraintsMap.entrySet())
{
 
-            Collection constraints = (Collection) entry.getValue();
+            Collection<String> constraints = entry.getValue();
             if (constraints == null || constraints.isEmpty()) {
                 continue;
             }
 
             Object tableName = entry.getKey();
-            Iterator cit = constraints.iterator();
-            while (cit.hasNext()) {
-                Object constraint = cit.next();
-                StringBuffer drop = new StringBuffer();
+            for (String constraint : constraints) {
+                StringBuilder drop = new StringBuilder();
                 drop
                         .append("ALTER TABLE ")
                         .append(tableName)
@@ -150,7 +152,7 @@
     public boolean supportsEqualNullSyntax() {
         return true;
     }
-    
+
     public boolean supportsAllAnySome() {
         return true;
     }
@@ -184,11 +186,11 @@
 
         return true;
     }
-    
+
     public boolean supportsFKConstraints() {
         return true;
     }
-    
+
     public boolean supportsColumnTypeReengineering() {
         return true;
     }
@@ -221,7 +223,7 @@
     }
 
     protected void executeDDL(Connection con, String ddl) throws Exception {
-        logObj.info(ddl);
+        logger.info(ddl);
         Statement st = con.createStatement();
 
         try {
@@ -284,14 +286,16 @@
      * Returns a map of database constraints with DbEntity names used as keys, and
      * Collections of constraint names as values.
      */
-    protected Map getConstraints(Connection conn, DataMap map, Collection includeTables)
-            throws SQLException {
-        Map constraintMap = new HashMap();
+    protected Map<String, Collection<String>> getConstraints(
+            Connection conn,
+            DataMap map,
+            Collection<String> includeTables) throws SQLException {
+
+        Map<String, Collection<String>> constraintMap = new HashMap<String,
Collection<String>>();
 
         DatabaseMetaData metadata = conn.getMetaData();
-        Iterator it = includeTables.iterator();
-        while (it.hasNext()) {
-            String name = (String) it.next();
+
+        for (String name : includeTables) {
             DbEntity entity = map.getDbEntity(name);
             if (entity == null) {
                 continue;
@@ -306,10 +310,10 @@
                     String fkTable = rs.getString("FKTABLE_NAME");
 
                     if (fk != null && fkTable != null) {
-                        Collection constraints = (Collection) constraintMap.get(fkTable);
+                        Collection<String> constraints = constraintMap.get(fkTable);
                         if (constraints == null) {
                             // use a set to avoid duplicate constraints
-                            constraints = new HashSet();
+                            constraints = new HashSet<String>();
                             constraintMap.put(fkTable, constraints);
                         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java?rev=606821&r1=606820&r2=606821&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
Tue Dec 25 14:11:40 2007
@@ -22,7 +22,6 @@
 import java.sql.Connection;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.cayenne.dba.DbAdapter;
@@ -35,9 +34,10 @@
  */
 public class MySQLStackAdapter extends AccessStackAdapter {
 
-    static final Collection NO_CONSTRAINTS_TABLES = Arrays.asList(new Object[] {
-            "REFLEXIVE_AND_TO_ONE", "ARTGROUP", "FK_OF_DIFFERENT_TYPE"
-    });
+    static final Collection<String> NO_CONSTRAINTS_TABLES = Arrays.asList(
+            "REFLEXIVE_AND_TO_ONE",
+            "ARTGROUP",
+            "FK_OF_DIFFERENT_TYPE");
 
     public MySQLStackAdapter(DbAdapter adapter) {
         super(adapter);
@@ -54,7 +54,7 @@
     public boolean supportsStoredProcedures() {
         return true;
     }
-    
+
     public boolean supportsTrimChar() {
         return true;
     }
@@ -68,25 +68,28 @@
         }
     }
 
-    public void willDropTables(Connection conn, DataMap map, Collection tablesToDrop)
-            throws Exception {
+    public void willDropTables(
+            Connection conn,
+            DataMap map,
+            Collection<String> tablesToDrop) throws Exception {
+
         // special DROP CONSTRAINT syntax for MySQL
 
-        Map constraintsMap = getConstraints(conn, map, tablesToDrop);
+        Map<String, Collection<String>> constraintsMap = getConstraints(
+                conn,
+                map,
+                tablesToDrop);
 
-        Iterator it = constraintsMap.entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+        for (Map.Entry<String, Collection<String>> entry : constraintsMap.entrySet())
{
 
-            Collection constraints = (Collection) entry.getValue();
+            Collection<String> constraints = entry.getValue();
             if (constraints == null || constraints.isEmpty()) {
                 continue;
             }
 
             Object tableName = entry.getKey();
-            Iterator cit = constraints.iterator();
-            while (cit.hasNext()) {
-                Object constraint = cit.next();
+
+            for (String constraint : constraints) {
                 StringBuffer drop = new StringBuffer();
                 drop
                         .append("ALTER TABLE ")



Mime
View raw message