Mercurial > hg > monetdb-java
changeset 43:2ab2b21cf930 embedded
Change some Java Class - BAT mappings
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Wed, 09 Nov 2016 16:54:19 +0100 (2016-11-09) |
parents | dfea8468cd1a |
children | cd6ff38c90f4 |
files | src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBEmbeddedBlob.java src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBToJavaMapping.java src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetColumn.java |
diffstat | 5 files changed, 25 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java +++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java @@ -10,7 +10,6 @@ package nl.cwi.monetdb.embedded.env; import nl.cwi.monetdb.embedded.resultset.*; import nl.cwi.monetdb.embedded.tables.MonetDBTable; -import nl.cwi.monetdb.embedded.tables.MonetDBTableColumn; import nl.cwi.monetdb.embedded.utils.StringEscaper; import java.util.HashSet; @@ -148,7 +147,7 @@ public class MonetDBEmbeddedConnection { /** * Creates a prepared query statement likewise the PreparedStatement in JDBC. * - * @param query The SQL query with ? indicating the parameters to replace in the query + * @param query The SQL query with '?' indicating the parameters to replace in the query * @return An instance of EmbeddedPreparedStatement * @throws MonetDBEmbeddedException If an error in the database occurred */ @@ -162,7 +161,7 @@ public class MonetDBEmbeddedConnection { /** * Creates a prepared query statement likewise the PreparedStatement in JDBC asynchronously. * - * @param query The SQL query with ? indicating the parameters to replace in the query + * @param query The SQL query with '?' indicating the parameters to replace in the query * @return An instance of EmbeddedPreparedStatement * @throws MonetDBEmbeddedException If an error in the database occurred */ @@ -176,37 +175,11 @@ public class MonetDBEmbeddedConnection { * * @param schemaName The schema of the table * @param tableName The name of the table - * @return A MonetDBTable instance with currentColumns details + * @return A MonetDBTable instance with column details * @throws MonetDBEmbeddedException If an error in the database occurred */ public MonetDBTable getMonetDBTable(String schemaName, String tableName) throws MonetDBEmbeddedException { - String qschemaName = StringEscaper.SQLStringEscape(schemaName); - String qtableName = StringEscaper.SQLStringEscape(tableName); - String query = "SELECT currentColumns.\"name\" AS column, currentColumns.\"type\", currentColumns.\"type_digits\", currentColumns.\"type_scale\", currentColumns.\"default\", currentColumns.\"null\" FROM (SELECT \"id\", \"table_id\", \"name\", \"type\", \"type_digits\", \"type_scale\", \"default\", \"null\", \"number\" FROM sys.currentColumns) AS currentColumns INNER JOIN (SELECT \"id\", \"schema_id\" FROM sys.tables WHERE name=" - + qtableName + ") AS tables ON (tables.\"id\"=currentColumns.\"table_id\") INNER JOIN (SELECT \"id\" FROM sys.schemas WHERE name=" - + qschemaName + ") AS schemas ON (tables.\"schema_id\"=schemas.\"id\") ORDER BY currentColumns.\"number\";"; - - QueryResultSet eqr = this.sendQuery(query); - int numberOfRows = eqr.getNumberOfRows(); - if(numberOfRows == 0) { - throw new MonetDBEmbeddedException("The table " + tableName + " on schema " + schemaName + " does not exist!"); - } - QueryResultSetRows rows = eqr.fetchAllRowValues(); - eqr.close(); - - MonetDBTableColumn<?>[] array = new MonetDBTableColumn<?>[numberOfRows]; - int i = 0; - for(QueryResultSetRows.QueryResulSetRow row : rows.getAllRows()) { - String columnName = row.getColumn(0); - String columnType = row.getColumn(1); - int ndigits = row.getColumn(2); - int nscale = row.getColumn(3); - String defaultValue = row.getColumn(4); - boolean isNullable = row.getColumn(5); - array[i] = new MonetDBTableColumn(i, columnName, columnType, ndigits, nscale, defaultValue, isNullable); - i++; - } - MonetDBTable res = new MonetDBTable(this, schemaName, tableName, array); + MonetDBTable res = this.getMonetDBTableInternal(this.connectionPointer, schemaName, tableName); results.add(res); return res; } @@ -216,7 +189,7 @@ public class MonetDBEmbeddedConnection { * * @param schemaName The schema of the table * @param tableName The name of the table - * @return A MonetDBTable instance with currentColumns details + * @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 { @@ -301,9 +274,7 @@ public class MonetDBEmbeddedConnection { /** * Removes a query result from this connection. */ - protected void removeQueryResult(AbstractConnectionResult res) { - this.results.remove(res); - } + protected void removeQueryResult(AbstractConnectionResult res) { this.results.remove(res); } /** * Internal implementation of sendUpdate. @@ -317,6 +288,12 @@ public class MonetDBEmbeddedConnection { private native QueryResultSet sendQueryInternal(long connectionPointer, String query, boolean execute) throws MonetDBEmbeddedException; + /** + * Internal implementation of getMonetDBTable. + */ + private native MonetDBTable getMonetDBTableInternal(long connectionPointer, String schemaName, String tableName) + throws MonetDBEmbeddedException; + /*private native EmbeddedPreparedStatement createPreparedStatementInternal(long connectionPointer, String query) throws MonetDBEmbeddedException;*/
--- a/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBEmbeddedBlob.java +++ b/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBEmbeddedBlob.java @@ -1,5 +1,6 @@ package nl.cwi.monetdb.embedded.mapping; +import java.io.Serializable; import java.util.Arrays; /** @@ -7,7 +8,7 @@ import java.util.Arrays; * * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a> */ -public class MonetDBEmbeddedBlob { +public class MonetDBEmbeddedBlob implements Serializable { /** * The BLOB's content as a Java byte array.
--- a/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBToJavaMapping.java +++ b/src/main/java/nl/cwi/monetdb/embedded/mapping/MonetDBToJavaMapping.java @@ -10,8 +10,8 @@ package nl.cwi.monetdb.embedded.mapping; import java.math.BigDecimal; import java.math.BigInteger; -import java.net.InetAddress; -import java.net.URI; +import java.net.Inet4Address; +import java.net.URL; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; @@ -30,7 +30,7 @@ public enum MonetDBToJavaMapping { Hugeint(BigInteger.class), Decimal(BigDecimal.class), Real(Float.class), Double(Double.class), MonthInterval(Integer.class), SecondInterval(Long.class), Time(Time.class), TimeTz(Time.class), Date(Date.class), Timestamp(Timestamp.class), TimestampTz(Timestamp.class), Blob(MonetDBEmbeddedBlob.class), - Geometry(MonetDBEmbeddedBlob.class), GeometryA(MonetDBEmbeddedBlob.class), URL(URI.class), Inet(InetAddress.class), + Geometry(MonetDBEmbeddedBlob.class), GeometryA(MonetDBEmbeddedBlob.class), URL(URL.class), Inet(Inet4Address.class), JSON(MonetDBEmbeddedBlob.class), UUID(UUID.class); /**
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java +++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/EmbeddedPreparedStatement.java @@ -17,8 +17,8 @@ import nl.cwi.monetdb.embedded.utils.Str import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; -import java.net.InetAddress; -import java.net.URI; +import java.net.Inet4Address; +import java.net.URL; import java.sql.PreparedStatement; import java.sql.Time; import java.sql.Timestamp; @@ -72,8 +72,8 @@ public class EmbeddedPreparedStatement { DirectMappingClasses.add(Float.class); DirectMappingClasses.add(Double.class); DirectMappingClasses.add(MonetDBEmbeddedBlob.class); - DirectMappingClasses.add(URI.class); - DirectMappingClasses.add(InetAddress.class); + DirectMappingClasses.add(URL.class); + DirectMappingClasses.add(Inet4Address.class); DirectMappingClasses.add(UUID.class); } @@ -366,6 +366,7 @@ public class EmbeddedPreparedStatement { /** * Creates the SQL String from the parsed parameters (adapted from the JDBC driver implementation). * + * @return The SQL statement with all parameters replaced * @throws MonetDBEmbeddedException If a parameter has not been set yet */ private String applyParameters() throws MonetDBEmbeddedException {
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetColumn.java +++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetColumn.java @@ -107,8 +107,7 @@ public class QueryResultSetColumn<T> ext throw new MonetDBEmbeddedException("Connection closed!"); } T[] newvalues = this.fetchValuesInternal(this.resultSetPointer, this.resultSetIndex, - (Class<T>) this.mapping.getJavaClass(), this.mapping.getJavaClass().getSimpleName(), - this.mapping.ordinal(), firstIndexToFetch, lastIndexToFetch); + (Class<T>) this.mapping.getJavaClass(), this.mapping.ordinal(), firstIndexToFetch, lastIndexToFetch); System.arraycopy(newvalues, 0, this.values, firstIndexToFetch, newvalues.length); } @@ -257,6 +256,6 @@ public class QueryResultSetColumn<T> ext /** * Internal implementation to fetch values from the column. */ - private native T[] fetchValuesInternal(long resultPointer, int resultSetIndex, Class<T> jclass, String className, - int enumEntry, int first, int last) throws MonetDBEmbeddedException; + private native T[] fetchValuesInternal(long resultPointer, int resultSetIndex, Class<T> jclass, int enumEntry, + int first, int last) throws MonetDBEmbeddedException; }