Changeset: 068ec5964f28 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=068ec5964f28
Added Files:
        src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java
        src/main/java/nl/cwi/monetdb/embedded/AbstractQueryResultSet.java
        src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java
        src/main/java/nl/cwi/monetdb/embedded/EmbeddedPreparedStatement.java
        src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedException.java
        src/main/java/nl/cwi/monetdb/embedded/MonetDBToJavaMapping.java
        src/main/java/nl/cwi/monetdb/embedded/QueryResultSet.java
        src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java
        src/main/java/nl/cwi/monetdb/embedded/QueryRowsResultSet.java
        src/main/java/nl/cwi/monetdb/embedded/UpdateResultSet.java
Removed Files:
        src/main/java/nl/cwi/monetdb/embedded/EmbeddedQueryResult.java
        src/main/java/nl/cwi/monetdb/embedded/column/BigintColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/BlobColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/BooleanColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/CharColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/ClobColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/Column.java
        src/main/java/nl/cwi/monetdb/embedded/column/DateColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/DecimalColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/DoubleColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/GeometryColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/HugeintColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/InetColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/IntColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/JSONColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/MonthIntervalColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/RealColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/SecondIntervalColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/SmallintColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/TimeColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/TimestampColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/TinyintColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/URLColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/UUIDColumn.java
        src/main/java/nl/cwi/monetdb/embedded/column/VarcharColumn.java
        src/main/java/nl/cwi/monetdb/embedded/types/MonetDBEmbeddedBlob.java
Modified Files:
        src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedConnection.java
        src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedDatabase.java
        src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedInstance.java
Branch: embedded
Log Message:

Major cleaning on the Embedded code. Added support for prepared statements, 
fetching rows, mapping results into Java Classes incrementally and future async 
support.


diffs (truncated from 3568 to 300 lines):

