use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class JDBCSchemaReader method getOrCreateProperty.
/**
* Gets or creates a property definition for the given column. Its type
* definition is created, too, if necessary.
*
* @param schema the schema the table belongs to
* @param tableType the type definition of the parent table this column
* belongs too
* @param column the column to get or create a property definition for
* @param overallNamespace the database namespace
* @param namespace the schema namespace
* @param typeIndex the type index
* @param connection the database connection
* @param reporter the reporter
* @param catalog the catalog for access to other column types
* @return the property definition for the given column
*/
private DefaultPropertyDefinition getOrCreateProperty(schemacrawler.schema.Schema schema, TypeDefinition tableType, Column column, String overallNamespace, String namespace, DefaultSchema typeIndex, Connection connection, IOReporter reporter, Catalog catalog) {
QName name = new QName(unquote(column.getName()));
// check for existing property definition
ChildDefinition<?> existing = tableType.getChild(name);
if (existing != null) {
return (DefaultPropertyDefinition) existing;
}
// create new one
// determine the column type
TypeDefinition columnType = getOrCreateColumnType(column, overallNamespace, typeIndex, connection, tableType, reporter, catalog);
SQLArray arrayInfo = columnType.getConstraint(SQLArray.class);
// create the property
DefaultPropertyDefinition property = new DefaultPropertyDefinition(name, tableType, columnType);
// configure property
if (column.getRemarks() != null && !column.getRemarks().isEmpty()) {
property.setDescription(column.getRemarks());
}
property.setConstraint(NillableFlag.get(column.isNullable()));
// XXX Default value is read as string from the meta data.
// This is probably not really a problem, but should be noted!
// XXX In particular the default value can be a function call like for
// example GETDATE().
String defaultValue = column.getDefaultValue();
if (arrayInfo.isArray() && arrayInfo.getDimension() <= 1) {
// dimension is not known (0)
if (!arrayInfo.hasSize(0)) {
property.setConstraint(Cardinality.CC_ANY_NUMBER);
} else {
// XXX what is appropriate as minimum?
long min = 0;
long max = arrayInfo.getSize(0);
property.setConstraint(Cardinality.get(min, max));
}
} else if (defaultValue != null) {
property.setConstraint(new DefaultValue(defaultValue));
property.setConstraint(Cardinality.CC_OPTIONAL);
} else
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
// incremented or not
if (column.isAutoIncremented()) {
property.setConstraint(AutoGenerated.get(true));
} else {
property.setConstraint(AutoGenerated.get(false));
}
// since they can have multiple columns
if (column.isPartOfForeignKey()) {
Column referenced = column.getReferencedColumn();
// StackOverFlow exception.
if (!(referenced.getParent().equals(column.getParent()) && referenced.equals(column))) {
// Referenced table can be in different schema.
// creation of referenced column's table should not be with same
// Schema or Namespace. It should be with referenced table's
// Schema and namespace.
String referencedNameSpace = getReferencedTableNamespace(referenced.getParent(), overallNamespace);
property.setConstraint(new Reference(getOrCreateTableType(referenced.getParent().getSchema(), referenced.getParent(), overallNamespace, referencedNameSpace, typeIndex, connection, reporter, catalog)));
}
}
return property;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class SQLSchemaReader method getOrCreateProperty.
/**
* Gets or creates a property definition for the given column. Its type
* definition is created, too, if necessary.
*
* @param tableType the type definition of the parent table this column
* belongs too
* @param column the column to get or create a property definition for
* @param namespace the schema namespace
* @param typeIndex the type index
* @param connection the database connection
* @param reporter the reporter
* @param catalog the database information
* @return the property definition for the given column
*/
private DefaultPropertyDefinition getOrCreateProperty(TypeDefinition tableType, ResultsColumn column, String namespace, DefaultSchema typeIndex, Connection connection, IOReporter reporter, Catalog catalog) {
QName name = new QName(unquote(column.getName()));
// check for existing property definition
ChildDefinition<?> existing = tableType.getChild(name);
if (existing != null)
return (DefaultPropertyDefinition) existing;
// create new one
// determine the column type
TypeDefinition columnType = JDBCSchemaReader.getOrCreateColumnType(column, namespace, typeIndex, connection, tableType, reporter, catalog);
SQLArray arrayInfo = columnType.getConstraint(SQLArray.class);
// create the property
DefaultPropertyDefinition property = new DefaultPropertyDefinition(name, tableType, columnType);
// configure property
if (column.getRemarks() != null && !column.getRemarks().isEmpty()) {
property.setDescription(column.getRemarks());
}
property.setConstraint(NillableFlag.get(column.isNullable()));
if (arrayInfo.isArray() && arrayInfo.getDimension() <= 1) {
// dimension is not known (0)
if (!arrayInfo.hasSize(0)) {
property.setConstraint(Cardinality.CC_ANY_NUMBER);
} else {
// XXX what is appropriate as minimum?
long min = 0;
long max = arrayInfo.getSize(0);
property.setConstraint(Cardinality.get(min, max));
}
} else {
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
}
return property;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition 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.DefaultPropertyDefinition 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.DefaultPropertyDefinition 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);
}
Aggregations