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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations