org.springframework.data.mapping.PersistentEntity Java Examples

The following examples show how to use org.springframework.data.mapping.PersistentEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MybatisPersistentPropertyImpl.java    From spring-data-mybatis with Apache License 2.0 7 votes vote down vote up
/**
 * Creates a new {@link AnnotationBasedPersistentProperty}.
 * @param property must not be {@literal null}.
 * @param owner must not be {@literal null}.
 */
public MybatisPersistentPropertyImpl(Property property,
		PersistentEntity<?, MybatisPersistentProperty> owner,
		SimpleTypeHolder simpleTypeHolder) {

	super(property, owner, simpleTypeHolder);

	this.isAssociation = Lazy.of(() -> ASSOCIATION_ANNOTATIONS.stream()
			.anyMatch(this::isAnnotationPresent));
	this.usePropertyAccess = detectPropertyAccess();
	this.associationTargetType = detectAssociationTargetType();
	this.updateable = detectUpdatability();

	this.isIdProperty = Lazy.of(
			() -> ID_ANNOTATIONS.stream().anyMatch(it -> isAnnotationPresent(it)));
	this.isEntity = Lazy.of(getActualType().isAnnotationPresent(Entity.class));
}
 
Example #2
Source File: DefaultNeo4jPersistentProperty.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link AnnotationBasedPersistentProperty}.
 *
 * @param property         must not be {@literal null}.
 * @param owner            must not be {@literal null}.
 * @param simpleTypeHolder type holder
 */
DefaultNeo4jPersistentProperty(Property property,
	PersistentEntity<?, Neo4jPersistentProperty> owner,
	Neo4jMappingContext mappingContext,
	SimpleTypeHolder simpleTypeHolder) {

	super(property, owner, simpleTypeHolder);

	this.graphPropertyName = Lazy.of(this::computeGraphPropertyName);
	this.isAssociation = Lazy.of(() -> {

		Class<?> targetType = getActualType();
		return !(simpleTypeHolder.isSimpleType(targetType) || mappingContext.hasCustomWriteTarget(targetType));
	});
	this.mappingContext = mappingContext;
}
 
Example #3
Source File: SimpleCratePersistentProperty.java    From spring-data-crate with Apache License 2.0 6 votes vote down vote up
public SimpleCratePersistentProperty(Field field, PropertyDescriptor propertyDescriptor, 
									 PersistentEntity<?, CratePersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
	super(field, propertyDescriptor, owner, simpleTypeHolder);
	
	this.fieldNamingStrategy = INSTANCE;

	String fieldName = getFieldName();
	
	if(RESERVED_ID_FIELD_NAME.equals(fieldName)) {				
		throw new MappingException(format(RESERVED_ID, fieldName, owner.getType()));
	}
	
	if(RESERVED_VESRION_FIELD_NAME.equals(fieldName)) {				
		throw new MappingException(format(RESERVED_VERSION, fieldName, owner.getType()));
	}
	
	if(startsWithIgnoreCase(fieldName, "_")) {
		throw new MappingException(format(STARTS_WITH_UNDERSCORE, fieldName, owner.getType()));
	}
}
 
Example #4
Source File: JsonSchemaBuilder.java    From moserp with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: DefaultArangoTypeMapper.java    From spring-data with Apache License 2.0 6 votes vote down vote up
private DefaultArangoTypeMapper(final String typeKey, final ArangoTypeAliasAccessor accessor,
	final MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext,
	final List<? extends TypeInformationMapper> additionalMappers) {

	Assert.notNull(accessor, "Accessor must not be null!");
	Assert.notNull(additionalMappers, "AdditionalMappers must not be null!");

	final List<TypeInformationMapper> mappers = new ArrayList<>(additionalMappers.size() + 1);
	if (mappingContext != null) {
		mappers.add(new MappingContextTypeInformationMapper(mappingContext));
	}
	mappers.addAll(additionalMappers);

	this.mappers = Collections.unmodifiableList(mappers);
	this.accessor = accessor;
	this.typeCache = new ConcurrentHashMap<>(16, 0.75f, 4);
	this.typeKey = typeKey;
}
 
