Changeset: cd6ff38c90f4 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/cd6ff38c90f4
Added Files:
src/main/java/nl/cwi/monetdb/embedded/mapping/AbstractRowSet.java
src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBRow.java
src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultRowSet.java
Removed Files:
src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetRows.java
Modified Files:
src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java
src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSet.java
src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetColumn.java
src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableIterator.java
src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableRemover.java
src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableUpdater.java
src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java
src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java
src/main/java/nl/cwi/monetdb/embedded/tables/RowRemover.java
src/main/java/nl/cwi/monetdb/embedded/tables/RowUpdater.java
Branch: embedded
Log Message:
Cleaned more code. Ready to implement the iterators internally.
diffs (truncated from 1270 to 300 lines):
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
--- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
@@ -111,9 +111,8 @@ public class MonetDBEmbeddedConnection {
* @return The update result object
* @throws MonetDBEmbeddedException If an error in the database occurred
*/
- /*public UpdateResultSet sendUpdateAsync(String query) throws
MonetDBEmbeddedException {
- /CompletableFuture.supplyAsync(() -> this.sendUpdate(query));
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<UpdateResultSet> sendUpdateAsync(String query)
throws MonetDBEmbeddedException {
+ return CompletableFuture.supplyAsync(() -> this.sendUpdate(query));
}*/
/**
@@ -139,9 +138,8 @@ public class MonetDBEmbeddedConnection {
* @return The query result object
* @throws MonetDBEmbeddedException If an error in the database occurred
*/
- /*public QueryResultSet sendQueryAsync(String query) throws
MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() -> this.sendQuery(query));
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<QueryResultSet> sendQueryAsync(String query)
throws MonetDBEmbeddedException {
+ return CompletableFuture.supplyAsync(() -> this.sendQuery(query));
}*/
/**
@@ -165,9 +163,8 @@ public class MonetDBEmbeddedConnection {
* @return An instance of EmbeddedPreparedStatement
* @throws MonetDBEmbeddedException If an error in the database occurred
*/
- /*public EmbeddedPreparedStatement createPreparedStatementAsync(String
query) throws MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() ->
this.createPreparedStatement(query));
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<EmbeddedPreparedStatement>
createPreparedStatementAsync(String query) throws MonetDBEmbeddedException {
+ return CompletableFuture.supplyAsync(() ->
this.createPreparedStatement(query));
}*/
/**
@@ -192,9 +189,8 @@ public class MonetDBEmbeddedConnection {
* @return A MonetDBTable instance with column details
* @throws MonetDBEmbeddedException If an error in the database occurred
*/
- /*public MonetDBTable getMonetDBTableAsync(String schemaName, String
tableName) throws MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() -> this.getMonetDBTable(schemaName,
tableName));
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<MonetDBTable> getMonetDBTableAsync(String
schemaName, String tableName) throws MonetDBEmbeddedException {
+ return CompletableFuture.supplyAsync(() ->
this.getMonetDBTable(schemaName, tableName));
}*/
/**
@@ -266,9 +262,8 @@ public class MonetDBEmbeddedConnection {
/**
* Shuts down this connection asynchronously. Any pending queries
connections will be immediately closed as well.
*/
- /*public void closeConnectionAsync() {
- CompletableFuture.supplyAsync(() -> this.closeConnection());
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<Void> closeConnectionAsync() {
+ return CompletableFuture.runAsync(() -> this.closeConnection());
}*/
/**
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
--- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
@@ -48,10 +48,9 @@ public class MonetDBEmbeddedDatabase {
* @return A MonetDBEmbeddedDatabase instance
* @throws MonetDBEmbeddedException If the JNI library has not been loaded
yet or an error in the database occurred
*/
- /*public static MonetDBEmbeddedDatabase StartDatabaseAsync(String
dbDirectory, boolean silentFlag,
+ /*public static CompletableFuture<MonetDBEmbeddedDatabase>
StartDatabaseAsync(String dbDirectory, boolean silentFlag,
boolean
sequentialFlag) throws MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() -> StartDatabase(dbDirectory,
silentFlag, sequentialFlag));
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ return CompletableFuture.supplyAsync(() -> StartDatabase(dbDirectory,
silentFlag, sequentialFlag));
}*/
private final String databaseDirectory;
@@ -127,9 +126,8 @@ public class MonetDBEmbeddedDatabase {
*
* @throws MonetDBEmbeddedException If the database is not running or an
error in the database occurred
*/
- /*public void stopDatabaseAsync() throws MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() -> this.stopDatabase());
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<Void> stopDatabaseAsync() throws
MonetDBEmbeddedException {
+ return CompletableFuture.runAsync(() -> this.stopDatabase());
}*/
/**
@@ -148,9 +146,8 @@ public class MonetDBEmbeddedDatabase {
* @return A MonetDBEmbeddedConnection instance
* @throws MonetDBEmbeddedException If the database is not running or an
error in the database occurred
*/
- /*public MonetDBEmbeddedConnection createConnectionAsync() throws
MonetDBEmbeddedException {
- CompletableFuture.supplyAsync(() -> this.createConnectionInternal());
- throw new UnsupportedOperationException("Must wait for Java 8 :(");
+ /*public CompletableFuture<MonetDBEmbeddedConnection>
createConnectionAsync() throws MonetDBEmbeddedException {
+ return CompletableFuture.supplyAsync(() ->
this.createConnectionInternal());
}*/
/**
diff --git a/src/main/java/nl/cwi/monetdb/embedded/mapping/AbstractRowSet.java
b/src/main/java/nl/cwi/monetdb/embedded/mapping/AbstractRowSet.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/mapping/AbstractRowSet.java
@@ -0,0 +1,35 @@
+package nl.cwi.monetdb.embedded.mapping;
+
+/**
+ * A row set retrieved from an embedded MonetDB query result. All the values
in this set are already mapped
+ * to Java classes a priori.
+ *
+ * @author <a href="mailto:[email protected]">Pedro
Ferreira</a>
+ */
+public abstract class AbstractRowSet {
+
+ /**
+ * The MonetDB-To-Java mappings of the columns.
+ */
+ protected final MonetDBToJavaMapping[] mappings;
+
+ /**
+ * The rows of this set.
+ */
+ protected final MonetDBRow[] rows;
+
+ protected AbstractRowSet(MonetDBToJavaMapping[] mappings, Object[][] rows)
{
+ this.mappings = mappings;
+ this.rows = new MonetDBRow[mappings.length];
+ for(int i = 0 ; i < mappings.length ; i++) {
+ this.rows[i] = new MonetDBRow(this, rows[i]);
+ }
+ }
+
+ /**
+ * Gets the number of columns in this set.
+ *
+ * @return The number of columns in this set
+ */
+ public int getNumberOfColumns() { return mappings.length; }
+}
diff --git a/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBRow.java
b/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBRow.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBRow.java
@@ -0,0 +1,107 @@
+package nl.cwi.monetdb.embedded.mapping;
+
+import java.util.Arrays;
+import java.util.ListIterator;
+
+/**
+ * A single MonetDB row in a result set.
+ *
+ * @author <a href="mailto:[email protected]">Pedro
Ferreira</a>
+ */
+public class MonetDBRow implements Iterable {
+
+ /**
+ * The original row result set from this row.
+ */
+ private final AbstractRowSet originalSet;
+
+ /**
+ * The columns values as Java objects.
+ */
+ private Object[] columns;
+
+ protected MonetDBRow(AbstractRowSet originalSet, Object[] columns) {
+ this.originalSet = originalSet;
+ this.columns = columns;
+ }
+
+ /**
+ * Gets the original row result set from this row.
+ *
+ * @return The original row result set from this row
+ */
+ public AbstractRowSet getOriginalSet() { return originalSet; }
+
+ /**
+ * Gets the columns values as Java objects.
+ *
+ * @return The columns values as Java objects
+ */
+ public Object[] getAllColumns() { return columns; }
+
+ /**
+ * Sets all columns values as Java objects.
+ *
+ * @param values An object array of the elements to update
+ */
+ public void setAllColumns(Object[] values) {
+ if(values.length != this.columns.length)
+ throw new ArrayStoreException("The values array and the columns
length differ!");
+ this.columns = values;
+ }
+
+ /**
+ * Gets the number of columns.
+ *
+ * @return The number of columns
+ */
+ public int getNumberOfColumns() { return columns.length; }
+
+ /**
+ * Gets a column value as a Java class.
+ *
+ * @param <T> A Java class mapped to a MonetDB data type
+ * @param index The index of the column
+ * @param javaClass The Java class
+ * @return The column value as a Java class
+ */
+ public <T> T getColumn(int index, Class<T> javaClass) { return
javaClass.cast(columns[index]); }
+
+ /**
+ * Gets a column value as a Java class using the default mapping.
+ *
+ * @param <T> A Java class mapped to a MonetDB data type
+ * @param index The index of the column
+ * @return The column value as a Java class
+ */
+ public <T> T getColumn(int index) {
+ Class<T> javaClass = this.originalSet.mappings[index].getJavaClass();
+ return javaClass.cast(columns[index]);
+ }
+
+ /**
+ * Sets a column value as a Java class.
+ *
+ * @param <T> A Java class mapped to a MonetDB data type
+ * @param index The index of the column
+ * @param value The value to set
+ */
+ public <T> void setColumn(int index, T value) {
+ this.columns[index] =
this.originalSet.mappings[index].getJavaClass().cast(value);
+ }
+
+ /**
+ * Sets a column value as a Java class.
+ *
+ * @param <T> A Java class mapped to a MonetDB data type
+ * @param index The index of the column
+ * @param javaClass The Java class
+ * @param value The value to set
+ */
+ public <T> void setColumn(int index, Class<T> javaClass, T value) {
+ this.columns[index] = javaClass.cast(value);
+ }
+
+ @Override
+ public ListIterator<Object> iterator() { return
Arrays.asList(this.columns).listIterator(); }
+}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java
---
a/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java
+++
b/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java
@@ -414,7 +414,7 @@ public class EmbeddedPreparedStatement {
* @return The update result object
* @throws MonetDBEmbeddedException If an error in the database occurred
or if a parameter has not been set yet
*/
- /*public UpdateResultSet sendUpdateAsync() throws MonetDBEmbeddedException
{
+ /*public CompletableFuture<UpdateResultSet> sendUpdateAsync() throws
MonetDBEmbeddedException {
return this.connection.sendUpdateAsync(this.applyParameters());
}*/
@@ -424,7 +424,7 @@ public class EmbeddedPreparedStatement {
* @return The query result object
* @throws MonetDBEmbeddedException If an error in the database occurred
or if a parameter has not been set yet
*/
- /*public QueryResultSet sendQueryAsync() throws MonetDBEmbeddedException {
+ /*public CompletableFuture<QueryResultSet> sendQueryAsync() throws
MonetDBEmbeddedException {
return this.connection.sendQueryAsync(this.applyParameters());
}*/
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetRows.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultRowSet.java
rename from
src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetRows.java
rename to src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultRowSet.java
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetRows.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultRowSet.java
@@ -8,6 +8,8 @@
package nl.cwi.monetdb.embedded.resultset;
+import nl.cwi.monetdb.embedded.mapping.AbstractRowSet;
+import nl.cwi.monetdb.embedded.mapping.MonetDBRow;
import nl.cwi.monetdb.embedded.mapping.MonetDBToJavaMapping;
import java.lang.reflect.Array;
@@ -15,106 +17,20 @@ import java.util.Arrays;
import java.util.ListIterator;
/**
- * A row set retrieved from an embedded MonetDB query result. All the values
in this set are already mapped
- * to Java classes a priori.
+ * The row result set from a sendQuery.
*
* @author <a href="mailto:[email protected]">Pedro
Ferreira</a>
*/
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list