List of usage examples for org.springframework.data.mapping PersistentProperty getType
Class<?> getType();
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
private Doc getDocFor(ResourceDescription description, PersistentProperty<?> property) { if (description == null) { return null; }// w w w . j a v a 2 s. c om String message = resolveMessage(description); // Manually post process the default message for enumerations if needed if (configuration.isEnableEnumTranslation() && property != null && property.getType().isEnum()) { if (description.isDefault()) { return new Doc( StringUtils.collectionToDelimitedString( translator.getValues((Class<? extends Enum<?>>) property.getType()), ", "), Format.TEXT); } } return message == null ? null : new Doc(message, Format.TEXT); }
From source file:com.turbospaces.model.BO.java
/** * create business object over actual basic persistent entity * //from w w w . j a v a 2 s . c o m * @param delegate * the actual persistent entity meta-data provider * @throws NoSuchMethodException * re-throw cglib exception * @throws SecurityException * re-throw cglib exception * @throws IntrospectionException * re-throw exceptions */ public BO(final BasicPersistentEntity delegate) throws SecurityException, NoSuchMethodException, IntrospectionException { this.delegate = delegate; this.fastConstructor = FastClass.create(delegate.getType()) .getConstructor(delegate.getType().getConstructor()); // find optimistic lock version/routing fields { final Collection<PersistentProperty> versionCandidates = Lists.newLinkedList(); final Collection<PersistentProperty> routingCandidates = Lists.newLinkedList(); delegate.doWithProperties(new PropertyHandler() { @Override public void doWithPersistentProperty(final PersistentProperty persistentProperty) { PropertyDescriptor propertyDescriptor = persistentProperty.getPropertyDescriptor(); Field field = persistentProperty.getField(); if (hasAnnotation(propertyDescriptor, field, Version.class)) versionCandidates.add(persistentProperty); if (hasAnnotation(propertyDescriptor, field, Routing.class)) routingCandidates.add(persistentProperty); } private boolean hasAnnotation(final PropertyDescriptor descriptor, final Field field, final Class annotation) { if (descriptor != null && descriptor.getReadMethod() != null && descriptor.getReadMethod().getAnnotation(annotation) != null) return true; if (field != null && field.getAnnotation(annotation) != null) return true; return false; } }); Preconditions.checkArgument(versionCandidates.size() <= 1, "too many fields marked with @Version annotation, candidates = " + versionCandidates.toString()); Preconditions.checkArgument(routingCandidates.size() <= 1, "too many fields marked with @Routing annotation, candidates = " + routingCandidates.toString()); if (!versionCandidates.isEmpty()) optimisticLockVersionProperty = versionCandidates.iterator().next(); if (!routingCandidates.isEmpty()) routingProperty = routingCandidates.iterator().next(); } { // Java Beans convention marker AtomicBoolean propertyAccess = new AtomicBoolean(true); List<String> setters = Lists.newLinkedList(); List<String> getters = Lists.newLinkedList(); List<Class<?>> types = Lists.newLinkedList(); for (PersistentProperty<?> persistentProperty : getOrderedProperties()) { PropertyDescriptor propertyDescriptor = persistentProperty.getPropertyDescriptor(); if (propertyDescriptor != null) { if (propertyDescriptor.getReadMethod() != null && propertyDescriptor.getWriteMethod() != null) { setters.add(propertyDescriptor.getWriteMethod().getName()); getters.add(propertyDescriptor.getReadMethod().getName()); types.add(persistentProperty.getType()); } } else { propertyAccess.set(false); brokenProperties.add(persistentProperty); } } if (propertyAccess.get()) // create properties extract for all persistent properties bulkBean = BulkBean.create(delegate.getType(), getters.toArray(new String[getters.size()]), setters.toArray(new String[setters.size()]), types.toArray(new Class[types.size()])); else Log.warn(String.format( "PropetiesSerializer-%s unable to use getters-setters access optimization. Suspected/Corrupted properties = %s", delegate.getType().getSimpleName(), getBrokenProperties())); boolean canOptimizeIdProperty = hasReadWriteMethods(delegate.getIdProperty()); boolean canOptimizeVersionProperty = hasReadWriteMethods(getOptimisticLockVersionProperty()); boolean canOptimizeRoutingProperty = hasReadWriteMethods(getRoutingProperty()); // create id/version/routing bulk fields extractor if (canOptimizeIdProperty && canOptimizeVersionProperty && canOptimizeRoutingProperty) { String[] g = new String[] { delegate.getIdProperty().getPropertyDescriptor().getReadMethod().getName(), getOptimisticLockVersionProperty().getPropertyDescriptor().getReadMethod().getName(), getRoutingProperty().getPropertyDescriptor().getReadMethod().getName() }; String[] s = new String[] { delegate.getIdProperty().getPropertyDescriptor().getWriteMethod().getName(), getOptimisticLockVersionProperty().getPropertyDescriptor().getWriteMethod().getName(), getRoutingProperty().getPropertyDescriptor().getWriteMethod().getName() }; Class<?>[] c = new Class[] { delegate.getIdProperty().getType(), getOptimisticLockVersionProperty().getType(), getRoutingProperty().getType() }; idVersionRoutingBulkBean = BulkBean.create(delegate.getType(), g, s, c); } } }
From source file:org.springframework.data.elasticsearch.core.DefaultResultMapper.java
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) { if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) { ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz); PersistentProperty<?> idProperty = persistentEntity.getIdProperty(); // Only deal with String because ES generated Ids are strings ! if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id); }/*from ww w . j a v a 2 s. co m*/ } }