Example #6
Source File: BasicPropertyFactoryTest.java    From moserp with Apache License 2.0 5 votes vote down vote up
@Before
public void setupBasicMocks() {
    jacksonMetadata = new JacksonMetadata(new ObjectMapperBuilder().build(), SimpleClass.class);
    persistentProperty = mock(PersistentProperty.class);

    persistentEntity = mock(PersistentEntity.class);
    when(persistentEntity.getType()).thenReturn(SimpleClass.class);
    when(persistentProperty.getOwner()).thenReturn(persistentEntity);
}
 
Example #7
Source File: ApplicationStructureBuilder.java    From moserp with Apache License 2.0 5 votes vote down vote up
private List<EntityProperty> buildProperties(Class<?> domainType) {
    List<EntityProperty> properties = new ArrayList<>();
    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) {
            properties.add(factory.create(context));
        }
    }
    return properties;
}
 
Example #8
Source File: ApplicationStructureBuilderTest.java    From moserp with Apache License 2.0 5 votes vote down vote up
public void setupMocks() throws URISyntaxException {
    configuration = mock(RepositoryRestConfiguration.class);
    when(configuration.getBaseUri()).thenReturn(new URI("http://localhost:8080/"));
    mappings = mock(ResourceMappings.class);
    metaData = mock(ResourceMetadata.class);
    when(metaData.getPath()).thenReturn(new Path("valueLists"));
    PersistentEntity persistentEntity = mock(PersistentEntity.class);
    when(persistentEntities.getPersistentEntity(any())).thenReturn(persistentEntity);
    PersistentProperty persistentProperty = mock(PersistentProperty.class);
    when(persistentEntity.getPersistentProperty(any(String.class))).thenReturn(persistentProperty);
    when(entityLinks.linkFor(any())).thenReturn(BaseUriLinkBuilder.create(new URI("http://localhost:8080/")));
    moduleRegistry = mock(ModuleRegistry.class);
    when(moduleRegistry.getBaseUriForResource(anyString())).thenReturn(new RestUri("http://localhost:8080/valueLists"));
}
 
Example #9
Source File: BasicPropertyFactoryTest.java    From moserp with Apache License 2.0 5 votes vote down vote up
@Before
public void setupBasicMocks() {
    jacksonMetadata = new JacksonMetadata(new ObjectMapperBuilder().build(), SimpleClass.class);
    persistentProperty = mock(PersistentProperty.class);

    persistentEntity = mock(PersistentEntity.class);
    when(persistentEntity.getType()).thenReturn(SimpleClass.class);
    when(persistentProperty.getOwner()).thenReturn(persistentEntity);
}
 
Example #10
Source File: MybatisBasicMapperBuilder.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public MybatisBasicMapperBuilder(Configuration configuration,
		RepositoryInformation repositoryInformation,
		PersistentEntity<?, ?> persistentEntity) {

	super(configuration, persistentEntity,
			repositoryInformation.getRepositoryInterface().getName());

}
 
Example #11
Source File: MybatisSimpleQueryMapperBuilder.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public MybatisSimpleQueryMapperBuilder(Configuration configuration,
		PersistentEntity<?, ?> persistentEntity, SimpleMybatisQuery query) {
	super(configuration, persistentEntity, query.getQueryMethod().getNamespace());

	method = query.getQueryMethod();
	stringQuery = query.getStringQuery();
	commandType = query.getCommandType();

}
 
Example #12
Source File: MybatisPartTreeMapperBuilder.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public MybatisPartTreeMapperBuilder(Configuration configuration,
		PersistentEntity<?, ?> persistentEntity, PartTreeMybatisQuery query) {
	super(configuration, persistentEntity, query.getQueryMethod().getNamespace());

	this.tree = query.getTree();
	this.method = query.getQueryMethod();
}
 
Example #13
Source File: Target_ClassGeneratingEntityInstantiator.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
@Substitute
private EntityInstantiator createEntityInstantiator(PersistentEntity<?, ?> entity) {

	if (shouldUseReflectionEntityInstantiator(entity)) {
		return ReflectionEntityInstantiator.INSTANCE;
	}

	throw new UnsupportedOperationException("Unsupported operation since CGLIB support has been removed");
}
 
