ft = jstore.getSchema(vt.getName());
@Test public void testVirtualTableOrder() throws Exception { FeatureTypeInfo ft = persister.load( getClass() .getResourceAsStream( "/org/geoserver/config/virtualtable_order_error.xml"), FeatureTypeInfo.class); VirtualTable vtc = (VirtualTable) ft.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE); assertEquals(vtc.getSql(), "select * from table\n"); assertEquals(vtc.getName(), "sqlview"); }
/** * 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; } }
VirtualTable vt = (VirtualTable) source; writer.startNode("name"); writer.setValue(vt.getName()); writer.endNode(); writer.startNode("sql");
jds.createVirtualTable(vt); FeatureTypeInfo vft = cb.buildFeatureType(jds.getFeatureSource(vt.getName())); vft.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); cat.add(vft);
/** * 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; } }
@Override protected void onValidate(IValidatable validatable) { String vtName = (String) validatable.getValue(); final DataStoreInfo store = getCatalog().getStore(storeId, DataStoreInfo.class); List<FeatureTypeInfo> ftis = getCatalog().getResourcesByStore(store, FeatureTypeInfo.class); for (FeatureTypeInfo curr : ftis) { VirtualTable currvt = curr.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class); if(currvt != null) { if(typeInfoId == null || !typeInfoId.equals(curr.getId())) { if(currvt.getName().equals(vtName)) { Map<String, String> map = new HashMap<String, String>(); map.put("name", vtName); map.put("typeName", curr.getName()); error(validatable, "duplicateSqlViewName", map); return; } } } } } }
/** * 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); } } }
/** * 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(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); } } }
@Override public void validate(IValidatable<String> validatable) { String vtName = validatable.getValue(); final DataStoreInfo store = getCatalog().getStore(storeId, DataStoreInfo.class); List<FeatureTypeInfo> ftis = getCatalog().getResourcesByStore(store, FeatureTypeInfo.class); for (FeatureTypeInfo curr : ftis) { VirtualTable currvt = curr.getMetadata() .get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class); if (currvt != null) { if (typeInfoId == null || !typeInfoId.equals(curr.getId())) { if (currvt.getName().equals(vtName)) { IValidationError err = new ValidationError("duplicateSqlViewName") .addKey("duplicateSqlViewName") .setVariable("name", vtName) .setVariable("typeName", curr.getName()); validatable.error(err); return; } } } } } }
public SQLViewEditPage(FeatureTypeInfo type, ResourceConfigurationPage previousPage) throws IOException { super(type.getStore().getWorkspace().getName(), type.getStore().getName(), type.getName(), type.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class)); VirtualTable vt = type.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class); tinfo = type; originalName = vt.getName(); this.previusPage = previousPage; }
public SQLViewEditPage(FeatureTypeInfo type, ResourceConfigurationPage previousPage) throws IOException { super( type.getStore().getWorkspace().getName(), type.getStore().getName(), type.getName(), type.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class)); VirtualTable vt = type.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class); tinfo = type; originalName = vt.getName(); this.previusPage = previousPage; }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); SimpleFeatureType rawFeatureType = getFeatureType(vt); // update the feature type info tinfo.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); CoordinateReferenceSystem crs = rawFeatureType.getCoordinateReferenceSystem(); if(crs != null) { tinfo.setNativeCRS(crs); } tinfo.setNativeName(vt.getName()); // set it back in the main page and redirect to it previusPage.updateResource(tinfo); setResponsePage(previusPage); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error(new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); SimpleFeatureType rawFeatureType = getFeatureType(vt); // update the feature type info tinfo.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); CoordinateReferenceSystem crs = rawFeatureType.getCoordinateReferenceSystem(); if (crs != null) { tinfo.setNativeCRS(crs); } tinfo.setNativeName(vt.getName()); // set it back in the main page and redirect to it previusPage.updateResource(tinfo); setResponsePage(previusPage); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error( new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); DataStoreInfo dsInfo = getCatalog().getStore(storeId, DataStoreInfo.class); JDBCDataStore ds = (JDBCDataStore) dsInfo.getDataStore(null); ds.createVirtualTable(vt); CatalogBuilder builder = new CatalogBuilder(getCatalog()); builder.setStore(dsInfo); FeatureTypeInfo fti = builder.buildFeatureType(ds.getFeatureSource(vt.getName())); fti.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error( new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); DataStoreInfo dsInfo = getCatalog().getStore(storeId, DataStoreInfo.class); JDBCDataStore ds = (JDBCDataStore) dsInfo.getDataStore(null); ds.addVirtualTable(vt); CatalogBuilder builder = new CatalogBuilder(getCatalog()); builder.setStore(dsInfo); FeatureTypeInfo fti = builder.buildFeatureType(ds.getFeatureSource(vt.getName())); fti.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error(new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
jds.addVirtualTable(vt); FeatureTypeInfo vft = cb.buildFeatureType(jds.getFeatureSource(vt.getName())); vft.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); cat.add(vft);
name = virtualTable.getName(); sql = virtualTable.getSql();