use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method getMapEntityRowMapper.
private RowMapper<?> getMapEntityRowMapper(PersistentPropertyPathExtension path, Identifier identifier) {
SqlIdentifier keyColumn = path.getQualifierColumn();
Assert.notNull(keyColumn, () -> "KeyColumn must not be null for " + path);
return new MapEntityRowMapper<>(path, converter, identifier, keyColumn, getIdentifierProcessing());
}
use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method getParameterSource.
private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance, RelationalPersistentEntity<S> persistentEntity, String prefix, Predicate<RelationalPersistentProperty> skipProperty, IdentifierProcessing identifierProcessing) {
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing);
PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance) : NoValuePropertyAccessor.instance();
persistentEntity.doWithAll(property -> {
if (skipProperty.test(property) || !property.isWritable()) {
return;
}
if (property.isEntity() && !property.isEmbedded()) {
return;
}
if (property.isEmbedded()) {
Object value = propertyAccessor.getProperty(property);
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType());
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value, (RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty, identifierProcessing);
parameters.addAll(additionalParameters);
} else {
Object value = propertyAccessor.getProperty(property);
SqlIdentifier paramName = property.getColumnName().transform(prefix::concat);
addConvertedPropertyValue(parameters, property, value, paramName);
}
});
return parameters;
}
use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method getKeyColumnNames.
private <T> String[] getKeyColumnNames(Class<T> domainType) {
RelationalPersistentEntity<?> requiredPersistentEntity = context.getRequiredPersistentEntity(domainType);
if (!requiredPersistentEntity.hasIdProperty()) {
return new String[0];
}
SqlIdentifier idColumn = requiredPersistentEntity.getIdColumn();
return new String[] { idColumn.getReference(getIdentifierProcessing()) };
}
use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.
the class SqlIdentifierUnitTests method quotedMultipartObjectIdentifier.
// DATAJDBC-386
@Test
public void quotedMultipartObjectIdentifier() {
SqlIdentifier identifier = SqlIdentifier.from(quoted("some"), quoted("name"));
String sql = identifier.toSql(IdentifierProcessing.ANSI);
assertThat(sql).isEqualTo("\"some\".\"name\"");
}
use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.
the class SqlIdentifierUnitTests method equality.
// DATAJDBC-386
@Test
public void equality() {
SqlIdentifier basis = SqlIdentifier.unquoted("simple");
SqlIdentifier equal = SqlIdentifier.unquoted("simple");
SqlIdentifier quoted = quoted("simple");
SqlIdentifier notSimple = SqlIdentifier.from(unquoted("simple"), unquoted("not"));
assertSoftly(softly -> {
softly.assertThat(basis).isEqualTo(equal);
softly.assertThat(equal).isEqualTo(basis);
softly.assertThat(basis).isNotEqualTo(quoted);
softly.assertThat(basis).isNotEqualTo(notSimple);
});
}
Aggregations