use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfPmbPropertyOptionReference method getPmbMetaDataPropertyOptionReferenceColumn.
// ===================================================================================
// Reference Column
// ================
public Column getPmbMetaDataPropertyOptionReferenceColumn(AppData appData) {
if (appData == null) {
return null;
}
final Database database = appData.getDatabase();
if (database == null) {
return null;
}
final String refPrefix = OPTION_PREFIX;
final String refSuffix = OPTION_SUFFIX;
final String option;
{
final String optionExp = getPmbMetaDataPropertyOption();
if (optionExp == null) {
return null;
}
final List<String> splitOption = splitOption(optionExp);
String firstOption = null;
for (String element : splitOption) {
if (element.startsWith(refPrefix) && element.endsWith(refSuffix)) {
firstOption = element;
break;
}
}
if (firstOption == null) {
return null;
}
option = firstOption;
}
final ScopeInfo scope = Srl.extractScopeFirst(option, refPrefix, refSuffix);
final String content = scope.getContent().trim();
final String delimiter = ".";
final String tableName;
final String columnName;
if (content.contains(".")) {
tableName = Srl.substringFirstFront(content, delimiter);
columnName = Srl.substringFirstRear(content, delimiter);
} else {
tableName = content;
columnName = null;
}
final Table table = database.getTable(tableName);
if (table == null) {
throwParameterBeanReferenceTableNotFoundException(option, tableName);
}
final String columnKeyName;
if (columnName != null) {
columnKeyName = columnName;
} else {
if (_pmbMetaData.isPropertyTypeList(_propertyName) && Srl.endsWith(_propertyName, "List")) {
// e.g. statusList to status
columnKeyName = Srl.substringLastFront(_propertyName, "List");
} else {
columnKeyName = _propertyName;
}
}
final Column column = table.getColumn(columnKeyName);
if (column == null) {
throwParameterBeanReferenceColumnNotFoundException(option, tableName, columnName);
}
return column;
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfIncludeQueryProperties method extractColumnDrivenTranslatedMap.
protected Map<String, Map<String, Map<String, List<String>>>> extractColumnDrivenTranslatedMap(Map<String, Object> plainMap) {
final Map<String, Map<String, List<String>>> interfaceMap = extractColumnDrivenInterfaceMap(plainMap);
final Map<String, Map<String, Map<String, List<String>>>> translatedMap = newLinkedHashMap();
for (Entry<String, Map<String, List<String>>> tableEntry : interfaceMap.entrySet()) {
final String tableName = tableEntry.getKey();
final Map<String, List<String>> columnTypeCKeyMap = tableEntry.getValue();
for (Entry<String, List<String>> columnTypeCKeyEntry : columnTypeCKeyMap.entrySet()) {
final String columnExp = columnTypeCKeyEntry.getKey();
final String columnName = Srl.substringFirstFront(columnExp, "(").trim();
final ScopeInfo scopeFirst = Srl.extractScopeFirst(columnExp, "(", ")");
if (scopeFirst == null) {
String msg = "The column expression should be e.g. Member(Date) but: " + columnExp;
throw new DfIllegalPropertySettingException(msg);
}
// e.g. String, OrderBy
final String propType = scopeFirst.getContent().trim();
final List<String> ckeyList = columnTypeCKeyEntry.getValue();
Map<String, Map<String, List<String>>> ckeyColumnMap = translatedMap.get(propType);
if (ckeyColumnMap == null) {
ckeyColumnMap = newLinkedHashMap();
translatedMap.put(propType, ckeyColumnMap);
}
for (String ckey : ckeyList) {
Map<String, List<String>> tableColumnMap = ckeyColumnMap.get(ckey);
if (tableColumnMap == null) {
tableColumnMap = newLinkedHashMap();
ckeyColumnMap.put(ckey, tableColumnMap);
}
List<String> columnList = tableColumnMap.get(tableName);
if (columnList == null) {
columnList = new ArrayList<String>();
tableColumnMap.put(tableName, columnList);
}
columnList.add(columnName);
}
}
}
return translatedMap;
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfStringUtilTest method test_extractScopeList_replaceContentOnBaseString.
public void test_extractScopeList_replaceContentOnBaseString() {
// ## Arrange ##
String str = "/*foo*/foo/*bar*/bar/*foobarbaz*/";
// ## Act ##
List<ScopeInfo> list = extractScopeList(str, "/*", "*/");
// ## Assert ##
ScopeInfo scope = list.get(1);
String baseString1 = scope.replaceContentOnBaseString("foo", "jflute");
assertEquals("/*jflute*/foo/*bar*/bar/*jflutebarbaz*/", baseString1);
String baseString2 = scope.replaceContentOnBaseString("*", "jflute");
// marks no change
assertEquals(str, baseString2);
// no change
assertEquals(str, scope.getBaseString());
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfStringUtilTest method test_extractScopeFirst_various.
public void test_extractScopeFirst_various() {
ScopeInfo scope = extractScopeFirst("FOObeginBARendDODO", "begin", "end");
log("baseString: " + scope.getBaseString());
log("beginIndex: " + scope.getBeginIndex());
log("endIndex: " + scope.getEndIndex());
log("beginMark: " + scope.getBeginMark());
log("endMark: " + scope.getEndMark());
log("scope: " + scope.getScope());
log("content: " + scope.getContent());
log("previous: " + scope.getPrevious());
log("next: " + scope.getNext());
log("substringInterspaceToPrevious(): " + scope.substringInterspaceToPrevious());
log("substringInterspaceToNext(): " + scope.substringInterspaceToNext());
log("substringScopeToPrevious(): " + scope.substringScopeToPrevious());
log("substringScopeToNext(): " + scope.substringScopeToNext());
log("replaceContentOnBaseString(): " + scope.replaceContentOnBaseString("SEA"));
log("replaceContentOnBaseString(): " + scope.replaceContentOnBaseString("A", "B"));
log("replaceInterspaceOnBaseString(): " + scope.replaceInterspaceOnBaseString("O", "R"));
assertEquals("FOObeginBARendDODO", scope.getBaseString());
assertEquals("beginBARend", scope.getScope());
assertEquals("BAR", scope.getContent());
assertNull(scope.getPrevious());
assertNull(scope.getNext());
assertEquals("FOO", scope.substringInterspaceToPrevious());
assertEquals("DODO", scope.substringInterspaceToNext());
assertEquals("FOObeginBARend", scope.substringScopeToPrevious());
assertEquals("beginBARendDODO", scope.substringScopeToNext());
assertEquals("FOObeginSEAendDODO", scope.replaceContentOnBaseString("SEA"));
assertEquals("FOObeginBBRendDODO", scope.replaceContentOnBaseString("A", "B"));
assertEquals("FRRbeginBARendDRDR", scope.replaceInterspaceOnBaseString("O", "R"));
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfSPolicyLogicalSecretary method parseStatement.
// ===================================================================================
// Statement
// =========
public DfSPolicyStatement parseStatement(String statement) {
if (!statement.startsWith("if ")) {
String msg = "The element of statementList should start with 'if' for SchemaPolicyCheck: " + statement;
throw new IllegalStateException(msg);
}
final ScopeInfo ifScope = Srl.extractScopeFirst(statement, "if ", " then ");
if (ifScope == null) {
final String additional = "The statement should start with 'if' and contain 'then'.";
throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
}
final DfSPolicyIfClause ifClause = analyzeIfClause(statement, ifScope);
final DfSPolicyThenClause thenClause = analyzeThenClause(statement, ifScope);
return new DfSPolicyStatement(statement, ifClause, thenClause);
}
Aggregations