Search in sources :

Example 1 with SqlIdentifier

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());
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 2 with SqlIdentifier

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;
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 3 with SqlIdentifier

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()) };
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 4 with SqlIdentifier

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\"");
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 5 with SqlIdentifier

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);
    });
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

SqlIdentifier (org.springframework.data.relational.core.sql.SqlIdentifier)27 Test (org.junit.jupiter.api.Test)13 Nullable (org.springframework.lang.Nullable)4 HashMap (java.util.HashMap)2 Table (org.springframework.data.relational.core.sql.Table)2 Lazy (org.springframework.data.util.Lazy)2 Objects (java.util.Objects)1 Optional (java.util.Optional)1 PersistentProperty (org.springframework.data.mapping.PersistentProperty)1 PersistentPropertyPath (org.springframework.data.mapping.PersistentPropertyPath)1 MappingContext (org.springframework.data.mapping.context.MappingContext)1 BasicPersistentEntity (org.springframework.data.mapping.model.BasicPersistentEntity)1 IdentifierProcessing (org.springframework.data.relational.core.sql.IdentifierProcessing)1 TypeInformation (org.springframework.data.util.TypeInformation)1 Assert (org.springframework.util.Assert)1 StringUtils (org.springframework.util.StringUtils)1