use of org.obeonetwork.dsl.database.view.parser.ColObject in project InformationSystem by ObeoNetwork.
the class DatabaseServices method initializeViewContent.
/**
* Initialize the content of a view.
*
* Tables and Columns are transient and not saved.
* They need to be be computed at the opening of the diagram.
* @param view to initialize.
*/
private void initializeViewContent(View view) {
/* The tables and the columns references are transient.
* Initializing the transient reference is a workaround
* to avoid some diagram refresh problems.
* The initializing need to be done only one time.
*/
ViewSpec viewSpec = (ViewSpec) view;
if (viewSpec.initialized == false) {
// Clear view content
if (viewSpec.getColumns() != null) {
viewSpec.getColumns().clear();
}
if (viewSpec.getTables() != null) {
viewSpec.getTables().clear();
}
// Parse new query and update view content
String query = viewSpec.getQuery();
if (!Strings.isNullOrEmpty(query)) {
ViewContentProvider viewContentProvider = new ViewContentProvider();
viewContentProvider.parseViewQuery(viewSpec.getQuery());
List<ColObject> listOfColumns = viewContentProvider.getColumns();
if (listOfColumns != null) {
for (ColObject column : listOfColumns) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(column.getName());
elem.setAlias(column.getAlias());
viewSpec.getColumns().add(elem);
}
}
List<String> listOfTables = viewContentProvider.getTables();
if (listOfTables != null) {
for (String table : listOfTables) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(table);
viewSpec.getTables().add(elem);
}
}
}
// The initialization was done update boolean.
viewSpec.initialized = true;
}
}
use of org.obeonetwork.dsl.database.view.parser.ColObject in project InformationSystem by ObeoNetwork.
the class ViewQueryChangeTrigger method localChangesAboutToCommit.
@Override
public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
Iterable<Notification> querySetNotification = Iterables.filter(notifications, IS_QUERY_SET);
for (Notification notification : querySetNotification) {
view = (View) notification.getNotifier();
query = view.getQuery();
final Session session = SessionManager.INSTANCE.getSession(view);
final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
if (!Strings.isNullOrEmpty(query)) {
final Command result = new RecordingCommand(domain) {
@Override
protected void doExecute() {
if (view.getColumns() != null) {
view.getColumns().clear();
}
if (view.getTables() != null) {
view.getTables().clear();
}
// Parse new query
ViewContentProvider viewContentProvider = new ViewContentProvider();
viewContentProvider.parseViewQuery(query);
List<ColObject> listOfColumns = viewContentProvider.getColumns();
if (listOfColumns != null) {
for (ColObject column : listOfColumns) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(column.getName());
elem.setAlias(column.getAlias());
view.getColumns().add(elem);
}
}
List<String> listOfTables = viewContentProvider.getTables();
if (listOfTables != null) {
for (String table : listOfTables) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(table);
view.getTables().add(elem);
}
}
}
};
return Options.newSome(result);
} else if (Strings.isNullOrEmpty(query)) {
final Command result = new RecordingCommand(domain) {
@Override
protected void doExecute() {
if (view.getColumns() != null) {
view.getColumns().clear();
}
if (view.getTables() != null) {
view.getTables().clear();
}
}
};
return Options.newSome(result);
}
}
return Options.newNone();
}
Aggregations