use of org.gdal.ogr.DataSource in project com.revolsys.open by revolsys.
the class OgrRecordStore method newDataSource.
protected DataSource newDataSource(final boolean update) {
final String path = FileUtil.getCanonicalPath(this.file);
DataSource dataSource;
if (this.file.exists()) {
dataSource = ogr.Open(path, update);
} else {
final Driver driver = ogr.GetDriverByName(this.driverName);
dataSource = driver.CreateDataSource(path);
}
return dataSource;
}
use of org.gdal.ogr.DataSource in project com.revolsys.open by revolsys.
the class OgrQueryIterator method initDo.
@Override
protected synchronized void initDo() {
if (this.recordStore != null) {
final DataSource dataSource = this.recordStore.getDataSource();
if (dataSource != null) {
final String sql = this.recordStore.getSql(this.query);
this.layer = dataSource.ExecuteSQL(sql);
this.recordStore.addLayerToClose(this.layer);
}
}
}
use of org.gdal.ogr.DataSource in project com.revolsys.open by revolsys.
the class OgrRecordStore method refreshSchemaElements.
@Override
protected synchronized Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
if (!isClosed()) {
final DataSource dataSource = getDataSource();
if (dataSource != null) {
for (int layerIndex = 0; layerIndex < dataSource.GetLayerCount(); layerIndex++) {
final Layer layer = dataSource.GetLayer(layerIndex);
if (layer != null) {
try {
final RecordDefinitionImpl recordDefinition = newLayerRecordDefinition(schema, layer);
final PathName typePath = recordDefinition.getPathName();
final String layerName = layer.GetName();
this.layerNameToPathMap.put(layerName.toUpperCase(), typePath);
this.pathToLayerNameMap.put(typePath, layerName);
elementsByPath.put(typePath, recordDefinition);
} finally {
layer.delete();
}
}
}
}
}
return elementsByPath;
}
use of org.gdal.ogr.DataSource in project com.revolsys.open by revolsys.
the class OgrRecordStore method getRecordCount.
@Override
public int getRecordCount(final Query query) {
if (query == null) {
return 0;
} else {
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 StringBuilder sql = new StringBuilder();
sql.append("SELECT COUNT(*) FROM ");
final String layerName = getLayerName(typePath);
sql.append(layerName);
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
final DataSource dataSource = getDataSource();
if (dataSource != null) {
final Layer result = dataSource.ExecuteSQL(sql.toString());
if (result != null) {
addLayerToClose(result);
try {
final Feature feature = result.GetNextFeature();
if (feature != null) {
try {
return feature.GetFieldAsInteger(0);
} finally {
feature.delete();
}
}
} finally {
releaseLayerToClose(result);
}
}
}
}
return 0;
}
Aggregations