// sql view handling
VirtualTable vt = null;
String vtName = null;
if(dataAccess instanceof JDBCDataStore && info.getMetadata() != null &&
(info.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE) instanceof VirtualTable)) {
JDBCDataStore jstore = (JDBCDataStore) dataAccess;
vt = info.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class);
if(!cacheable) {
// use a highly random name, we don't want to actually add the
// virtual table to the store as this feature type is not cacheable,
// it is "dirty" or un-saved. The renaming below will take care
// of making the user see the actual name
final String[] typeNames = jstore.getTypeNames();
do {
vtName = UUID.randomUUID().toString();
} while (Arrays.asList(typeNames).contains(vtName));
// try adding the vt and see if that works
jstore.addVirtualTable(new VirtualTable(vtName, vt));
ft = jstore.getSchema(vtName);
} else {
vtName = vt.getName();
jstore.addVirtualTable(vt);
ft = jstore.getSchema(vt.getName());
}
} else {
ft = dataAccess.getSchema(info.getQualifiedNativeName());
}
// TODO: support reprojection for non-simple FeatureType
if (ft instanceof SimpleFeatureType) {
SimpleFeatureType sft = (SimpleFeatureType) ft;
//create the feature type so it lines up with the "declared" schema
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.setName( info.getName() );
tb.setNamespaceURI( info.getNamespace().getURI() );
if ( info.getAttributes() == null || info.getAttributes().isEmpty() ) {
//take this to mean just load all native
for ( PropertyDescriptor pd : ft.getDescriptors() ) {
if ( !( pd instanceof AttributeDescriptor ) ) {
continue;
}
AttributeDescriptor ad = (AttributeDescriptor) pd;
if(handleProjectionPolicy) {
ad = handleDescriptor(ad, info);
}
tb.add( ad );
}
}
else {
//only load native attributes configured
for ( AttributeTypeInfo att : info.getAttributes() ) {
String attName = att.getName();
//load the actual underlying attribute type
PropertyDescriptor pd = ft.getDescriptor( attName );
if ( pd == null || !( pd instanceof AttributeDescriptor) ) {
throw new IOException("the SimpleFeatureType " + info.getPrefixedName()
+ " does not contains the configured attribute " + attName
+ ". Check your schema configuration");
}
AttributeDescriptor ad = (AttributeDescriptor) pd;
ad = handleDescriptor(ad, info);
tb.add( (AttributeDescriptor) ad );
}
}
ft = tb.buildFeatureType();
} // end special case for SimpleFeatureType
if(cacheable) {
featureTypeCache.put( info.getId(), ft );
} else if(vtName != null) {
JDBCDataStore jstore = (JDBCDataStore) dataAccess;
jstore.removeVirtualTable(vtName);
}
}
}
}