cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [4/4] cayenne git commit: Cleanup
Date Sun, 25 Jan 2015 10:53:08 GMT
Cleanup

* deleting internally used QueryResult class - it is not really needed,
  and we'll reuse its name for the new response object per separate Jiras


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/88361d20
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/88361d20
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/88361d20

Branch: refs/heads/master
Commit: 88361d20d6fb1c72da7271f9957a152b52dd82fd
Parents: e8346f3
Author: aadamchik <aadamchik@apache.org>
Authored: Sun Jan 25 05:48:14 2015 -0500
Committer: aadamchik <aadamchik@apache.org>
Committed: Sun Jan 25 05:48:14 2015 -0500

----------------------------------------------------------------------
 .../dba/frontbase/FrontBasePkGenerator.java     | 191 ++++++++++---------
 1 file changed, 99 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/88361d20/cayenne-server/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
index 61f9baa..716cbd8 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
@@ -22,11 +22,12 @@ package org.apache.cayenne.dba.frontbase;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.QueryResult;
+import org.apache.cayenne.access.OperationObserver;
+import org.apache.cayenne.access.util.DoNothingOperationObserver;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
@@ -38,94 +39,100 @@ import org.apache.cayenne.query.SQLTemplate;
  */
 public class FrontBasePkGenerator extends JdbcPkGenerator {
 
-    public FrontBasePkGenerator(JdbcAdapter adapter) {
-        super(adapter);
-        pkStartValue = 1000000;
-    }
-
-    /**
-     * Retruns zero as PK caching is not supported by FrontBaseAdapter.
-     */
-    @Override
-    public int getPkCacheSize() {
-        return 0;
-    }
-
-    @Override
-    public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
-        // For each entity (re)set the unique counter
-        for (DbEntity entity : dbEntities) {
-            runUpdate(node, pkCreateString(entity.getName()));
-        }
-    }
-
-    @Override
-    public List<String> createAutoPkStatements(List<DbEntity> dbEntities) {
-        List<String> list = new ArrayList<String>();
-        for (DbEntity entity : dbEntities) {
-            list.add(pkCreateString(entity.getName()));
-        }
-        return list;
-    }
-
-    @Override
-    public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
-    }
-
-    @Override
-    protected String pkTableCreateString() {
-        return "";
-    }
-
-    @Override
-    protected String pkDeleteString(List<DbEntity> dbEntities) {
-        return "-- The 'Drop Primary Key Support' option is unavailable";
-    }
-
-    @Override
-    protected String pkCreateString(String entName) {
-        StringBuilder buf = new StringBuilder();
-        buf.append("SET UNIQUE = ").append(pkStartValue).append(" FOR \"").append(entName).append("\"");
-        return buf.toString();
-    }
-
-    @Override
-    protected String pkSelectString(String entName) {
-        StringBuilder buf = new StringBuilder();
-        buf.append("SELECT UNIQUE FROM \"").append(entName).append("\"");
-        return buf.toString();
-    }
-
-    @Override
-    protected String pkUpdateString(String entName) {
-        return "";
-    }
-
-    @Override
-    protected String dropAutoPkString() {
-        return "";
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    protected long longPkFromDatabase(DataNode node, DbEntity entity) throws Exception {
-
-        String template = "SELECT #result('UNIQUE' 'long') FROM " + entity.getName();
-
-        SQLTemplate query = new SQLTemplate(entity, template);
-        QueryResult observer = new QueryResult();
-        node.performQueries(Collections.singleton((Query) query), observer);
-
-        List results = observer.getFirstRows(query);
-        if (results.size() != 1) {
-            throw new CayenneRuntimeException("Error fetching PK. Expected one row, got "
-                    + results.size());
-        }
-
-        Map row = (Map) results.get(0);
-        Number pk = (Number) row.get("UNIQUE");
-        return pk.longValue();
-    }
+	public FrontBasePkGenerator(JdbcAdapter adapter) {
+		super(adapter);
+		pkStartValue = 1000000;
+	}
+
+	/**
+	 * Retruns zero as PK caching is not supported by FrontBaseAdapter.
+	 */
+	@Override
+	public int getPkCacheSize() {
+		return 0;
+	}
+
+	@Override
+	public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
+		// For each entity (re)set the unique counter
+		for (DbEntity entity : dbEntities) {
+			runUpdate(node, pkCreateString(entity.getName()));
+		}
+	}
+
+	@Override
+	public List<String> createAutoPkStatements(List<DbEntity> dbEntities) {
+		List<String> list = new ArrayList<String>();
+		for (DbEntity entity : dbEntities) {
+			list.add(pkCreateString(entity.getName()));
+		}
+		return list;
+	}
+
+	@Override
+	public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception
{
+	}
+
+	@Override
+	protected String pkTableCreateString() {
+		return "";
+	}
+
+	@Override
+	protected String pkDeleteString(List<DbEntity> dbEntities) {
+		return "-- The 'Drop Primary Key Support' option is unavailable";
+	}
+
+	@Override
+	protected String pkCreateString(String entName) {
+		StringBuilder buf = new StringBuilder();
+		buf.append("SET UNIQUE = ").append(pkStartValue).append(" FOR \"").append(entName).append("\"");
+		return buf.toString();
+	}
+
+	@Override
+	protected String pkSelectString(String entName) {
+		StringBuilder buf = new StringBuilder();
+		buf.append("SELECT UNIQUE FROM \"").append(entName).append("\"");
+		return buf.toString();
+	}
+
+	@Override
+	protected String pkUpdateString(String entName) {
+		return "";
+	}
+
+	@Override
+	protected String dropAutoPkString() {
+		return "";
+	}
+
+	/**
+	 * @since 3.0
+	 */
+	@Override
+	protected long longPkFromDatabase(DataNode node, DbEntity entity) throws Exception {
+
+		String template = "SELECT #result('UNIQUE' 'long') FROM " + entity.getName();
+
+		final long[] pkHolder = new long[1];
+
+		SQLTemplate query = new SQLTemplate(entity, template);
+		OperationObserver observer = new DoNothingOperationObserver() {
+
+			@Override
+			public void nextRows(Query query, List<?> dataRows) {
+				if (dataRows.size() != 1) {
+					throw new CayenneRuntimeException("Error fetching PK. Expected one row, got " + dataRows.size());
+				}
+
+				DataRow row = (DataRow) dataRows.get(0);
+				Number pk = (Number) row.get("UNIQUE");
+				pkHolder[0] = pk.longValue();
+			}
+		};
+
+		node.performQueries(Collections.singleton((Query) query), observer);
+		return pkHolder[0];
+	}
 }


Mime
View raw message