Search in sources :

Example 31 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class PostgreSQLGeometryFieldAdder method newField.

@Override
public JdbcFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final PathName typePath = recordDefinition.getPathName();
    String dbSchemaName = schema.getDbName();
    if (!Property.hasValue(dbSchemaName)) {
        dbSchemaName = "public";
    }
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toLowerCase();
    try {
        int srid = 0;
        String type = "geometry";
        int axisCount = 3;
        try {
            final String sql = "select SRID, TYPE, COORD_DIMENSION from GEOMETRY_COLUMNS where UPPER(F_TABLE_SCHEMA) = UPPER(?) AND UPPER(F_TABLE_NAME) = UPPER(?) AND UPPER(F_GEOMETRY_COLUMN) = UPPER(?)";
            final Map<String, Object> values = JdbcUtils.selectMap(this.recordStore, sql, dbSchemaName, tableName, columnName);
            srid = (Integer) values.get("srid");
            type = (String) values.get("type");
            axisCount = (Integer) values.get("coord_dimension");
        } catch (final IllegalArgumentException e) {
            Logs.warn(this, "Cannot get geometry column metadata for " + typePath + "." + columnName);
        }
        final DataType dataType = DATA_TYPE_MAP.get(type);
        final GeometryFactory storeGeometryFactory = this.recordStore.getGeometryFactory();
        final GeometryFactory geometryFactory;
        if (storeGeometryFactory == null) {
            geometryFactory = GeometryFactory.floating(srid, axisCount);
        } else {
            final double[] scales = storeGeometryFactory.newScales(axisCount);
            geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
        }
        final PostgreSQLGeometryJdbcFieldDefinition field = new PostgreSQLGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, srid, axisCount, geometryFactory);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        return field;
    } catch (final Throwable e) {
        Logs.error(this, "Attribute not registered in GEOMETRY_COLUMN table " + dbSchemaName + "." + tableName + "." + name, e);
        return null;
    }
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 32 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class RecordStoreLayer method refreshDo.

