use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class SelectNextValCommand method doPrepareSequenceCache.
protected String doPrepareSequenceCache(String sql, SequenceCache sequenceCache, Integer incrementSize, Integer cacheSize) {
if (sequenceCache != null) {
final DBMeta dbmeta = _dbmeta;
if (incrementSize != null) {
assertIncrementSizeNotMinusAndNotZero(incrementSize, dbmeta);
// cacheSize is not null here because the sequence cache has been found
sql = _sequenceCacheHandler.filterNextValSql(cacheSize, incrementSize, sql);
}
}
return sql;
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class InsertEntityCommand method createNonPrimaryInsertSqlExecution.
/**
* @param bmd The meta data of bean. (NotNull)
* @return Whether the method is target. (For example if it has primary key, returns false.)
*/
protected SqlExecution createNonPrimaryInsertSqlExecution(TnBeanMetaData bmd) {
final DBMeta dbmeta = findDBMeta();
if (dbmeta.hasPrimaryKey()) {
return null;
}
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
final StringBuilder columnDefSb = new StringBuilder();
for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
columnDefSb.append(", ").append(columnInfo.getColumnSqlName());
}
columnDefSb.delete(0, ", ".length()).insert(0, "(").append(")");
final StringBuilder columnValuesSb = new StringBuilder();
for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
columnValuesSb.append(", /*pmb.").append(columnInfo.getPropertyName()).append("*/null");
}
columnValuesSb.delete(0, ", ".length()).insert(0, "(").append(")");
final String sql = "insert into " + dbmeta.getTableSqlName() + columnDefSb + " values" + columnValuesSb;
return createOutsideSqlExecuteExecution(_entity.getClass(), sql);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class SelectCBExecution method processPagingSelectAndQuerySplit.
// ===================================================================================
// Paging Select and Query Split
// =============================
protected Object processPagingSelectAndQuerySplit(Object[] args, ConditionBean cb) {
if (!cb.canPagingSelectAndQuerySplit()) {
return null;
}
if (!cb.isFetchScopeEffective()) {
return null;
}
final DBMeta dbmeta = cb.asDBMeta();
final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
if (primaryInfo.isCompoundKey()) {
// basically no way, already checked
return null;
}
final ColumnInfo pkColumn = primaryInfo.getFirstColumn();
final SqlClause sqlClause = cb.getSqlClause();
final List<Object> pkList = doSplitSelectFirst(args, cb, dbmeta, sqlClause);
if (pkList == null) {
// no way just in case
return null;
}
if (pkList.isEmpty()) {
return pkList;
}
return doSplitSelectSecond(args, cb, pkColumn, sqlClause, pkList);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class TnRelationRowCreatorExtension method setupRelationKeyValue.
// ===================================================================================
// Relation KeyValue Setup
// =======================
@Override
protected void setupRelationKeyValue(TnRelationRowCreationResource res) {
// /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// setup of relation key is handled at all-value setup marked as '#RELKEY'
// so only entity instance creation exists in this method
// = = = = = = = = = =/
final TnRelationPropertyType rpt = res.getRelationPropertyType();
final TnBeanMetaData yourBmd = rpt.getYourBeanMetaData();
if (!res.hasRowInstance()) {
// always no instance here (check just in case)
final DBMeta dbmeta = yourBmd.getDBMeta();
final Object row = newRelationRow(rpt, res.getRelationSelector(), res.getRelationNoSuffix(), dbmeta);
res.setRow(row);
}
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class TnRelationRowOptionalNullThrower method throwRelationEntityNotFoundException.
protected void throwRelationEntityNotFoundException() {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Not found the relation entity.");
br.addItem("Advice");
br.addElement("Confirm the existence in your business rule.");
br.addElement("If the relation entity might not exist, check it.");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" List<Member> memberList = memberBhv.selectList(cb -> {");
br.addElement(" cb.setupSelect_MemberServiceAsOne();");
br.addElement(" });");
br.addElement(" for (Member member : memberList) {");
br.addElement(" ... = member.getMemberServiceAsOne().alwaysPresent(...); // *No");
br.addElement(" }");
br.addElement(" (o):");
br.addElement(" List<Member> memberList = memberBhv.selectList(cb -> {");
br.addElement(" cb.setupSelect_MemberServiceAsOne();");
br.addElement(" });");
br.addElement(" for (Member member : memberList) {");
br.addElement(" member.getMemberServiceAsOne().ifPresent(service -> { // OK");
br.addElement(" ... = service.getServicePointCount();");
br.addElement(" });");
br.addElement(" }");
br.addItem("Your Operation");
final String localTable;
final String localSuffix;
if (_row instanceof Entity) {
// basically here
final Entity entity = ((Entity) _row);
final DBMeta dbmeta = entity.asDBMeta();
localTable = dbmeta.getTableDispName();
localSuffix = dbmeta.extractPrimaryKeyMap(entity).toString();
} else {
// just in case
localTable = _row != null ? _row.getClass().getSimpleName() : null;
localSuffix = "{" + _row + "}";
}
br.addElement(localTable + ":" + localSuffix + " => " + _propertyName);
if (_row instanceof Entity) {
// basically here
final Entity entity = ((Entity) _row);
br.addItem("Local Entity");
try {
br.addElement(entity.toStringWithRelation());
} catch (RuntimeException continued) {
final String tableDbName = entity.asTableDbName();
final String msg = "*Failed to build string from the entity for debug: " + tableDbName;
if (_log.isDebugEnabled()) {
_log.debug(msg);
}
br.addElement(msg);
}
} else {
br.addItem("Local Entity");
br.addElement(_row);
}
if (_invokePath != null) {
// if saved
br.addItem("Behavior");
br.addElement(_invokePath);
}
if (_sql != null) {
// basically true, just in case
br.addItem("ConditionBean");
try {
final TimeZone finalTimeZone = getFinalTimeZone();
final DisplaySqlBuilder displaySqlBuilder = createDisplaySqlBuilder(finalTimeZone);
br.addElement(displaySqlBuilder.buildDisplaySql(_sql, _args));
br.addElement("");
br.addElement("(using DBFlute system time-zone: " + finalTimeZone.getID() + ")");
} catch (RuntimeException continued) {
final String msg = "*Failed to get display SQL from the condition-bean for debug.";
if (_log.isDebugEnabled()) {
_log.debug(msg);
}
br.addElement(_sql);
if (_args != null) {
br.addElement(Arrays.asList(_args));
}
}
}
// no way outsideSql
// if (outsideSqlPath != null) {
// br.addItem("OutsideSql");
// br.addElement("path : " + outsideSqlPath);
// br.addElement("pmb : " + parameterBean);
// }
final String msg = br.buildExceptionMessage();
throw new RelationEntityNotFoundException(msg);
}
Aggregations