コード例 #1
0
 @Test
 public void testSplitCatalogSchemaTableName() {
   check("mytable", null, "", "", "mytable", "\"mytable\"", "\"mytable\"", "mytable");
   check(
       "myschema.mytable",
       null,
       "",
       "myschema",
       "mytable",
       "\"myschema\".\"mytable\"",
       "\"myschema\".\"mytable\"",
       "myschema.mytable");
   check(
       "mydb.myschema.mytable",
       null,
       "mydb",
       "myschema",
       "mytable",
       "\"mydb\".\"myschema\".\"mytable\"",
       "\"mydb\".\"myschema\".\"mytable\"",
       "mydb.myschema.mytable");
   check(
       TableLocation.parse("mydb.myschema.mytable").toString(),
       null,
       "mydb",
       "myschema",
       "mytable",
       "\"mydb\".\"myschema\".\"mytable\"",
       "\"mydb\".\"myschema\".\"mytable\"",
       "mydb.myschema.mytable");
 }
コード例 #2
0
 @Test
 public void testSplitCatalogSchemaTableNameWithQuotes() {
   check("`mytable`", null, "", "", "mytable", "\"mytable\"", "\"mytable\"", "mytable");
   check(
       "`myschema`.`mytable`",
       null,
       "",
       "myschema",
       "mytable",
       "\"myschema\".\"mytable\"",
       "\"myschema\".\"mytable\"",
       "myschema.mytable");
   check(
       "`mydb`.`myschema`.`mytable`",
       null,
       "mydb",
       "myschema",
       "mytable",
       "\"mydb\".\"myschema\".\"mytable\"",
       "\"mydb\".\"myschema\".\"mytable\"",
       "mydb.myschema.mytable");
   check(
       "`mydb`.`myschema`.`mytable.hello`",
       null,
       "mydb",
       "myschema",
       "mytable.hello",
       "\"mydb\".\"myschema\".\"mytable.hello\"",
       "\"mydb\".\"myschema\".\"mytable.hello\"",
       "mydb.myschema.\"mytable.hello\"");
   check(
       "`mydb`.`my schema`.`my table`",
       null,
       "mydb",
       "my schema",
       "my table",
       "\"mydb\".\"my schema\".\"my table\"",
       "\"mydb\".\"my schema\".\"my table\"",
       "mydb.\"my schema\".\"my table\"");
   check(
       TableLocation.parse("`mydb`.`my schema`.`my table`").toString(),
       null,
       "mydb",
       "my schema",
       "my table",
       "\"mydb\".\"my schema\".\"my table\"",
       "\"mydb\".\"my schema\".\"my table\"",
       "mydb.\"my schema\".\"my table\"");
   check(
       "public.MYTABLE",
       null,
       "",
       "public",
       "MYTABLE",
       "\"public\".\"MYTABLE\"",
       "\"public\".MYTABLE",
       "public.\"MYTABLE\"");
 }
コード例 #3
0
 private void check(
     String input,
     Boolean isH2,
     String catalog,
     String schema,
     String table,
     String toString,
     String toStringTrue,
     String toStringFalse) {
   TableLocation location =
       isH2 == null ? TableLocation.parse(input) : TableLocation.parse(input, isH2);
   assertEquals(catalog, location.getCatalog());
   assertEquals(schema, location.getSchema());
   assertEquals(table, location.getTable());
   assertEquals(toString, location.toString());
   assertEquals(toStringTrue, location.toString(true));
   assertEquals(toStringFalse, location.toString(false));
 }
コード例 #4
0
ファイル: GridRowSet.java プロジェクト: aforino/h2gis
 /**
  * Return the first spatial geometry field name
  *
  * @param tableName
  * @param connection
  * @return the name of the first geometry column
  * @throws SQLException
  */
 private static String getFirstGeometryField(String tableName, Connection connection)
     throws SQLException {
   // Find first geometry column
   List<String> geomFields =
       SFSUtilities.getGeometryFields(
           connection,
           TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())));
   if (!geomFields.isEmpty()) {
     return geomFields.get(0);
   } else {
     throw new SQLException("The table " + tableName + " does not contain a geometry field");
   }
 }
