private boolean isPolymorphic(MappedProperty<?> mappedProperty) { if (mappedProperty.isCollection() || mappedProperty.isMap()) { return configuration.isPolymorphic(mappedProperty.getComponentType()); } else { return configuration.isPolymorphic(mappedProperty.getType()); } }
public boolean isIndexed() { return isList() || ContainerType.SEQ.equals(getContainerType()); }
public String getName() { return mappedProperty.getName(); }
public Class<?> getTargetType() { Class<?> clazz = getComponentType(); if (clazz == null) { clazz = getType(); } return clazz; }
@SuppressWarnings("unchecked") @Nullable public Class<? extends Collection> getCollectionType() { if (isCollection()) { return getConcreteCollectionType(getType()); } else { return null; } }
if (statements.containsKey(predicate)) { for (STMT statement : statements.get(predicate)) { if (property.isLocalized() && String.class.equals(property.getType())) { LIT lit = (LIT) statement.getObject(); if (Objects.equal(getCurrentLocale(), lit.getLang())) { NODE object = statement.getObject(); if (object.isResource()) { if (property.isList()) { removeList((ID) object, context); } else if (property.isContainer()) { removeContainer((ID) object, context); Object object = property.getValue(beanMap); if (object != null) { if (property.isArray()) { if (object.getClass().getComponentType().isPrimitive()) { int size = Array.getLength(object); if (property.isList()) { ID first = toRDFList((List<?>) object, context); if (first != null) { } else if (property.isContainer()) { ID container = toRDFContainer((Collection<?>) object, context, property.getContainerType()); if (container != null) { recordAddStatement(subject, predicate, container, context); } else if (property.isCollection()) {
} else if (!mappedProperty.isAnyResource()) { if (!(property instanceof DatatypeProperty)) { throw new IllegalArgumentException("Expected DatatypeProperty for: " + mappedPath); if (mappedProperty.isAnyResource()) { property = new RDFProperty(puid); } else if (mappedPath.isReference() || mappedProperty.isCollection()) { property = new ObjectProperty(puid); } else { if (mappedProperty.isCollection()) { if (mappedProperty.isList()) { if (property.getRange().isEmpty()) { RDFSClass<?> componentType = processClass(session, mappedProperty.getComponentType(), resources); if (useTypedLists && componentType != null) { property.addRange(new TypedList(cuid.ns(), componentType)); processClass(session, mappedProperty.getComponentType(), resources); if (componentType != null) { if (property.getRange().isEmpty()) { RDFSClass<?> range = processClass(session, mappedProperty.getType(), resources); if (range != null) { owlClass.setAllValuesFrom(property, range); } else if (mappedProperty.isAnyResource()) { owlClass.setAllValuesFrom(property, (RDFSClass<?>) resources.get(RDFS.Resource));
@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 (property.isIncludeMapped() || !mappedClass.isMappedPredicate(stmt.getPredicate())) { Class<?> componentType; if (property.isDynamicCollection()) { componentType = property.getDynamicCollectionComponentType(); } else { componentType = property.getComponentType(); if (property.isDynamicCollection()) { Collection<Object> collection = (Collection<Object>) values.get(stmt.getPredicate()); if (collection == null) { try { collection = property.getDynamicCollectionType().newInstance(); values.put(stmt.getPredicate(), collection); } catch (InstantiationException e) { property.setValue(beanMap, values);
private <T> void setId(MappedClass mappedClass, ID subject, BeanMap instance) { MappedProperty<?> idProperty = mappedClass.getIdProperty(); if (idProperty != null && !mappedClass.isEnum() && !idProperty.isVirtual()) { Object id = null; Identifier identifier; Class<?> type = idProperty.getType(); IDType idType = idProperty.getIDType(); if (idType == IDType.LOCAL) { identifier = getLID(subject); String ns = idProperty.getIDNamespace(); if (ns.isEmpty()) { id = identifier.getId(); idProperty.setValue(instance, id); Object mixinValue = mixinProperty.getValue(instance); if (mixinValue != null) { MappedClass mixinClass = configuration.getMappedClass(mixinProperty.getTargetType());
@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); }
/** * Create a new Query-by-example query * * @param session * @param entity */ @SuppressWarnings("unchecked") public ExampleQuery(Configuration configuration, Session session, T entity) { this.session = Assert.notNull(session, "session"); this.entityPath = (PathBuilder) pathBuilderFactory.create(entity.getClass()); this.conditions = new BooleanBuilder(); BeanMap beanMap = new BeanMap(entity); MappedClass mappedClass = configuration.getMappedClass(entity.getClass()); for (MappedPath mappedPath : mappedClass.getProperties()) { MappedProperty<?> property = mappedPath.getMappedProperty(); Object value = property.getValue(beanMap); if (value != null // date/time values are skipped && !DATE_TIME_TYPES.contains(value.getClass()) // collection values are skipped && !property.isCollection() // map values are skipped && !property.isMap() // blank nodes are skipped && !(value instanceof BID)) { Expression<Object> propertyPath = (Expression) entityPath.get(property.getName(), property.getType()); conditions.and(ExpressionUtils.eqConst(propertyPath, value)); } } }
@SuppressWarnings("unchecked") private Object convertCollection(MappedPath propertyPath, Collection<? extends NODE> values, UID context) throws InstantiationException, IllegalAccessException { MappedProperty<?> mappedProperty = propertyPath.getMappedProperty(); Class<?> targetType = mappedProperty.getComponentType(); int size = values.size(); if (size == 1) { NODE node = values.iterator().next(); if (node instanceof ID) { if (mappedProperty.isList()) { values = convertList((ID) node, context); } else if (mappedProperty.isContainer()) { values = convertContainer((ID) node, context, mappedProperty.isIndexed()); } } // TODO else log error? } // TODO else log error? Class collectionType = mappedProperty.getCollectionType(); Collection collection = (Collection) collectionType.newInstance(); for (NODE value : values) { if (value != null) { collection.add(convertValue(value, targetType, propertyPath)); } else { collection.add(null); } } return collection; }
if (mappedProperty.isCollection()) { convertedValue = convertCollection(propertyPath, values, context); else if (mappedProperty.isArray()) { convertedValue = convertArray(propertyPath, values, context); else if (mappedProperty.isLocalized()) { if (mappedProperty.isMap()) { convertedValue = convertLocalizedMap(propertyPath, values); } else if (mappedProperty.getType().equals(String.class)) { convertedValue = convertLocalized(propertyPath, values); } else { throw new SessionException("Illegal use of @Localized with " + mappedProperty.getType() + " at " + propertyPath); else if (mappedProperty.isMap()) { convertedValue = convertMap(propertyPath, values);
private void collectTypes() { for (MappedClass mappedClass : configuration.getMappedClasses()) { if (mappedClass.isEnum()) { // skip enum types continue; } EntityType entityType = (EntityType) createType(mappedClass.getJavaClass()); for (MappedPath mappedPath : mappedClass.getProperties()) { MappedProperty<?> mappedProperty = mappedPath.getMappedProperty(); Class<?> type = mappedPath.getMappedProperty().getType(); Type propertyType = null; if (type.equals(Map.class)) { propertyType = new SimpleType(Types.MAP, createType(mappedProperty.getKeyType()), createType(mappedProperty.getComponentType())); } else if (type.equals(List.class)) { propertyType = new SimpleType(Types.LIST, createType(mappedProperty.getComponentType())); } else if (type.equals(Set.class)) { propertyType = new SimpleType(Types.SET, createType(mappedProperty.getComponentType())); } else if (type.equals(Collection.class)) { propertyType = new SimpleType(Types.COLLECTION, createType(mappedProperty.getComponentType())); } else { propertyType = createType(type); } entityType.addProperty(createProperty(entityType, mappedPath.getName(), propertyType, mappedProperty.getAnnotations())); } } }
@SuppressWarnings("unchecked") private Object convertMap(MappedPath propertyPath, Set<? extends NODE> values) { MappedProperty<?> propertyDefinition = propertyPath.getMappedProperty(); Object convertedValue; Class<?> componentType = propertyDefinition.getComponentType(); Class<?> keyType = propertyDefinition.getKeyType(); Map map = new HashMap(); for (NODE value : values) { // Map key Object key = convertValue( getFunctionalValue((ID) value, propertyDefinition.getKeyPredicate(), false, null), keyType, propertyPath); // Map Value Object mapValue; UID valuePredicate = propertyDefinition.getValuePredicate(); if (valuePredicate != null) { mapValue = convertValue(getFunctionalValue((ID) value, valuePredicate, false, null), componentType, propertyPath); } else { mapValue = convertValue(value, componentType, propertyPath); } map.put(key, mapValue); } convertedValue = map; return convertedValue; }
assertEquals(Parent.class, path.getMappedProperty().getType()); assertFalse(path.isInherited()); assertEquals(Object.class, path.getMappedProperty().getType()); assertFalse(path.getMappedProperty().isRequired()); assertFalse(path.isInherited()); assertEquals(Parent.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(FirstChild.class, path.getMappedProperty().getType()); assertFalse(path.isInherited()); assertEquals(Integer.class, path.getMappedProperty().getType()); assertFalse(path.getMappedProperty().isRequired()); assertFalse(path.isInherited()); assertEquals(FirstChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(NestedChild.class, path.getMappedProperty().getType()); assertFalse(path.isInherited()); assertEquals(String.class, path.getMappedProperty().getType()); assertTrue(path.getMappedProperty().isRequired()); assertTrue(path.isInherited()); assertEquals(NestedChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited());
public boolean isReference() { return isMappedClass(mappedProperty.getTargetType()) || mappedProperty.isURI() || mappedProperty.isInjection(); }
public boolean isAnyResource() { return UID.class == getType(); }
if (idProperty != null) { Object id = idProperty.getValue(toBeanMap(instance)); if (id != null) { if (idProperty.getIDType() == IDType.LOCAL) { LID lid; if (id instanceof LID) { if (id instanceof UID) { rid = (UID) id; } else if (idProperty.getIDType() == IDType.URI) { if (idProperty.getIDNamespace().isEmpty()) { rid = new UID(id.toString()); } else { rid = new UID(idProperty.getIDNamespace(), id.toString());