use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class RecordGraph method getTypeName.
/**
* Get the type name for the edge.
*
* @param edge The edge.
* @return The type name.
*/
@Override
public String getTypeName(final Edge<Record> edge) {
final Record record = edge.getObject();
if (record == null) {
return null;
} else {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String typePath = recordDefinition.getPath();
return typePath;
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class JdbcUtils method getSelectSql.
public static String getSelectSql(final Query query) {
final String tableName = query.getTypeName();
final String dbTableName = getQualifiedTableName(tableName);
String sql = query.getSql();
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (sql == null) {
if (recordDefinition == null) {
recordDefinition = new RecordDefinitionImpl(PathName.newPathName(tableName));
// throw new IllegalArgumentException("Unknown table name " +
// tableName);
}
final List<String> fieldNames = new ArrayList<>(query.getFieldNames());
if (fieldNames.isEmpty()) {
final List<String> recordDefinitionFieldNames = recordDefinition.getFieldNames();
if (recordDefinitionFieldNames.isEmpty()) {
fieldNames.add("T.*");
} else {
fieldNames.addAll(recordDefinitionFieldNames);
}
}
final String fromClause = query.getFromClause();
final LockMode lockMode = query.getLockMode();
final boolean distinct = query.isDistinct();
sql = newSelectSql(recordDefinition, "T", distinct, fromClause, fieldNames, query, orderBy, lockMode);
} else {
if (sql.toUpperCase().startsWith("SELECT * FROM ")) {
final StringBuilder newSql = new StringBuilder("SELECT ");
addColumnNames(newSql, recordDefinition, dbTableName);
newSql.append(" FROM ");
newSql.append(sql.substring(14));
sql = newSql.toString();
}
if (!orderBy.isEmpty()) {
final StringBuilder buffer = new StringBuilder(sql);
addOrderBy(buffer, orderBy);
sql = buffer.toString();
}
}
return sql;
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class JdbcUtils method appendWhere.
public static void appendWhere(final StringBuilder sql, final Query query) {
final Condition where = query.getWhereCondition();
if (!where.isEmpty()) {
sql.append(" WHERE ");
final RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
where.appendSql(query, null, sql);
} else {
final RecordStore recordStore = recordDefinition.getRecordStore();
where.appendSql(query, recordStore, sql);
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class RecordCodeTableValueFilter method test.
/**
* Match the fieldName on the data object with the required value.
*
* @param object The object.
* @return True if the object matched the filter, false otherwise.
*/
@Override
public boolean test(final Record object) {
final Object propertyValue = object.getValue(this.fieldName);
if (this.values.contains(propertyValue)) {
return true;
} else {
final RecordDefinition recordDefinition = object.getRecordDefinition();
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(this.fieldName);
if (codeTable != null) {
final Object codeValue = codeTable.getValue(Identifier.newIdentifier(propertyValue));
if (this.values.contains(codeValue)) {
this.values.add(propertyValue);
return true;
} else {
return false;
}
} else {
return false;
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class AbstractJdbcRecordStore method getRecordDefinition.
@Override
public JdbcRecordDefinition getRecordDefinition(String typePath, final ResultSetMetaData resultSetMetaData, final String dbTableName) {
if (Property.isEmpty(typePath)) {
typePath = "Record";
}
try {
final PathName pathName = PathName.newPathName(typePath);
final PathName schemaName = pathName.getParent();
final JdbcRecordStoreSchema schema = getSchema(schemaName);
final JdbcRecordDefinition resultRecordDefinition = newRecordDefinition(schema, pathName, dbTableName);
final RecordDefinition recordDefinition = getRecordDefinition(typePath);
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
final String fieldName = resultSetMetaData.getColumnName(i).toUpperCase();
if (recordDefinition != null && recordDefinition.isIdField(fieldName)) {
resultRecordDefinition.setIdFieldIndex(i - 1);
}
addField(resultSetMetaData, resultRecordDefinition, fieldName, i, null);
}
addRecordDefinitionProperties(resultRecordDefinition);
return resultRecordDefinition;
} catch (final SQLException e) {
throw new IllegalArgumentException("Unable to load metadata for " + typePath);
}
}
Aggregations