コード例 #5
0
 /**
  * Populates the names array with the names of legends that can be applied to the given layer.
  *
  * @param layer Layer
  */
 private void initNamesList(ILayer layer) {
   // Recover the geometry type of this ILayer.
   DataSource ds = layer.getDataManager().getDataSource();
   int geometryColumnsCount = 0;
   int geomType = GeometryTypeCodes.GEOMETRY;
   try (Connection connection = ds.getConnection()) {
     TableLocation tableLocation = TableLocation.parse(layer.getTableReference());
     geomType = SFSUtilities.getGeometryType(connection, tableLocation, "");
     geometryColumnsCount = SFSUtilities.getGeometryFields(connection, tableLocation).size();
   } catch (SQLException e) {
     LOGGER.warn("Could not determine the specific geometry type for " + "this layer.");
   }
   // Convert to a simple geometry.
   int simpleGeomType = SimpleGeometryType.getSimpleType(geomType);
   // Fill the names array.
   ArrayList<String> typeNames = new ArrayList<>();
   final int lineOrPolygon = SimpleGeometryType.LINE | SimpleGeometryType.POLYGON;
   if ((simpleGeomType & SimpleGeometryType.ALL) != 0) {
     typeNames.add(UniqueSymbolPoint.NAME);
     if ((simpleGeomType & lineOrPolygon) != 0) {
       typeNames.add(UniqueSymbolLine.NAME);
     }
     if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
       typeNames.add(UniqueSymbolArea.NAME);
     }
     // Do not display the thematic maps that need an attribute if there is
     // only one geometry
     if (geometryColumnsCount > -1) {
       typeNames.add(RecodedPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(RecodedLine.NAME);
       }
       if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
         typeNames.add(RecodedArea.NAME);
       }
       typeNames.add(ProportionalPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(ProportionalLine.NAME);
       }
       typeNames.add(CategorizedPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(CategorizedLine.NAME);
       }
       if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
         typeNames.add(CategorizedArea.NAME);
       }
     }
   }
   names = typeNames.toArray(new String[typeNames.size()]);
 }
コード例 #6
0
ファイル: SHPRead.java プロジェクト: nicolas-f/h2gis
 /**
  * Copy data from Shape File into a new table in specified connection.
  *
  * @param connection Active connection
  * @param tableReference [[catalog.]schema.]table reference
  * @param fileName File path of the SHP file or URI
  * @param forceEncoding Use this encoding instead of DBF file header encoding property.
  */
 public static void readShape(
     Connection connection, String fileName, String tableReference, String forceEncoding)
     throws IOException, SQLException {
   File file = URIUtility.fileFromString(fileName);
   if (!file.exists()) {
     throw new FileNotFoundException("The following file does not exists:\n" + fileName);
   }
   SHPDriverFunction shpDriverFunction = new SHPDriverFunction();
   shpDriverFunction.importFile(
       connection,
       TableLocation.parse(tableReference, true).toString(true),
       file,
       new EmptyProgressVisitor(),
       forceEncoding);
 }
コード例 #7
0
ファイル: OwsMapContext.java プロジェクト: lovely3x/orbisgis
 @Override
 public ILayer createLayer(String layerName, String tableRef) throws LayerException {
   try {
     try (Connection connection = dataManager.getDataSource().getConnection()) {
       List<String> geoFields =
           SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableRef));
       if (!geoFields.isEmpty()) {
         return new Layer(layerName, tableRef, dataManager);
       } else {
         throw new LayerException(I18N.tr("The source contains no spatial info"));
       }
     }
   } catch (SQLException ex) {
     throw new LayerException("Cannot retrieve spatial metadata", ex);
   }
 }
コード例 #8
0
ファイル: OwsMapContext.java プロジェクト: lovely3x/orbisgis
 @Override
 public ILayer createLayer(String tableRef) throws LayerException {
   return createLayer(TableLocation.parse(tableRef).getTable(), tableRef);
 }
コード例 #9
0
ファイル: TableUtilities.java プロジェクト: SPalominos/h2gis
 /**
  * Convert an input table String to a TableLocation
  *
  * @param connection Connection
  * @param inputTable Input table
  * @return corresponding TableLocation
  * @throws SQLException
  */
 public static TableLocation parseInputTable(Connection connection, String inputTable)
     throws SQLException {
   return TableLocation.parse(inputTable, JDBCUtilities.isH2DataBase(connection.getMetaData()));
 }