@Override
protected void refreshDo() {
    synchronized (getSync()) {
        if (this.loadingWorker != null) {
            this.loadingWorker.cancel(true);
        }
        this.loadedBoundingBox = BoundingBox.empty();
        this.loadingBoundingBox = this.loadedBoundingBox;
        super.refreshDo();
    }
    final RecordStore recordStore = getRecordStore();
    final PathName pathName = getPathName();
    final CodeTable codeTable = recordStore.getCodeTable(pathName);
    if (codeTable != null) {
        codeTable.refresh();
    }
    if (hasIdField()) {
        final List<Identifier> identifiers = new ArrayList<>();
        synchronized (getSync()) {
            identifiers.addAll(this.recordsByIdentifier.keySet());
        }
        if (!identifiers.isEmpty()) {
            identifiers.sort(Identifier.comparator());
            final RecordDefinition recordDefinition = recordStore.getRecordDefinition(pathName);
            final List<FieldDefinition> idFields = recordDefinition.getIdFields();
            final int idFieldCount = idFields.size();
            if (idFieldCount == 1) {
                final FieldDefinition idField = idFields.get(0);
                final int pageSize = 999;
                final int identifierCount = identifiers.size();
                for (int i = 0; i < identifiers.size(); i += pageSize) {
                    final List<Identifier> queryIdentifiers = identifiers.subList(i, Math.min(identifierCount, i + pageSize));
                    final In in = Q.in(idField, queryIdentifiers);
                    final Query query = new Query(recordDefinition, in);
                    updateCachedRecords(recordStore, query);
                }
            } else if (!idFields.isEmpty()) {
                for (final Identifier identifier : identifiers) {
                    final Query query = new Query(recordDefinition, Q.equalId(idFields, identifier));
                    updateCachedRecords(recordStore, query);
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) In(com.revolsys.record.query.In) RecordStore(com.revolsys.record.schema.RecordStore) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 33 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class WebServiceConnectionTrees method getLayerGroup.

public static LayerGroup getLayerGroup(final WebServiceResource webServiceResource) {
    LayerGroup layerGroup = Project.get();
    if (layerGroup != null) {
        final WebService<?> webService = webServiceResource.getWebService();
        if (webService != null) {
            final String webServiceName = webService.getName();
            if (Property.hasValue(webServiceName)) {
                layerGroup = layerGroup.addLayerGroup(webServiceName);
            }
        }
        final PathName layerPath = webServiceResource.getPathName();
        if (layerPath != null) {
            final PathName parent = layerPath.getParent();
            if (parent != null) {
                for (final String groupName : parent.getElements()) {
                    layerGroup = layerGroup.addLayerGroup(groupName);
                }
            }
        }
    }
    return layerGroup;
}
Also used : LayerGroup(com.revolsys.swing.map.layer.LayerGroup) PathName(com.revolsys.io.PathName)

Example 34 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class RecordStoreConnectionTrees method addLayer.

private static void addLayer(final RecordDefinitionImpl recordDefinition) {
    final PathName typePath = recordDefinition.getPathName();
    final RecordStore recordStore = recordDefinition.getRecordStore();
    final Map<String, Object> connection = recordStore.getConnectionProperties();
    final Map<String, Object> layerConfig = new LinkedHashMap<>();
    MapObjectFactory.setType(layerConfig, "recordStoreLayer");
    layerConfig.put("name", recordDefinition.getName());
    layerConfig.put("connection", connection);
    layerConfig.put("typePath", typePath);
    layerConfig.put("showTableView", AbstractLayer.isShowNewLayerTableView());
    final LinkedList<String> path = new LinkedList<>();
    {
        BaseTreeNode node = BaseTree.getMenuNode();
        node = node.getParent();
        while (node != null) {
            final Object nodeValue = node.getUserObject();
            String nodeName = node.getName();
            if (node instanceof PathTreeNode) {
                nodeName = FileUtil.getBaseName(nodeName);
            }
            if (nodeValue instanceof RecordStoreSchemaElement) {
                path.addFirst(nodeName);
                node = node.getParent();
            } else {
                path.addFirst(nodeName);
                node = null;
            }
        }
    }
    final AbstractLayer layer = new RecordStoreLayer(layerConfig);
    LayerGroup layerGroup = Project.get();
    for (final String name : path) {
        try {
            layerGroup = layerGroup.addLayerGroup(name);
        } catch (final IllegalArgumentException e) {
            int i = 1;
            while (layerGroup.hasLayerWithSameName(null, name + i)) {
                i++;
            }
            layerGroup = layerGroup.addLayerGroup(name + i);
        }
    }
    layerGroup.addLayer(layer);
}
Also used : RecordStoreLayer(com.revolsys.swing.map.layer.record.RecordStoreLayer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) PathTreeNode(com.revolsys.swing.tree.node.file.PathTreeNode) RecordStore(com.revolsys.record.schema.RecordStore) BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode) PathName(com.revolsys.io.PathName) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 35 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class MapGuideWebServerRecordLayer method initializeDo.

@Override
protected boolean initializeDo() {
    FeatureLayer webServiceLayer = getWebServiceLayer();
    if (webServiceLayer == null) {
        final String url = getUrl();
        final PathName layerPath = getLayerPath();
        if (url == null) {
            Logs.error(this, Classes.className(this) + " requires a url: " + getPath());
            return false;
        }
        if (layerPath == null) {
            Logs.error(this, Classes.className(this) + " requires a layerPath: " + getPath());
            return false;
        }
        ArcGisRestCatalog server;
        try {
            server = ArcGisRestCatalog.newArcGisRestCatalog(url);
        } catch (final Throwable e) {
            Logs.error(this, "Unable to connect to server: " + url + " for " + getPath(), e);
            return false;
        }
        try {
            webServiceLayer = server.getWebServiceResource(layerPath, FeatureLayer.class);
        } catch (final IllegalArgumentException e) {
            Logs.error(this, "Layer is not valid: " + getPath(), e);
            return false;
        }
        if (webServiceLayer == null) {
            Logs.error(this, "Layer does not exist: " + layerPath + " for " + getPath());
            return false;
        } else {
            setWebServiceLayer(webServiceLayer);
        }
    }
    if (webServiceLayer != null) {
        final RecordDefinition recordDefinition = webServiceLayer.getRecordDefinition();
        if (recordDefinition != null) {
            setRecordDefinition(recordDefinition);
            setBoundingBox(webServiceLayer.getBoundingBox());
            // initRenderer();
            return super.initializeDo();
        }
    }
    return false;
}
Also used : FeatureLayer(com.revolsys.record.io.format.mapguide.FeatureLayer) ArcGisRestCatalog(com.revolsys.record.io.format.esri.rest.ArcGisRestCatalog) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

PathName (com.revolsys.io.PathName)64 FieldDefinition (com.revolsys.record.schema.FieldDefinition)15 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)14 DataType (com.revolsys.datatype.DataType)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)13 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)12 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)9 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)7 ArrayList (java.util.ArrayList)7 TreeMap (java.util.TreeMap)7 MapEx (com.revolsys.collection.map.MapEx)5 ResultSet (java.sql.ResultSet)5 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)4 Identifier (com.revolsys.identifier.Identifier)4 JdbcConnection (com.revolsys.jdbc.JdbcConnection)4 Record (com.revolsys.record.Record)4 File (java.io.File)4 PreparedStatement (java.sql.PreparedStatement)4 Geometry (com.revolsys.geometry.model.Geometry)3