Search in sources :

Example 11 with SqlIdentifier

use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.

the class DerivedSqlIdentifierUnitTests method quotedSimpleObjectIdentifierWithAdjustableLetterCasing.

// DATAJDBC-386
@Test
public void quotedSimpleObjectIdentifierWithAdjustableLetterCasing() {
    SqlIdentifier identifier = new DerivedSqlIdentifier("someName", true);
    assertThat(identifier.toSql(BRACKETS_LOWER_CASE)).isEqualTo("[somename]");
    assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("someName");
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 12 with SqlIdentifier

use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.

the class ColumnVisitor method leaveMatched.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.relational.core.sql.render.TypedSubtreeVisitor#leaveMatched(org.springframework.data.relational.core.sql.Visitable)
	 */
@Override
Delegation leaveMatched(Column segment) {
    SqlIdentifier column = context.getNamingStrategy().getName(segment);
    CharSequence name = considerTablePrefix && tableName != null ? NameRenderer.render(context, SqlIdentifier.from(tableName, column)) : NameRenderer.render(context, segment);
    target.onRendered(name);
    return super.leaveMatched(segment);
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 13 with SqlIdentifier

use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.

the class IdentifierUnitTests method parametersWithStringKeysUseObjectAsTypeForNull.

// DATAJDBC-326
@Test
public void parametersWithStringKeysUseObjectAsTypeForNull() {
    HashMap<SqlIdentifier, Object> parameters = new HashMap<>();
    parameters.put(unquoted("one"), null);
    Identifier identifier = Identifier.from(parameters);
    // 
    assertThat(identifier.getParts()).extracting("name", "value", // 
    "targetType").containsExactly(// 
    Assertions.tuple(unquoted("one"), null, Object.class));
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) HashMap(java.util.HashMap) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 14 with SqlIdentifier

use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests method countRowsInTable.

private int countRowsInTable(String name, long idValue) {
    SqlIdentifier id = SqlIdentifier.quoted("ID");
    String whereClause = id.toSql(dialect.getIdentifierProcessing()) + " = " + idValue;
    return JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), name, whereClause);
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 15 with SqlIdentifier

use of org.springframework.data.relational.core.sql.SqlIdentifier in project spring-data-jdbc by spring-projects.

the class PersistentPropertyPathExtension method assembleTableAlias.

private SqlIdentifier assembleTableAlias() {
    Assert.state(path != null, "Path is null");
    RelationalPersistentProperty leafProperty = path.getRequiredLeafProperty();
    String prefix = isEmbedded() ? leafProperty.getEmbeddedPrefix() : leafProperty.getName();
    if (path.getLength() == 1) {
        Assert.notNull(prefix, "Prefix mus not be null.");
        return SqlIdentifier.quoted(prefix);
    }
    PersistentPropertyPathExtension parentPath = getParentPath();
    SqlIdentifier sqlIdentifier = parentPath.assembleTableAlias();
    return parentPath.isEmbedded() ? sqlIdentifier.transform(name -> name.concat(prefix)) : sqlIdentifier.transform(name -> name + "_" + prefix);
}
Also used : Objects(java.util.Objects) IdentifierProcessing(org.springframework.data.relational.core.sql.IdentifierProcessing) MappingContext(org.springframework.data.mapping.context.MappingContext) Nullable(org.springframework.lang.Nullable) Lazy(org.springframework.data.util.Lazy) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) PersistentProperty(org.springframework.data.mapping.PersistentProperty) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) Assert(org.springframework.util.Assert) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

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