use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class CustomTypeContentHelper method applyElementsMode.
private static void applyElementsMode(PropertyDefinition propDef, DefinitionGroup propParent, CustomTypeContent config, XmlIndex index) {
// build new property type based on config
DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(propDef.getIdentifier(), "customElementsContentType"), false);
type.setConstraint(MappableFlag.DISABLED);
DefaultGroupPropertyDefinition choice = new DefaultGroupPropertyDefinition(new QName(propDef.getIdentifier(), "customElementsContentChoice"), type, false);
choice.setConstraint(new DisplayName("elements"));
choice.setConstraint(ChoiceFlag.ENABLED);
choice.setConstraint(Cardinality.CC_ANY_NUMBER);
for (QName elementName : config.getElements()) {
XmlElement element = index.getElements().get(elementName);
if (element != null) {
DefaultPropertyDefinition elementProp = new DefaultPropertyDefinition(elementName, choice, element.getType());
elementProp.setConstraint(Cardinality.CC_EXACTLY_ONCE);
elementProp.setConstraint(NillableFlag.DISABLED);
} else {
log.error("Element {} could not be found when creating custom type content", elementName);
}
}
replaceTypeForProperty(propDef, propParent, type);
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class CQLFilterDialogFactory method openDialog.
@Override
public Filter openDialog(Shell shell, EntityDefinition entityDef, String title, String message) {
TypeEntityDefinition parentType;
if (entityDef.getPropertyPath().isEmpty())
parentType = AlignmentUtil.getTypeEntity(entityDef);
else {
Definition<?> def = entityDef.getDefinition();
TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
// create a dummy type for the filter
TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
// create dummy type entity
Condition condition = AlignmentUtil.getContextCondition(entityDef);
Filter filter = condition == null ? null : condition.getFilter();
parentType = new TypeEntityDefinition(dummyType, entityDef.getSchemaSpace(), filter);
// with the property type being contained as value
// property
new DefaultPropertyDefinition(new QName("value"), dummyType, propertyType);
// and the parent type as parent property
new DefaultPropertyDefinition(new QName("parent"), dummyType, ((PropertyDefinition) def).getParentType());
}
CQLFilterDialog dialog = new CQLFilterDialog(shell, parentType, title, message);
if (dialog.open() == CQLFilterDialog.OK) {
return dialog.getFilter();
}
return null;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class PropertyFunctionScriptPage method createDummyEntity.
private EntityDefinition createDummyEntity(DefaultCustomPropertyFunctionEntity entity, SchemaSpaceID ssid) {
DefaultTypeDefinition parent = new DefaultTypeDefinition(new QName("dummy"));
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(entity.getName()), parent, createDummyType(entity));
property.setConstraint(Cardinality.get(entity.getMinOccurrence(), entity.getMaxOccurrence()));
return new PropertyEntityDefinition(parent, Collections.singletonList(new ChildContext(property)), ssid, null);
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class JDBCSchemaReader method getOrCreateColumnType.
/**
* Get or create the type definition for the given column.
*
* @param column the column
* @param overallNamespace the database namespace
* @param types the type index
* @param connection the database connection
* @param tableType the type definition of the table the column is part of
* @param reporter the reporter
* @param catalog the catalog for access to other column types
* @return the type definition for the column type
*/
public static TypeDefinition getOrCreateColumnType(BaseColumn<?> column, final String overallNamespace, DefaultSchema types, Connection connection, TypeDefinition tableType, IOReporter reporter, Catalog catalog) {
// XXX what about shared types?
// TODO the size/width info (VARCHAR(_30_)) is in column, the
// columntype/-name is not sufficient
// getType();
ColumnDataType columnType = column.getColumnDataType();
String localName = columnType.getName();
QName typeName = new QName(overallNamespace, localName);
// check for geometry type
GeometryTypeInfo geomType = GeometryTypeExtension.getInstance().getTypeInfo(columnType.getName(), connection);
@SuppressWarnings("rawtypes") GeometryAdvisor geomAdvisor = null;
if (geomType != null) {
geomAdvisor = geomType.getGeometryAdvisor();
// determine if a type specifically for this column is needed
if (!geomAdvisor.isFixedType(columnType)) {
// must use a specific type definition for this column
// -> use a type name based on the column
// new namespace is the table and column name
String ns = tableType.getName().getNamespaceURI() + '/' + tableType.getName().getLocalPart() + '/' + unquote(column.getName());
typeName = new QName(ns, localName);
}
}
// check for existing type
TypeDefinition existing = types.getType(typeName);
if (existing != null)
return existing;
// create new type
DefaultTypeDefinition type = new DefaultTypeDefinition(typeName);
type.setConstraint(HasValueFlag.ENABLED);
CustomType cust = CustomTypeExtension.getInstance().getCustomType(localName, connection);
/*
* Oracle jdbc was returning sqltype -6 for NUMBER data type, but it is
* bound to boolean by Types.java class. Configured the sqltype 6 for
* NUMBER data type.
*/
if (cust != null) {
type.setConstraint(SQLType.get(cust.getSQLType()));
} else {
type.setConstraint(SQLType.get(columnType.getJavaSqlType().getJavaSqlType()));
}
if (geomType != null && geomAdvisor != null) {
// configure geometry type
@SuppressWarnings("unchecked") Class<? extends Geometry> geomClass = geomAdvisor.configureGeometryColumnType(connection, column, type, reporter);
type.setConstraint(GeometryType.get(geomClass));
// always a single geometry
type.setConstraint(Binding.get(GeometryProperty.class));
// remember advisor for type (used in instance writer)
type.setConstraint(geomType.getConstraint());
} else {
// configure type
Class<?> binding = null;
if (cust != null) {
binding = cust.getBinding();
} else {
if (column.getColumnDataType().getJavaSqlType().getJavaSqlType() == Types.ARRAY) {
// TODO let this be handled by a possible advisor?
/*
* Special handling for arrays.
*
* Challenges:
*
* - find the type of contained items
*
* - determine dimensions and size
*/
Class<?> elementBinding;
// determine type/binding of contained items
ColumnDataType cdt = column.getColumnDataType();
ColumnDataType itemType = null;
String dbTypeName = cdt.getDatabaseSpecificTypeName();
// prefix and look up type
if (dbTypeName.startsWith("_")) {
String testName = dbTypeName.substring(1);
itemType = catalog.getSystemColumnDataType(testName);
}
if (itemType == null) {
// generic binding
elementBinding = Object.class;
reporter.error(new IOMessageImpl("Could not determine element type for array column", null));
} else {
elementBinding = itemType.getTypeMappedClass();
// TODO support custom bindings?
// XXX probably needed for Oracle?
}
// dimensions and size cannot be determined from schema
// crawler it seems - would need database specific queries
// (if the info is available at all)
/*
* Postgres:
*
* Dimensions and size are not part of the schema, they can
* only be determined for a value.
*/
// XXX for now, stick to what we can determine
int dimension = SQLArray.UNKNOWN_DIMENSION;
String specificTypeName = (itemType != null) ? (itemType.getDatabaseSpecificTypeName()) : (null);
type.setConstraint(new SQLArray(elementBinding, specificTypeName, dimension, null));
// set binding
if (dimension <= 1) {
// XXX for now, use this representation also if
// dimension is not known
// 1-dimensional -> as multiple occurrences
binding = elementBinding;
} else {
// XXX use collection or something similar instead?
binding = Object.class;
}
} else {
binding = column.getColumnDataType().getTypeMappedClass();
}
}
type.setConstraint(Binding.get(binding));
type.setConstraint(HasValueFlag.ENABLED);
}
if (columnType.getRemarks() != null && !columnType.getRemarks().isEmpty())
type.setDescription(columnType.getRemarks());
types.addType(type);
return type;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class JDBCSchemaReader method getOrCreateTableType.
/**
* Get or create the type definition for the given table.
*
* @param schema the schema in which the table exists
* @param table the table
* @param overallNamespace the database namespace
* @param namespace the schema namespace
* @param types the type index
* @param connection the database connection
* @param reporter the reporter
* @param catalog the catalog for access to other column types
* @return the type definition for the given table
*/
private TypeDefinition getOrCreateTableType(schemacrawler.schema.Schema schema, Table table, String overallNamespace, String namespace, DefaultSchema types, Connection connection, IOReporter reporter, Catalog catalog) {
QName typeName = new QName(namespace, unquote(table.getName()));
// check for existing type
TypeDefinition existingType = types.getType(typeName);
if (existingType != null)
return existingType;
// create new type
DefaultTypeDefinition type = new DefaultTypeDefinition(typeName);
// set description if available
if (table.getRemarks() != null && !table.getRemarks().isEmpty())
type.setDescription(table.getRemarks());
// configure type
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
// set schema and table name
DatabaseTable tableConstraint = new DatabaseTable(unquote(schema.getName()), unquote(table.getName()), useQuote);
type.setConstraint(tableConstraint);
// set SQL query constraint
String query = "SELECT * FROM " + tableConstraint.getFullTableName();
type.setConstraint(new SQLQuery(query));
// set primary key if possible
PrimaryKey key = null;
try {
key = table.getPrimaryKey();
} catch (Exception e) {
reporter.warn(new IOMessageImpl("Could not read primary key metadata for table: " + table.getFullName(), e));
}
if (key != null) {
List<IndexColumn> columns = key.getColumns();
if (columns.size() > 1) {
reporter.warn(new IOMessageImpl("Primary keys over multiple columns are not yet supported.", null));
} else if (columns.size() == 1) {
// create constraint, get property definition for original table
// column (maybe could use index column, too)
type.setConstraint(new eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey(Collections.<QName>singletonList(getOrCreateProperty(schema, type, table.getColumn(columns.get(0).getName()), overallNamespace, namespace, types, connection, reporter, catalog).getName())));
}
}
// TODO validation of constraints? Most are about several instances (i.
// e. UNIQUE)
types.addType(type);
return type;
}
Aggregations