use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getTable.
protected Table getTable(final RecordDefinition recordDefinition) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final RecordDefinition fgdbRecordDefinition = getRecordDefinition(recordDefinition);
if (!isExists() || fgdbRecordDefinition == null) {
return null;
} else {
try {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return null;
} else {
final String catalogPath = getCatalogPath(fgdbRecordDefinition);
try {
Table table = this.tableByCatalogPath.get(catalogPath);
if (table == null) {
table = this.geodatabase.openTable(catalogPath);
if (table != null) {
if (this.tableByCatalogPath.isEmpty()) {
this.geodatabaseReferenceCount++;
}
Maps.addCount(this.tableReferenceCountsByCatalogPath, catalogPath);
this.tableByCatalogPath.put(catalogPath, table);
}
} else {
Maps.addCount(this.tableReferenceCountsByCatalogPath, catalogPath);
}
return table;
} catch (final RuntimeException e) {
throw new RuntimeException("Unable to open table " + catalogPath, e);
}
}
} finally {
releaseGeodatabase();
}
}
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method insertRecord.
@Override
public void insertRecord(final Record record) {
if (record == null) {
} else {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final Table table = getTableWithWriteLock(recordDefinition);
try {
insertRecord(table, record);
} finally {
releaseTableAndWriteLock(recordDefinition);
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getRecord.
@Override
public Record getRecord(final PathName typePath, final Object... id) {
synchronized (this.apiSync) {
final RecordDefinition recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
throw new IllegalArgumentException("Unknown type " + typePath);
} else {
final String catalogPath = getCatalogPath(typePath);
final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, recordDefinition.getIdFieldName() + " = " + id[0]);
try {
if (iterator.hasNext()) {
return iterator.next();
} else {
return null;
}
} finally {
iterator.close();
}
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getRecordDefinition.
@SuppressWarnings("unchecked")
@Override
public <RD extends RecordDefinition> RD getRecordDefinition(final RecordDefinition sourceRecordDefinition) {
synchronized (this.apiSync) {
if (getGeometryFactory() == null) {
setGeometryFactory(sourceRecordDefinition.getGeometryFactory());
}
final String typePath = sourceRecordDefinition.getPath();
RecordDefinition recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
if (!sourceRecordDefinition.hasGeometryField()) {
recordDefinition = getRecordDefinition(PathUtil.getName(typePath));
}
if (this.createMissingTables && recordDefinition == null) {
recordDefinition = newTableRecordDefinition(sourceRecordDefinition);
}
}
return (RD) recordDefinition;
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getRecordCount.
@Override
public int getRecordCount(final Query query) {
if (query == null) {
return 0;
} else {
synchronized (this.apiSync) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return 0;
} else {
try {
String typePath = query.getTypeName();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
typePath = query.getTypeName();
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
return 0;
}
} else {
typePath = recordDefinition.getPath();
}
final StringBuilder whereClause = getWhereClause(query);
final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
if (boundingBox == null) {
final StringBuilder sql = new StringBuilder();
sql.append("SELECT OBJECTID FROM ");
sql.append(JdbcUtils.getTableName(typePath));
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
int count = 0;
for (@SuppressWarnings("unused") final Row row : rows) {
count++;
}
return count;
}
} else {
final GeometryFieldDefinition geometryField = (GeometryFieldDefinition) recordDefinition.getGeometryField();
if (geometryField == null || boundingBox.isEmpty()) {
return 0;
} else {
final StringBuilder sql = new StringBuilder();
sql.append("SELECT " + geometryField.getName() + " FROM ");
sql.append(JdbcUtils.getTableName(typePath));
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
int count = 0;
for (final Row row : rows) {
final Geometry geometry = (Geometry) geometryField.getValue(row);
if (geometry != null) {
final BoundingBox geometryBoundingBox = geometry.getBoundingBox();
if (geometryBoundingBox.intersects(boundingBox)) {
count++;
}
}
}
return count;
}
}
}
} finally {
releaseGeodatabase();
}
}
}
}
}
Aggregations