Search in sources :

Example 21 with SqlIdentifier

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

the class SqlContext method getTable.

Table getTable(PersistentPropertyPathExtension path) {
    SqlIdentifier tableAlias = path.getTableAlias();
    Table table = Table.create(path.getTableName());
    return tableAlias == null ? table : table.as(tableAlias);
}
Also used : Table(org.springframework.data.relational.core.sql.Table) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 22 with SqlIdentifier

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

the class SqlIdentifierParameterSource method addAll.

void addAll(SqlIdentifierParameterSource others) {
    for (SqlIdentifier identifier : others.getIdentifiers()) {
        String name = identifier.getReference(identifierProcessing);
        addValue(identifier, others.getValue(name), others.getSqlType(name));
    }
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 23 with SqlIdentifier

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

the class JdbcRepositoryEmbeddedWithCollectionIntegrationTests 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 24 with SqlIdentifier

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

the class IdentifierUnitTests method identifierPartsCanBeAccessedByString.

// DATAJDBC-542
@Test
public void identifierPartsCanBeAccessedByString() {
    Map<SqlIdentifier, Object> idParts = new HashMap<>();
    idParts.put(unquoted("aName"), "one");
    idParts.put(quoted("Other"), "two");
    Identifier id = Identifier.from(idParts);
    Map<SqlIdentifier, Object> map = id.toMap();
    assertSoftly(softly -> {
        softly.assertThat(map.get("aName")).describedAs("aName").isEqualTo("one");
        softly.assertThat(map.get("Other")).describedAs("Other").isEqualTo("two");
        softly.assertThat(map.get("other")).describedAs("other").isNull();
        softly.assertThat(map.get("OTHER")).describedAs("OTHER").isNull();
    });
}
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 25 with SqlIdentifier

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

the class DerivedSqlIdentifierUnitTests method equality.

// DATAJDBC-386
@Test
public void equality() {
    SqlIdentifier basis = new DerivedSqlIdentifier("simple", false);
    SqlIdentifier equal = new DerivedSqlIdentifier("simple", false);
    SqlIdentifier quoted = new DerivedSqlIdentifier("simple", true);
    SqlIdentifier notSimple = SqlIdentifier.from(new DerivedSqlIdentifier("simple", false), new DerivedSqlIdentifier("not", false));
    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