diff --git a/src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java 
b/src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java
@@ -0,0 +1,116 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2016 MonetDB B.V.
+ */
+
+package nl.cwi.monetdb.embedded;
+
+/**
+ * A single Java representation of a MonetDB column.
+ *
+ * @param <T> A Java class mapped to a MonetDB data type
+ * @author <a href="mailto:pedro.ferre...@monetdbsolutions.com";>Pedro 
Ferreira</a>
+ */
+public abstract class AbstractColumn<T> implements Iterable<T> {
+
+    /**
+     * The pointer to the corresponding AbstractQueryResultSet
+     */
+    protected final long resultSetPointer;
+
+    /**
+     * Index on the AbstractQueryResultSet
+     */
+    protected final int resultSetIndex;
+
+    /**
+     * The number of rows in this column
+     */
+    protected final int numberOfRows;
+
+    /**
+     * The name of the columns in the query result
+     */
+    protected final String columnName;
+
+    /**
+     * The Mapping between MonetDB type and the Java Class
+     */
+    protected final MonetDBToJavaMapping mapping;
+
+    /**
+     * The number of digits (radix 2) for numeric types or max length for 
character/binary strings.
+     */
+    protected final int columnDigits;
+
+    /**
+     *         The precision after decimal point. Only applicable for 
decimal/numeric types.
+     */
+    protected final int columnScale;
+
+    protected AbstractColumn(long resultSetPointer, int resultSetIndex, int 
numberOfRows, String columnName,
+                             String columnType, int columnDigits, int 
columnScale) {
+        this.resultSetPointer = resultSetPointer;
+        this.resultSetIndex = resultSetIndex;
+        this.numberOfRows = numberOfRows;
+        this.columnName = columnName;
+        this.mapping = Enum.valueOf(MonetDBToJavaMapping.class, columnType);
+        this.columnDigits = columnDigits;
+        this.columnScale = columnScale;
+    }
+
+    /**
+     * Get the number of rows in this column
+     *
+     * @return The number of rows
+     */
+    public int getNumberOfRows() { return numberOfRows; }
+
+    /**
+     * Get the result set index of the column.
+     *
+     * @return The index number
+     */
+    public int getResultSetIndex() { return resultSetIndex; }
+
+    /**
+     * Get the name of the column.
+     *
+     * @return The column name
+     */
+    public String getColumnName() {
+        return columnName;
+    }
+
+    /**
+     * Get the type of the column.
+     *
+     * @return The Column type
+     */
+    public String getColumnType() { return mapping.toString(); }
+
+    /**
+     * Get the Java mapping of the column.
+     *
+     * @return A enum constant of the Java mapping
+     */
+    public MonetDBToJavaMapping getMapping() { return mapping; }
+
+    /**
+     * Get column digits of the column.
+     *
+     * @return The number of digits
+     */
+    public int getColumnDigits() { return columnDigits; }
+
+    /**
+     * Get scale of the column.
+     *
+     * @return The scale
+     */
+    public int getColumnScale() { return columnScale; }
+
+}
diff --git a/src/main/java/nl/cwi/monetdb/embedded/AbstractQueryResultSet.java 
b/src/main/java/nl/cwi/monetdb/embedded/AbstractQueryResultSet.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/AbstractQueryResultSet.java
@@ -0,0 +1,155 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2016 MonetDB B.V.
+ */
+
+package nl.cwi.monetdb.embedded;
+
+/**
+ * The result set from a sendQuery method from a connection.
+ *
+ * @author <a href="mailto:pedro.ferre...@monetdbsolutions.com";>Pedro 
Ferreira</a>
+ */
+public abstract class AbstractQueryResultSet extends AbstractStatementResult 
implements Iterable {
+
+    /**
+     * The number of columns in the query result.
+     */
+    protected final int numberOfColumns;
+
+    /**
+     * The number of rows in the query result.
+     */
+    protected final int numberOfRows;
+
+    protected AbstractQueryResultSet(MonetDBEmbeddedConnection connection, 
long resultPointer, int numberOfColumns,
+                                     int numberOfRows) {
+        super(connection, resultPointer);
+        this.numberOfColumns = numberOfColumns;
+        this.numberOfRows = numberOfRows;
+    }
+
+    /**
+     * Get the query set column values as an Iterable.
+     *
+     * @return An Iterable over the columns
+     */
+    protected abstract Iterable<AbstractColumn<?>> getIterable();
+
+    /**
+     * Returns the number of columns in the result set.
+     *
+     * @return Number of columns
+     */
+    public int getNumberOfColumns() {
+        return this.numberOfColumns;
+    }
+
+    /**
+     * Returns the number of rows in the result set.
+     *
+     * @return Number of rows
+     */
+    public int getNumberOfRows() {
+        return this.numberOfRows;
+    }
+
+    /**
+     * Get the columns names as a string array.
+     *
+     * @return The columns names array
+     */
+    public String[] getColumnNames() {
+        int i = 0;
+        String[] result = new String[this.numberOfColumns];
+        for(AbstractColumn col : this.getIterable()) {
+            result[i] = col.getColumnName();
+        }
+        return result;
+    }
+
+    /**
+     * Get the columns types as a string array.
+     *
+     * @return The columns types array
+     */
+    public String[] getColumnTypes() {
+        int i = 0;
+        String[] result = new String[this.numberOfColumns];
+        for(AbstractColumn col : this.getIterable()) {
+            result[i] = col.getColumnType();
+        }
+        return result;
+    }
+
+    /**
+     * Get the Java mappings as a MonetDBToJavaMapping array.
+     *
+     * @return The columns MonetDBToJavaMapping array
+     */
+    public MonetDBToJavaMapping[] getMappings() {
+        int i = 0;
+        MonetDBToJavaMapping[] result = new 
MonetDBToJavaMapping[this.numberOfColumns];
+        for(AbstractColumn col : this.getIterable()) {
+            result[i] = col.getMapping();
+        }
+        return result;
+    }
+
+    /**
+     * Get the columns digits as a int array.
+     *
+     * @return The columns digits array
+     */
+    public int[] getColumnDigits() {
+        int i = 0;
+        int[] result = new int[this.numberOfColumns];
+        for(AbstractColumn col : this.getIterable()) {
+            result[i] = col.getColumnDigits();
+        }
+        return result;
+    }
+
+    /**
+     * Get the columns scales as a int array.
+     *
+     * @return The columns scales array
+     */
+    public int[] getColumnScales() {
+        int i = 0;
+        int[] result = new int[this.numberOfColumns];
+        for(AbstractColumn col : this.getIterable()) {
+            result[i] = col.getColumnScale();
+        }
+        return result;
+    }
+
+    /**
+     * Get a columns' values from the result set by index.
+     *
+     * @param index QueryResultSetColumn index (starting from 0)
+     * @return The columns, {@code null} if index not in bounds
+     */
+    public abstract <T> QueryResultSetColumn<T> getColumn(int index);
+
+    /**
+     * Get a columns from the result set by name.
+     *
+     * @param name QueryResultSetColumn name
+     * @return The columns
+     */
+    public <T> QueryResultSetColumn<T> getColumn(String name) {
+        int index = 0;
+        for (AbstractColumn col : this.getIterable()) {
+            if (col.getColumnName().equals(name)) {
+                return this.getColumn(index);
+            }
+            index++;
+        }
+        throw new ArrayIndexOutOfBoundsException("The columns is not present 
in the result set!");
+    }
+
+}
diff --git a/src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java 
b/src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java
@@ -0,0 +1,64 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2016 MonetDB B.V.
+ */
+
+package nl.cwi.monetdb.embedded;
+
+import java.io.Closeable;
+
+/**
+ * The base class for a query result.
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to