Mercurial > hg > monetdb-java
changeset 35:5e58809cfbed embedded
Removed unused class.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Tue, 01 Nov 2016 18:01:09 +0100 (2016-11-01) |
parents | 068ec5964f28 |
children | 18432f31d1e3 |
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/MonetDBEmbeddedInstance.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/QueryResultSetRows.java src/main/java/nl/cwi/monetdb/embedded/QueryRowsResultSet.java |
diffstat | 8 files changed, 378 insertions(+), 431 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java +++ b/src/main/java/nl/cwi/monetdb/embedded/AbstractColumn.java @@ -17,27 +17,22 @@ package nl.cwi.monetdb.embedded; public abstract class AbstractColumn<T> implements Iterable<T> { /** - * The pointer to the corresponding AbstractQueryResultSet - */ - protected final long resultSetPointer; - - /** - * Index on the AbstractQueryResultSet + * Index on the result set. */ protected final int resultSetIndex; /** - * The number of rows in this column + * The number of rows in this column. */ protected final int numberOfRows; /** - * The name of the columns in the query result + * The name of the columns in the query result. */ protected final String columnName; /** - * The Mapping between MonetDB type and the Java Class + * The Mapping between MonetDB type and the Java Class. */ protected final MonetDBToJavaMapping mapping; @@ -51,9 +46,8 @@ public abstract class AbstractColumn<T> */ protected final int columnScale; - protected AbstractColumn(long resultSetPointer, int resultSetIndex, int numberOfRows, String columnName, - String columnType, int columnDigits, int columnScale) { - this.resultSetPointer = resultSetPointer; + protected AbstractColumn(int resultSetIndex, int numberOfRows, String columnName, String columnType, + int columnDigits, int columnScale) { this.resultSetIndex = resultSetIndex; this.numberOfRows = numberOfRows; this.columnName = columnName; @@ -63,7 +57,7 @@ public abstract class AbstractColumn<T> } /** - * Get the number of rows in this column + * Get the number of rows in this column. * * @return The number of rows */
deleted file mode 100644 --- a/src/main/java/nl/cwi/monetdb/embedded/AbstractQueryResultSet.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.ferreira@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!"); - } - -}
--- a/src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java +++ b/src/main/java/nl/cwi/monetdb/embedded/AbstractStatementResult.java @@ -35,23 +35,21 @@ public abstract class AbstractStatementR } /** - * Get the corresponding connection to this statement result + * Get the corresponding connection to this statement result. * * @return A MonetDBEmbeddedConnection instance */ - public MonetDBEmbeddedConnection getConnection() { return connection;} + public MonetDBEmbeddedConnection getConnection() { return connection; } /** - * Tells if the connection of this statement result has been closed or not + * Tells if the connection of this statement result has been closed or not. * * @return A boolean indicating if the statement result has been cleaned or not */ - public boolean isStatementClosed() { - return this.resultPointer == 0; - } + public boolean isStatementClosed() { return this.resultPointer == 0; } /** - * Close the query data so no more new results can be retrieved + * Close the query data so no more new results can be retrieved. */ @Override public void close() {
--- a/src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedInstance.java +++ b/src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedInstance.java @@ -22,7 +22,7 @@ public class MonetDBEmbeddedInstance { private static final String NATIVE_LIB_NAME = "monetdb5"; /** - * Tries to load the JNI library with MonetDBLite from the current Java Classpath + * Tries to load the JNI library with MonetDBLite from the current Java Classpath. * * @param libraryName The library name, if null will load the default name "monetdb5" * @return A boolean indicating if the load was successful @@ -39,7 +39,7 @@ public class MonetDBEmbeddedInstance { } /** - * Tries to load the JNI library with MonetDBLite from the given path + * Tries to load the JNI library with MonetDBLite from the given path. * * @param libraryPath The full library path name * @return A boolean indicating if the load was successful @@ -56,7 +56,7 @@ public class MonetDBEmbeddedInstance { } /** - * Check if the JNI library with MonetDBLite has been loaded yet or not + * Check if the JNI library with MonetDBLite has been loaded yet or not. * * @return A boolean indicating if it is loaded */
--- a/src/main/java/nl/cwi/monetdb/embedded/QueryResultSet.java +++ b/src/main/java/nl/cwi/monetdb/embedded/QueryResultSet.java @@ -19,28 +19,117 @@ import java.util.ListIterator; * * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a> */ -public class QueryResultSet extends AbstractQueryResultSet { +public class QueryResultSet 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; /** - * The query result set columns listing + * The query result set columns listing. */ private final QueryResultSetColumn<?>[] columns; protected QueryResultSet(MonetDBEmbeddedConnection connection, long resultPointer, QueryResultSetColumn<?>[] columns, int numberOfRows) { - super(connection, resultPointer, columns.length, numberOfRows); + super(connection, resultPointer); + this.numberOfColumns = columns.length; + this.numberOfRows = numberOfRows; this.columns = columns; - this.resultPointer = resultPointer; } /** - * Get the query set column values as an Iterable. + * 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 An Iterable over the columns + * @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.columns) { + result[i] = col.getColumnName(); + } + return result; + } + + /** + * Get the columns types as a string array. + * + * @return The columns types array */ - @Override - protected Iterable<AbstractColumn<?>> getIterable() { - return Arrays.asList(columns); + public String[] getColumnTypes() { + int i = 0; + String[] result = new String[this.numberOfColumns]; + for(AbstractColumn col : this.columns) { + 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.columns) { + 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.columns) { + 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.columns) { + result[i] = col.getColumnScale(); + } + return result; } /** @@ -49,21 +138,37 @@ public class QueryResultSet extends Abst * @param index QueryResultSetColumn index (starting from 0) * @return The columns, {@code null} if index not in bounds */ - @Override @SuppressWarnings("unchecked") public <T> QueryResultSetColumn<T> getColumn(int index) { return (QueryResultSetColumn<T>) columns[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.columns) { + if (col.getColumnName().equals(name)) { + return this.getColumn(index); + } + index++; + } + throw new ArrayIndexOutOfBoundsException("The columns is not present in the result set!"); + } + + /** * Fetches rows from the result set. * * @param startIndex The first row index to retrieve * @param endIndex The last row index to retrieve - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchResultSetRows(int startIndex, int endIndex) throws MonetDBEmbeddedException { + public QueryResultSetRows fetchResultSetRows(int startIndex, int endIndex) throws MonetDBEmbeddedException { if(endIndex < startIndex) { int aux = startIndex; startIndex = endIndex; @@ -84,7 +189,7 @@ public class QueryResultSet extends Abst temp[j][i] = nextColumn[j]; } } - return new QueryRowsResultSet(this, this.getMappings(), temp); + return new QueryResultSetRows(this, this.getMappings(), temp); } /** @@ -92,10 +197,10 @@ public class QueryResultSet extends Abst * * @param startIndex The first row index to retrieve * @param endIndex The last row index to retrieve - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchResultSetRowsAsync(int startIndex, int endIndex) throws MonetDBEmbeddedException { + public QueryResultSetRows fetchResultSetRowsAsync(int startIndex, int endIndex) throws MonetDBEmbeddedException { /* CompletableFuture.supplyAsync(() -> this.fetchResultSetRows(startIndex, endIndex)); */ throw new UnsupportedOperationException("Must wait for Java 8 :("); } @@ -104,10 +209,10 @@ public class QueryResultSet extends Abst * Fetches the first N rows from the result set. * * @param n The last row index to retrieve - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchFirstNRowValues(int n) throws MonetDBEmbeddedException { + public QueryResultSetRows fetchFirstNRowValues(int n) throws MonetDBEmbeddedException { return this.fetchResultSetRows(0, n); } @@ -115,35 +220,35 @@ public class QueryResultSet extends Abst * Fetches the first N rows from the result set asynchronously. * * @param n The last row index to retrieve - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchFirstNRowValuesAsync(int n) throws MonetDBEmbeddedException { + public QueryResultSetRows fetchFirstNRowValuesAsync(int n) throws MonetDBEmbeddedException { return this.fetchResultSetRowsAsync(0, n); } /** * Fetches all rows from the result set. * - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchAllRowValues() throws MonetDBEmbeddedException { + public QueryResultSetRows fetchAllRowValues() throws MonetDBEmbeddedException { return this.fetchResultSetRows(0, this.numberOfRows); } /** * Fetches all rows from the result set asynchronously. * - * @return The rows as {@code QueryRowsResultSet} + * @return The rows as {@code QueryResultSetRows} * @throws MonetDBEmbeddedException If an error in the database occurred */ - public QueryRowsResultSet fetchAllRowValuesAsync() throws MonetDBEmbeddedException { + public QueryResultSetRows fetchAllRowValuesAsync() throws MonetDBEmbeddedException { return this.fetchResultSetRowsAsync(0, this.numberOfRows); } @Override - public ListIterator<QueryRowsResultSet.QueryResulSetSingleRow> iterator() { + public ListIterator<QueryResultSetRows.QueryResulSetRow> iterator() { try { return Arrays.asList(this.fetchAllRowValues().getAllRows()).listIterator(); } catch (MonetDBEmbeddedException ex) {
--- a/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java +++ b/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java @@ -22,6 +22,11 @@ import java.util.ListIterator; public class QueryResultSetColumn<T> extends AbstractColumn<T> { /** + * The C pointer of the result set of the column. + */ + protected final long resultSetPointer; + + /** * Array with the retrieved values. */ private final T[] values; @@ -37,9 +42,10 @@ public class QueryResultSetColumn<T> ext private int lastRetrievedIndex; @SuppressWarnings("unchecked") - protected QueryResultSetColumn(long resultSetPointer, int resultSetIndex, int numberOfRows, String columnName, - String columnType, int columnDigits, int columnScale) { - super(resultSetPointer, resultSetIndex, numberOfRows, columnName, columnType, columnDigits, columnScale); + protected QueryResultSetColumn(int resultSetIndex, int numberOfRows, String columnName, String columnType, + int columnDigits, int columnScale, long resultSetPointer) { + super(resultSetIndex, numberOfRows, columnName, columnType, columnDigits, columnScale); + this.resultSetPointer = resultSetPointer; this.firstRetrievedIndex = numberOfRows; this.lastRetrievedIndex = 0; this.values = (T[]) Array.newInstance(this.mapping.getJavaClass(), numberOfRows);
rename from src/main/java/nl/cwi/monetdb/embedded/QueryRowsResultSet.java rename to src/main/java/nl/cwi/monetdb/embedded/QueryResultSetRows.java --- a/src/main/java/nl/cwi/monetdb/embedded/QueryRowsResultSet.java +++ b/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetRows.java @@ -18,26 +18,26 @@ import java.util.ListIterator; * * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a> */ -public class QueryRowsResultSet implements Iterable { +public class QueryResultSetRows implements Iterable { /** * A single row in a result set. * * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a> */ - static public class QueryResulSetSingleRow implements Iterable { + static public class QueryResulSetRow implements Iterable { /** * The original row result set from this row. */ - private final QueryRowsResultSet resultSet; + private final QueryResultSetRows resultSet; /** * The columns values as Java objects. */ private final Object[] columns; - protected QueryResulSetSingleRow(QueryRowsResultSet resultSet, Object[] columns) { + protected QueryResulSetRow(QueryResultSetRows resultSet, Object[] columns) { this.resultSet = resultSet; this.columns = columns; } @@ -47,7 +47,7 @@ public class QueryRowsResultSet implemen * * @return The original row result set from this row */ - public QueryRowsResultSet getRowResultSet() { return resultSet; } + public QueryResultSetRows getRowResultSet() { return resultSet; } /** * Gets the columns values as Java objects. @@ -98,7 +98,7 @@ public class QueryRowsResultSet implemen /** * The original query result set this row set belongs. */ - private final AbstractQueryResultSet queryResultSet; + private final QueryResultSet queryResultSet; /** * The MonetDB-To-Java mappings of the columns. @@ -108,15 +108,14 @@ public class QueryRowsResultSet implemen /** * The rows of this set. */ - private final QueryResulSetSingleRow[] rows; + private final QueryResulSetRow[] rows; - protected QueryRowsResultSet(AbstractQueryResultSet queryResultSet, MonetDBToJavaMapping[] mappings, - Object[][] rows) { + protected QueryResultSetRows(QueryResultSet queryResultSet, MonetDBToJavaMapping[] mappings, Object[][] rows) { this.queryResultSet = queryResultSet; this.mappings = mappings; - this.rows = new QueryResulSetSingleRow[mappings.length]; + this.rows = new QueryResulSetRow[mappings.length]; for(int i = 0 ; i < mappings.length ; i++) { - this.rows[i] = new QueryResulSetSingleRow(this, rows[i]); + this.rows[i] = new QueryResulSetRow(this, rows[i]); } } @@ -125,7 +124,7 @@ public class QueryRowsResultSet implemen * * @return The original query result set this row set belongs */ - public AbstractQueryResultSet getQueryResultSet() { + public QueryResultSet getQueryResultSet() { return queryResultSet; } @@ -134,7 +133,7 @@ public class QueryRowsResultSet implemen * * @return All rows of this set */ - public QueryResulSetSingleRow[] getAllRows() { return rows; } + public QueryResulSetRow[] getAllRows() { return rows; } /** * Gets the number of rows in this set. @@ -156,7 +155,7 @@ public class QueryRowsResultSet implemen * @param row The index of the row to retrieve * @return A single row in this set */ - public QueryResulSetSingleRow getSingleRow(int row) { + public QueryResulSetRow getSingleRow(int row) { return rows[row]; } @@ -220,7 +219,7 @@ public class QueryRowsResultSet implemen } @Override - public ListIterator<QueryResulSetSingleRow> iterator() { + public ListIterator<QueryResulSetRow> iterator() { return Arrays.asList(this.rows).listIterator(); } }