Search in sources :

Example 1 with Schema

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

the class SchemaPropertiesEditionComponent 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 Schema schema = (Schema) elt;
        final SchemaPropertiesEditionPart schemaPart = (SchemaPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Schema.Properties.name))
            schemaPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, schema.getName()));
        if (isAccessible(DatabaseViewsRepository.Schema.Properties.comments))
            schemaPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, schema.getComments()));
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Schema(org.obeonetwork.dsl.database.Schema) SchemaPropertiesEditionPart(org.obeonetwork.dsl.database.parts.SchemaPropertiesEditionPart)

Example 2 with Schema

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

the class GenerateSQLFromDatabaseHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    // We have to compute an emfdiff file from a comparison with an empty database
    // ---
    // First let's create an empty model containing only
    Resource resource = new DatabaseResourceImpl(URI.createURI("memory:/empty_database"));
    TableContainer rootContainer = getFirstTableContainer(selection);
    TableContainer newContainer = null;
    if (rootContainer instanceof DataBase) {
        newContainer = copyDatabase((DataBase) rootContainer);
        resource.getContents().add(newContainer);
    } else if (rootContainer instanceof Schema) {
        newContainer = copySchema((Schema) rootContainer);
        resource.getContents().add(newContainer);
    }
    // Then compare the two models
    Comparison comparison = null;
    try {
        comparison = DatabaseCompareService.compare(rootContainer, newContainer);
    } catch (Exception e) {
    }
    // The diff model can now be used to generate the SQL script
    if (comparison != null) {
        ExportAsSQLScriptsAction action = new ExportAsSQLScriptsAction();
        action.exportComparison(comparison);
    }
    return null;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) TableContainer(org.obeonetwork.dsl.database.TableContainer) DatabaseResourceImpl(org.obeonetwork.dsl.database.util.DatabaseResourceImpl) Schema(org.obeonetwork.dsl.database.Schema) ISelection(org.eclipse.jface.viewers.ISelection) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ExecutionException(org.eclipse.core.commands.ExecutionException) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 3 with Schema

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

the class GenerateSQLFromDatabaseHandler method copySchema.

private Schema copySchema(Schema schema) {
    Schema newSchema = DatabaseFactory.eINSTANCE.createSchema();
    newSchema.setName(schema.getName());
    return newSchema;
}
Also used : Schema(org.obeonetwork.dsl.database.Schema)

Example 4 with Schema

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

the class MpdToMldBidiRules method createSchema.

private void createSchema(Schema sourceSchema, DataBase targetDatabase) {
    Schema targetSchema = getFromInputTraceabilityMap(sourceSchema, DatabasePackage.Literals.SCHEMA);
    if (targetSchema != null) {
    // Reuse existing schema
    } else {
        // We have to create a new schema
        targetSchema = DatabaseFactory.eINSTANCE.createSchema();
        targetDatabase.getSchemas().add(targetSchema);
    }
    addToOutputTraceability(sourceSchema, targetSchema);
    targetSchema.setName(sourceSchema.getName());
    targetSchema.setComments(sourceSchema.getComments());
    createTables(sourceSchema, targetSchema);
    createViews(sourceSchema, targetSchema);
}
Also used : Schema(org.obeonetwork.dsl.database.Schema)

Example 5 with Schema

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

the class MpdToMldBidiRules method processTableContainer.

private void processTableContainer(TableContainer sourceTableContainer, TableContainer targetTableContainer) {
    createTables(sourceTableContainer, targetTableContainer);
    if (sourceTableContainer instanceof DataBase) {
        DataBase sourceDatabase = (DataBase) sourceTableContainer;
        for (Schema sourceSchema : sourceDatabase.getSchemas()) {
            if (targetTableContainer instanceof DataBase) {
                DataBase targetDatabase = (DataBase) targetTableContainer;
                createSchema(sourceSchema, targetDatabase);
            } else {
                createTables(sourceSchema, targetTableContainer);
            }
        }
    }
}
Also used : Schema(org.obeonetwork.dsl.database.Schema) DataBase(org.obeonetwork.dsl.database.DataBase)

Aggregations

Schema (org.obeonetwork.dsl.database.Schema)25 DataBase (org.obeonetwork.dsl.database.DataBase)8 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)3 AddSchema (org.obeonetwork.dsl.database.dbevolution.AddSchema)3 AlterSchema (org.obeonetwork.dsl.database.dbevolution.AlterSchema)3 RemoveSchema (org.obeonetwork.dsl.database.dbevolution.RemoveSchema)3 Table (org.obeonetwork.dsl.database.Table)2 TableContainer (org.obeonetwork.dsl.database.TableContainer)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IResource (org.eclipse.core.resources.IResource)1 Comparison (org.eclipse.emf.compare.Comparison)1