protected Property createProperty(EntityType classModel, String normalizedColumnName, String propertyName, Type typeModel) { return new Property( classModel, propertyName, propertyName, typeModel, Collections.<String>emptyList(), false); }
protected Property createProperty(EntityType entityType, String propertyName, Type propertyType, AnnotatedElement annotated) { List<String> inits = Collections.<String>emptyList(); if (annotated.isAnnotationPresent(QueryInit.class)) { inits = ImmutableList.copyOf(annotated.getAnnotation(QueryInit.class).value()); } return new Property(entityType, propertyName, propertyType, inits); }
private Property createProperty(EntityType entityType, String propertyName, Type propertyType, Map<Class<? extends Annotation>, Annotation> annotations) { String[] inits = new String[0]; if (annotations.containsKey(QueryInit.class)) { inits = ((QueryInit) annotations.get(QueryInit.class)).value(); } if (annotations.containsKey(QueryType.class)) { propertyType = propertyType.as(TypeCategory.valueOf(((QueryType) annotations.get(QueryType.class)).value().name())); } Property property = new Property(entityType, propertyName, propertyType, Arrays.asList(inits)); return property; }
@Test public void Equals_And_HashCode() { Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false,false); EntityType type = new EntityType(typeModel); Property p1 = new Property(type, "property", type, Collections.<String>emptyList()); Property p2 = new Property(type, "property", type, Collections.<String>emptyList()); assertEquals(p1, p1); assertEquals(p1, p2); assertEquals(p1.hashCode(), p2.hashCode()); }
private Property createProperty(EntityType entityType, UID entityId, RDFProperty rdfProperty, @Nullable RDFSClass<?> range) { UID propertyId = rdfProperty.getId().asURI(); Type propertyType = getPropertyType(rdfProperty, range); String propertyName = getPropertyName(propertyId); Property property = new Property(entityType, propertyName, propertyType); if (propertyId.getNamespace().equals(entityId.getNamespace())) { if (propertyName.equals(propertyId.getLocalName())) { property.addAnnotation(new PredicateImpl("", "", "", false)); } else { property.addAnnotation(new PredicateImpl("", "", propertyId.getLocalName(), false)); } } else { property.addAnnotation(new PredicateImpl("", propertyId, false)); } return property; }
@Test public void Capitalization() throws IOException{ // property type.addProperty(new Property(type, "cId", type)); BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public DomainClass getcId() {")); }
@Test public void EscapedName() { Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false,false); EntityType type = new EntityType(typeModel); Property property = new Property(type, "boolean", type, Collections.<String>emptyList()); assertEquals("boolean$", property.getEscapedName()); }
@Test public void FullConstructor() throws IOException{ // property type.addProperty(new Property(type, "entityField", type)); type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel))); type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel))); type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel))); type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class))); type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel))); BeanSerializer serializer = new BeanSerializer(); serializer.setAddFullConstructor(true); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); //System.out.println(writer.toString()); }
@Test public void Properties() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "b", new ClassType(TypeCategory.BOOLEAN, Boolean.class))); entityType.addProperty(new Property(entityType, "c", new ClassType(TypeCategory.COMPARABLE, String.class))); entityType.addProperty(new Property(entityType, "cu", new ClassType(TypeCategory.CUSTOM, PropertyType.class))); entityType.addProperty(new Property(entityType, "d", new ClassType(TypeCategory.DATE, Date.class))); entityType.addProperty(new Property(entityType, "e", new ClassType(TypeCategory.ENUM, PropertyType.class))); entityType.addProperty(new Property(entityType, "dt", new ClassType(TypeCategory.DATETIME, Date.class))); entityType.addProperty(new Property(entityType, "i", new ClassType(TypeCategory.NUMERIC, Integer.class))); entityType.addProperty(new Property(entityType, "s", new ClassType(TypeCategory.STRING, String.class))); entityType.addProperty(new Property(entityType, "t", new ClassType(TypeCategory.TIME, Time.class))); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // TODO : assertions }
@Test public void ToString() throws IOException{ // property type.addProperty(new Property(type, "entityField", type)); type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel))); type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel))); type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel))); type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class))); type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel))); BeanSerializer serializer = new BeanSerializer(); serializer.setAddToString(true); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(String.valueOf(writer).contains( " @Override\n" + " public String toString()")); }
@Test public void Annotated_Property() throws IOException{ Property property = new Property(type, "entityField", type); property.addAnnotation(new QueryEntityImpl()); type.addProperty(property); BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString(); assertTrue(str.contains("import com.mysema.query.annotations.QueryEntity;")); assertTrue(str.contains("@QueryEntity")); }
@Test public void GetPropertyNameForPrimaryKey_Clash() { entityModel.addProperty(new Property(entityModel, "id", Types.STRING)); assertEquals("idPk", namingStrategy.getPropertyNameForPrimaryKey("id", entityModel)); }
@Test public void Annotated_Property_Not_Serialized() throws IOException{ Property property = new Property(type, "entityField", type); property.addAnnotation(new QueryEntityImpl()); type.addProperty(property); BeanSerializer serializer = new BeanSerializer(false); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString(); assertFalse(str.contains("import com.mysema.query.annotations.QueryEntity;")); assertFalse(str.contains("@QueryEntity")); }
@Test public void Primitive_Array() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "bytes", new ClassType(byte[].class))); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes")); }
@Test public void Include() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "b", new ClassType(TypeCategory.BOOLEAN, Boolean.class))); entityType.addProperty(new Property(entityType, "c", new ClassType(TypeCategory.COMPARABLE, String.class))); entityType.addProperty(new Property(entityType, "cu", new ClassType(TypeCategory.CUSTOM, PropertyType.class))); entityType.addProperty(new Property(entityType, "d", new ClassType(TypeCategory.DATE, Date.class))); entityType.addProperty(new Property(entityType, "e", new ClassType(TypeCategory.ENUM, PropertyType.class))); entityType.addProperty(new Property(entityType, "dt", new ClassType(TypeCategory.DATETIME, Date.class))); entityType.addProperty(new Property(entityType, "i", new ClassType(TypeCategory.NUMERIC, Integer.class))); entityType.addProperty(new Property(entityType, "s", new ClassType(TypeCategory.STRING, String.class))); entityType.addProperty(new Property(entityType, "t", new ClassType(TypeCategory.TIME, Time.class))); EntityType subType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); subType.include(new Supertype(type,entityType)); serializer.serialize(subType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // TODO : assertions }
@Test public void Include() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "b", new ClassType(TypeCategory.BOOLEAN, Boolean.class))); entityType.addProperty(new Property(entityType, "c", new ClassType(TypeCategory.COMPARABLE, String.class))); entityType.addProperty(new Property(entityType, "cu", new ClassType(TypeCategory.CUSTOM, PropertyType.class))); entityType.addProperty(new Property(entityType, "d", new ClassType(TypeCategory.DATE, Date.class))); entityType.addProperty(new Property(entityType, "e", new ClassType(TypeCategory.ENUM, PropertyType.class))); entityType.addProperty(new Property(entityType, "dt", new ClassType(TypeCategory.DATETIME, Date.class))); entityType.addProperty(new Property(entityType, "i", new ClassType(TypeCategory.NUMERIC, Integer.class))); entityType.addProperty(new Property(entityType, "s", new ClassType(TypeCategory.STRING, String.class))); entityType.addProperty(new Property(entityType, "t", new ClassType(TypeCategory.TIME, Time.class))); EntityType subType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); subType.include(new Supertype(type,entityType)); serializer.serialize(subType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // TODO : assertions }
@Test public void Primitive_Array() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "bytes", new ClassType(byte[].class))); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes")); }
@Test public void UncapSimpleName_Escaped2() { ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class); EntityType entityModel = new EntityType(typeModel); assertEquals("object", entityModel.getModifiedSimpleName()); entityModel.addProperty(new Property(entityModel, "OBJECT", "object", typeModel, Collections.<String> emptyList(), false)); assertEquals("object1", entityModel.getModifiedSimpleName()); }
@Test public void CustomType() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "property", new ClassType(Double[].class))); typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); assertTrue(typeMappings.isRegistered(entityType.getProperties().iterator().next().getType())); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains( "public final com.mysema.query.codegen.Point property = " + "new com.mysema.query.codegen.Point(forProperty(\"property\"));")); }
@Test public void UncapSimpleName_Escaped() { ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class); EntityType entityModel = new EntityType(typeModel); assertEquals("object", entityModel.getModifiedSimpleName()); entityModel.addProperty(new Property(entityModel, "object", typeModel)); assertEquals("object1", entityModel.getModifiedSimpleName()); }