public List<AttributeTypeInfo> loadAttributes(FeatureTypeInfo info) throws IOException { List<AttributeTypeInfo> attributes = new ArrayList(); FeatureType ft = getFeatureType(info); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
/** * Extracts the AttributeTypeInfo by copying them from the specified feature type. * * @param ft The schema to be harvested * @param info The optional feature type info from which all the attributes belong to */ public List<AttributeTypeInfo> getAttributes(FeatureType ft, FeatureTypeInfo info) { List<AttributeTypeInfo> attributes = new ArrayList<AttributeTypeInfo>(); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
/** * Quick heuristic used to find a small attribute to use when scanning over the entire * collection just to get the size of the collection. The result is indicative, just an * heuristic to quickly compare attributes in order to find a suitably small one, it's not meant * to be the actual size of an attribute in bytes. * * @param ad * @return */ int size(AttributeDescriptor ad) { Class<?> binding = ad.getType().getBinding(); if (binding.isPrimitive() || Number.class.isAssignableFrom(binding) || Date.class.isAssignableFrom(binding)) { return 4; } else if (binding.equals(String.class)) { int fieldLen = FeatureTypes.getFieldLength(ad); if (fieldLen > 0) { return fieldLen * 2; } else { return Integer.MAX_VALUE; } } else if (Point.class.isAssignableFrom(binding)) { return 4 * 3; } else { return Integer.MAX_VALUE; } }
String colName = type.getLocalName(); int fieldLen = FeatureTypes.getFieldLength(type); if (fieldLen == FeatureTypes.ANY_LENGTH) fieldLen = 255; if ((colType == Integer.class) || (colType == Short.class) || (colType == Byte.class)) {
@Test public void testNoLength() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("NoLength"); builder.setCRS(null); builder.add("name", String.class); builder.add("geom", Point.class); SimpleFeatureType ft = builder.buildFeatureType(); assertEquals( FeatureTypes.ANY_LENGTH, FeatureTypes.getFieldLength(ft.getDescriptor("name"))); assertEquals( FeatureTypes.ANY_LENGTH, FeatureTypes.getFieldLength(ft.getDescriptor("geom"))); }
@Test public void testStandardLength() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("StdLength"); builder.setCRS(null); builder.length(20); builder.add("name", String.class); builder.add("geom", Point.class); SimpleFeatureType ft = builder.buildFeatureType(); assertEquals(20, FeatureTypes.getFieldLength(ft.getDescriptor("name"))); assertEquals( FeatureTypes.ANY_LENGTH, FeatureTypes.getFieldLength(ft.getDescriptor("geom"))); }
@Test public void testCustomLengthExpressions() { AttributeTypeBuilder builder = new AttributeTypeBuilder(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Function length = ff.function("LengthFunction", new Expression[] {ff.property(".")}); // strict less builder.addRestriction(ff.less(length, ff.literal(20))); builder.setBinding(String.class); AttributeDescriptor attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); // flip expression builder.addRestriction(ff.greater(ff.literal(20), length)); builder.setBinding(String.class); attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); }
/** * Quick heuristic used to find a small attribute to use when * scanning over the entire collection just to get the size of the * collection. * The result is indicative, just an heuristic to quickly compare attributes * in order to find a suitably small one, * it's not meant to be the actual size of an attribute in bytes. * @param ad * @return */ int size(AttributeDescriptor ad) { Class<?> binding = ad.getType().getBinding(); if(binding.isPrimitive() || Number.class.isAssignableFrom(binding) || Date.class.isAssignableFrom(binding)) { return 4; } else if(binding.equals(String.class)) { int fieldLen = FeatureTypes.getFieldLength(ad); if(fieldLen > 0) { return fieldLen * 2; } else { return Integer.MAX_VALUE; } } else if(Point.class.isAssignableFrom(binding)) { return 4 * 3; } else { return Integer.MAX_VALUE; } }
protected String getH2DataType(AttributeDescriptor ad) { if (String.class.equals(ad.getType().getBinding())) { int length = FeatureTypes.getFieldLength(ad); if (length <= 0) length = 255; return "VARCHAR(" + length + ")"; } else { return CLASS_MAPPINGS.get(ad.getType().getBinding()); } }
protected String getH2DataType(AttributeDescriptor ad) { if (String.class.equals(ad.getType().getBinding())) { int length = FeatureTypes.getFieldLength(ad); if (length <= 0) length = 255; return "VARCHAR(" + length + ")"; } else { return CLASS_MAPPINGS.get(ad.getType().getBinding()); } }
typeName = "GEOMETRY"; } else if (typeName.equals("VARCHAR")) { int length = FeatureTypes.getFieldLength(attributeType[i]); if (length < 1) { LOGGER.warning("FeatureType did not specify string length; defaulted to 256");
int fieldLen = FeatureTypes.getFieldLength(type);
handler = shapeType.getShapeHandler(new GeometryFactory()); } else { int fieldLen = FeatureTypes.getFieldLength(descriptor); if (fieldLen == FeatureTypes.ANY_LENGTH) { fieldLen = 255;
String colName = type.getLocalName(); int fieldLen = FeatureTypes.getFieldLength(type); if (fieldLen == FeatureTypes.ANY_LENGTH) fieldLen = 255;
String colName = type.getLocalName(); int fieldLen = FeatureTypes.getFieldLength(type); if (fieldLen == FeatureTypes.ANY_LENGTH) fieldLen = 255;
} else if (String.class.equals(type)) { def = ogr.CreateStringField(name); int length = FeatureTypes.getFieldLength(ad); if (length <= 0) { length = 255;