use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class Query method setWhereCondition.
public Query setWhereCondition(final Condition whereCondition) {
if (whereCondition == null) {
this.whereCondition = Condition.ALL;
} else {
this.whereCondition = whereCondition;
final RecordDefinition recordDefinition = getRecordDefinition();
if (recordDefinition != null) {
whereCondition.setRecordDefinition(recordDefinition);
}
}
return this;
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class OracleJdbcQueryResultPager method updateResults.
/**
* Update the cached results for the current page.
*/
@Override
protected void updateResults() {
synchronized (this) {
final JdbcRecordStore recordStore = getRecordStore();
final Query query = getQuery();
setNumResults(recordStore.getRecordCount(query));
updateNumPages();
final ArrayList<Record> results = new ArrayList<>();
final int pageSize = getPageSize();
final int pageNumber = getPageNumber();
if (pageNumber != -1) {
String sql = getSql();
final int startRowNum = (pageNumber - 1) * pageSize + 1;
final int endRowNum = startRowNum + pageSize - 1;
sql = "SELECT * FROM ( SELECT T2.*, ROWNUM TROWNUM FROM ( " + sql + ") T2 ) WHERE TROWNUM BETWEEN " + startRowNum + " AND " + endRowNum;
try (final JdbcConnection connection = getRecordStore().getJdbcConnection()) {
final RecordFactory<Record> recordFactory = getRecordFactory();
final RecordDefinition recordDefinition = getRecordDefinition();
final List<FieldDefinition> attributes = new ArrayList<>();
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
attributes.addAll(recordDefinition.getFields());
} else {
for (final String fieldName : fieldNames) {
if (fieldName.equals("*")) {
attributes.addAll(recordDefinition.getFields());
} else {
final FieldDefinition attribute = recordDefinition.getField(fieldName);
if (attribute != null) {
attributes.add(attribute);
}
}
}
}
try (final PreparedStatement statement = connection.prepareStatement(sql);
final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
if (resultSet.next()) {
int i = 0;
do {
final Record record = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
results.add(record);
i++;
} while (resultSet.next() && i < pageSize);
}
} catch (final SQLException e) {
throw connection.getException("updateResults", sql, e);
}
}
setResults(results);
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class OgrRecordStore method getSql.
protected String getSql(final Query query) {
final RecordDefinition recordDefinition = query.getRecordDefinition();
final String typePath = recordDefinition.getPath();
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
fieldNames = recordDefinition.getFieldNames();
}
fieldNames.remove("ROWID");
StringBuilders.append(sql, fieldNames);
sql.append(" FROM ");
final String layerName = getLayerName(typePath);
sql.append(layerName);
final StringBuilder whereClause = getWhereClause(query);
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
boolean first = true;
for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
final CharSequence fieldName = entry.getKey();
if (first) {
sql.append(" ORDER BY ");
first = false;
} else {
sql.append(", ");
}
if (fieldName instanceof FieldDefinition) {
final FieldDefinition field = (FieldDefinition) fieldName;
field.appendColumnName(sql);
} else {
sql.append(fieldName);
}
final Boolean ascending = entry.getValue();
if (!ascending) {
sql.append(" DESC");
}
}
return sql.toString();
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class OgrRecordStore method newIterator.
@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
String typePath = query.getTypeName();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
typePath = query.getTypeName();
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
throw new IllegalArgumentException("Type name does not exist " + typePath);
} else {
query.setRecordDefinition(recordDefinition);
}
} else {
typePath = recordDefinition.getPath();
}
final OgrQueryIterator iterator = new OgrQueryIterator(this, query);
return iterator;
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class OgrRecordWriter method delete.
private void delete(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final Layer layer = getLayer(recordDefinition);
final String driverName = this.recordStore.getDriverName();
if (OgrRecordStore.SQLITE.equals(driverName) || OgrRecordStore.GEO_PAKCAGE.equals(driverName)) {
final Integer fid = record.getInteger(OgrRecordStore.ROWID);
if (fid != null) {
layer.DeleteFeature(fid);
}
}
}
Aggregations