use of org.dbflute.dbway.DBDef in project dbflute-core by dbflute.
the class Table method getSequenceNextValSql.
/**
* Get the SQL for next value of sequence.
* @return The SQL for next value of sequence. (NotNull: If a sequence is not found, return empty string.)
*/
public String getSequenceNextValSql() {
// basically for C#
if (!isUseSequence()) {
return "";
}
final DBDef dbdef = getBasicProperties().getCurrentDBDef();
final String sequenceName = getSequenceSqlName();
final String sql = dbdef.dbway().buildSequenceNextValSql(sequenceName);
return sql != null ? sql : "";
}
use of org.dbflute.dbway.DBDef in project dbflute-core by dbflute.
the class TnProcedureMetaDataFactory method findValueType.
// ===================================================================================
// Value Type
// ==========
protected ValueType findValueType(DfPropertyDesc parameterDesc) {
final Class<?> pmbType = parameterDesc.getBeanDesc().getBeanClass();
final String paramName = parameterDesc.getPropertyName();
final Class<?> paramType = parameterDesc.getPropertyType();
final Object valueTypeDef = _annotationReader.getValueType(parameterDesc);
if (valueTypeDef instanceof ValueType) {
return (ValueType) valueTypeDef;
} else {
final String keyName = (valueTypeDef != null ? valueTypeDef.toString() : null);
final DBDef dbdef = ResourceContext.currentDBDef();
return _valueTypeProvider.provide(pmbType, paramName, paramType, keyName, dbdef);
}
}
use of org.dbflute.dbway.DBDef in project dbflute-core by dbflute.
the class DfDatabaseNameMapping method findDBDef.
public DBDef findDBDef(String databaseType) {
final Map<String, String> mapping = findMapping(databaseType);
final String defName = (String) mapping.get("defName");
if (defName == null || defName.trim().length() == 0) {
String msg = "The database should have its defName: " + mapping;
throw new IllegalStateException(msg);
}
final DBDef dbdef = DBDef.codeOf(defName);
return dbdef != null ? dbdef : DBDef.Unknown;
}
use of org.dbflute.dbway.DBDef in project dbflute-core by dbflute.
the class DfTaskControlLogic method initializeVariousEnvironment.
public void initializeVariousEnvironment() {
if (getDatabaseTypeFacadeProp().isDatabaseOracle()) {
// basically for data loading of ReplaceSchema
final DBDef currentDBDef = ResourceContext.currentDBDef();
TnValueTypes.registerBasicValueType(currentDBDef, java.util.Date.class, TnValueTypes.UTILDATE_AS_TIMESTAMP);
}
}
use of org.dbflute.dbway.DBDef in project dbflute-core by dbflute.
the class DfOutsideSqlTestTask method getSqlFileRunner.
protected DfSqlFileRunnerExecute getSqlFileRunner(final DfRunnerInformation runInfo) {
final String nonTargetMark = "df:x";
final DBDef currentDBDef = getDatabaseTypeFacadeProp().getCurrentDBDef();
return new DfSqlFileRunnerExecute(runInfo, getDataSource()) {
protected DfOutsideSqlChecker _outsideSqlChecker;
@Override
protected String filterSql(String sql) {
// /- - - - - - - - - - - - - - - - - - - - - - - - - -
// check parameter comments in the SQL before filtering
// - - - - - - - - - -/
checkParameterComment(_sqlFile, sql);
// filter comments if it needs.
if (!currentDBDef.dbway().isBlockCommentSupported()) {
sql = removeBlockComment(sql);
}
if (!currentDBDef.dbway().isLineCommentSupported()) {
sql = removeLineComment(sql);
}
return super.filterSql(sql);
}
protected String removeBlockComment(final String sql) {
return Srl.removeBlockComment(sql);
}
protected String removeLineComment(final String sql) {
return Srl.removeLineComment(sql);
}
@Override
protected boolean isTargetSql(String sql) {
final String entityName = getEntityName(sql);
if (entityName != null && nonTargetMark.equalsIgnoreCase(entityName)) {
// non-target SQL
_nonTargetSqlFileSet.add(_sqlFile);
_log.info("...Skipping the SQL by non-target mark '" + nonTargetMark + "'");
return false;
}
return super.isTargetSql(sql);
}
@Override
protected void traceSql(String sql) {
_log.info("SQL:" + ln() + sql);
}
@Override
protected void traceResult(int goodSqlCount, int totalSqlCount) {
_log.info(" -> success=" + goodSqlCount + " failure=" + (totalSqlCount - goodSqlCount) + ln());
}
protected String getEntityName(final String sql) {
return getTargetString(sql, "#");
}
protected String getTargetString(final String sql, final String mark) {
final List<String> targetList = getTargetList(sql, mark);
return !targetList.isEmpty() ? targetList.get(0) : null;
}
protected List<String> getTargetList(final String sql, final String mark) {
if (sql == null || sql.trim().length() == 0) {
String msg = "The sql is invalid: " + sql;
throw new IllegalArgumentException(msg);
}
final List<String> betweenBeginEndMarkList = getListBetweenBeginEndMark(sql, "--" + mark, mark);
if (!betweenBeginEndMarkList.isEmpty()) {
return betweenBeginEndMarkList;
} else {
// basically for MySQL
return getListBetweenBeginEndMark(sql, "-- " + mark, mark);
}
}
protected List<String> getListBetweenBeginEndMark(String targetStr, String beginMark, String endMark) {
final List<ScopeInfo> scopeList = Srl.extractScopeList(targetStr, beginMark, endMark);
final List<String> resultList = DfCollectionUtil.newArrayList();
for (ScopeInfo scope : scopeList) {
resultList.add(scope.getContent());
}
return resultList;
}
protected void checkParameterComment(File sqlFile, String sql) {
final DfOutsideSqlProperties outsideSqlProp = getOutsideSqlProperties();
if (outsideSqlProp.isSuppressParameterCommentCheck()) {
return;
}
if (_outsideSqlChecker == null) {
_outsideSqlChecker = createOutsideSqlChecker(outsideSqlProp);
}
_outsideSqlChecker.check(sqlFile.getName(), sql);
}
};
}
Aggregations