use of com.robotoworks.mechanoid.db.sqliteModel.TableDefinition in project mechanoid by robotoworks.
the class SqliteModelProposalProvider method getDisplayString.
@Override
protected String getDisplayString(EObject element, String qualifiedNameAsString, String shortName) {
if (element instanceof ColumnDef) {
ColumnDef def = (ColumnDef) element;
EObject container = def.eContainer();
if (container instanceof TableDefinition) {
return def.getName() + ":" + def.getType().getName() + " - " + ((TableDefinition) def.eContainer()).getName();
} else if (container instanceof AlterTableAddColumnStatement) {
return def.getName() + ":" + def.getType().getName() + " - " + ((AlterTableAddColumnStatement) def.eContainer()).getTable().getName();
} else {
return def.getName() + ":" + def.getType().getName();
}
} else if (element instanceof SingleSourceTable) {
SingleSourceTable t = (SingleSourceTable) element;
return (t.getName() == null ? t.getTableReference().getName() : t.getName() + " - " + t.getTableReference().getName());
} else if (element instanceof CreateTableStatement) {
CreateTableStatement t = (CreateTableStatement) element;
return t.getName();
} else if (element instanceof ResultColumn) {
ResultColumn r = (ResultColumn) element;
if (r.getName() != null) {
return r.getName() + ":" + ModelUtil.getInferredColumnType(r).getName();
}
}
return super.getDisplayString(element, qualifiedNameAsString, shortName);
}
use of com.robotoworks.mechanoid.db.sqliteModel.TableDefinition in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scopeForViewDefinitionsBeforeStatement.
public IScope scopeForViewDefinitionsBeforeStatement(final DDLStatement stmt, final boolean inclusive) {
ArrayList<CreateViewStatement> refs = ModelUtil.<CreateViewStatement>findPreviousStatementsOfType(stmt, CreateViewStatement.class, inclusive);
final HashMap<String, EObject> map = new HashMap<String, EObject>();
List<CreateViewStatement> _reverse = ListExtensions.<CreateViewStatement>reverse(refs);
for (final CreateViewStatement ref : _reverse) {
{
String _name = ref.getName();
boolean _equals = Objects.equal(_name, null);
if (_equals) {
return IScope.NULLSCOPE;
}
String _name_1 = ref.getName();
boolean _containsKey = map.containsKey(_name_1);
boolean _not = (!_containsKey);
if (_not) {
String _name_2 = ref.getName();
map.put(_name_2, ref);
}
}
}
Collection<EObject> _values = map.values();
final Function<EObject, QualifiedName> _function = new Function<EObject, QualifiedName>() {
public QualifiedName apply(final EObject it) {
return NameHelper.getName(((TableDefinition) it));
}
};
return Scopes.<EObject>scopeFor(_values, _function, IScope.NULLSCOPE);
}
use of com.robotoworks.mechanoid.db.sqliteModel.TableDefinition in project mechanoid by robotoworks.
the class ModelUtil method findColumnDefs.
/**
* Find column definitions from caller going back to the definition
*/
public static ArrayList<EObject> findColumnDefs(final DDLStatement caller, final TableDefinition definition) {
final ArrayList<EObject> columns = new ArrayList<EObject>();
LinkedList<TableDefinition> tableHistory = ModelUtil.getHistory(definition);
TableDefinition last = tableHistory.peekLast();
if ((last instanceof CreateViewStatement)) {
CreateViewStatement view = ((CreateViewStatement) last);
ArrayList<ColumnSource> _viewResultColumns = ModelUtil.getViewResultColumns(view);
columns.addAll(_viewResultColumns);
return columns;
}
EList<ColumnSource> _columnDefs = ((CreateTableStatement) last).getColumnDefs();
columns.addAll(_columnDefs);
while ((!tableHistory.isEmpty())) {
{
final TableDefinition stmt = tableHistory.removeLast();
ArrayList<AlterTableAddColumnStatement> _findStatementsOfTypeBetween = ModelUtil.<AlterTableAddColumnStatement>findStatementsOfTypeBetween(AlterTableAddColumnStatement.class, stmt, caller);
final Function1<AlterTableAddColumnStatement, Boolean> _function = new Function1<AlterTableAddColumnStatement, Boolean>() {
public Boolean apply(final AlterTableAddColumnStatement it) {
TableDefinition _table = it.getTable();
return Boolean.valueOf(Objects.equal(_table, stmt));
}
};
Iterable<AlterTableAddColumnStatement> _filter = IterableExtensions.<AlterTableAddColumnStatement>filter(_findStatementsOfTypeBetween, _function);
final Consumer<AlterTableAddColumnStatement> _function_1 = new Consumer<AlterTableAddColumnStatement>() {
public void accept(final AlterTableAddColumnStatement it) {
ColumnSource _columnDef = it.getColumnDef();
columns.add(_columnDef);
}
};
_filter.forEach(_function_1);
}
}
return columns;
}
use of com.robotoworks.mechanoid.db.sqliteModel.TableDefinition in project mechanoid by robotoworks.
the class StatementSequenceValidator method _sequence.
protected void _sequence(final DropTableStatement stmt) {
TableDefinition _table = stmt.getTable();
String _name = _table.getName();
this.tables.remove(_name);
}
use of com.robotoworks.mechanoid.db.sqliteModel.TableDefinition in project mechanoid by robotoworks.
the class StatementSequenceValidator method validateTablesInExpression.
public void validateTablesInExpression(final StatementSequenceValidatorResult result, final SelectCoreExpression expr) {
ArrayList<EObject> sources = ModelUtil.getAllReferenceableSingleSources(expr);
for (final EObject source : sources) {
if ((source instanceof SingleSourceTable)) {
SingleSourceTable table = ((SingleSourceTable) source);
TableDefinition _tableReference = table.getTableReference();
String _name = _tableReference.getName();
boolean _sourceExists = this.sourceExists(_name);
boolean _not = (!_sourceExists);
if (_not) {
result.source = table;
result.valid = false;
result.message = "No such reference";
result.feature = SqliteModelPackage.Literals.SINGLE_SOURCE_TABLE__TABLE_REFERENCE;
return;
}
}
}
}
Aggregations