use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause in project dbflute-core by dbflute.
the class DfSPolicyColumnStatementChecker method evaluateColumnThenClause.
// -----------------------------------------------------
// Then Clause
// -----------
protected void evaluateColumnThenClause(DfSPolicyStatement statement, DfSPolicyResult result, Column column) {
final String policy = toPolicy(statement);
final DfSPolicyThenClause thenClause = statement.getThenClause();
final String thenTheme = thenClause.getThenTheme();
if (thenTheme != null) {
final boolean notThenClause = thenClause.isNotThenTheme();
final String notOr = notThenClause ? "not " : "";
if (thenTheme.equalsIgnoreCase("bad") == !notThenClause) {
result.violate(policy, "The column is no good: " + toColumnDisp(column));
} else if (thenTheme.equalsIgnoreCase("notNull")) {
if (!column.isNotNull() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be not-null: " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("identity")) {
if (!column.isAutoIncrement() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be identity (auto increment): " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("pk")) {
if (!column.isPrimaryKey() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be primary key: " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("fk")) {
if (!column.isForeignKey() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be foreign key: " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("unique")) {
if (!column.isUnique() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be unique: " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("index")) {
if (!column.hasIndex() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "have index: " + toColumnDisp(column));
}
} else if (thenTheme.equalsIgnoreCase("classification")) {
if (!column.hasClassification() == !notThenClause) {
result.violate(policy, "The column should " + notOr + "be classification: " + toColumnDisp(column));
}
} else {
throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown then-clause: " + thenClause);
}
} else {
evaluateColumnThenItemValue(statement, result, column);
}
}
use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause in project dbflute-core by dbflute.
the class DfSPolicyLogicalSecretaryTest method createMockStatement.
protected DfSPolicyStatement createMockStatement() {
List<DfSPolicyIfPart> ifPartList = newArrayList(new DfSPolicyIfPart("columnName", "$$ALL$$", false));
DfSPolicyIfClause ifClause = new DfSPolicyIfClause(ifPartList, false);
DfSPolicyThenClause thenClause = new DfSPolicyThenClause("bad", false, DfCollectionUtil.emptyList(), false, null);
return new DfSPolicyStatement("if columnName is $$ALL$$ then bad", ifClause, thenClause);
}
use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause 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);
}
use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause in project dbflute-core by dbflute.
the class DfSPolicyTableStatementChecker method evaluateTableThenTheme.
// -----------------------------------------------------
// Then Theme
// ----------
protected void evaluateTableThenTheme(DfSPolicyStatement statement, DfSPolicyResult result, Table table) {
final String policy = toPolicy(statement);
final DfSPolicyThenClause thenClause = statement.getThenClause();
// already not null here
final String thenTheme = thenClause.getThenTheme();
final boolean notThenClause = thenClause.isNotThenTheme();
final String notOr = notThenClause ? "not " : "";
if (thenTheme.equalsIgnoreCase("bad")) {
if (notThenClause) {
throwSchemaPolicyCheckIllegalThenNotThemeException(statement, "bad");
} else {
result.violate(policy, "The table is no good: " + toTableDisp(table));
}
} else if (thenTheme.contains("hasPK")) {
if (!table.hasPrimaryKey() == !notThenClause) {
result.violate(policy, "The table should " + notOr + "have primary key: " + toTableDisp(table));
}
} else if (thenTheme.contains("upperCaseBasis")) {
if (Srl.isLowerCaseAny(toComparingTableName(table)) == !notThenClause) {
result.violate(policy, "The table name should " + notOr + "be on upper case basis: " + toTableDisp(table));
}
} else if (thenTheme.contains("lowerCaseBasis")) {
if (Srl.isUpperCaseAny(toComparingTableName(table)) == !notThenClause) {
result.violate(policy, "The table name should " + notOr + "be on lower case basis: " + toTableDisp(table));
}
} else if (thenTheme.contains("identityIfPureIDPK")) {
if (_logicalSecretary.isNotIdentityIfPureIDPK(table) == !notThenClause) {
result.violate(policy, "The primary key should " + notOr + "be identity: " + toTableDisp(table));
}
} else if (thenTheme.contains("sequenceIfPureIDPK")) {
if (_logicalSecretary.isNotSequenceIfPureIDPK(table) == !notThenClause) {
result.violate(policy, "The primary key should " + notOr + "be sequence: " + toTableDisp(table));
}
} else if (thenTheme.contains("hasCommonColumn")) {
if (!table.hasAllCommonColumn() == !notThenClause) {
result.violate(policy, "The table should " + notOr + "have common columns: " + toTableDisp(table));
}
} else if (thenTheme.contains("hasAlias")) {
if (!table.hasAlias() == !notThenClause) {
result.violate(policy, "The table should " + notOr + "have table alias: " + toTableDisp(table));
}
} else if (thenTheme.contains("hasComment")) {
if (!table.hasComment() == !notThenClause) {
result.violate(policy, "The table should " + notOr + "have table comment: " + toTableDisp(table));
}
} else {
throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown then-clause: " + thenClause);
}
}
use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause in project dbflute-core by dbflute.
the class DfSPolicyTableStatementChecker method evaluateTableThenClause.
// -----------------------------------------------------
// Then Clause
// -----------
protected void evaluateTableThenClause(DfSPolicyStatement statement, DfSPolicyResult result, Table table) {
final String policy = toPolicy(statement);
final DfSPolicyThenClause thenClause = statement.getThenClause();
final String thenTheme = thenClause.getThenTheme();
if (thenTheme != null) {
final boolean notThenClause = thenClause.isNotThenTheme();
final String notOr = notThenClause ? "not " : "";
if (thenTheme.equalsIgnoreCase("bad") == !notThenClause) {
result.violate(policy, "The table is no good: " + toTableDisp(table));
} else if (thenTheme.contains("hasCommonColumn")) {
if (!table.hasAllCommonColumn() == !notThenClause) {
result.violate(policy, "The table should " + notOr + "have common columns: " + toTableDisp(table));
}
} else {
throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown then-clause: " + thenClause);
}
} else {
evaluateColumnThenItemValue(statement, result, table);
}
}
Aggregations