Search in sources :

Example 1 with Table

use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.

the class DatabaseServices method allSelectableExternalTables.

/**
 * Retrieve all non referenced external tables excluding those already displayed on the diagram
 * @param context the Table Container
 * @param diagram DSemanticDiagram diagram used to check for already displayed tables
 * @return List of tables
 */
public List<Table> allSelectableExternalTables(TableContainer context, DSemanticDiagram diagram) {
    // Retrieve all non Referenced External Tables
    List<Table> allNonReferencedExternalTables = allNonReferencedExternalTables(context);
    List<Table> tablesInDiagram = new ArrayList<Table>();
    // Retrieve all AbstracteDNode contained in diagram.
    List<EObject> allDNodes = EcoreServices.eAllContents(diagram, AbstractDNode.class);
    for (EObject node : allDNodes) {
        // Retrieve all tables contained in AbstractDNode
        if (((AbstractDNode) node).getTarget() instanceof Table) {
            tablesInDiagram.add((Table) ((AbstractDNode) node).getTarget());
        }
    }
    // Remove all tables contained in AbstractDNode present in allNonReferencedExternalTables
    allNonReferencedExternalTables.removeAll(tablesInDiagram);
    return allNonReferencedExternalTables;
}
Also used : Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) EObject(org.eclipse.emf.ecore.EObject) AbstractDNode(org.eclipse.sirius.diagram.AbstractDNode) ArrayList(java.util.ArrayList)

Example 2 with Table

use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.

the class DatabaseServices method allReferencedTables.

/**
 * Retrieve all referenced Tables.
 * @param context the Table Container
 * @return list of Tables
 */
public List<Table> allReferencedTables(TableContainer context) {
    // Retrieve all tables
    List<AbstractTable> abstractTables = context.getTables();
    List<Table> tables = new ArrayList<Table>();
    List<Table> tablesFKtarget = new ArrayList<Table>();
    // Retrieve all tables instance of Table
    for (AbstractTable abstractTable : abstractTables) {
        if (abstractTable instanceof Table) {
            tables.add((Table) abstractTable);
        }
    }
    // Retrieve all foreigns keys for the tables
    for (Table table : tables) {
        for (ForeignKey fk : table.getForeignKeys()) {
            if (!tablesFKtarget.contains(fk.getTarget())) {
                // retrieve all table from target of foreigns keys
                tablesFKtarget.add(fk.getTarget());
            }
        }
    }
    Set<Table> allReferencedTables = new HashSet<Table>();
    // Remove duplicates
    allReferencedTables.addAll(tablesFKtarget);
    return new ArrayList<Table>(allReferencedTables);
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) ArrayList(java.util.ArrayList) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) HashSet(java.util.HashSet)

Example 3 with Table

use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.

the class DatabaseServices method getForeignKeys.

/**
 * Return ForeignKeys from tables.
 * @param tableContainer
 * @return foreignKeys
 */
public List<ForeignKey> getForeignKeys(TableContainer tableContainer, DSemanticDiagram diagram) {
    List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
    List<AbstractTable> tables = tableContainer.getTables();
    for (AbstractTable abstractTable : tables) {
        if (abstractTable instanceof Table) {
            foreignKeys.addAll(((Table) abstractTable).getForeignKeys());
        }
    }
    // Foreign keys from external tables on diagram
    for (DDiagramElement diagramElement : diagram.getDiagramElements()) {
        EObject semanticElt = diagramElement.getTarget();
        if (semanticElt instanceof Table) {
            foreignKeys.addAll(((Table) semanticElt).getForeignKeys());
        }
    }
    return foreignKeys;
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) DDiagramElement(org.eclipse.sirius.diagram.DDiagramElement)

Example 4 with Table

use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.

the class DatabaseServices method allTables.

/**
 * Retrieve all Tables.
 * @param context the Table Container
 * @return list of Tables
 */
public List<Table> allTables(TableContainer context) {
    EcoreServices ecoreServices = new EcoreServices();
    // Retrieve all roots from context
    Collection<EObject> allRoots = ecoreServices.allRoots(context);
    List<Table> tables = new ArrayList<Table>();
    // Retrieve all Tables contained in all roots
    for (EObject object : allRoots) {
        List<Table> allContainedTables = new ArrayList<Table>();
        for (EObject obj : EcoreServices.eAllContents(object, Table.class)) {
            allContainedTables.add((Table) obj);
        }
        tables.addAll(allContainedTables);
    }
    return tables;
}
Also used : Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList)

Example 5 with Table

use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.

the class TableConstraintsPropertiesEditionComponent method initPart.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
 *      org.eclipse.emf.ecore.resource.ResourceSet)
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        final Table table = (Table) elt;
        final ConstraintsPropertiesEditionPart constraintsPart = (ConstraintsPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Constraints.Properties.constraints_)) {
            constraintsSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getTable_Constraints());
            constraintsPart.initConstraints(constraintsSettings);
        }
        // init filters
        if (isAccessible(DatabaseViewsRepository.Constraints.Properties.constraints_)) {
            constraintsPart.addFilterToConstraints(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof Constraint);
                }
            });
        // Start of user code for additional businessfilters for constraints
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Table(org.obeonetwork.dsl.database.Table) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ConstraintsPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ConstraintsPropertiesEditionPart) Constraint(org.obeonetwork.dsl.database.Constraint) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Table (org.obeonetwork.dsl.database.Table)86 Column (org.obeonetwork.dsl.database.Column)41 Test (org.junit.Test)31 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)31 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)22 EObject (org.eclipse.emf.ecore.EObject)17 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)16 ArrayList (java.util.ArrayList)11 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)7 Index (org.obeonetwork.dsl.database.Index)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)6 Viewer (org.eclipse.jface.viewers.Viewer)6 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)6 Constraint (org.obeonetwork.dsl.database.Constraint)6 Sequence (org.obeonetwork.dsl.database.Sequence)6 BigInteger (java.math.BigInteger)5 PreparedStatement (java.sql.PreparedStatement)5 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)5