Search in sources :

Example 6 with TableContainer

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

the class AbtractTest method diff.

protected Comparison diff(String left, String right) throws Exception {
    ResourceSet rs = new ResourceSetImpl();
    standaloneBootStrap(rs);
    InputStream leftStream = getClass().getClassLoader().getResourceAsStream(left);
    assertNotNull(leftStream);
    InputStream rightStream = getClass().getClassLoader().getResourceAsStream(right);
    assertNotNull(rightStream);
    EObject rootSource = ModelUtils.load(leftStream, "left.database", rs);
    assertNotNull(rootSource);
    EObject rootTarget = ModelUtils.load(rightStream, "right.database", rs);
    assertNotNull(rootTarget);
    assertTrue(rootSource instanceof TableContainer);
    assertTrue(rootTarget instanceof TableContainer);
    return diff((TableContainer) rootSource, (TableContainer) rootTarget);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) InputStream(java.io.InputStream) TableContainer(org.obeonetwork.dsl.database.TableContainer) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 7 with TableContainer

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

the class AbstractSQLGenerationTest method loadTableContainerFromFile.

private TableContainer loadTableContainerFromFile(String folderName, String filename) {
    URI uri = URI.createPlatformPluginURI(INPUT_FOLDER + folderName + "/" + filename, true);
    ResourceSet set = new ResourceSetImpl();
    Resource resource = set.getResource(uri, true);
    for (EObject eObject : resource.getContents()) {
        if (eObject instanceof TableContainer) {
            return (TableContainer) eObject;
        }
    }
    return null;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) TableContainer(org.obeonetwork.dsl.database.TableContainer) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 8 with TableContainer

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

the class EntityToMLD method getTargetTableContainer.

protected TableContainer getTargetTableContainer(Namespace namespace) {
    if (!cacheNamespaceToTableContainer.containsKey(namespace)) {
        TableContainer target = null;
        // First we look for a schema with the right name
        String schemaName = getSchemaNameFromNamespace(namespace);
        // Look for a schema with the right name
        target = getSchemaByName(schemaName);
        if (target == null) {
            if (defaultTarget instanceof Schema) {
                if (((Schema) defaultTarget).getTables().isEmpty()) {
                    // We consider the schema is contained is a newly created model
                    // we can change its name
                    target = (Schema) defaultTarget;
                    target.setName(schemaName);
                }
            } else if (defaultTarget instanceof DataBase) {
                DataBase database = (DataBase) defaultTarget;
                if (database.getSchemas().size() == 1 && database.getSchemas().get(0).getTables().isEmpty()) {
                    target = database.getSchemas().get(0);
                    target.setName(schemaName);
                }
            }
            // We create a schema if the target object is a database
            if (target == null) {
                target = createSchema(schemaName);
            }
            // Last solution
            if (target == null && defaultTarget instanceof TableContainer) {
                target = (TableContainer) defaultTarget;
            }
        }
        cacheNamespaceToTableContainer.put(namespace, target);
    }
    // Ensure schema comments are retrieved from namespace
    TableContainer tableContainer = cacheNamespaceToTableContainer.get(namespace);
    tableContainer.setComments(namespace.getDescription());
    return tableContainer;
}
Also used : TableContainer(org.obeonetwork.dsl.database.TableContainer) Schema(org.obeonetwork.dsl.database.Schema) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 9 with TableContainer

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

the class AbstractTransformationTest method getRootObject.

private EObject getRootObject(URI modelURI) {
    ResourceSet set = getResourceSet();
    Resource resource = set.getResource(modelURI, true);
    for (Iterator<EObject> it = resource.getAllContents(); it.hasNext(); ) {
        EObject object = it.next();
        if (object instanceof TableContainer || object instanceof Root || object instanceof Namespace || object instanceof ScaffoldInfo) {
            return object;
        }
    }
    return null;
}
Also used : Root(org.obeonetwork.dsl.entity.Root) TableContainer(org.obeonetwork.dsl.database.TableContainer) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ScaffoldInfo(fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Namespace(org.obeonetwork.dsl.environment.Namespace)

Example 10 with TableContainer

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

the class ViewChangeBuilder method handleAddChange.

@Override
protected Diff handleAddChange(ReferenceChange change) {
    Comparison comparison = change.getMatch().getComparison();
    TableContainer tableContainer = (TableContainer) change.getMatch().getRight();
    View view = (View) change.getValue();
    return createAddView(comparison, tableContainer, view, change);
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) TableContainer(org.obeonetwork.dsl.database.TableContainer) View(org.obeonetwork.dsl.database.View) AlterView(org.obeonetwork.dsl.database.dbevolution.AlterView) RemoveView(org.obeonetwork.dsl.database.dbevolution.RemoveView) AddView(org.obeonetwork.dsl.database.dbevolution.AddView)

Aggregations

TableContainer (org.obeonetwork.dsl.database.TableContainer)12 Comparison (org.eclipse.emf.compare.Comparison)4 EObject (org.eclipse.emf.ecore.EObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 Table (org.obeonetwork.dsl.database.Table)3 Namespace (org.obeonetwork.dsl.environment.Namespace)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 DataBase (org.obeonetwork.dsl.database.DataBase)2 Schema (org.obeonetwork.dsl.database.Schema)2 Root (org.obeonetwork.dsl.entity.Root)2 ScaffoldInfo (fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IResource (org.eclipse.core.resources.IResource)1 BasicMonitor (org.eclipse.emf.common.util.BasicMonitor)1