VirtualTable vt = new VirtualTable(name, sql, false);
jstore.createVirtualTable(new VirtualTable(temporaryName.getLocalPart(), vt)); return true; } else {
@Test public void testByCopyConstructor() { VirtualTable source = new VirtualTable("test", "select * from tables"); VirtualTable copy = ModificationProxyCloner.clone(source); assertNotSame(source, copy); assertEquals(source, copy); }
/** * Returns a live, immutable view of the virtual tables map (from name to definition) * * @return */ public Map<String, VirtualTable> getVirtualTables() { Map<String, VirtualTable> result = new HashMap<String, VirtualTable>(); for (String key : virtualTables.keySet()) { result.put(key, new VirtualTable(virtualTables.get(key))); } return Collections.unmodifiableMap(result); }
new VirtualTable( VT_NAME, "select \"name\", \"pointProperty\" from \"pgeo\" where \"booleanProperty\" = %bool% and \"name\" = '%name%'");
/** * Adds a virtual table to the data store. If a virtual table with the same name was registered * this method will replace it with the new one. * @param vt * * @throws IOException If the view definition is not valid */ public void createVirtualTable(VirtualTable vtable) throws IOException { try { virtualTables.put(vtable.getName(), new VirtualTable(vtable)); // the new vtable might be overriding a previous definition entries.remove(new NameImpl(namespaceURI, vtable.getName())); getSchema(vtable.getName()); } catch (IOException e) { virtualTables.remove(vtable.getName()); throw e; } }
new VirtualTable( "riverReduced", "select a, b, c * %mulparam% \n from table \n where x > 1 %andparam%");
public void testVirtualTable() throws Exception { // geopoint( id:Integer; name:String; geo:Geography(Point) ) StringBuffer sb = new StringBuffer(); sb.append("select * from "); dialect.encodeTableName(tname("geopoint"), sb); VirtualTable vt = new VirtualTable("geopoint_vt", sb.toString()); dataStore.addVirtualTable(vt); SimpleFeatureType featureType = dataStore.getSchema("geopoint_vt"); assertNotNull(featureType); assertNotNull(featureType.getGeometryDescriptor()); } }
public void testInvalidQuery() throws Exception { String sql = dataStore.getVirtualTables().get("riverReduced").getSql(); VirtualTable vt = new VirtualTable("riverPolluted", "SOME EXTRA GARBAGE " + sql); vt.addGeometryMetadatata("geom", LineString.class, -1); try { dataStore.addVirtualTable(vt); fail("Should have failed with invalid sql definition"); } catch (IOException e) { // ok, that's what we expected } }
VirtualTable vt = new VirtualTable("invalid_attribute", sb.toString());
VirtualTable vt = new VirtualTable("riverFull", sb.toString()); dataStore.addVirtualTable(vt); vt = new VirtualTable("riverFullPlaceHolder", sb.toString()); dataStore.addVirtualTable(vt); dialect.encodeColumnName(aname("flow"), sb); sb.append(" > 4"); vt = new VirtualTable("riverReduced", sb.toString()); vt.addGeometryMetadatata(aname("geom"), LineString.class, 4326); dataStore.addVirtualTable(vt); vt = new VirtualTable("riverReducedComment", sb.toString()); vt.addGeometryMetadatata(aname("geom"), LineString.class, 4326); dataStore.addVirtualTable(vt); vt = new VirtualTable("riverReducedPk", sb.toString()); vt.addGeometryMetadatata(aname("geom"), LineString.class, 4326); vt.setPrimaryKeyColumns(Arrays.asList(aname("id"))); vt = new VirtualTable("riverParam", sb.toString()); vt.addGeometryMetadatata(aname("geom"), LineString.class, 4326); vt.addParameter(
/** * Returns a live, immutable view of the virtual tables map (from name to definition) * @return */ public Map<String, VirtualTable> getVirtualTables() { Map<String, VirtualTable> result = new HashMap<String, VirtualTable>(); for (String key : virtualTables.keySet()) { result.put(key, new VirtualTable(virtualTables.get(key))); } return Collections.unmodifiableMap(result); }
public void testSqlEscaping() throws Exception { VirtualTable vt = new VirtualTable("test", "%param1%"); vt.setEscapeSql(true); vt.addParameter(
protected VirtualTable buildVirtualTable() { VirtualTable vt = new VirtualTable(name, sql); attProvider.fillVirtualTable(vt); paramProvider.updateVirtualTable(vt); return vt; }
protected VirtualTable buildVirtualTable() { VirtualTable vt = new VirtualTable(name, sql); attProvider.fillVirtualTable(vt); paramProvider.updateVirtualTable(vt); return vt; }
protected SimpleFeatureType getFeatureType(VirtualTable vt) throws IOException { // check out if the view can be used JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null); String vtName = null; try { // use a highly random name do { vtName = UUID.randomUUID().toString(); } while (Arrays.asList(ds.getTypeNames()).contains(vtName)); // try adding the vt and see if that works ds.addVirtualTable(new VirtualTable(vtName, vt)); return ds.getSchema(vtName); } finally { if(vtName != null) { ds.removeVirtualTable(vtName); } } }
/** * Adds a virtual table to the data store. If a virtual table with the same name was registered this * method will replace it with the new one. * * @param vt * @throws IOException If the view definition is not valid */ public void addVirtualTable(VirtualTable vtable) throws IOException { try { virtualTables.put(vtable.getName(), new VirtualTable(vtable)); // the new vtable might be overriding a previous definition entries.remove(new NameImpl(namespaceURI, vtable.getName())); getSchema(vtable.getName()); } catch(IOException e) { virtualTables.remove(vtable.getName()); throw e; } }
protected SimpleFeatureType getFeatureType(VirtualTable vt) throws IOException { // check out if the view can be used JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null); String vtName = null; try { // use a highly random name do { vtName = UUID.randomUUID().toString(); } while (Arrays.asList(ds.getTypeNames()).contains(vtName)); // try adding the vt and see if that works ds.createVirtualTable(new VirtualTable(vtName, vt)); return ds.getSchema(vtName); } finally { if (vtName != null) { ds.dropVirtualTable(vtName); } } }
/** * Checks the view definition works as expected and returns the feature type guessed solely by * looking at the sql and the first row of its output * * @param newSchema * @throws IOException */ protected SimpleFeatureType testViewDefinition(boolean guessGeometrySrid) throws IOException { // check out if the view can be used JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null); String vtName = null; try { // use a highly random name do { vtName = UUID.randomUUID().toString(); } while (Arrays.asList(ds.getTypeNames()).contains(vtName)); // try adding the vt and see if that works VirtualTable vt = new VirtualTable(vtName, sql); paramProvider.updateVirtualTable(vt); ds.createVirtualTable(vt); return guessFeatureType(ds, vt.getName(), guessGeometrySrid); } finally { if (vtName != null) { ds.dropVirtualTable(vtName); } } }
/** * Checks the view definition works as expected and returns the feature type guessed solely by * looking at the sql and the first row of its output * * @param newSchema * @return * @throws IOException */ protected SimpleFeatureType testViewDefinition(boolean guessGeometrySrid) throws IOException { // check out if the view can be used JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null); String vtName = null; try { // use a highly random name do { vtName = UUID.randomUUID().toString(); } while (Arrays.asList(ds.getTypeNames()).contains(vtName)); // try adding the vt and see if that works VirtualTable vt = new VirtualTable(vtName, sql); paramProvider.updateVirtualTable(vt); ds.addVirtualTable(vt); return guessFeatureType(ds, vt.getName(), guessGeometrySrid); } finally { if(vtName != null) { ds.removeVirtualTable(vtName); } } }