org.springframework.data.mapping.PropertyHandler Java Examples
The following examples show how to use
org.springframework.data.mapping.PropertyHandler.
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: DefaultNeo4jConverter.java From sdn-rx with Apache License 2.0 | 6 votes |
private PropertyHandler<Neo4jPersistentProperty> populateFrom( MapAccessor queryResult, PersistentPropertyAccessor<?> propertyAccessor, Predicate<Neo4jPersistentProperty> isConstructorParameter, Collection<String> surplusLabels ) { return property -> { if (isConstructorParameter.test(property)) { return; } if (property.isDynamicLabels()) { propertyAccessor .setProperty(property, createDynamicLabelsProperty(property.getTypeInformation(), surplusLabels)); } else { propertyAccessor.setProperty(property, readValueForProperty(extractValueOf(property, queryResult), property.getTypeInformation())); } }; }
Example #2
Source File: DefaultNeo4jPersistentEntity.java From sdn-rx with Apache License 2.0 | 6 votes |
private void verifyNoDuplicatedGraphProperties() { Set<String> seen = new HashSet<>(); Set<String> duplicates = new HashSet<>(); this.doWithProperties((PropertyHandler<Neo4jPersistentProperty>) persistentProperty -> { String propertyName = persistentProperty.getPropertyName(); if (seen.contains(propertyName)) { duplicates.add(propertyName); } else { seen.add(propertyName); } }); Assert.state(duplicates.isEmpty(), () -> String.format("Duplicate definition of propert%s %s in entity %s.", duplicates.size() == 1 ? "y" : "ies", duplicates, getUnderlyingClass())); }
Example #3
Source File: DefaultNeo4jPersistentEntity.java From sdn-rx with Apache License 2.0 | 6 votes |
private void verifyDynamicLabels() { Set<String> namesOfPropertiesWithDynamicLabels = new HashSet<>(); this.doWithProperties((PropertyHandler<Neo4jPersistentProperty>) persistentProperty -> { if (!persistentProperty.isAnnotationPresent(DynamicLabels.class)) { return; } String propertyName = persistentProperty.getPropertyName(); namesOfPropertiesWithDynamicLabels.add(propertyName); Assert.state(persistentProperty.isCollectionLike(), () -> String.format("Property %s on %s must extends %s.", persistentProperty.getFieldName(), persistentProperty.getOwner().getType(), Collection.class.getName()) ); }); Assert.state(namesOfPropertiesWithDynamicLabels.size() <= 1, () -> String.format( "Multiple properties in entity %s are annotated with @%s: %s.", getUnderlyingClass(), DynamicLabels.class.getSimpleName(), namesOfPropertiesWithDynamicLabels)); }
Example #4
Source File: SolrSchemaResolver.java From dubbox with Apache License 2.0 | 6 votes |
public SchemaDefinition resolveSchemaForEntity(SolrPersistentEntity<?> entity) { Assert.notNull(entity, "Schema cannot be resolved for 'null'."); final SchemaDefinition schemaDefinition = new SchemaDefinition(entity.getSolrCoreName()); entity.doWithProperties(new PropertyHandler<SolrPersistentProperty>() { @Override public void doWithPersistentProperty(SolrPersistentProperty persistentProperty) { SchemaDefinition.FieldDefinition fieldDefinition = createFieldDefinitionForProperty(persistentProperty); if (fieldDefinition != null) { schemaDefinition.addFieldDefinition(fieldDefinition); } } }); return schemaDefinition; }
Example #5
Source File: SpannerSchemaUtils.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
private void getDdlStringForInterleavedHierarchy(String parentTable, Class entityClass, List<String> ddlStrings, Set<Class> seenClasses, BiFunction<Class, String, String> generateSingleDdlStringFunc, boolean prependDdlString) { if (seenClasses.contains(entityClass)) { return; } seenClasses.add(entityClass); ddlStrings.add(prependDdlString ? 0 : ddlStrings.size(), generateSingleDdlStringFunc.apply(entityClass, parentTable)); SpannerPersistentEntity spannerPersistentEntity = this.mappingContext .getPersistentEntity(entityClass); spannerPersistentEntity.doWithInterleavedProperties( (PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> getDdlStringForInterleavedHierarchy( spannerPersistentEntity.tableName(), spannerPersistentProperty.getColumnInnerType(), ddlStrings, seenClasses, generateSingleDdlStringFunc, prependDdlString)); }
Example #6
Source File: SimpleCratePersistentEntity.java From spring-data-crate with Apache License 2.0 | 5 votes |
/** * Returns all fields excluding static and transient fields */ @Override public Set<CratePersistentProperty> getPersistentProperties() { final Set<CratePersistentProperty> properties = new LinkedHashSet<>(); doWithProperties(new PropertyHandler<CratePersistentProperty>() { @Override public void doWithPersistentProperty(CratePersistentProperty persistentProperty) { properties.add(persistentProperty); } }); return properties; }
Example #7
Source File: DefaultNeo4jConverter.java From sdn-rx with Apache License 2.0 | 5 votes |
/** * @param queryResult The original query result * @param nodeDescription The node description of the current entity to be mapped from the result * @param knownObjects The current list of known objects * @param <ET> As in entity type * @return */ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescription, KnownObjects knownObjects) { List<String> allLabels = getLabels(queryResult); NodeDescriptionAndLabels nodeDescriptionAndLabels = nodeDescriptionStore .deriveConcreteNodeDescription(nodeDescription, allLabels); Neo4jPersistentEntity<ET> concreteNodeDescription = (Neo4jPersistentEntity<ET>) nodeDescriptionAndLabels .getNodeDescription(); Collection<RelationshipDescription> relationships = concreteNodeDescription.getRelationships(); ET instance = instantiate(concreteNodeDescription, queryResult, knownObjects, relationships, nodeDescriptionAndLabels.getDynamicLabels()); PersistentPropertyAccessor<ET> propertyAccessor = concreteNodeDescription.getPropertyAccessor(instance); if (concreteNodeDescription.requiresPropertyPopulation()) { // Fill simple properties Predicate<Neo4jPersistentProperty> isConstructorParameter = concreteNodeDescription .getPersistenceConstructor()::isConstructorParameter; PropertyHandler<Neo4jPersistentProperty> handler = populateFrom( queryResult, propertyAccessor, isConstructorParameter, nodeDescriptionAndLabels.getDynamicLabels()); concreteNodeDescription.doWithProperties(handler); // Fill associations concreteNodeDescription.doWithAssociations( populateFrom(queryResult, propertyAccessor, isConstructorParameter, relationships, knownObjects)); } return instance; }
Example #8
Source File: MybatisBasicMapperBuilder.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
private void addResultMap() { List<ResultMapping> resultMappings = new ArrayList<>(); entity.doWithProperties((PropertyHandler<MybatisPersistentProperty>) p -> { if (p.isAnnotationPresent(EmbeddedId.class) || p.isEmbeddable()) { ((MybatisPersistentEntityImpl) entity) .getRequiredPersistentEntity(p.getActualType()).doWithProperties( (PropertyHandler<MybatisPersistentProperty>) ep -> { resultMappings.add( assistant.buildResultMapping(ep.getType(), String.format("%s.%s", p.getName(), ep.getName()), ep.getColumnName(), ep.getType(), ep.getJdbcType(), null, null, null, null, ep.getSpecifiedTypeHandler(), p.isIdProperty() ? Collections.singletonList( ResultFlag.ID) : null)); }); return; } resultMappings.add(assistant.buildResultMapping(p.getType(), p.getName(), p.getColumnName(), p.getType(), p.getJdbcType(), null, null, null, null, p.getSpecifiedTypeHandler(), p.isIdProperty() ? Collections.singletonList(ResultFlag.ID) : null)); }); addResultMap(RESULT_MAP, entity.getType(), resultMappings); }
Example #9
Source File: SpannerPersistentPropertyImplTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testIgnoredProperty() { new SpannerMappingContext().getPersistentEntity(TestEntity.class) .doWithProperties( (PropertyHandler<SpannerPersistentProperty>) (prop) -> assertThat(prop.getColumnName()) .isNotEqualTo("not_mapped")); }
Example #10
Source File: SpannerPersistentPropertyImplTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testAssociations() { new SpannerMappingContext().getPersistentEntity(TestEntity.class) .doWithProperties((PropertyHandler<SpannerPersistentProperty>) (prop) -> { assertThat(((SpannerPersistentPropertyImpl) prop).createAssociation().getInverse()).isSameAs(prop); assertThat(((SpannerPersistentPropertyImpl) prop).createAssociation() .getObverse()).isNull(); }); }
Example #11
Source File: SpannerPersistentEntityImplTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void doWithChildrenCollectionsTest() { PropertyHandler<SpannerPersistentProperty> mockHandler = mock(PropertyHandler.class); SpannerPersistentEntity spannerPersistentEntity = this.spannerMappingContext.getPersistentEntity(ParentInRelationship.class); doAnswer((invocation) -> { String colName = ((SpannerPersistentProperty) invocation.getArgument(0)) .getName(); assertThat(colName.equals("childrenA") || colName.equals("childrenB")).isTrue(); return null; }).when(mockHandler).doWithPersistentProperty(any()); spannerPersistentEntity.doWithInterleavedProperties(mockHandler); verify(mockHandler, times(2)).doWithPersistentProperty(any()); }
Example #12
Source File: SpannerPersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public void doWithColumnBackedProperties( PropertyHandler<SpannerPersistentProperty> handler) { doWithProperties( (PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> { if (!spannerPersistentProperty.isInterleaved()) { handler.doWithPersistentProperty(spannerPersistentProperty); } }); }
Example #13
Source File: SpannerPersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public void doWithInterleavedProperties( PropertyHandler<SpannerPersistentProperty> handler) { doWithProperties( (PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> { if (spannerPersistentProperty.isInterleaved()) { handler.doWithPersistentProperty(spannerPersistentProperty); } }); }
Example #14
Source File: DatastorePersistentPropertyImplTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testAssociations() { this.datastoreMappingContext.getPersistentEntity(TestEntity.class) .doWithProperties((PropertyHandler<DatastorePersistentProperty>) (prop) -> { assertThat(prop).isSameAs( ((DatastorePersistentPropertyImpl) prop).createAssociation().getInverse()); assertThat(((DatastorePersistentPropertyImpl) prop).createAssociation().getObverse()).isNull(); }); }
Example #15
Source File: DatastorePersistentPropertyImplTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void propertiesTest() { this.datastoreMappingContext.getPersistentEntity(TestEntity.class) .doWithProperties( (PropertyHandler<DatastorePersistentProperty>) (property) -> { if (property.isIdProperty()) { assertThat(property.getFieldName()).isEqualTo("__key__"); } else if (property.getFieldName().equals("custom_field")) { assertThat(property.getType()).isEqualTo(String.class); } else if (property.getFieldName().equals("other")) { assertThat(property.getType()).isEqualTo(String.class); } else if (property.getFieldName().equals("doubleList")) { assertThat(property.getComponentType()).isEqualTo(Double.class); assertThat(property.isCollectionLike()).isTrue(); } else if (property.getFieldName().equals("embeddedEntity")) { assertThat(property.getEmbeddedType()).isEqualTo(EmbeddedType.EMBEDDED_ENTITY); } else if (property.getFieldName().equals("embeddedMap")) { assertThat(property.getEmbeddedType()).isEqualTo(EmbeddedType.EMBEDDED_MAP); assertThat(property.getTypeInformation().getTypeArguments().get(1).getType()) .isEqualTo(String.class); } else if (property.getFieldName().equals("linkedEntity")) { assertThat(property.isDescendants()).isTrue(); } else if (property.getFieldName().equals("linkedEntityRef")) { assertThat(property.isAssociation()).isTrue(); } else { fail("All properties of the test entity are expected to match a checked" + " case above, but this did not: " + property); } }); }
Example #16
Source File: DatastorePersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public void doWithDescendantProperties( PropertyHandler<DatastorePersistentProperty> handler) { doWithProperties( (PropertyHandler<DatastorePersistentProperty>) (datastorePersistentProperty) -> { if (datastorePersistentProperty.isDescendants()) { handler.doWithPersistentProperty(datastorePersistentProperty); } }); }
Example #17
Source File: DatastorePersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public void doWithColumnBackedProperties( PropertyHandler<DatastorePersistentProperty> handler) { doWithProperties( (PropertyHandler<DatastorePersistentProperty>) (datastorePersistentProperty) -> { if (datastorePersistentProperty.isColumnBacked()) { handler.doWithPersistentProperty(datastorePersistentProperty); } }); }
Example #18
Source File: MappingSolrConverter.java From dubbox with Apache License 2.0 | 5 votes |
private <S extends Object> S read(final SolrPersistentEntity<S> entity, final Map<String, ?> source, Object parent) { ParameterValueProvider<SolrPersistentProperty> parameterValueProvider = getParameterValueProvider(entity, source, parent); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final S instance = instantiator.createInstance(entity, parameterValueProvider); final PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(instance), getConversionService()); entity.doWithProperties(new PropertyHandler<SolrPersistentProperty>() { @Override public void doWithPersistentProperty(SolrPersistentProperty persistentProperty) { if (entity.isConstructorArgument(persistentProperty)) { return; } Object o = getValue(persistentProperty, source, instance); if (o != null) { accessor.setProperty(persistentProperty, o); } } }); return instance; }
Example #19
Source File: ConverterAwareMappingSpannerEntityReader.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
/** * Reads a single POJO from a Cloud Spanner row. * @param type the type of POJO * @param source the Cloud Spanner row * @param includeColumns the columns to read. If null then all columns will be read. * @param allowMissingColumns if true, then properties with no corresponding column are * not mapped. If false, then an exception is thrown. * @param <R> the type of the POJO. * @return the POJO */ @SuppressWarnings("unchecked") public <R> R read(Class<R> type, Struct source, Set<String> includeColumns, boolean allowMissingColumns) { boolean readAllColumns = includeColumns == null; SpannerPersistentEntity<R> persistentEntity = (SpannerPersistentEntity<R>) this.spannerMappingContext.getPersistentEntity(type); StructAccessor structAccessor = new StructAccessor(source); StructPropertyValueProvider propertyValueProvider = new StructPropertyValueProvider( structAccessor, this.converter, this, allowMissingColumns); PreferredConstructor<?, SpannerPersistentProperty> persistenceConstructor = persistentEntity .getPersistenceConstructor(); // @formatter:off ParameterValueProvider<SpannerPersistentProperty> parameterValueProvider = new PersistentEntityParameterValueProvider<>(persistentEntity, propertyValueProvider, null); // @formatter:on EntityInstantiator instantiator = this.instantiators.getInstantiatorFor(persistentEntity); R instance = instantiator.createInstance(persistentEntity, parameterValueProvider); PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(instance); persistentEntity.doWithProperties( (PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> { if (spannerPersistentProperty.isEmbedded()) { accessor.setProperty(spannerPersistentProperty, read(spannerPersistentProperty.getType(), source, includeColumns, allowMissingColumns)); } else { if (!shouldSkipProperty(structAccessor, spannerPersistentProperty, includeColumns, readAllColumns, allowMissingColumns, persistenceConstructor)) { Object value = propertyValueProvider .getPropertyValue(spannerPersistentProperty); accessor.setProperty(spannerPersistentProperty, value); } } }); return instance; }
Example #20
Source File: SpannerPersistentPropertyImplTests.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
@Test public void testNoPojoIdProperties() { new SpannerMappingContext().getPersistentEntity(TestEntity.class) .doWithProperties( (PropertyHandler<SpannerPersistentProperty>) (prop) -> assertThat(prop.isIdProperty()).isFalse()); }
Example #21
Source File: MappingSolrConverter.java From dubbox with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") protected void write(Object source, final Map target, SolrPersistentEntity<?> entity) { final PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(source), getConversionService()); entity.doWithProperties(new PropertyHandler<SolrPersistentProperty>() { @SuppressWarnings("unchecked") @Override public void doWithPersistentProperty(SolrPersistentProperty persistentProperty) { Object value = accessor.getProperty(persistentProperty); if (value == null || persistentProperty.isReadonly()) { return; } if (persistentProperty.containsWildcard() && !persistentProperty.isMap()) { throw new IllegalArgumentException("Field '" + persistentProperty.getFieldName() + "' must not contain wildcards. Consider excluding Field from beeing indexed."); } Collection<SolrInputField> fields; if (persistentProperty.isMap() && persistentProperty.containsWildcard()) { fields = writeWildcardMapPropertyToTarget(target, persistentProperty, (Map<?, ?>) value); } else { fields = writeRegularPropertyToTarget(target, persistentProperty, value); } if (persistentProperty.isBoosted()) { for (SolrInputField field : fields) { field.setBoost(persistentProperty.getBoost()); } } } }); if (entity.isBoosted() && target instanceof SolrInputDocument) { ((SolrInputDocument) target).setDocumentBoost(entity.getBoost()); } }
Example #22
Source File: MybatisBasicMapperBuilder.java From spring-data-mybatis with Apache License 2.0 | 4 votes |
private String buildCondition() { final StringBuilder builder = new StringBuilder(); entity.doWithProperties((PropertyHandler<MybatisPersistentProperty>) p -> { Set<Condition> set = new HashSet<>(); Conditions conditions = p.findAnnotation(Conditions.class); if (null != conditions && conditions.value().length > 0) { set.addAll(Stream.of(conditions.value()).collect(Collectors.toSet())); } Condition condition = p.findAnnotation(Condition.class); if (null != condition) { set.add(condition); } builder.append(set.stream().map(c -> { String[] properties = c.properties(); if (null == properties || properties.length == 0) { properties = new String[] { p.getName() }; } Type type = Type.valueOf(c.type().name()); if (type.getNumberOfArguments() > 0 && type.getNumberOfArguments() != properties.length) { throw new MappingException("@Condition with type " + type + " needs " + type.getNumberOfArguments() + " arguments, but only find " + properties.length + " properties in this @Condition."); } StringBuilder sb = new StringBuilder(); sb.append("<if test=\""); sb.append(Stream.of(properties).map( property -> String.format("__condition.%s != null", property)) .collect(Collectors.joining(" and "))); sb.append("\">"); sb.append(" and ") .append(queryConditionLeft( StringUtils.hasText(c.column()) ? c.column() : p.getColumnName(), IgnoreCaseType.valueOf(c.ignoreCaseType().name()))) .append(calculateOperation(type)); sb.append(queryConditionRight(type, IgnoreCaseType.valueOf(c.ignoreCaseType().name()), Stream.of(properties).map(p1 -> "__condition." + p1) .toArray(String[]::new))); sb.append("</if>"); return sb; }).collect(Collectors.joining(" "))); }); return builder.toString(); }
Example #23
Source File: MybatisMapperBuildAssistant.java From spring-data-mybatis with Apache License 2.0 | 4 votes |
protected List<MybatisPersistentProperty> findNormalColumns(PersistentEntity entity) { List<MybatisPersistentProperty> columns = new ArrayList<>(); entity.doWithProperties( (PropertyHandler<MybatisPersistentProperty>) columns::add); return columns; }
Example #24
Source File: DefaultNeo4jPersistentEntity.java From sdn-rx with Apache License 2.0 | 3 votes |
private Collection<GraphPropertyDescription> computeGraphProperties() { final List<GraphPropertyDescription> computedGraphProperties = new ArrayList<>(); doWithProperties((PropertyHandler<Neo4jPersistentProperty>) computedGraphProperties::add); return Collections.unmodifiableCollection(computedGraphProperties); }
Example #25
Source File: DatastorePersistentEntity.java From spring-cloud-gcp with Apache License 2.0 | 2 votes |
/** * Applies the given {@link PropertyHandler} to all * {@link DatastorePersistentProperty} contained in this * {@link DatastorePersistentEntity} that are properties backed by descendants. * * @param handler must not be {@literal null}. */ void doWithDescendantProperties( PropertyHandler<DatastorePersistentProperty> handler);
Example #26
Source File: SpannerPersistentEntity.java From spring-cloud-gcp with Apache License 2.0 | 2 votes |
/** * Applies the given {@link PropertyHandler} to all {@link SpannerPersistentProperty}s * contained in this {@link SpannerPersistentProperty} that are collections of child * entities. * * @param handler must not be {@literal null}. */ void doWithInterleavedProperties( PropertyHandler<SpannerPersistentProperty> handler);
Example #27
Source File: SpannerPersistentEntity.java From spring-cloud-gcp with Apache License 2.0 | 2 votes |
/** * Applies the given {@link PropertyHandler} to all {@link SpannerPersistentProperty}s * contained in this {@link SpannerPersistentProperty} that are stored as columns in * the table for this entity. * * @param handler must not be {@literal null}. */ void doWithColumnBackedProperties(PropertyHandler<SpannerPersistentProperty> handler);
Example #28
Source File: DatastorePersistentEntity.java From spring-cloud-gcp with Apache License 2.0 | 2 votes |
/** * Applies the given {@link PropertyHandler} to all * {@link DatastorePersistentProperty} contained in this * {@link DatastorePersistentEntity} that are stored as columns in the table for this * entity. This means properties backed by descendants or references to entities of * other Kinds are not provided to the {@code handler}. * * @param handler must not be {@literal null}. */ void doWithColumnBackedProperties( PropertyHandler<DatastorePersistentProperty> handler);