Search in sources :

Example 6 with DataBase

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

the class TestReverse method testSQLServer.

@Test
public void testSQLServer() {
    DataSource dataSource = new DataSource("Northwind", "dbo");
    dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=Northwind");
    dataSource.setJdbcUsername("testUser");
    dataSource.setJdbcPassword("test");
    dataSource.setVendor("SQLServer-2008");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/sqlserver/outputRef.database", "pathmap://NativeDBTypes/SQLServer-2008");
    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)

Example 7 with DataBase

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

the class TestReverse method loadModel.

private static DataBase loadModel(String databaseTestPluginRelativePath, String typesLibraryPathmapUri) {
    URI uri = URI.createFileURI(databaseTestPluginRelativePath);
    DatabaseResourceFactoryImpl databaseResourceFactory = new DatabaseResourceFactoryImpl();
    Resource resourceDatabase = databaseResourceFactory.createResource(uri);
    TypesLibraryResourceFactoryImpl typesLibraryresourceFactory = new TypesLibraryResourceFactoryImpl();
    Resource typeResource = typesLibraryresourceFactory.createResource(URI.createURI(typesLibraryPathmapUri));
    ResourceSet rs = new ResourceSetImpl();
    rs.getResources().add(resourceDatabase);
    rs.getResources().add(typeResource);
    try {
        Map options = rs.getLoadOptions();
        options.put(DatabasePackage.eINSTANCE.getNsURI(), DatabasePackage.eINSTANCE);
        options.put(TypesLibraryPackage.eINSTANCE.getNsURI(), TypesLibraryPackage.eINSTANCE);
        resourceDatabase.load(options);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return (DataBase) resourceDatabase.getContents().get(0);
}
Also used : DatabaseResourceFactoryImpl(org.obeonetwork.dsl.database.util.DatabaseResourceFactoryImpl) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) TypesLibraryResourceFactoryImpl(org.obeonetwork.dsl.typeslibrary.util.TypesLibraryResourceFactoryImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) Map(java.util.Map) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 8 with DataBase

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

the class TestReverse method testH2Embedded.

@Test
public void testH2Embedded() {
    String databaseLocation = getH2DatabaseLocation(this.getClass(), "input");
    DataSource dataSource = new DataSource("appli1", "PUBLIC");
    dataSource.setJdbcUrl("jdbc:h2:" + databaseLocation);
    dataSource.setJdbcUsername("sa");
    dataSource.setVendor("H2-1.3");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/h2/outputRef.database", "pathmap://NativeDBTypes/H2-1.3");
    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)

Example 9 with DataBase

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

the class AbstractDataBaseBuilder method initialize.

private void initialize(DataSource source, ProgressListener progressListener, Queries queries) throws SQLException {
    connection = null;
    try {
        connection = source.getConnection();
    } catch (DataSourceException e) {
        throw new SQLException("Unable to connect to database", e.getCause());
    }
    if (connection != null) {
        try {
            this.metaData = connection.getMetaData();
        } catch (SQLException e) {
            JdbcUtils.closeConnection(connection);
            throw e;
        }
    }
    this.progressListener = progressListener;
    if (this.progressListener == null) {
        this.progressListener = new ProgressListener() {

            @Override
            public void start(int numberOfSteps) {
            }

            @Override
            public void progressTo(int step, String message) {
            }

            @Override
            public void end(String message) {
            }
        };
    }
    this.queries = queries;
    dataBase = buildDataBase(source.getDatabaseName());
    queries.registerDatabase(dataBase);
    tableContainer = dataBase;
    if (isSet(source.getSchemaName())) {
        tableContainer = buildSchema(source.getSchemaName(), (DataBase) tableContainer);
    }
    setUsedLibraries();
}
Also used : DataSourceException(org.obeonetwork.dsl.database.reverse.source.DataSourceException) ProgressListener(org.obeonetwork.dsl.database.reverse.utils.ProgressListener) SQLException(java.sql.SQLException) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 10 with DataBase

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

the class AbstractTest method loadModel.

/**
 * Returns the DataBase in the specified resource's file name.
 *
 * @param fileName
 * @return
 */
public DataBase loadModel(String fileName) {
    Resource resource = resourceSet.getResource(URI.createURI(fileName), true);
    int i = 0;
    int s = resource.getContents().size();
    while (i < s && !(resource.getContents().get(i) instanceof DataBase)) {
        i++;
    }
    if (i < s) {
        return (DataBase) resource.getContents().get(i);
    } else {
        return null;
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) DataBase(org.obeonetwork.dsl.database.DataBase)

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