Example #14
Source File: MybatisPersistentEntityImpl.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public PersistentEntity<?, ? extends PersistentProperty<?>> getRequiredPersistentEntity(
		Class<?> type) {

	Assert.notNull(type, "Domain type must not be null!");

	return getPersistentEntity(type).orElseThrow(() -> new IllegalArgumentException(
			String.format("Couldn't find PersistentEntity for type %s!", type)));
}
 
Example #15
Source File: JsonSchemaBuilderTest.java    From moserp with Apache License 2.0 5 votes vote down vote up
public void setupMocks() throws URISyntaxException {
    configuration = mock(RepositoryRestConfiguration.class);
    when(configuration.getBaseUri()).thenReturn(new URI("http://localhost:8080/"));
    mappings = mock(ResourceMappings.class);
    metaData = mock(ResourceMetadata.class);
    when(metaData.getPath()).thenReturn(new Path("valueLists"));
    PersistentEntity persistentEntity = mock(PersistentEntity.class);
    when(persistentEntities.getPersistentEntity(any())).thenReturn(persistentEntity);
    PersistentProperty persistentProperty = mock(PersistentProperty.class);
    when(persistentEntity.getPersistentProperty(any(String.class))).thenReturn(persistentProperty);
    when(entityLinks.linkFor(any())).thenReturn(BaseUriLinkBuilder.create(new URI("http://localhost:8080/")));
    moduleRegistry = mock(ModuleRegistry.class);
    when(moduleRegistry.getBaseUriForResource(anyString())).thenReturn(new RestUri("http://localhost:8080/valueLists"));
}
 
Example #16
Source File: AbstractContentPropertyController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
protected PersistentProperty<?> getContentPropertyDefinition(
		PersistentEntity<?, ?> persistentEntity, String contentProperty) {
	PersistentProperty<?> prop = persistentEntity
			.getPersistentProperty(contentProperty);
	if (null == prop)
		throw new ResourceNotFoundException();

	return prop;
}
 
Example #17
Source File: DefaultVaultTypeMapper.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
private DefaultVaultTypeMapper(@Nullable String typeKey, TypeAliasAccessor<Map<String, Object>> accessor,
		MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext,
		List<? extends TypeInformationMapper> mappers) {

	super(accessor, mappingContext, mappers);

	this.typeKey = typeKey;
}
 
Example #18
Source File: CypherQueryCreator.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
private Expression toCypherProperty(Neo4jPersistentProperty persistentProperty, boolean addToLower) {

		PersistentEntity<?, Neo4jPersistentProperty> owner = persistentProperty.getOwner();
		Expression expression;

		if (owner.equals(this.nodeDescription)) {
			expression = Cypher.property(NAME_OF_ROOT_NODE, persistentProperty.getPropertyName());
		} else {
			PropertyPathWrapper propertyPathWrapper = propertyPathWrappers.stream()
				.filter(rp -> rp.getLeafProperty().equals(persistentProperty))
				.findFirst().get();

			String cypherElementName;
			// this "entity" is a representation of a relationship with properties
			if (owner.isAnnotationPresent(RelationshipProperties.class)) {
				cypherElementName = propertyPathWrapper.getRelationshipName();
			} else {
				cypherElementName = propertyPathWrapper.getNodeName();
			}
			expression = Cypher.property(cypherElementName, persistentProperty.getPropertyName());
		}

		if (addToLower) {
			expression = Functions.toLower(expression);
		}

		return expression;
	}
 
Example #19
Source File: HazelcastRepositoryFactory.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
    PersistentEntity<T, ?> entity = (PersistentEntity<T, ?>) keyValueOperations.getMappingContext()
                                                                               .getPersistentEntity(domainClass);
    Assert.notNull(entity, "Entity must not be 'null'.");
    return new HazelcastEntityInformation<>(entity);
}
 
Example #20
Source File: HazelcastEntityInformation.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
/**
 * @param entity must not be {@literal null}.
 */
HazelcastEntityInformation(PersistentEntity<T, ?> entity) {
    super(entity);
    if (!entity.hasIdProperty()) {
        throw new MappingException(
                String.format("Entity %s requires a field annotated with %s", entity.getName(), Id.class.getName()));
    }
}
 
