use of mil.nga.geopackage.user.UserColumn in project hale by halestudio.
the class GeopackageInstanceWriter method populateRow.
private void populateRow(UserCoreRow<?, ?> row, Instance instance, SimpleLog log) {
for (String column : row.getColumnNames()) {
Object value = new InstanceAccessor(instance).findChildren(column).value();
if (value != null) {
UserColumn col = row.getColumn(column);
if (col.isPrimaryKey()) {
// it seems for primary key we can't set a value
continue;
}
// any value processing
try {
switch(col.getDataType()) {
case DATE:
// convert to LocalDate, then to String
LocalDate ld = ConversionUtil.getAs(value, LocalDate.class);
value = ld.toString();
break;
case DATETIME:
// convert to Instant, then to String
Instant inst = ConversionUtil.getAs(value, Instant.class);
value = inst.toString();
break;
case INT:
case INTEGER:
case MEDIUMINT:
case SMALLINT:
case TINYINT:
case REAL:
case FLOAT:
case DOUBLE:
case TEXT:
// generic conversion to data type
value = ConversionUtil.getAs(value, col.getDataType().getClassType());
break;
default:
// use as-is
break;
}
} catch (ConversionException e) {
log.error("Could not convert value to column type", e);
}
row.setValue(column, value);
}
}
}
use of mil.nga.geopackage.user.UserColumn in project hale by halestudio.
the class GeopackageSchemaBuilder method buildType.
private TypeDefinition buildType(UserDao<?, ?, ?, ?> dao, GeometryColumns geomColumns, DefaultSchema schema) {
QName name = new QName(defaultNamespace, dao.getTableName());
DefaultTypeDefinition type = new DefaultTypeDefinition(name);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
type.setConstraint(Binding.get(Instance.class));
UserTable<? extends UserColumn> table = dao.getTable();
// set primary key constraint
UserColumn pkColumn = table.getPkColumn();
if (pkColumn != null) {
type.setConstraint(new PrimaryKey(Collections.singletonList(new QName(pkColumn.getName()))));
}
for (String columnName : table.getColumnNames()) {
UserColumn column = table.getColumn(columnName);
QName propertyName = new QName(columnName);
// determine property type
TypeDefinition propertyType = getOrCreatePropertyType(column, geomColumns, schema);
DefaultPropertyDefinition property = new DefaultPropertyDefinition(propertyName, type, propertyType);
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
if (column.isNotNull()) {
property.setConstraint(NillableFlag.DISABLED);
} else {
property.setConstraint(NillableFlag.ENABLED);
}
}
return type;
}
Aggregations