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;
}
}
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);
}
}
}
}
}
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;
}
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);
}
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;
}
Aggregations