Search in sources :

Example 1 with Naming

use of org.seasar.doma.jdbc.Naming in project doma by domaframework.

the class AutoDeleteQuery method prepareSql.

protected void prepareSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.DELETE, sqlLogType);
    builder.appendSql("delete from ");
    builder.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
    boolean whereClauseAppended = false;
    if (idPropertyTypes.size() > 0) {
        builder.appendSql(" where ");
        whereClauseAppended = true;
        for (EntityPropertyType<ENTITY, ?> propertyType : idPropertyTypes) {
            Property<ENTITY, ?> property = propertyType.createProperty();
            property.load(entity);
            builder.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
            builder.appendSql(" = ");
            builder.appendParameter(property.asInParameter());
            builder.appendSql(" and ");
        }
        builder.cutBackSql(5);
    }
    if (versionPropertyType != null && !versionIgnored) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = versionPropertyType.createProperty();
        property.load(entity);
        builder.appendSql(versionPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    if (tenantIdPropertyType != null) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            // noinspection UnusedAssignment
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = tenantIdPropertyType.createProperty();
        property.load(entity);
        builder.appendSql(tenantIdPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    sql = builder.build(this::comment);
}
Also used : Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) PreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)

Example 2 with Naming

use of org.seasar.doma.jdbc.Naming in project doma by domaframework.

the class ReservedIdProvider method createSql.

protected Sql<?> createSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    String catalogName = entityType.getCatalogName();
    String schemaName = entityType.getSchemaName();
    String tableName = entityType.getTableName(naming::apply);
    String idColumnName = entityType.getGeneratedIdPropertyType().getColumnName(naming::apply);
    boolean isQuoteRequired = entityType.isQuoteRequired();
    boolean isIdColumnQuoteRequired = entityType.getGeneratedIdPropertyType().isQuoteRequired();
    return dialect.getIdentityReservationSql(catalogName, schemaName, tableName, idColumnName, isQuoteRequired, isIdColumnQuoteRequired, reservationSize);
}
Also used : Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming)

Example 3 with Naming

use of org.seasar.doma.jdbc.Naming in project doma by domaframework.

the class AutoBatchDeleteQuery method prepareSql.

protected void prepareSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.BATCH_DELETE, sqlLogType);
    builder.appendSql("delete from ");
    builder.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
    boolean whereClauseAppended = false;
    if (idPropertyTypes.size() > 0) {
        builder.appendSql(" where ");
        whereClauseAppended = true;
        for (EntityPropertyType<ENTITY, ?> propertyType : idPropertyTypes) {
            Property<ENTITY, ?> property = propertyType.createProperty();
            property.load(currentEntity);
            builder.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
            builder.appendSql(" = ");
            builder.appendParameter(property.asInParameter());
            builder.appendSql(" and ");
        }
        builder.cutBackSql(5);
    }
    if (versionPropertyType != null && !versionIgnored) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = versionPropertyType.createProperty();
        property.load(currentEntity);
        builder.appendSql(versionPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    if (tenantIdPropertyType != null) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            // noinspection UnusedAssignment
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = tenantIdPropertyType.createProperty();
        property.load(currentEntity);
        builder.appendSql(tenantIdPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    PreparedSql sql = builder.build(this::comment);
    sqls.add(sql);
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) PreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)

Example 4 with Naming

use of org.seasar.doma.jdbc.Naming in project doma by domaframework.

the class AutoBatchInsertQuery method prepareSql.

protected void prepareSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.BATCH_INSERT, sqlLogType);
    builder.appendSql("insert into ");
    builder.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
    builder.appendSql(" (");
    for (EntityPropertyType<ENTITY, ?> p : targetPropertyTypes) {
        builder.appendSql(p.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(", ");
    }
    builder.cutBackSql(2);
    builder.appendSql(") values (");
    for (EntityPropertyType<ENTITY, ?> propertyType : targetPropertyTypes) {
        Property<ENTITY, ?> property = propertyType.createProperty();
        property.load(currentEntity);
        builder.appendParameter(property.asInParameter());
        builder.appendSql(", ");
    }
    builder.cutBackSql(2);
    builder.appendSql(")");
    PreparedSql sql = builder.build(this::comment);
    sqls.add(sql);
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) PreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)

Example 5 with Naming

use of org.seasar.doma.jdbc.Naming in project doma by domaframework.

the class AutoBatchUpdateQuery method prepareSql.

protected void prepareSql() {
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.BATCH_UPDATE, sqlLogType);
    builder.appendSql("update ");
    builder.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
    builder.appendSql(" set ");
    helper.populateValues(currentEntity, targetPropertyTypes, versionPropertyType, builder);
    boolean whereClauseAppended = false;
    if (idPropertyTypes.size() > 0) {
        builder.appendSql(" where ");
        whereClauseAppended = true;
        for (EntityPropertyType<ENTITY, ?> propertyType : idPropertyTypes) {
            Property<ENTITY, ?> property = propertyType.createProperty();
            property.load(currentEntity);
            builder.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
            builder.appendSql(" = ");
            builder.appendParameter(property.asInParameter());
            builder.appendSql(" and ");
        }
        builder.cutBackSql(5);
    }
    if (versionPropertyType != null && !versionIgnored) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = versionPropertyType.createProperty();
        property.load(currentEntity);
        builder.appendSql(versionPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    if (tenantIdPropertyType != null) {
        if (whereClauseAppended) {
            builder.appendSql(" and ");
        } else {
            builder.appendSql(" where ");
            // noinspection UnusedAssignment
            whereClauseAppended = true;
        }
        Property<ENTITY, ?> property = tenantIdPropertyType.createProperty();
        property.load(currentEntity);
        builder.appendSql(tenantIdPropertyType.getColumnName(naming::apply, dialect::applyQuote));
        builder.appendSql(" = ");
        builder.appendParameter(property.asInParameter());
    }
    PreparedSql sql = builder.build(this::comment);
    sqls.add(sql);
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) PreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)

Aggregations

Naming (org.seasar.doma.jdbc.Naming)13 Dialect (org.seasar.doma.jdbc.dialect.Dialect)10 PreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)6 PreparedSql (org.seasar.doma.jdbc.PreparedSql)4 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 FetchType (org.seasar.doma.FetchType)1 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)1 Value (org.seasar.doma.internal.expr.Value)1 BasicSingleResultHandler (org.seasar.doma.internal.jdbc.command.BasicSingleResultHandler)1 ExpandNode (org.seasar.doma.internal.jdbc.sql.node.ExpandNode)1 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)1 AssertionUtil.assertNotNull (org.seasar.doma.internal.util.AssertionUtil.assertNotNull)1 JdbcException (org.seasar.doma.jdbc.JdbcException)1 ResultMappingException (org.seasar.doma.jdbc.ResultMappingException)1