Example #21
Source File: DatastorePersistentPropertyImpl.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param property the property to store
 * @param owner the entity to which this property belongs
 * @param simpleTypeHolder the type holder
 * @param fieldNamingStrategy the naming strategy used to get the column name of this
 * property
 */
DatastorePersistentPropertyImpl(Property property,
		PersistentEntity<?, DatastorePersistentProperty> owner,
		SimpleTypeHolder simpleTypeHolder, FieldNamingStrategy fieldNamingStrategy) {
	super(property, owner, simpleTypeHolder);
	this.fieldNamingStrategy = (fieldNamingStrategy != null)
			? fieldNamingStrategy
			: PropertyNameFieldNamingStrategy.INSTANCE;
	verify();
}
 
Example #22
Source File: SimpleQuerydslJdbcRepository.java    From infobip-spring-data-querydsl with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public SimpleQuerydslJdbcRepository(JdbcAggregateOperations entityOperations,
                                    PersistentEntity<T, ?> entity,
                                    SQLQueryFactory sqlQueryFactory,
                                    ConstructorExpression<T> constructorExpression,
                                    RelationalPath<?> path) {
    this.sqlQueryFactory = sqlQueryFactory;
    this.constructorExpression = constructorExpression;
    this.path = (RelationalPath<T>) path;
    this.repository = new SimpleJdbcRepository<>(entityOperations, entity);
}
 
Example #23
Source File: KeyValueRepositoryFactory.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {

	PersistentEntity<T, ?> entity = (PersistentEntity<T, ?>) context.getRequiredPersistentEntity(domainClass);

	return new PersistentEntityInformation<>(entity);
}
 
Example #24
Source File: DefaultArangoPersistentProperty.java    From spring-data with Apache License 2.0 5 votes vote down vote up
public DefaultArangoPersistentProperty(final Property property,
	final PersistentEntity<?, ArangoPersistentProperty> owner, final SimpleTypeHolder simpleTypeHolder,
	final FieldNamingStrategy fieldNamingStrategy) {
	super(property, owner, simpleTypeHolder);
	this.fieldNamingStrategy = fieldNamingStrategy != null ? fieldNamingStrategy
			: PropertyNameFieldNamingStrategy.INSTANCE;
}
 
Example #25
Source File: SimpleKeyValueRepositoryUnitTests.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T, S> EntityInformation<T, S> getEntityInformationFor(Class<T> type) {

	PersistentEntity<T, ?> requiredPersistentEntity = (PersistentEntity<T, ?>) context
			.getRequiredPersistentEntity(type);

	return new PersistentEntityInformation<>(requiredPersistentEntity);
}
 
Example #26
Source File: Target_BeanWrapperPropertyAccessorFactory.java    From spring-graalvm-native with Apache License 2.0 4 votes vote down vote up
@Alias
public boolean isSupported(PersistentEntity<?, ?> entity) {
	return false;
}
 
Example #27
Source File: TypicalEntityReaderBenchmark.java    From spring-data-dev-tools with Apache License 2.0 4 votes vote down vote up
MyPersistentProperty(Property property, PersistentEntity<?, MyPersistentProperty> owner,
		SimpleTypeHolder simpleTypeHolder) {
	super(property, owner, simpleTypeHolder);
}
 
Example #28
Source File: HazelcastEntityInformationTest.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
@Test(expected = MappingException.class)
public void throwsMappingExceptionWhenNoIdPropertyPresent() {
    PersistentEntity<?, ?> persistentEntity = operations.getMappingContext().getPersistentEntity(NoIdEntity.class);
    new HazelcastEntityInformation<>(persistentEntity);
}
 
Example #29
Source File: KeyValuePersistentProperty.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
public KeyValuePersistentProperty(Property property, PersistentEntity<?, P> owner,
		SimpleTypeHolder simpleTypeHolder) {
	super(property, owner, simpleTypeHolder);
}
 
Example #30
Source File: MybatisMapperBuildAssistant.java    From spring-data-mybatis with Apache License 2.0 4 votes vote down vote up
protected List<MybatisPersistentProperty> findNormalColumns(PersistentEntity entity) {
	List<MybatisPersistentProperty> columns = new ArrayList<>();
	entity.doWithProperties(
			(PropertyHandler<MybatisPersistentProperty>) columns::add);
	return columns;
}