use of com.revolsys.record.schema.RecordDefinitionImpl 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.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class AbstractJdbcRecordStore method refreshSchemaElementsDo.
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElementsDo(final JdbcRecordStoreSchema schema, final PathName schemaPath) {
final String dbSchemaName = schema.getDbName();
final Map<PathName, JdbcRecordDefinition> recordDefinitionMap = loadRecordDefinitionsPermissions(schema);
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
try {
try (final Connection connection = getJdbcConnection()) {
final DatabaseMetaData databaseMetaData = connection.getMetaData();
final Map<String, List<String>> idFieldNameMap = loadIdFieldNames(dbSchemaName);
for (final JdbcRecordDefinition recordDefinition : recordDefinitionMap.values()) {
final PathName typePath = recordDefinition.getPathName();
final List<String> idFieldNames = idFieldNameMap.get(typePath);
if (Property.isEmpty(idFieldNames)) {
addRowIdFieldDefinition(recordDefinition);
}
elementsByPath.put(typePath, recordDefinition);
}
try (final ResultSet columnsRs = databaseMetaData.getColumns(null, dbSchemaName, "%", "%")) {
while (columnsRs.next()) {
final String tableName = columnsRs.getString("TABLE_NAME").toUpperCase();
final PathName typePath = schemaPath.newChild(tableName);
final JdbcRecordDefinition recordDefinition = recordDefinitionMap.get(typePath);
if (recordDefinition != null) {
final String dbColumnName = columnsRs.getString("COLUMN_NAME");
final String name = dbColumnName.toUpperCase();
final int sqlType = columnsRs.getInt("DATA_TYPE");
final String dataType = columnsRs.getString("TYPE_NAME");
final int length = columnsRs.getInt("COLUMN_SIZE");
int scale = columnsRs.getInt("DECIMAL_DIGITS");
if (columnsRs.wasNull()) {
scale = -1;
}
final boolean required = !columnsRs.getString("IS_NULLABLE").equals("YES");
final String description = columnsRs.getString("REMARKS");
addField(recordDefinition, dbColumnName, name, dataType, sqlType, length, scale, required, description);
}
}
for (final RecordDefinitionImpl recordDefinition : recordDefinitionMap.values()) {
final String typePath = recordDefinition.getPath();
final List<String> idFieldNames = idFieldNameMap.get(typePath);
if (!Property.isEmpty(idFieldNames)) {
recordDefinition.setIdFieldNames(idFieldNames);
}
}
}
}
} catch (final Throwable e) {
throw new IllegalArgumentException("Unable to load metadata for schema " + dbSchemaName, e);
}
return elementsByPath;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getRecordDefinition.
public static RecordDefinition getRecordDefinition(final String schemaName, final Domain domain, final boolean appendIdToName) {
final String tableName;
if (appendIdToName) {
tableName = domain.getName() + "_ID";
} else {
tableName = domain.getName();
}
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
final FieldType fieldType = domain.getFieldType();
final DataType dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
int length = 0;
for (final CodedValue codedValue : domain.getCodedValues()) {
length = Math.max(length, codedValue.getCode().toString().length());
}
recordDefinition.addField(tableName, dataType, length, true);
recordDefinition.addField("DESCRIPTION", DataTypes.STRING, 255, true);
recordDefinition.setIdFieldIndex(0);
return recordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class MoepConstants method newRecordDefinition.
public static RecordDefinitionImpl newRecordDefinition(final String typePath) {
final RecordDefinitionImpl type = new RecordDefinitionImpl(PathName.newPathName(typePath));
type.addField(FEATURE_CODE, DataTypes.STRING, 10, true);
type.addField(MAPSHEET_NAME, DataTypes.STRING, 7, false);
type.addField(DISPLAY_TYPE, DataTypes.STRING, 20, true);
type.addField(ANGLE, DataTypes.DECIMAL, false);
type.addField(ELEVATION, DataTypes.DECIMAL, false);
type.addField(TEXT_GROUP, DataTypes.DECIMAL, false);
type.addField(TEXT_INDEX, DataTypes.DECIMAL, false);
type.addField(TEXT, DataTypes.STRING, 200, false);
type.addField(FONT_NAME, DataTypes.STRING, 10, false);
type.addField(FONT_SIZE, DataTypes.DECIMAL, false);
type.addField(FONT_WEIGHT, DataTypes.STRING, 10, false);
type.addField(ORIGINAL_FILE_TYPE, DataTypes.STRING, 20, false);
type.addField(ADMIT_SOURCE_DATE, DataTypes.DATE, false);
type.addField(ADMIT_REASON_FOR_CHANGE, DataTypes.STRING, 1, false);
type.addField(ADMIT_INTEGRATION_DATE, DataTypes.DATE, false);
type.addField(ADMIT_REVISION_KEY, DataTypes.STRING, 10, false);
type.addField(ADMIT_SPECIFICATIONS_RELEASE, DataTypes.STRING, 10, false);
type.addField(RETIRE_SOURCE_DATE, DataTypes.DATE, false);
type.addField(RETIRE_REASON_FOR_CHANGE, DataTypes.STRING, 1, false);
type.addField(RETIRE_INTEGRATION_DATE, DataTypes.DATE, false);
type.addField(RETIRE_REVISION_KEY, DataTypes.STRING, 10, false);
type.addField(RETIRE_SPECIFICATIONS_RELEASE, DataTypes.STRING, 10, false);
type.addField(GEOMETRY, DataTypes.GEOMETRY, true);
type.setGeometryFieldName(GEOMETRY);
return type;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class OsnReader method skipToFirstRecord.
/**
* Skip all objects and attributes until the first object in the collection.
*
* @return True if an object was found.
* @throws IOException If an I/O error occurs.
*/
private boolean skipToFirstRecord() throws IOException {
if (this.osnIterator.next() == OsnIterator.START_DEFINITION) {
final String typePath = this.osnIterator.getPathValue();
final RecordDefinitionImpl type = (RecordDefinitionImpl) this.recordDefinitionFactory.getRecordDefinition(typePath);
final RecordDefinition spatialDataSetType = this.recordDefinitionFactory.getRecordDefinition("/SpatialDataSet");
if (type != null && type.isInstanceOf(spatialDataSetType)) {
final String oiName = this.osnIterator.nextFieldName();
if (oiName != null && oiName.equals("objectIdentifier")) {
this.osnIterator.nextStringValue();
final String fieldName = this.osnIterator.nextFieldName();
if (fieldName != null && (fieldName.equals("geoComponents") || fieldName.equals("annotationComponents"))) {
if (this.osnIterator.next() == OsnIterator.START_SET) {
return true;
} else {
this.osnIterator.throwParseError("Expecting a set of objects");
}
} else {
this.osnIterator.throwParseError("Excepecting the 'geoComponents' attribute");
}
} else {
this.osnIterator.throwParseError("Expecting the 'objectIdentifier' attribute");
}
} else {
return true;
}
} else {
this.osnIterator.throwParseError("Expecting a start of an object definition");
}
return false;
}
Aggregations