From fa1d5b99fa00d2428ed7152404126d57399998e4 Mon Sep 17 00:00:00 2001 From: Sylvain Palominos Date: Wed, 13 Nov 2019 10:13:50 +0100 Subject: [PATCH 1/3] Fix column getting on emtpy table and ass column filtering on JdbcTables --- .../datamanagerapi/dataset/IJdbcTable.java | 3 +- .../datamanagerapi/dsl/IColumnsBuilder.java | 59 +++++++++++++++++++ .../dataset/IJdbcTableTest.java | 2 + .../org/orbisgis/datamanager/JdbcTable.java | 52 ++++++++++++---- .../dsl/ConditionOrOptionBuilder.java | 2 +- .../orbisgis/datamanager/JdbcTableTest.java | 37 +++++++++++- 6 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dsl/IColumnsBuilder.java diff --git a/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dataset/IJdbcTable.java b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dataset/IJdbcTable.java index cf8d7ee2..fff5403a 100644 --- a/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dataset/IJdbcTable.java +++ b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dataset/IJdbcTable.java @@ -37,6 +37,7 @@ package org.orbisgis.datamanagerapi.dataset; import groovy.lang.Closure; +import org.orbisgis.datamanagerapi.dsl.IColumnsBuilder; import org.orbisgis.datamanagerapi.dsl.IWhereBuilderOrOptionBuilder; import java.sql.ResultSet; @@ -48,7 +49,7 @@ * Extension of the {@link ITable} specially dedicated to the JDBC databases thanks to the extension of the * {@link ResultSet} interface. It also extends the {@link IWhereBuilderOrOptionBuilder} for the SQL requesting */ -public interface IJdbcTable extends ITable, ResultSet, IWhereBuilderOrOptionBuilder { +public interface IJdbcTable extends ITable, ResultSet, IWhereBuilderOrOptionBuilder, IColumnsBuilder { /** {@link String} name of the metadata property */ String META_PROPERTY = "meta"; diff --git a/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dsl/IColumnsBuilder.java b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dsl/IColumnsBuilder.java new file mode 100644 index 00000000..915f2d0e --- /dev/null +++ b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/dsl/IColumnsBuilder.java @@ -0,0 +1,59 @@ +/* + * Bundle DataManager API is part of the OrbisGIS platform + * + * OrbisGIS is a java GIS application dedicated to research in GIScience. + * OrbisGIS is developed by the GIS group of the DECIDE team of the + * Lab-STICC CNRS laboratory, see . + * + * The GIS group of the DECIDE team is located at : + * + * Laboratoire Lab-STICC – CNRS UMR 6285 + * Equipe DECIDE + * UNIVERSITÉ DE BRETAGNE-SUD + * Institut Universitaire de Technologie de Vannes + * 8, Rue Montaigne - BP 561 56017 Vannes Cedex + * + * DataManager API is distributed under GPL 3 license. + * + * Copyright (C) 2019 CNRS (Lab-STICC UMR CNRS 6285) + * + * + * DataManager API is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * DataManager API is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * DataManager API. If not, see . + * + * For more information, please consult: + * or contact directly: + * info_at_ orbisgis.org + */ +package org.orbisgis.datamanagerapi.dsl; + +import org.orbisgis.datamanagerapi.dataset.ITable; + +/** + * Interface defining methods for the SQL 'select ... from' building. The request construction can be continued thanks to the + * {@link IWhereBuilderOrOptionBuilder} or its result can be get calling 'eachRow' to iterate on the resultSet or + * 'as ITable' to get the {@link ITable} object + * + * @author Erwan Bocher (CNRS) + * @author Sylvain PALOMINOS (UBS 2019) + */ +public interface IColumnsBuilder { + + /** + * Indicates the columns use for the selection. + * + * @param columns Array of the columns use for the selection. + * + * @return {@link IWhereBuilderOrOptionBuilder} instance to continue building. + */ + IWhereBuilderOrOptionBuilder columns(String... columns); +} diff --git a/data-manager-api/src/test/java/org/orbisgis/datamanagerapi/dataset/IJdbcTableTest.java b/data-manager-api/src/test/java/org/orbisgis/datamanagerapi/dataset/IJdbcTableTest.java index f2d05a72..648073d1 100644 --- a/data-manager-api/src/test/java/org/orbisgis/datamanagerapi/dataset/IJdbcTableTest.java +++ b/data-manager-api/src/test/java/org/orbisgis/datamanagerapi/dataset/IJdbcTableTest.java @@ -40,6 +40,7 @@ import org.junit.jupiter.api.Test; import org.orbisgis.datamanagerapi.dsl.IConditionOrOptionBuilder; import org.orbisgis.datamanagerapi.dsl.IOptionBuilder; +import org.orbisgis.datamanagerapi.dsl.IWhereBuilderOrOptionBuilder; import javax.sql.rowset.RowSetMetaDataImpl; import java.io.InputStream; @@ -454,5 +455,6 @@ private void getPrivateMethod(){/*Does nothing*/} @Override public Object asType(Class clazz) {return null;} @Override public ITable getTable() {return null;} @Override public ISpatialTable getSpatialTable() {return null;} + @Override public IWhereBuilderOrOptionBuilder columns(String... columns) {return null;} } } diff --git a/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java b/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java index 067e7e51..adcfed00 100644 --- a/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java +++ b/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java @@ -53,6 +53,7 @@ import org.orbisgis.datamanagerapi.dataset.*; import org.orbisgis.datamanagerapi.dsl.IConditionOrOptionBuilder; import org.orbisgis.datamanagerapi.dsl.IOptionBuilder; +import org.orbisgis.datamanagerapi.dsl.IWhereBuilderOrOptionBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +62,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.*; +import java.util.stream.Collectors; import static org.orbisgis.commons.printer.ICustomPrinter.CellPosition.*; @@ -138,18 +140,24 @@ protected ResultSet getResultSet(){ } /** - * Return the {@link ResultSet} with a limit set to 1. + * Return the {@link ResultSet} with a limit. * - * @return The {@link ResultSet} with a limit set to 1. + * @param limit Limit of the result set. + * + * @return The {@link ResultSet} with a limit. */ - protected ResultSet getResultSetLimit1(){ + protected ResultSet getResultSetLimit(int limit){ + if(limit < 0){ + LOGGER.warn("The ResultSet limit should not be under 0. Set it to 0."); + limit = 0; + } ResultSet resultSet; try { if(getBaseQuery().contains(" LIMIT ")){ resultSet = getResultSet(); } else { - resultSet = jdbcDataSource.getConnection().createStatement().executeQuery(getBaseQuery() + " LIMIT 1"); + resultSet = jdbcDataSource.getConnection().createStatement().executeQuery(getBaseQuery() + " LIMIT " + limit); } } catch (SQLException e) { LOGGER.error("Unable to execute the query '"+getBaseQuery()+"'.\n"+e.getLocalizedMessage()); @@ -167,7 +175,7 @@ protected ResultSet getResultSetLimit1(){ @Override public ResultSetMetaData getMetaData(){ try { - ResultSet rs = getResultSetLimit1(); + ResultSet rs = getResultSetLimit(0); if(rs == null){ LOGGER.error("The ResultSet is null."); } @@ -237,7 +245,11 @@ public boolean isTemporary(){ @Override public Collection getColumnNames() { try { - return JDBCUtilities.getFieldNames(getResultSetLimit1().getMetaData()); + return JDBCUtilities + .getFieldNames(getResultSetLimit(0).getMetaData()) + .stream() + .map(this::formatColumnName) + .collect(Collectors.toCollection(ArrayList::new)); } catch (SQLException e) { LOGGER.error("Unable to get the collection of columns names"); return null; @@ -371,6 +383,15 @@ private String getQuery(){ return "SELECT * FROM " + getTableLocation().getTable().toUpperCase(); } + private String getQuery(String ... columns){ + return "SELECT " + String.join(", ", columns) + " FROM " + getTableLocation().getTable().toUpperCase(); + } + + @Override + public IWhereBuilderOrOptionBuilder columns(String... columns){ + return new WhereBuilder(getQuery(columns), getJdbcDataSource()); + } + @Override public IConditionOrOptionBuilder where(String condition) { return new WhereBuilder(getQuery(), getJdbcDataSource()).where(condition); @@ -419,7 +440,7 @@ public ISpatialTable getSpatialTable() { @Override public List getFirstRow(){ List list = new ArrayList<>(); - ResultSet rs = getResultSetLimit1(); + ResultSet rs = getResultSetLimit(1); try { if(rs.next()){ for(int i=1; i<=getColumnCount(); i++){ @@ -456,10 +477,10 @@ public Object getProperty(String propertyName) { Collection columns = getColumnNames(); if(columns!= null && (columns.contains(propertyName.toLowerCase()) || columns.contains(propertyName.toUpperCase())) - || "id".equals(propertyName)) { + || "id".equalsIgnoreCase(propertyName)) { try { - if(isBeforeFirst()){ - return new JdbcColumn(propertyName, this.getName(), getJdbcDataSource()); + if(isBeforeFirst() || (this.getRow() == 0 && this.getRowCount() == 0)){ + return new JdbcColumn(formatColumnName(propertyName), this.getName(), getJdbcDataSource()); } return getObject(propertyName); } catch (SQLException e) { @@ -531,4 +552,15 @@ else if(ISpatialTable.class.equals(clazz)) { } return null; } + + /** + * Format the column according to the DB type. + * + * @param column Columne name to format. + * + * @return The formatted column name. + */ + private String formatColumnName(String column){ + return getDbType()==DataBaseType.H2GIS ? column.toUpperCase() : column.toLowerCase(); + } } diff --git a/data-manager/src/main/java/org/orbisgis/datamanager/dsl/ConditionOrOptionBuilder.java b/data-manager/src/main/java/org/orbisgis/datamanager/dsl/ConditionOrOptionBuilder.java index 2195f04d..09637933 100644 --- a/data-manager/src/main/java/org/orbisgis/datamanager/dsl/ConditionOrOptionBuilder.java +++ b/data-manager/src/main/java/org/orbisgis/datamanager/dsl/ConditionOrOptionBuilder.java @@ -40,7 +40,7 @@ import org.orbisgis.datamanagerapi.dsl.IConditionOrOptionBuilder; /** - * Implementation of IConditionOrOptionBuilder + * Implementation of {@link IConditionOrOptionBuilder} * * @author Erwan Bocher (CNRS) * @author Sylvain PALOMINOS (UBS 2019) diff --git a/data-manager/src/test/java/org/orbisgis/datamanager/JdbcTableTest.java b/data-manager/src/test/java/org/orbisgis/datamanager/JdbcTableTest.java index 26737414..6e5e44df 100644 --- a/data-manager/src/test/java/org/orbisgis/datamanager/JdbcTableTest.java +++ b/data-manager/src/test/java/org/orbisgis/datamanager/JdbcTableTest.java @@ -90,18 +90,22 @@ public class JdbcTableTest { private static TableLocation linkedLocation; /** Temporary table location */ private static TableLocation tempLocation; + /** Empty table location */ + private static TableLocation emptyLocation; private static final String BASE_DATABASE = JdbcTableTest.class.getSimpleName(); private static final String TABLE_NAME = "ORBISGIS"; private static final String BASE_QUERY = "SELECT * FROM "+TABLE_NAME; private static final String TEMP_NAME = "TEMPTABLE"; private static final String TEMP_QUERY = "SELECT * FROM "+TEMP_NAME; + private static final String EMPTY_NAME = "ORBISGIS_EMPTY"; + private static final String EMPTY_QUERY = "SELECT * FROM "+EMPTY_NAME; private static final String LINKED_DATABASE = JdbcTableTest.class.getSimpleName()+"linked"; private static final String LINKED_NAME = "LINKEDTABLE"; private static final String LINKED_QUERY = "SELECT * FROM "+LINKED_NAME; private static final String COL_THE_GEOM = "THE_GEOM"; - private static final String COL_THE_GEOM2 = "THE_GEOM2"; + private static final String COL_THE_GEOM2 = "the_geom2"; private static final String COL_ID = "ID"; private static final String COL_VALUE = "VALUE"; private static final String COL_MEANING = "MEANING"; @@ -137,7 +141,7 @@ public void prepareDB(){ COL_ID+" INTEGER, "+COL_VALUE+" FLOAT, "+COL_MEANING+" VARCHAR)"); statement = connection.createStatement(); - statement.execute("DROP TABLE IF EXISTS "+TABLE_NAME+","+LINKED_NAME+","+TEMP_NAME); + statement.execute("DROP TABLE IF EXISTS "+TABLE_NAME+","+LINKED_NAME+","+TEMP_NAME+","+EMPTY_NAME); statement.execute("CREATE TABLE "+TABLE_NAME+" ("+COL_THE_GEOM+" GEOMETRY, "+COL_THE_GEOM2+" GEOMETRY(POINT Z)," + COL_ID+" INTEGER, "+COL_VALUE+" FLOAT, "+COL_MEANING+" VARCHAR)"); statement.execute("INSERT INTO "+TABLE_NAME+" VALUES ('POINT(0 0)', 'POINT(1 1 0)', 1, 2.3, 'Simple points')"); @@ -146,10 +150,13 @@ public void prepareDB(){ "','sa','sa','"+TABLE_NAME+"')"); statement.execute("CREATE TEMPORARY TABLE "+TEMP_NAME+" ("+COL_THE_GEOM+" GEOMETRY, "+COL_THE_GEOM2+" GEOMETRY(POINT Z)," + COL_ID+" INTEGER, "+COL_VALUE+" FLOAT, "+COL_MEANING+" VARCHAR)"); + statement.execute("CREATE TABLE "+EMPTY_NAME+" ("+COL_THE_GEOM+" GEOMETRY, "+COL_THE_GEOM2+" GEOMETRY(POINT Z)," + + COL_ID+" INTEGER, "+COL_VALUE+" FLOAT, "+COL_MEANING+" VARCHAR)"); tableLocation = new TableLocation(BASE_DATABASE, TABLE_NAME); linkedLocation = new TableLocation(BASE_DATABASE, LINKED_NAME); tempLocation = new TableLocation(BASE_DATABASE, TEMP_NAME); + emptyLocation = new TableLocation(BASE_DATABASE, EMPTY_NAME); } catch (Exception e) { fail(e); } @@ -179,6 +186,14 @@ private DummyJdbcTable getTempTable(){ return new DummyJdbcTable(DataBaseType.H2GIS, dataSource, tempLocation, statement, TEMP_QUERY); } + /** + * Returns an empty {@link DummyJdbcTable} for test purpose. + * @return An empty {@link DummyJdbcTable} for test purpose. + */ + private DummyJdbcTable getEmptyTable(){ + return new DummyJdbcTable(DataBaseType.H2GIS, dataSource, emptyLocation, statement, EMPTY_QUERY); + } + /** * Test the {@link JdbcTable#JdbcTable(DataBaseType, JdbcDataSource, TableLocation, Statement, String)} constructor. */ @@ -459,6 +474,21 @@ public void testGetProperty(){ assertNull(table.getProperty(null)); assertTrue(table.getProperty("meaning") instanceof JdbcColumn); assertEquals("MEANING", ((JdbcColumn)table.getProperty("meaning")).getName()); + assertTrue(table.getProperty(COL_THE_GEOM.toUpperCase()) instanceof JdbcColumn); + assertTrue(table.getProperty(COL_THE_GEOM.toLowerCase()) instanceof JdbcColumn); + + JdbcTable empty = getEmptyTable(); + assertDoesNotThrow(empty::beforeFirst); + assertThrows(MissingPropertyException.class, () -> empty.getProperty("getLocation")); + assertEquals(empty.getLocation(), empty.getProperty("location")); + assertEquals(JdbcResultSetMetaData.class, empty.getProperty("meta").getClass()); + assertArrayEquals(new Object[]{"string", 0.2}, (Object[])empty.getProperty("data")); + assertEquals("tutu", empty.getProperty("privateData")); + assertNull(empty.getProperty(null)); + assertTrue(empty.getProperty("meaning") instanceof JdbcColumn); + assertEquals("MEANING", ((JdbcColumn)empty.getProperty("meaning")).getName()); + assertTrue(empty.getProperty(COL_THE_GEOM.toUpperCase()) instanceof JdbcColumn); + assertTrue(empty.getProperty(COL_THE_GEOM.toLowerCase()) instanceof JdbcColumn); } /** @@ -500,7 +530,7 @@ public void testGetColumnsType() { @Test public void testGetColumns() { Map map = getTable().getColumns(); - String[] keys = {COL_THE_GEOM2, COL_THE_GEOM, COL_ID, COL_VALUE, COL_MEANING}; + String[] keys = {COL_THE_GEOM2.toUpperCase(), COL_THE_GEOM, COL_ID, COL_VALUE, COL_MEANING}; String[] values = {"POINTZ", "GEOMETRY", "INTEGER", "DOUBLE", "VARCHAR"}; assertArrayEquals(keys, map.keySet().toArray()); assertArrayEquals(values, map.values().toArray()); @@ -515,6 +545,7 @@ public void testSqlBuilding() { map.put("toto", IOptionBuilder.Order.ASC); map.put("tata", IOptionBuilder.Order.DESC); + assertEquals("SELECT TOTO, tata, TIti FROM ORBISGIS WHERE toto", getTable().columns("TOTO", "tata", "TIti").where("toto").toString().trim()); assertEquals("SELECT * FROM ORBISGIS WHERE toto", getTable().where("toto").toString().trim()); assertEquals("SELECT * FROM ORBISGIS GROUP BY toto", getTable().groupBy("toto").toString().trim()); assertEquals("SELECT * FROM ORBISGIS GROUP BY toto, tata", getTable().groupBy("toto", "tata").toString().trim()); From 643ca8ec4be6f39f003464d55459da02eb1bc846 Mon Sep 17 00:00:00 2001 From: Sylvain Palominos Date: Wed, 13 Nov 2019 10:21:24 +0100 Subject: [PATCH 2/3] Fix javadoc. --- .../datasource/IJdbcDataSource.java | 74 ++++++++++++------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/datasource/IJdbcDataSource.java b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/datasource/IJdbcDataSource.java index ab302888..82e770d5 100644 --- a/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/datasource/IJdbcDataSource.java +++ b/data-manager-api/src/main/java/org/orbisgis/datamanagerapi/datasource/IJdbcDataSource.java @@ -63,7 +63,7 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { /** * Return the {@link ITable} contained by the database with the given name. If the table contains a geometric - * field, return a ISpatialTable. + * field, return a {@link ISpatialTable}. * * @param tableName Name of the requested table. * @@ -108,7 +108,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * Load a file into the database. * * @param filePath Path of the file. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(String filePath); @@ -117,7 +118,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param filePath Path of the file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(String filePath, boolean delete); @@ -126,7 +128,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param filePath Path of the file. * @param tableName Name of the table. - * @return + * + * @return The {@link ITable} containing the loaded data. */ ITable load(String filePath, String tableName); @@ -136,7 +139,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param filePath Path of the file. * @param tableName Name of the table. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(String filePath, String tableName, boolean delete); @@ -147,7 +151,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param tableName Name of the table * @param encoding Encoding of the loaded file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(String filePath, String tableName, String encoding, boolean delete); @@ -155,7 +160,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * Load a file into the database. * * @param url {@link URL} of the file. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URL url); @@ -164,7 +170,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param url {@link URL} of the file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URL url, boolean delete); @@ -173,7 +180,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param url {@link URL} of the file. * @param tableName Name of the table. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URL url, String tableName); @@ -183,7 +191,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param url {@link URL} of the file. * @param tableName Name of the table. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URL url, String tableName, boolean delete); @@ -194,7 +203,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param tableName Name of the table * @param encoding Encoding of the loaded file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URL url, String tableName, String encoding, boolean delete); @@ -202,7 +212,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * Load a file into the database. * * @param uri {@link URI} of the file. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URI uri); @@ -211,7 +222,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param uri {@link URI} of the file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URI uri, boolean delete); @@ -220,7 +232,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param uri {@link URI} of the file. * @param tableName Name of the table. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URI uri, String tableName); @@ -230,7 +243,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param uri {@link URI} of the file. * @param tableName Name of the table. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URI uri, String tableName, boolean delete); @@ -241,7 +255,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param tableName Name of the table * @param encoding Encoding of the loaded file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(URI uri, String tableName, String encoding, boolean delete); @@ -249,7 +264,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * Load a file into the database. * * @param file {@link File}. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(File file); @@ -258,7 +274,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param file {@link File}. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(File file, boolean delete); @@ -267,7 +284,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param file {@link File}. * @param tableName Name of the table. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(File file, String tableName); @@ -277,7 +295,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param file {@link File}. * @param tableName Name of the table. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(File file, String tableName, boolean delete); @@ -288,7 +307,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param tableName Name of the table * @param encoding Encoding of the loaded file. * @param delete True to delete the table if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(File file, String tableName, String encoding, boolean delete); @@ -297,7 +317,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * * @param properties Properties used to connect to the database. * @param inputTableName Name of the table to import. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(Map properties, String inputTableName); @@ -308,7 +329,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param properties Properties used to connect to the database. * @param inputTableName Name of the table to import. * @param outputTableName Name of the imported table in the database. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(Map properties, String inputTableName, String outputTableName); @@ -318,7 +340,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param properties Properties used to connect to the database. * @param inputTableName Name of the table to import. * @param delete True to delete the outputTableName if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(Map properties, String inputTableName, boolean delete); @@ -329,7 +352,8 @@ public interface IJdbcDataSource extends IDataSource, GroovyObject { * @param inputTableName Name of the table to import. * @param outputTableName Name of the imported table in the database. * @param delete True to delete the outputTableName if exists, false otherwise. - * @return a ITable + * + * @return The {@link ITable} containing the loaded data. */ ITable load(Map properties, String inputTableName, String outputTableName, boolean delete); From c97e20935535babc5dfdda720930f090c12a269c Mon Sep 17 00:00:00 2001 From: Sylvain Palominos Date: Wed, 13 Nov 2019 11:06:50 +0100 Subject: [PATCH 3/3] Imprive code quality. --- .../main/java/org/orbisgis/datamanager/JdbcTable.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java b/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java index 2746e4db..aa19307d 100644 --- a/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java +++ b/data-manager/src/main/java/org/orbisgis/datamanager/JdbcTable.java @@ -140,10 +140,11 @@ protected ResultSet getResultSet(){ * * @return The {@link ResultSet} with a limit. */ - protected ResultSet getResultSetLimit(int limit){ - if(limit < 0){ + private ResultSet getResultSetLimit(int limit){ + int _limit = limit; + if(_limit < 0){ LOGGER.warn("The ResultSet limit should not be under 0. Set it to 0."); - limit = 0; + _limit = 0; } ResultSet resultSet; try { @@ -151,7 +152,7 @@ protected ResultSet getResultSetLimit(int limit){ resultSet = getResultSet(); } else { - resultSet = jdbcDataSource.getConnection().createStatement().executeQuery(getBaseQuery() + " LIMIT " + limit); + resultSet = jdbcDataSource.getConnection().createStatement().executeQuery(getBaseQuery() + " LIMIT " + _limit); } } catch (SQLException e) { LOGGER.error("Unable to execute the query '"+getBaseQuery()+"'.\n"+e.getLocalizedMessage());