diff --git a/.github/workflows/CI build.yml b/.github/workflows/CI build.yml index 533a5934..348c1b28 100644 --- a/.github/workflows/CI build.yml +++ b/.github/workflows/CI build.yml @@ -18,11 +18,11 @@ jobs: steps: # Checkout the source code of the project - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Setup the jdk using version 11 of Adoptium Temurin - name: Setup java 11 using Adoptium Temurin - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/.github/workflows/CI release.yml b/.github/workflows/CI release.yml index 49823ca1..5ad4bf94 100644 --- a/.github/workflows/CI release.yml +++ b/.github/workflows/CI release.yml @@ -14,11 +14,11 @@ jobs: steps: # Checkout the source code of the project - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Setup the jdk using version 11 of Adoptium Temurin - name: Setup java 11 using Adoptium Temurin - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/.github/workflows/CI snapshot.yml b/.github/workflows/CI snapshot.yml index 460b9a07..ed8fb74e 100644 --- a/.github/workflows/CI snapshot.yml +++ b/.github/workflows/CI snapshot.yml @@ -17,11 +17,11 @@ jobs: steps: # Checkout the source code of the project - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Setup the jdk using version 11 of Adoptium Temurin - name: Setup java 11 using Adoptium Temurin - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IColumn.java b/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IColumn.java deleted file mode 100644 index 41a3efaf..00000000 --- a/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IColumn.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 LGPL 3 license. - * - * Copyright (C) 2019-2020 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.data.api.dataset; - - -/** - * Column of a {@link IDataSet}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (Lab-STICC UBS 2019) - */ -public interface IColumn { - - /** - * Returns the name of the column. If there isn't a name, returns an empty string. It the column name can't be - * get, return null. - * - * @return The name of the column. - */ - String getName(); - - /** - * Returns the sql type of the column. If there isn't a type, returns null. - * - * @return The sql type of the column. - */ - String getType(); - - /** - * Returns the number of values inside the column. If the size of the column can't be get, returns -1. - * - * @return The number of values inside the column. - */ - long getSize(); - - @Override - String toString(); - - /** - * Convert the current object into another with the given class. - * - * @param clazz New class of the result. - * @return The current object into an other class. - */ - Object asType(Class clazz); -} diff --git a/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IJdbcColumn.java b/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IJdbcColumn.java deleted file mode 100644 index 2ce421b5..00000000 --- a/data/data-api/src/main/java/org/orbisgis/data/api/dataset/IJdbcColumn.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 LGPL 3 license. - * - * Copyright (C) 2019-2020 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.data.api.dataset; - -/** - * Column of a {@link IJdbcTable}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (Lab-STICC UBS 2019) - */ -public interface IJdbcColumn extends IColumn { - - /** - * Return true if the column contains spatial data. - * - * @return True if the column contains spatial data. - */ - boolean isSpatial(); - - /** - * Return true if the column has an index, false otherwise. - * - * @return True if the column has an index, false otherwise. - */ - boolean isIndexed(); - - /** - * Return true if the column has a spatial index, false otherwise. - * - * @return True if the column has a spatial index, false otherwise. - */ - boolean isSpatialIndexed() throws Exception; - - /** - * Create an index of the column. If the column already has an index, no new index is created. - * - * @return True if an index has been created. - */ - boolean createIndex(); - - /** - * Create an index of the column. If the column already has an index, no new index is created. - * - * @return True if an index has been created. - */ - @Deprecated - boolean createSpatialIndex(); - - /** - * Drop the index of the column if exists. - */ - void dropIndex() throws Exception; - - /** - * Return the SRID code of the column if it is a spatial one, -1 otherwise. - * - * @return The SRID code of the column if it is a spatial one, -1 otherwise. - */ - int getSrid(); - - /** - * Sets the SRID code of the column. - * - * @param srid The SRID code of the column. - * - * @return TRUE is the SRID is updated - */ - boolean setSrid(int srid) throws Exception; -} diff --git a/data/data-api/src/main/java/org/orbisgis/data/api/datasource/IJdbcDataSource.java b/data/data-api/src/main/java/org/orbisgis/data/api/datasource/IJdbcDataSource.java index bccec433..4f510d5e 100644 --- a/data/data-api/src/main/java/org/orbisgis/data/api/datasource/IJdbcDataSource.java +++ b/data/data-api/src/main/java/org/orbisgis/data/api/datasource/IJdbcDataSource.java @@ -1145,8 +1145,16 @@ default void setProperty(String propertyName, Object newValue) { /** * Print the content of the table - * @param tableName + * @param tableName name of table */ void print(String tableName) throws Exception; + + /** + * Print the content of the table + * @param tableName name of the table + * @param numberOfRows number of rows to print + */ + void print(String tableName, int numberOfRows) throws Exception; + } diff --git a/data/data-api/src/test/java/org/orbisgis/data/api/datasource/IJdbcDataSourceTest.java b/data/data-api/src/test/java/org/orbisgis/data/api/datasource/IJdbcDataSourceTest.java index f787148d..3d62fe36 100644 --- a/data/data-api/src/test/java/org/orbisgis/data/api/datasource/IJdbcDataSourceTest.java +++ b/data/data-api/src/test/java/org/orbisgis/data/api/datasource/IJdbcDataSourceTest.java @@ -523,6 +523,11 @@ public boolean isEmpty(String tableName) { public void print(String tableName) { } + @Override + public void print(String tableName, int numberOfRows) throws Exception { + + } + @Override public String link(Map dataSourceProperties, String tableName) { return null; diff --git a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy index a3667870..eeb5cd1c 100644 --- a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy +++ b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy @@ -1105,8 +1105,9 @@ class GroovyH2GISTest { INSERT INTO orbisgis VALUES (1, 'POINT(10 10)'::GEOMETRY, 'just a string a bit too long'), (2, 'POINT(1 1)'::GEOMETRY, 'another string'); """) + h2GIS.print("orbisgis", -1) h2GIS.print("orbisgis") - h2GIS.print("(SELECT * FROM generate_series(0, 10000) where x > 1000 limit 10)") + h2GIS.print("(SELECT * FROM generate_series(0, 10000))", 10) h2GIS.print("(SELECT * FROM generate_series(0, 10000))") } diff --git a/data/h2gis/src/test/java/org/orbisgis/data/H2GISColumnTest.java b/data/h2gis/src/test/java/org/orbisgis/data/H2GISColumnTest.java deleted file mode 100644 index 70c2e198..00000000 --- a/data/h2gis/src/test/java/org/orbisgis/data/H2GISColumnTest.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Bundle DataFrame 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 is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * DataManager 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 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. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.data; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.orbisgis.data.jdbc.JdbcColumn; -import org.orbisgis.data.jdbc.JdbcDataSource; - -import java.sql.SQLException; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link JdbcColumn} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public class H2GISColumnTest { - - /** - * Default database name - */ - private static final String BASE_DATABASE = "./target/" + H2GISColumnTest.class.getSimpleName(); - /** - * Database connection - */ - private static JdbcDataSource dataSource; - - private static final String TABLE_NAME = "orbisgis"; - private static final String TEMP_NAME = "tempTable"; - private static final String LINKED_NAME = "linkedTable"; - private static final String EMPTY_TABLE_NAME = "emptyTable"; - - private static final String COL_THE_GEOM = "the_geom"; - private static final String COL_THE_GEOM2 = "the_geom2"; - private static final String COL_ID = "id"; - private static final String COL_VALUE = "val"; - private static final String COL_MEANING = "meaning"; - - private static final String COL_NO_COL = "COL_NO_COL"; - private static final String COL_NO_TAB = "COL_NO_TAB"; - - @BeforeAll - public static void beforeAll() throws Exception { - dataSource = H2GIS.open(BASE_DATABASE); - } - - /** - * Initialization of the database. - */ - @BeforeEach - public void init() { - try { - dataSource.execute("DROP TABLE IF EXISTS " + TABLE_NAME + "," + LINKED_NAME + "," + TEMP_NAME + "," + EMPTY_TABLE_NAME); - dataSource.execute("CREATE TABLE " + TABLE_NAME + " (" + COL_THE_GEOM + " GEOMETRY, " + COL_THE_GEOM2 + " GEOMETRY(POINT Z)," + - COL_ID + " INTEGER, " + COL_VALUE + " FLOAT, " + COL_MEANING + " VARCHAR)"); - dataSource.execute("INSERT INTO " + TABLE_NAME + " VALUES ('POINT(0 0)', 'POINTZ(1 1 0)', 1, 2.3, 'Simple points')"); - dataSource.execute("INSERT INTO " + TABLE_NAME + " VALUES ('POINT(0 1)', 'POINTZ(10 11 12)', 2, 0.568, '3D point')"); - dataSource.execute("INSERT INTO " + TABLE_NAME + " VALUES (null, 'POINTZ(110 111 112)', 2, null, '3D point')"); - dataSource.execute("CREATE TABLE " + EMPTY_TABLE_NAME + " (" + COL_THE_GEOM + " GEOMETRY, " + COL_THE_GEOM2 + " GEOMETRY(POINT Z)," + - COL_ID + " INTEGER, " + COL_VALUE + " FLOAT, " + COL_MEANING + " VARCHAR)"); - } catch (SQLException e) { - fail(e); - } - } - - /** - * Return a simple instantiation of a {@link JdbcColumn}. - * - * @param name Name of the column - * @return A simple instantiation of a {@link JdbcColumn}. - */ - private JdbcColumn getColumn(String name) { - if (COL_NO_TAB.equals(name)) { - return new DummyJdbcColumn(name, name, dataSource); - } - return new DummyJdbcColumn(name, TABLE_NAME, dataSource); - } - - /** - * Test the {@link JdbcColumn#getName()} method. - */ - @Test - public void testGetName() { - assertEquals(COL_THE_GEOM.toUpperCase(), getColumn(COL_THE_GEOM).getName()); - assertEquals(COL_THE_GEOM2.toUpperCase(), getColumn(COL_THE_GEOM2).getName()); - assertEquals(COL_ID.toUpperCase(), getColumn(COL_ID).getName()); - assertEquals(COL_VALUE.toUpperCase(), getColumn(COL_VALUE).getName()); - assertEquals(COL_MEANING.toUpperCase(), getColumn(COL_MEANING).getName()); - assertEquals(COL_NO_COL.toUpperCase(), getColumn(COL_NO_COL).getName()); - assertEquals(COL_NO_TAB.toUpperCase(), getColumn(COL_NO_TAB).getName()); - } - - /** - * Test the {@link JdbcColumn#getType()} method. - */ - @Test - public void testGetType() { - assertEquals("GEOMETRY", getColumn(COL_THE_GEOM).getType()); - assertEquals("GEOMETRY", getColumn(COL_THE_GEOM2).getType()); - assertEquals("INTEGER", getColumn(COL_ID).getType()); - assertEquals("DOUBLE PRECISION", getColumn(COL_VALUE).getType()); - assertEquals("CHARACTER VARYING", getColumn(COL_MEANING).getType()); - assertNull(getColumn(COL_NO_COL).getType()); - assertNull(getColumn(COL_NO_TAB).getType()); - } - - /** - * Test the {@link JdbcColumn#getSize()} method. - */ - @Test - public void testGetSize() { - assertEquals(2, getColumn(COL_THE_GEOM).getSize()); - assertEquals(3, getColumn(COL_THE_GEOM2).getSize()); - assertEquals(3, getColumn(COL_ID).getSize()); - assertEquals(2, getColumn(COL_VALUE).getSize()); - assertEquals(3, getColumn(COL_MEANING).getSize()); - assertEquals(-1, getColumn(COL_NO_COL).getSize()); - assertEquals(-1, getColumn(COL_NO_TAB).getSize()); - } - - /** - * Test the {@link JdbcColumn#isSpatial()} method. - */ - @Test - public void testIsSpatial() { - assertTrue(getColumn(COL_THE_GEOM).isSpatial()); - assertTrue(getColumn(COL_THE_GEOM2).isSpatial()); - assertFalse(getColumn(COL_ID).isSpatial()); - assertFalse(getColumn(COL_VALUE).isSpatial()); - assertFalse(getColumn(COL_MEANING).isSpatial()); - assertFalse(getColumn(COL_NO_COL).isSpatial()); - assertFalse(getColumn(COL_NO_TAB).isSpatial()); - } - - /** - * Test that there is no spatial index - */ - private void testNoSpatialIndexes() throws Exception { - //Test no spatial index - assertFalse(getColumn(COL_THE_GEOM).isSpatialIndexed()); - assertFalse(getColumn(COL_THE_GEOM2).isSpatialIndexed()); - assertFalse(getColumn(COL_ID).isSpatialIndexed()); - assertFalse(getColumn(COL_VALUE).isSpatialIndexed()); - assertFalse(getColumn(COL_MEANING).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_COL).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_TAB).isSpatialIndexed()); - } - - /** - * Test that there is no index - */ - private void testNoIndexes() { - //Test no index - assertFalse(getColumn(COL_THE_GEOM).isIndexed()); - assertFalse(getColumn(COL_THE_GEOM2).isIndexed()); - assertFalse(getColumn(COL_ID).isIndexed()); - assertFalse(getColumn(COL_VALUE).isIndexed()); - assertFalse(getColumn(COL_MEANING).isIndexed()); - assertFalse(getColumn(COL_NO_COL).isIndexed()); - assertFalse(getColumn(COL_NO_TAB).isIndexed()); - } - - /** - * Drop indexes on all columns - */ - private void dropIndexes() throws Exception { - //Test drop index - getColumn(COL_THE_GEOM).dropIndex(); - getColumn(COL_THE_GEOM2).dropIndex(); - getColumn(COL_ID).dropIndex(); - getColumn(COL_VALUE).dropIndex(); - getColumn(COL_MEANING).dropIndex(); - getColumn(COL_NO_COL).dropIndex(); - getColumn(COL_NO_TAB).dropIndex(); - } - - /** - * Test the {@link JdbcColumn#isIndexed()}, {@link JdbcColumn#isSpatialIndexed()}, - * {@link JdbcColumn#createIndex()}, {@link JdbcColumn#createSpatialIndex()}, {@link JdbcColumn#dropIndex()} - * methods. - */ - @Test - public void testIndexes() throws Exception { - dropIndexes(); - testNoSpatialIndexes(); - testNoIndexes(); - - //Test standard index creation - assertTrue(getColumn(COL_THE_GEOM).createSpatialIndex()); - assertTrue(getColumn(COL_THE_GEOM2).createSpatialIndex()); - assertTrue(getColumn(COL_ID).createIndex()); - assertTrue(getColumn(COL_VALUE).createIndex()); - assertTrue(getColumn(COL_MEANING).createIndex()); - assertFalse(getColumn(COL_NO_COL).createIndex()); - assertFalse(getColumn(COL_NO_TAB).createIndex()); - - - //Test index - assertTrue(getColumn(COL_THE_GEOM).isIndexed()); - assertTrue(getColumn(COL_THE_GEOM2).isIndexed()); - assertTrue(getColumn(COL_ID).isIndexed()); - assertTrue(getColumn(COL_VALUE).isIndexed()); - assertTrue(getColumn(COL_MEANING).isIndexed()); - assertFalse(getColumn(COL_NO_COL).isIndexed()); - assertFalse(getColumn(COL_NO_TAB).isIndexed()); - - assertTrue(getColumn(COL_THE_GEOM).isSpatialIndexed()); - assertTrue(getColumn(COL_THE_GEOM2).isSpatialIndexed()); - assertFalse(getColumn(COL_ID).isSpatialIndexed()); - assertFalse(getColumn(COL_VALUE).isSpatialIndexed()); - assertFalse(getColumn(COL_MEANING).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_COL).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_TAB).isSpatialIndexed()); - - dropIndexes(); - testNoSpatialIndexes(); - testNoIndexes(); - - //Test spatial index creation - assertTrue(getColumn(COL_THE_GEOM).createSpatialIndex()); - assertTrue(getColumn(COL_THE_GEOM2).createSpatialIndex()); - assertFalse(getColumn(COL_ID).createSpatialIndex()); - assertFalse(getColumn(COL_VALUE).createSpatialIndex()); - assertFalse(getColumn(COL_MEANING).createSpatialIndex()); - assertFalse(getColumn(COL_NO_COL).createSpatialIndex()); - assertFalse(getColumn(COL_NO_TAB).createSpatialIndex()); - - //Test standard index - assertTrue(getColumn(COL_THE_GEOM).isIndexed()); - assertTrue(getColumn(COL_THE_GEOM2).isIndexed()); - assertFalse(getColumn(COL_ID).isIndexed()); - assertFalse(getColumn(COL_VALUE).isIndexed()); - assertFalse(getColumn(COL_MEANING).isIndexed()); - assertFalse(getColumn(COL_NO_COL).isIndexed()); - assertFalse(getColumn(COL_NO_TAB).isIndexed()); - - //Test spatial index - assertTrue(getColumn(COL_THE_GEOM).isSpatialIndexed()); - assertTrue(getColumn(COL_THE_GEOM2).isSpatialIndexed()); - assertFalse(getColumn(COL_ID).isSpatialIndexed()); - assertFalse(getColumn(COL_VALUE).isSpatialIndexed()); - assertFalse(getColumn(COL_MEANING).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_COL).isSpatialIndexed()); - assertFalse(getColumn(COL_NO_TAB).isIndexed()); - } - - /** - * Test the {@link JdbcColumn#getSrid()}, {@link JdbcColumn#setSrid(int)} methods. - */ - @Test - public void testGetSrid() throws Exception { - JdbcColumn column = getColumn(COL_THE_GEOM); - assertEquals(0, column.getSrid()); - column.setSrid(2121); - assertEquals(2121, column.getSrid()); - JdbcColumn column2 = getColumn(COL_ID); - assertEquals(-1, column2.getSrid()); - assertFalse(column2.setSrid(2121)); - } - - /** - * Test the {@link JdbcColumn#getMetaClass()} and {@link JdbcColumn#setMetaClass(MetaClass)} methods. - */ - @Test - public void testMetaClass() { - JdbcColumn column = getColumn(COL_THE_GEOM); - assertEquals(InvokerHelper.getMetaClass(JdbcColumn.class), column.getMetaClass()); - column.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), column.getMetaClass()); - } - - /** - * Test the {@link JdbcColumn#invokeMethod(String, Object)} method. - */ - @Test - public void testInvokeMethod() { - JdbcColumn column = getColumn(COL_THE_GEOM); - column.invokeMethod("dropIndex", null); - assertTrue((Boolean) column.invokeMethod("createIndex", null)); - assertTrue((Boolean) column.invokeMethod("indexed", null)); - assertTrue((Boolean) column.invokeMethod("isIndexed", null)); - assertEquals(COL_THE_GEOM.toUpperCase(), column.invokeMethod("getName", null)); - assertEquals(COL_THE_GEOM.toUpperCase(), column.invokeMethod("name", null)); - } - - /** - * Test the {@link JdbcColumn#getProperty(String)}, {@link JdbcColumn#setProperty(String, Object)} method. - */ - @Test - public void testProperties() { - JdbcColumn column = getColumn(COL_THE_GEOM); - column.createIndex(); - assertTrue((Boolean) column.getProperty("indexed")); - assertEquals(COL_THE_GEOM.toUpperCase(), column.getProperty("name")); - column.setProperty("name", "toto"); - assertEquals("toto", column.getProperty("name")); - } - - /** - * Simple extension of the {@link JdbcColumn} class. - */ - private static class DummyJdbcColumn extends JdbcColumn { - private DummyJdbcColumn(String name, String tableName, JdbcDataSource dataSource) { - super(name, tableName, dataSource); - } - } -} diff --git a/data/h2gis/src/test/java/org/orbisgis/data/H2GISDataSourceTest.java b/data/h2gis/src/test/java/org/orbisgis/data/H2GISDataSourceTest.java index 0a91ba6a..94b365dc 100644 --- a/data/h2gis/src/test/java/org/orbisgis/data/H2GISDataSourceTest.java +++ b/data/h2gis/src/test/java/org/orbisgis/data/H2GISDataSourceTest.java @@ -906,11 +906,8 @@ public void testDataSourceMethods() throws Exception { h2gis.execute("DROP TABLE IF EXISTS geodata; CREATE TABLE geodata ;"); assertTrue(h2gis.isEmpty("geodata")); - h2gis.dropTable(new ArrayList()); h2gis.dropTable("",""); - assertTrue(h2gis.getColumnNames("geodata").isEmpty()); - } } diff --git a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcColumn.java b/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcColumn.java deleted file mode 100644 index cb80b8a9..00000000 --- a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcColumn.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Bundle DataManager 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 is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * DataManager 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 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. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.data.jdbc; - -import groovy.lang.GroovyObject; -import groovy.lang.MetaClass; -import groovy.lang.MissingMethodException; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.h2gis.utilities.GeometryTableUtilities; -import org.h2gis.utilities.JDBCUtilities; -import org.h2gis.utilities.TableLocation; -import org.h2gis.utilities.dbtypes.DBTypes; -import org.orbisgis.data.api.dataset.IJdbcColumn; -import org.orbisgis.data.api.datasource.IJdbcDataSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Contains the methods which are in common to all the {@link IJdbcColumn} subclasses. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public class JdbcColumn implements IJdbcColumn, GroovyObject { - - private static final Logger LOGGER = LoggerFactory.getLogger(JdbcColumn.class); - - /** - * MetaClass use for groovy methods/properties binding - */ - private MetaClass metaClass; - /** - * Name of the column. - */ - private String name; - /** - * Name of the table of the column. - */ - private TableLocation tableName; - /** - * {@link IJdbcDataSource} of the column. - */ - private JdbcDataSource dataSource; - - /** - * Indicates if the database type. - */ - private DBTypes dbType; - - /** - * Default constructor. - * - * @param name Name of the column. - * @param tableName Name of the table of the column. - * @param dataSource {@link IJdbcDataSource} of the column. - */ - public JdbcColumn(String name, String tableName, IJdbcDataSource dataSource) { - if(dataSource != null) { - this.dataSource = (JdbcDataSource) dataSource; - } - else{ - LOGGER.warn("Null datasource for the column creation."); - } - if(name != null) { - this.name = TableLocation.capsIdentifier(name, dataSource.getDataBaseType()); - } - else{ - LOGGER.warn("Null name for the column creation."); - } - if(tableName != null) { - this.tableName = TableLocation.parse(tableName, dataSource.getDataBaseType()); - } - else{ - LOGGER.warn("Null table name for the column creation."); - } - this.metaClass = InvokerHelper.getMetaClass(JdbcColumn.class); - } - - @Override - public String getName() { - return name; - } - - @Override - public String getType() { - if(dataSource == null || name == null || tableName == null){ - return null; - } - try { - if(dataSource.getDataBaseType()==DBTypes.H2GIS|| dataSource.getDataBaseType()==DBTypes.H2) { - Map map = dataSource.firstRow("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS " + - "WHERE INFORMATION_SCHEMA.COLUMNS.TABLE_NAME=? " + - "AND INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA=? " + - "AND INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME=?;", - new Object[]{tableName.getTable(), tableName.getSchema("PUBLIC"), name}); - if (map != null && map.containsKey("DATA_TYPE")) { - return map.get("DATA_TYPE").toString(); - } - }else { - Map map = dataSource.firstRow("SELECT udt_name FROM INFORMATION_SCHEMA.COLUMNS " + - "WHERE INFORMATION_SCHEMA.COLUMNS.TABLE_NAME=? " + - "AND INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA=? " + - "AND INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME=?;", - new Object[]{tableName.getTable(), tableName.getSchema("PUBLIC"), name}); - if (map != null && map.containsKey("udt_name")) { - return map.get("udt_name").toString(); - } - } - } catch (SQLException e) { - LOGGER.error("Unable to get the type of the column '" + name + "' in the table '" + tableName + "'.\n" + - e.getLocalizedMessage()); - } - return null; - } - - @Override - public long getSize() { - if(dataSource == null || name == null || tableName == null){ - return -1; - } - try { - Map map = dataSource.firstRow("SELECT count(" + TableLocation.quoteIdentifier(name, dbType) + - ") FROM " + tableName.getTable()); - if (map != null && !map.isEmpty() && map.values().toArray()[0] instanceof Long) { - return (Long) map.values().toArray()[0]; - } - } catch (SQLException e) { - LOGGER.error("Unable to get the size of the column '" + name + "' in the table '" + tableName + "'.\n" + - e.getLocalizedMessage()); - } - return -1; - } - - @Override - public Object asType(Class clazz) { - return null; - } - - @Override - public boolean isSpatial() { - return "GEOMETRY".equals(getType()); - } - - @Override - public boolean isIndexed() { - if(name == null || tableName == null){ - LOGGER.error("Unable to find an index"); - } - return dataSource.isIndexed(tableName.toString(dataSource.getDataBaseType()), name); - } - - @Override - public boolean isSpatialIndexed() throws Exception { - if(dataSource == null){ - LOGGER.error("Unable to find a spatial index"); - } - return dataSource.isSpatialIndexed(tableName.toString(dataSource.getDataBaseType()), name); - } - - @Override - public boolean createSpatialIndex() { - if(dataSource == null || name == null || tableName == null){ - LOGGER.error("Unable to create a spatial index"); - } - return dataSource.createSpatialIndex(tableName.toString(dataSource.getDataBaseType()), name); - } - - @Override - public boolean createIndex() { - if(dataSource == null){ - LOGGER.error("Unable to create an index"); - } - return dataSource.createIndex(tableName.toString(dataSource.getDataBaseType()), name); - } - - @Override - public void dropIndex() throws Exception { - if( name == null || tableName == null){ - LOGGER.error("Unable to drop index"); - } - dataSource.dropIndex(tableName.toString(dataSource.getDataBaseType()), name); - } - - @Override - public int getSrid() { - if (!isSpatial()) { - return -1; - } - try { - Connection con = dataSource.getConnection(); - if(con == null){ - LOGGER.error("Unable to get connection for the table SRID."); - return -1; - } - return GeometryTableUtilities.getSRID(con, tableName); - } catch (SQLException e) { - LOGGER.error("Unable to get the table SRID.", e); - } - return -1; - } - - @Override - public boolean setSrid(int srid) throws Exception { - if( name == null || tableName == null){ - LOGGER.error("Unable to set the srid"); - } - return dataSource.setSrid(tableName.toString(dataSource.getDataBaseType()), name, srid); - } - - @Override - public Object invokeMethod(String name, Object args) { - try { - return getMetaClass().invokeMethod(this, name, args); - } catch (MissingMethodException e) { - LOGGER.debug("Unable to find the '" + name + "' methods, trying with the getter.\n" + e.getLocalizedMessage()); - try { - return getMetaClass() - .invokeMethod(this, "get" + name.substring(0, 1).toUpperCase() + name.substring(1), args); - } catch (MissingMethodException e2) { - LOGGER.debug("Unable to find the '" + name + "' methods, trying with the is getter.\n" + - e.getLocalizedMessage()); - } - return getMetaClass() - .invokeMethod(this, "is" + name.substring(0, 1).toUpperCase() + name.substring(1), args); - } - } - - @Override - public Object getProperty(String propertyName) { - return getMetaClass().getProperty(this, propertyName); - } - - @Override - public void setProperty(String propertyName, Object newValue) { - getMetaClass().setProperty(this, propertyName, newValue); - } - - @Override - public MetaClass getMetaClass() { - return this.metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass; - } -} diff --git a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java b/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java index 43a7ff5d..e0327e87 100644 --- a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java +++ b/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java @@ -1291,6 +1291,11 @@ public boolean isEmpty(String tableName) throws Exception{ @Override public void print(String tableName) throws Exception{ + print(tableName, 1000); + } + + @Override + public void print(String tableName, int numberOfRows) throws Exception{ if (tableName == null || tableName.isEmpty()) { System.out.println("The table name is null or empty."); } @@ -1318,11 +1323,9 @@ public void print(String tableName) throws Exception{ boolean tooManyRows = false; if (rs != null) { try { - int limit = 1000; int count = 0; - while (rs.next()) { - if (count > limit) { + if (count > numberOfRows) { tooManyRows = true; break; } @@ -1340,8 +1343,8 @@ public void print(String tableName) throws Exception{ throw new SQLException("Error while reading the table '" + tableName + "'.\n" + e.getLocalizedMessage()); } } - if (tooManyRows) { - printer.appendText(".... more than 1000 rows"); + if (tooManyRows && numberOfRows>1) { + printer.appendText("Note that the table contains more than " + numberOfRows + " rows"); } else { printer.appendTableLineSeparator(); } diff --git a/data/postgis/src/test/groovy/org/orbisgis/data/GroovyPostGISTest.groovy b/data/postgis/src/test/groovy/org/orbisgis/data/GroovyPostGISTest.groovy index 96be8654..cb0b8e31 100644 --- a/data/postgis/src/test/groovy/org/orbisgis/data/GroovyPostGISTest.groovy +++ b/data/postgis/src/test/groovy/org/orbisgis/data/GroovyPostGISTest.groovy @@ -152,7 +152,6 @@ class GroovyPostGISTest { def concat = "" postGIS.getSpatialTable "postgis_imported" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" } assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat) - println(concat) } @Test @@ -169,7 +168,6 @@ class GroovyPostGISTest { def concat = "" postGIS.getSpatialTable "postgis_imported" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" } assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat) - println(concat) } @Test @@ -185,7 +183,6 @@ class GroovyPostGISTest { def concat = "" postGIS.getSpatialTable "postgis_imported" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" } assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat) - println(concat) } @Test @@ -201,7 +198,6 @@ class GroovyPostGISTest { def concat = "" postGIS.getSpatialTable "postgis_imported" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" } assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat) - println(concat) } @Test @@ -219,7 +215,6 @@ class GroovyPostGISTest { def concat = "" postGIS.getSpatialTable "postgis_imported" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" } assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat) - println(concat) } @Test diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9106083f..578ef8e2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,4 +5,5 @@ - Standardizing method names - Update to H2GIS 2.2.2-SNAPSHOT - Use new sonatype auth -- Upgrade many deps : H2, Groovy, Apache Common, JTS \ No newline at end of file +- Upgrade many deps : H2, Groovy, Apache Common, JTS +- Clean data API \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1fdb234f..47cc2b52 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 5.8.2 - 2.2.2-SNAPSHOT + 2.2.3 1.20.0 4.0.22 4.7.6