private Multimap<UID, STMT> getProperties(ID subject, MappedClass mappedClass, boolean polymorphic) { Multimap<UID, STMT> properties = MultimapFactory.<UID, STMT> create(); if (mappedClass.getDynamicProperties().isEmpty() && !polymorphic && mappedClass.getMappedPredicates().size() < 5) { if (logger.isDebugEnabled()) { logger.debug("query for properties of " + subject); } RDFQuery query = new RDFQueryImpl(connection); CloseableIterator<STMT> stmts = query.where( Blocks.SPOC, QNODE.p.in(mappedClass.getMappedPredicates())) .set(QNODE.s, subject) .construct(Blocks.SPOC); try { while (stmts.hasNext()) { STMT stmt = stmts.next(); properties.put(stmt.getPredicate(), stmt); } } finally { stmts.close(); } } else { for (STMT stmt : findStatements(subject, null, null, null, true)) { properties.put(stmt.getPredicate(), stmt); } } return properties; }
private RDFQuery createQuery(MappedClass mappedClass, @Nullable UID type, boolean polymorphic) { RDFQuery query = new RDFQueryImpl(connection); if (type != null) { query.where(Blocks.S_TYPE); if (mappedClass.getContext() != null) { query.set(QNODE.typeContext, mappedClass.getContext()); } if (polymorphic) { Collection<UID> types = ontology.getSubtypes(type); if (types.size() > 1 && connection.getInferenceOptions().subClassOf()) { query.where(QNODE.type.in(types)); } else { query.set(QNODE.type, type); } } else { query.set(QNODE.type, type); } } query.where(Blocks.SPOC); if (!polymorphic && mappedClass.getDynamicProperties().isEmpty() && mappedClass.getMappedPredicates().size() < 5) { query.where(QNODE.p.in(mappedClass.getMappedPredicates())); } return query; }
@Test public void MappedClass() throws SecurityException, NoSuchFieldException { Field field = Project.class.getDeclaredField("infos"); assertNotNull(field); MappedClass mappedClass = configuration.getMappedClass(Project.class); boolean containsInfos = false; for (MappedProperty<?> property : mappedClass.getDynamicProperties()) { if (property.isDynamic() && property.getName().equals("infos")) { containsInfos = true; assertEquals(UID.class, property.getKeyType()); assertTrue(Set.class.isAssignableFrom(property.getDynamicCollectionType())); assertEquals(String.class, property.getDynamicCollectionComponentType()); } } assertTrue("Could not find property 'infos'", containsInfos); }
for (MappedProperty<?> property : mappedClass.getDynamicProperties()) { Map<?, ?> properties = (Map) property.getValue(beanMap); if (properties != null) {
@SuppressWarnings("unchecked") private void bindDynamicProperties(ID subject, Multimap<UID, STMT> properties, BeanMap beanMap, MappedClass mappedClass) { for (MappedProperty<?> property : mappedClass.getDynamicProperties()) { UID context = property.getContext(); Map<UID, Object> values = new HashMap<UID, Object>();
if (!mappedClass.getDynamicProperties().isEmpty()) { bindDynamicProperties(subject, properties.getDirect(), beanMap, mappedClass);