Search in sources :

Example 1 with DataBase

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

the class DataBasePropertiesEditionComponent 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 DataBase dataBase = (DataBase) elt;
        final DataBasePropertiesEditionPart dataBasePart = (DataBasePropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.DataBase_.Properties.name))
            dataBasePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, dataBase.getName()));
        if (isAccessible(DatabaseViewsRepository.DataBase_.Properties.url))
            dataBasePart.setUrl(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, dataBase.getUrl()));
        if (isAccessible(DatabaseViewsRepository.DataBase_.Properties.comments))
            dataBasePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, dataBase.getComments()));
        if (isAccessible(DatabaseViewsRepository.DataBase_.Properties.usedLibraries)) {
            usedLibrariesSettings = new ReferencesTableSettings(dataBase, TypesLibraryPackage.eINSTANCE.getTypesLibraryUser_UsedLibraries());
            dataBasePart.initUsedLibraries(usedLibrariesSettings);
        }
        if (isAccessible(DatabaseViewsRepository.DataBase_.Properties.usedLibraries)) {
            dataBasePart.addFilterToUsedLibraries(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) {
                    if (element instanceof EObject)
                        return (!dataBasePart.isContainedInUsedLibrariesTable((EObject) element));
                    return element instanceof String && element.equals("");
                }
            });
            dataBasePart.addFilterToUsedLibraries(new EObjectStrictFilter(TypesLibraryPackage.Literals.TYPES_LIBRARY));
        // Start of user code for additional businessfilters for usedLibraries
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : EObjectStrictFilter(org.eclipse.emf.eef.runtime.impl.filters.EObjectStrictFilter) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) EObject(org.eclipse.emf.ecore.EObject) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) DataBasePropertiesEditionPart(org.obeonetwork.dsl.database.parts.DataBasePropertiesEditionPart) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 2 with DataBase

use of org.obeonetwork.dsl.database.DataBase 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 DataBase

use of org.obeonetwork.dsl.database.DataBase 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)

Example 4 with DataBase

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

the class DatabaseGen method computeTargetFolder.

private File computeTargetFolder(File folder, Comparison comparison) {
    String folderName = "";
    String dbtypeFolderName = "";
    if (comparison != null) {
        DataBase database = (DataBase) comparison.getMatches().get(0).getLeft();
        TypesLibrary physicalTypesLibrary = new TypesServices().getPhysicalTypesLibrary(database);
        if (physicalTypesLibrary instanceof NativeTypesLibrary) {
            dbtypeFolderName += ((NativeTypesLibrary) physicalTypesLibrary).getName() + "/";
        } else if (physicalTypesLibrary instanceof UserDefinedTypesLibrary) {
            dbtypeFolderName += ((UserDefinedTypesLibrary) physicalTypesLibrary).getName() + "/";
        }
        folderName = database.getName();
        if (database.getSchemas().size() > 0) {
            Schema schema = database.getSchemas().get(0);
            folderName = schema.getName();
        }
        folderName += "-";
    }
    java.sql.Timestamp timeStampDate = new Timestamp(System.currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd/HH-mm-ss");
    String timestamp = formatter.format(timeStampDate);
    folderName += timestamp;
    File targetFolder = new File(folder.getAbsolutePath() + "/" + dbtypeFolderName + folderName);
    return targetFolder;
}
Also used : NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) Schema(org.obeonetwork.dsl.database.Schema) Timestamp(java.sql.Timestamp) NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) TypesLibrary(org.obeonetwork.dsl.typeslibrary.TypesLibrary) UserDefinedTypesLibrary(org.obeonetwork.dsl.typeslibrary.UserDefinedTypesLibrary) UserDefinedTypesLibrary(org.obeonetwork.dsl.typeslibrary.UserDefinedTypesLibrary) TypesServices(org.obeonetwork.dsl.database.sqlgen.services.TypesServices) Timestamp(java.sql.Timestamp) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 5 with DataBase

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

the class TestReverse method testMySQL.

@Test
public void testMySQL() {
    DataSource dataSource = new DataSource("northwind", null);
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/northwind");
    dataSource.setJdbcUsername("root");
    dataSource.setJdbcPassword(null);
    dataSource.setVendor("MySQL-5");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/mysql/outputRef.database", "pathmap://NativeDBTypes/MySQL-5");
    checkEquality(database, databaseRef);
}
Also used : MultiDataBaseQueries(org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource) DataBase(org.obeonetwork.dsl.database.DataBase) Test(org.junit.Test)

Aggregations

DataBase (org.obeonetwork.dsl.database.DataBase)26 Schema (org.obeonetwork.dsl.database.Schema)8 Resource (org.eclipse.emf.ecore.resource.Resource)6 Test (org.junit.Test)6 DataSource (org.obeonetwork.dsl.database.reverse.source.DataSource)6 MultiDataBaseQueries (org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries)6 EObject (org.eclipse.emf.ecore.EObject)5 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 TypesLibrary (org.obeonetwork.dsl.typeslibrary.TypesLibrary)3 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 Comparison (org.eclipse.emf.compare.Comparison)2 ISelection (org.eclipse.jface.viewers.ISelection)2 DAnalysisSessionEObject (org.eclipse.sirius.viewpoint.DAnalysisSessionEObject)2 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)2 Table (org.obeonetwork.dsl.database.Table)2 File (java.io.File)1 IOException (java.io.IOException)1