public Configuration build() { if (converterRegistry == null) { converterRegistry = new ConverterRegistryImpl(); } // populate mappedSuperClasses for (MappedClass mappedClass : mappedClasses.values()) { if (!mappedClass.getJavaClass().getSuperclass().equals(Object.class)) { MappedClass mappedSuperClass = mappedClasses.get(mappedClass.getJavaClass().getSuperclass()); if (mappedSuperClass != null) { mappedClass.getMappedSuperClasses().add(mappedSuperClass); } } } // merge data for (MappedClass mappedClass : mappedClasses.values()) { Deque<MappedClass> supers = new ArrayDeque<MappedClass>(mappedClass.getMappedSuperClasses()); while (!supers.isEmpty()) { MappedClass mappedSuperClass = supers.pop(); supers.addAll(mappedSuperClass.getMappedSuperClasses()); for (MappedPath path : mappedSuperClass.getProperties()) { MappedProperty<?> property = (MappedProperty<?>) path.getMappedProperty().clone(); property.resolve(mappedClass); mappedClass.addMappedPath(new MappedPath(property, path.getPredicatePath(), !mappedClass.equals(property.getDeclaringClass()))); } } } return new SimpleConfiguration(converterRegistry, new HashSet<MappedClass>(mappedClasses.values())); }
private void loadReferences(MappedClass mappedClass, Map<ID, Multimap<UID, STMT>> directProps, Set<ID> handled) { Map<UID, Class<?>> directToType = new HashMap<UID, Class<?>>(); for (MappedPath mappedPath : mappedClass.getProperties()) { if (mappedPath.isReference() && !mappedPath.getPredicatePath().isEmpty()) { MappedProperty<?> property = mappedPath.getMappedProperty(); if (!property.isList()) {
@SuppressWarnings("unchecked") void addMappedPath(MappedPath path) { if (path.getPredicatePath().size() > 0) { if (!path.get(0).inv()) { mappedPredicates.add(path.get(0).getUID());
@Test public void Inverse() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Company.class) .addId("id") .addProperty("departments", new UID(TEST.NS, "company"), true) .addProperties(); Configuration configuration = builder.build(); // company MappedClass company = configuration.getMappedClass(Company.class); MappedPath company_departments = company.getMappedPath("departments"); assertEquals(TEST.NS, company_departments.getPredicatePath().get(0).getUID().ns()); assertEquals("company", company_departments.getPredicatePath().get(0).getUID().ln()); assertTrue(company_departments.getPredicatePath().get(0).inv()); }
@Test public void Namespaces() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Labeled.class) .addProperty("label", RDFS.label) .addProperty("comment", RDFS.comment); Configuration configuration = builder.build(); // labeled MappedClass labeled = configuration.getMappedClass(Labeled.class); MappedPath labeled_label = labeled.getMappedPath("label"); assertEquals(RDFS.label, labeled_label.getPredicatePath().get(0).getUID()); MappedPath labeled_comment = labeled.getMappedPath("comment"); assertEquals(RDFS.comment, labeled_comment.getPredicatePath().get(0).getUID()); }
property.resolve(mappedClass); mappedClass.addMappedPath(new MappedPath(property, path.getPredicatePath(), !mappedClass.equals(property.getDeclaringClass())));
@Test public void AddProperty() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Person.class) .addId("id") .addProperty("firstName") .addProperty("lastName", new UID(TEST.NS, "surName")) .addProperty("superior") .addProperty("department"); Configuration configuration = builder.build(); // person MappedClass person = configuration.getMappedClass(Person.class); MappedPath person_id = person.getMappedPath("id"); assertTrue(person_id.getPredicatePath().isEmpty()); MappedPath person_firstName = person.getMappedPath("firstName"); assertEquals(TEST.NS, person_firstName.getPredicatePath().get(0).getUID().ns()); assertEquals("firstName", person_firstName.getPredicatePath().get(0).getUID().ln()); MappedPath person_lastName = person.getMappedPath("lastName"); assertEquals("surName", person_lastName.getPredicatePath().get(0).getUID().ln()); MappedPath person_superior = person.getMappedPath("superior"); assertEquals("superior", person_superior.getPredicatePath().get(0).getUID().ln()); MappedPath person_department = person.getMappedPath("department"); assertEquals("department", person_department.getPredicatePath().get(0).getUID().ln()); }
assertTrue(person_id.getPredicatePath().isEmpty()); MappedPath person_firstName = person.getMappedPath("firstName"); assertEquals("firstName", person_firstName.getPredicatePath().get(0).getUID().ln()); MappedPath person_lastName = person.getMappedPath("lastName"); assertEquals("lastName", person_lastName.getPredicatePath().get(0).getUID().ln()); MappedPath person_superior = person.getMappedPath("superior"); assertEquals("superior", person_superior.getPredicatePath().get(0).getUID().ln()); MappedPath person_department = person.getMappedPath("department"); assertEquals("department", person_department.getPredicatePath().get(0).getUID().ln()); assertTrue(department_id.getPredicatePath().isEmpty()); MappedPath department_name = department.getMappedPath("name"); assertEquals("name", department_name.getPredicatePath().get(0).getUID().ln()); MappedPath department_company = department.getMappedPath("company"); assertEquals("company", department_company.getPredicatePath().get(0).getUID().ln()); assertTrue(company_id.getPredicatePath().isEmpty()); MappedPath company_name = company.getMappedPath("name"); assertEquals("name", company_name.getPredicatePath().get(0).getUID().ln());
@SuppressWarnings("unchecked") private Operation<?> transformPathEqNeConstant(Operation<?> operation) { Path<?> path = (Path<?>) operation.getArg(0); Constant<?> constant = (Constant<?>) operation.getArg(1); MappedPath mappedPath = getMappedPath(path); // id property if (path.getMetadata().getPathType() == PathType.PROPERTY && constant.getType().equals(String.class) && mappedPath.getPredicatePath().isEmpty()) { operation = PredicateOperation.create((Operator) operation.getOperator(), path, new ConstantImpl<ID>(session.getId(new LID(constant.toString())))); // localized property } else if (mappedPath.getMappedProperty().isLocalized()) { Locale locale; if (path.getMetadata().getPathType() == PathType.PROPERTY) { locale = session.getCurrentLocale(); } else { locale = (Locale) path.getMetadata().getElement(); } operation = PredicateOperation.create((Operator) operation.getOperator(), path, new ConstantImpl<LIT>(new LIT(constant.toString(), locale))); } return operation; }
@Test public void Without_namespace() { ConfigurationBuilder builder = new ConfigurationBuilder(); for (Class<?> cl : Arrays.<Class<?>> asList(Person.class, Department.class, Company.class, Labeled.class)) { builder.addClass(cl).addProperties(); } Configuration configuration = builder.build(); MappedClass person = configuration.getMappedClass(Person.class); String ns = "java:com.mysema.rdfbean.object.ConfigurationBuilderTest.Person#"; assertEquals(new UID(ns, "Person"), person.getUID()); assertEquals(new UID(ns, "labeled"), person.getMappedPath("labeled").getPredicatePath().get(0).getUID()); }
List<MappedPredicate> predPath = mappedPath.getPredicatePath(); if (predPath.size() > 0) { MappedPredicate last = predPath.get(predPath.size() - 1);
@Test public void Container() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Company.class) .addId("id") .addProperty("departments", new UID(TEST.NS, "company"), ContainerType.SEQ) .addProperties(); Configuration configuration = builder.build(); // company MappedClass company = configuration.getMappedClass(Company.class); MappedPath company_departments = company.getMappedPath("departments"); assertEquals(TEST.NS, company_departments.getPredicatePath().get(0).getUID().ns()); assertEquals("company", company_departments.getPredicatePath().get(0).getUID().ln()); assertEquals(ContainerType.SEQ, company_departments.getMappedProperty().getContainerType()); }
@Test public void Localized() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Labeled.class) .addLocalized("label", RDFS.label) .addProperty("comment", RDFS.comment); Configuration configuration = builder.build(); // labeled MappedClass labeled = configuration.getMappedClass(Labeled.class); MappedPath labeled_label = labeled.getMappedPath("label"); assertTrue(labeled_label.getMappedProperty().isLocalized()); assertEquals(RDFS.label, labeled_label.getPredicatePath().get(0).getUID()); MappedPath labeled_comment = labeled.getMappedPath("comment"); assertFalse(labeled_comment.getMappedProperty().isLocalized()); assertEquals(RDFS.comment, labeled_comment.getPredicatePath().get(0).getUID()); }