@Override public void start(BundleContext bc) { for(Function function : H2GISFunctions.getBuiltInsFunctions()) { bc.registerService(Function.class, function, null); if(function instanceof DriverFunction) { bc.registerService(DriverFunction.class, (DriverFunction) function, null); } } //Driver registering bc.registerService(DriverFunction.class, new DBFDriverFunction(), null); bc.registerService(DriverFunction.class, new SHPDriverFunction(), null); bc.registerService(DriverFunction.class, new GPXDriverFunction(), null); bc.registerService(DriverFunction.class, new GeoJsonDriverFunction(), null); bc.registerService(DriverFunction.class, new OSMDriverFunction(), null); bc.registerService(DriverFunction.class, new KMLDriverFunction(), null); bc.registerService(DriverFunction.class, new CSVDriverFunction(), null); bc.registerService(DriverFunction.class, new TSVDriverFunction(), null); DataSourceTracker dataSourceTracker = new DataSourceTracker(bc); databaseTracker = new ServiceTracker<>(bc,DataSource.class,dataSourceTracker); databaseTracker.open(); }
/** * Read a table and write it into a shape file. * @param connection Active connection * @param fileName Shape file name or URI * @param tableReference Table name or select query * Note : The select query must be enclosed in parenthesis * @param encoding File encoding * @throws IOException * @throws SQLException */ public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException { String regex = ".*(?i)\\b(select|from)\\b.*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(tableReference); SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); if (matcher.find()) { if (tableReference.startsWith("(") && tableReference.endsWith(")")) { shpDriverFunction.exportResultset(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } else { throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'."); } } else { shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } }
/** * Read a table and write it into a shape file. * @param connection Active connection * @param fileName Shape file name or URI * @param tableReference Table name or select query * Note : The select query must be enclosed in parenthesis * @param encoding File encoding * @throws IOException * @throws SQLException */ public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException { String regex = ".*(?i)\\b(select|from)\\b.*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(tableReference); SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); if (matcher.find()) { if (tableReference.startsWith("(") && tableReference.endsWith(")")) { shpDriverFunction.exportResultset(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } else { throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'."); } } else { shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } }
/** * Read a table and write it into a shape file. * @param connection Active connection * @param fileName Shape file name or URI * @param tableReference Table name or select query * Note : The select query must be enclosed in parenthesis * @param encoding File encoding * @throws IOException * @throws SQLException */ public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException { SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); }
/** * 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. * @throws java.io.IOException * @throws java.sql.SQLException */ public static void readShape(Connection connection, String fileName, String tableReference,String forceEncoding) throws IOException, SQLException { File file = URIUtilities.fileFromString(fileName); if (FileUtil.isFileImportable(file, "shp")) { SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); shpDriverFunction.importFile(connection, TableLocation.parse(tableReference, true).toString(true), file, new EmptyProgressVisitor(), forceEncoding); } }
/** * 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. * @throws java.io.IOException * @throws java.sql.SQLException */ public static void readShape(Connection connection, String fileName, String tableReference,String forceEncoding) throws IOException, SQLException { File file = URIUtilities.fileFromString(fileName); if (FileUtil.isFileImportable(file, "shp")) { SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); shpDriverFunction.importFile(connection, TableLocation.parse(tableReference, true).toString(true), file, new EmptyProgressVisitor(), forceEncoding); } }
/** * 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. * @throws java.io.IOException * @throws java.sql.SQLException */ public static void readShape(Connection connection, String fileName, String tableReference,String forceEncoding) throws IOException, SQLException { File file = URIUtilities.fileFromString(fileName); if (FileUtil.isFileImportable(file, "shp")) { SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); shpDriverFunction.importFile(connection, TableLocation.parse(tableReference, true).toString(true), file, new EmptyProgressVisitor(), forceEncoding); } }