Search in sources :

Example 16 with SqlIdentifier

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

the class RelationalPersistentEntityImpl method getTableName.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.relational.mapping.model.RelationalPersistentEntity#getTableName()
	 */
@Override
public SqlIdentifier getTableName() {
    SqlIdentifier schema = determineCurrentEntitySchema();
    Optional<SqlIdentifier> explicitlySpecifiedTableName = tableName.get();
    final SqlIdentifier schemalessTableIdentifier = createDerivedSqlIdentifier(namingStrategy.getTableName(getType()));
    if (schema == null) {
        return explicitlySpecifiedTableName.orElse(schemalessTableIdentifier);
    }
    return explicitlySpecifiedTableName.map(sqlIdentifier -> SqlIdentifier.from(schema, sqlIdentifier)).orElse(SqlIdentifier.from(schema, schemalessTableIdentifier));
}
Also used : Optional(java.util.Optional) TypeInformation(org.springframework.data.util.TypeInformation) Nullable(org.springframework.lang.Nullable) BasicPersistentEntity(org.springframework.data.mapping.model.BasicPersistentEntity) Lazy(org.springframework.data.util.Lazy) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) StringUtils(org.springframework.util.StringUtils) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

Example 17 with SqlIdentifier

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

the class Criteria method and.

/**
 * Create a new {@link Criteria} and combine it with {@code AND} using the provided {@code column} name.
 *
 * @param column Must not be {@literal null} or empty.
 * @return a new {@link CriteriaStep} object to complete the next {@link Criteria}.
 */
public CriteriaStep and(String column) {
    Assert.hasText(column, "Column name must not be null or empty!");
    SqlIdentifier identifier = SqlIdentifier.unquoted(column);
    return new DefaultCriteriaStep(identifier) {

        @Override
        protected Criteria createCriteria(Comparator comparator, @Nullable Object value) {
            return new Criteria(Criteria.this, Combinator.AND, Collections.emptyList(), identifier, comparator, value);
        }
    };
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Nullable(org.springframework.lang.Nullable)

Example 18 with SqlIdentifier

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

the class JdbcRepositoryEmbeddedWithReferenceIntegrationTests 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 19 with SqlIdentifier

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

the class Criteria method or.

/**
 * Create a new {@link Criteria} and combine it with {@code OR} using the provided {@code column} name.
 *
 * @param column Must not be {@literal null} or empty.
 * @return a new {@link CriteriaStep} object to complete the next {@link Criteria}.
 */
public CriteriaStep or(String column) {
    Assert.hasText(column, "Column name must not be null or empty!");
    SqlIdentifier identifier = SqlIdentifier.unquoted(column);
    return new DefaultCriteriaStep(identifier) {

        @Override
        protected Criteria createCriteria(Comparator comparator, @Nullable Object value) {
            return new Criteria(Criteria.this, Combinator.OR, Collections.emptyList(), identifier, comparator, value);
        }
    };
}
Also used : SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Nullable(org.springframework.lang.Nullable)

Example 20 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)

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