vt.setPrimaryKeyColumns(primaryKeys);
"select a, b, c * %mulparam% \n from table \n where x > 1 %andparam%"); vt.addGeometryMetadatata("geom", LineString.class, 4326); vt.setPrimaryKeyColumns(Arrays.asList("a", "b")); vt.addParameter(new VirtualTableParameter("mulparam", "1", new RegexpValidator("\\d+"))); vt.addParameter(new VirtualTableParameter("andparam", null));
vt.setPrimaryKeyColumns(Arrays.asList(aname("id"))); dataStore.addVirtualTable(vt);
/** * Sets the geometries details and the primary key columns into the virtual table * @param vt */ public void fillVirtualTable(VirtualTable vt) { List<String> pks = new ArrayList<String>(); for(SQLViewAttribute att : attributes) { if(Geometry.class.isAssignableFrom(att.getType())) { if(att.getSrid() == null) { vt.addGeometryMetadatata(att.getName(), att.getType(), 4326); } else { vt.addGeometryMetadatata(att.getName(), att.getType(), att.getSrid()); } } if(att.pk) { pks.add(att.getName()); } } if(pks.size() > 0) { vt.setPrimaryKeyColumns(pks); } }
/** * 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(VirtualTable virtualTable, 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, virtualTable); // hide the primary key definitions or we'll loose some columns vt.setPrimaryKeyColumns(Collections.EMPTY_LIST); ds.addVirtualTable(vt); return guessFeatureType(ds, vt.getName(), guessGeometrySrid); } finally { if(vtName != null) { ds.removeVirtualTable(name); } } }
/** * 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( VirtualTable virtualTable, 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, virtualTable); // hide the primary key definitions or we'll loose some columns vt.setPrimaryKeyColumns(Collections.emptyList()); vt.setEscapeSql(escapeSql); ds.createVirtualTable(vt); return guessFeatureType(ds, vt.getName(), guessGeometrySrid); } finally { if (vtName != null) { ds.dropVirtualTable(name); } } }
/** * Sets the geometries details and the primary key columns into the virtual table * * @param vt */ @SuppressWarnings("unchecked") public void fillVirtualTable(VirtualTable vt) { List<String> pks = new ArrayList<String>(); for (SQLViewAttribute att : attributes) { if (Geometry.class.isAssignableFrom(att.getType())) { if (att.getSrid() == null) { vt.addGeometryMetadatata( att.getName(), (Class<? extends Geometry>) att.getType(), 4326); } else { vt.addGeometryMetadatata( att.getName(), (Class<? extends Geometry>) att.getType(), att.getSrid()); } } if (att.pk) { pks.add(att.getName()); } } if (pks.size() > 0) { vt.setPrimaryKeyColumns(pks); } } }
vt.setPrimaryKeyColumns(Arrays.asList(gidName));