本文整理汇总了Java中org.springframework.data.mapping.PersistentProperty类的典型用法代码示例。如果您正苦于以下问题:Java PersistentProperty类的具体用法?Java PersistentProperty怎么用?Java PersistentProperty使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistentProperty类属于org.springframework.data.mapping包,在下文中一共展示了PersistentProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAuditDate
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
private void setAuditDate(PersistentProperty<?> property, T entity,
Class<? extends Annotation> annotationType) {
Object val = persistentEntity.getPropertyAccessor(entity).getProperty(property);
if (null != val) {
return;
}
if (null != auditDateAware) {
persistentEntity.getPropertyAccessor(entity)
.setProperty(property, auditDateAware.getCurrentDate());
return;
}
Class<?> type = property.getRawType();
if (Date.class.isAssignableFrom(type)) {
persistentEntity.getPropertyAccessor(entity).setProperty(property, new Date());
} else if (Long.class == type || long.class == type) {
persistentEntity.getPropertyAccessor(entity)
.setProperty(property, System.currentTimeMillis());
} else {
throw new IllegalArgumentException(
"now we can not support " + type.getName() + " for " + annotationType.getName()
+ ", you can implement org.springframework.data.mybatis.domains.AuditDateAware interface as a spring bean.");
}
}
示例2: getContentPropertyType
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
public static Class<?> getContentPropertyType(PersistentProperty<?> prop) {
Class<?> contentEntityClass = null;
// null single-valued content property
if (!PersistentEntityUtils.isPropertyMultiValued(prop)) {
contentEntityClass = prop.getActualType();
}
// null multi-valued content property
else if (PersistentEntityUtils.isPropertyMultiValued(prop)) {
if (prop.isArray()) {
contentEntityClass = prop.getComponentType();
}
else if (prop.isCollectionLike()) {
contentEntityClass = prop.getActualType();
}
}
return contentEntityClass;
}
示例3: setContentProperty
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
protected void setContentProperty(Object domainObj, PersistentProperty<?> property, String contentId, Object newValue) {
PersistentPropertyAccessor accessor = property.getOwner().getPropertyAccessor(domainObj);
Object contentPropertyObject = accessor.getProperty(property);
if (contentPropertyObject == null)
return;
else if (!PersistentEntityUtils.isPropertyMultiValued(property)) {
accessor.setProperty(property, newValue);
} else {
// handle multi-valued
if (property.isArray()) {
throw new UnsupportedOperationException();
} else if (property.isCollectionLike() && contentPropertyObject instanceof Set) {
@SuppressWarnings("unchecked")
Set<Object> contentSet = (Set<Object>)contentPropertyObject;
Object oldValue = findContentPropertyObjectInSet(contentId, contentSet);
contentSet.remove(oldValue);
if (newValue != null)
contentSet.add(newValue);
}
}
}
示例4: getContentProperty
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
protected Object getContentProperty(Object domainObj, PersistentProperty<?> property, String contentId) {
PersistentPropertyAccessor accessor = property.getOwner().getPropertyAccessor(domainObj);
Object contentPropertyObject = accessor.getProperty(property);
// multi-valued property?
if (PersistentEntityUtils.isPropertyMultiValued(property)) {
if (property.isArray()) {
throw new UnsupportedOperationException();
} else if (property.isCollectionLike()) {
contentPropertyObject = findContentPropertyObjectInSet(contentId, (Collection<?>)contentPropertyObject);
}
}
if (contentPropertyObject == null) {
throw new ResourceNotFoundException();
}
if (BeanUtils.hasFieldWithAnnotation(contentPropertyObject, ContentId.class)) {
if (BeanUtils.getFieldWithAnnotation(contentPropertyObject, ContentId.class) == null) {
throw new ResourceNotFoundException();
}
}
return contentPropertyObject;
}
示例5: populateProperties
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
private void populateProperties(Class<?> domainType, BusinessEntity entity) {
Map<String, EntityProperty> properties = new HashMap<>();
final PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(domainType);
JacksonMetadata jacksonMetadata = new JacksonMetadata(objectMapper, domainType);
for (BeanPropertyDefinition definition : jacksonMetadata) {
PersistentProperty<?> persistentProperty = persistentEntity.getPersistentProperty(definition.getInternalName());
PropertyFactoryContext context = new PropertyFactoryContext(definition, jacksonMetadata, persistentProperty);
PropertyFactory factory = getFactoryFor(context);
if (factory != null) {
EntityProperty property = factory.create(context);
properties.put(definition.getInternalName(), property);
if(property.isRequired()) {
entity.getRequired().add(definition.getInternalName());
}
}
}
entity.setProperties(properties);
}
示例6: update
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public void update(Object objectToUpdate) {
PersistentEntity<?, ? extends PersistentProperty> entity = this.mappingContext.getPersistentEntity(ClassUtils
.getUserClass(objectToUpdate));
if (!entity.hasIdProperty()) {
throw new InvalidDataAccessApiUsageException(String.format("Cannot determine id for type %s",
ClassUtils.getUserClass(objectToUpdate)));
}
update((Serializable) entity.getIdentifierAccessor(objectToUpdate).getIdentifier(), objectToUpdate);
}
示例7: delete
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public <T> T delete(T objectToDelete) {
Class<T> type = (Class<T>) ClassUtils.getUserClass(objectToDelete);
PersistentEntity<?, ? extends PersistentProperty> entity = this.mappingContext.getPersistentEntity(type);
return delete((Serializable) entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
}
示例8: setPersistentEntityId
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
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);
}
}
}
示例9: findByColumnName
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public MybatisPersistentProperty findByColumnName(final String columnName) {
final MybatisPersistentProperty[] result = new MybatisPersistentProperty[1];
doWithProperties(new SimplePropertyHandler() {
@Override
public void doWithPersistentProperty(PersistentProperty<?> pp) {
MybatisPersistentProperty property = (MybatisPersistentProperty) pp;
if (columnName.equalsIgnoreCase(property.getColumnName())) {
result[0] = property;
return;
}
}
});
return result[0];
}
示例10: getIdType
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public Class<ID> getIdType() {
if (null == persistentEntity) {
return null;
}
PersistentProperty idProperty = persistentEntity.getIdProperty();
if (null == idProperty) {
return null;
}
return (Class<ID>) idProperty.getType();
}
示例11: setCurrentAuditor
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
private void setCurrentAuditor(PersistentProperty<?> property, T entity) {
Object val = persistentEntity.getPropertyAccessor(entity).getProperty(property);
if (null != val) {
return;
}
persistentEntity.getPropertyAccessor(entity)
.setProperty(property, auditorAware.getCurrentAuditor());
}
示例12: increaseVersion
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public int increaseVersion(T entity) {
PersistentProperty<?> versionProperty = persistentEntity.getVersionProperty();
if (null == versionProperty) {
return 0;
}
PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(entity);
int newVer = (Integer) accessor.getProperty(versionProperty) + 1;
accessor.setProperty(versionProperty, newVer);
return newVer;
}
示例13: setVersion
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
@Override
public void setVersion(T entity, int version) {
PersistentProperty<?> versionProperty = persistentEntity.getVersionProperty();
if (null == versionProperty) {
return;
}
persistentEntity.getPropertyAccessor(entity).setProperty(versionProperty, version);
}
示例14: getPersistentProperty
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
public static PersistentProperty<?> getPersistentProperty(PersistentEntity<?,?> entity, String propertyName) {
PersistentProperty<?> prop = entity.getPersistentProperty(propertyName);
if (null == prop)
throw new ResourceNotFoundException();
return prop;
}
示例15: getContentPropertyDefinition
import org.springframework.data.mapping.PersistentProperty; //导入依赖的package包/类
protected PersistentProperty<?> getContentPropertyDefinition(PersistentEntity<?, ?> persistentEntity, String contentProperty) {
PersistentProperty<?> prop = persistentEntity.getPersistentProperty(contentProperty);
if (null == prop)
throw new ResourceNotFoundException();
return prop;
}