Search in sources :

Example 1 with TypesLibrary

use of org.obeonetwork.dsl.typeslibrary.TypesLibrary 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 2 with TypesLibrary

use of org.obeonetwork.dsl.typeslibrary.TypesLibrary in project InformationSystem by ObeoNetwork.

the class TypesServices method getPhysicalTypesLibrary.

public TypesLibrary getPhysicalTypesLibrary(DatabaseElement element) {
    TypesLibraryUser tlu = getTypesLibraryUser(element);
    TypesLibrary physicalTypesLibrary = getTargetPhysicalTypesLibrary(tlu);
    return physicalTypesLibrary;
}
Also used : TypesLibraryUser(org.obeonetwork.dsl.typeslibrary.TypesLibraryUser) TypesLibrary(org.obeonetwork.dsl.typeslibrary.TypesLibrary)

Example 3 with TypesLibrary

use of org.obeonetwork.dsl.typeslibrary.TypesLibrary in project InformationSystem by ObeoNetwork.

the class EntityToMLD method loadTypesLibrary.

private Map<String, NativeType> loadTypesLibrary() {
    Map<String, NativeType> types = new HashMap<String, NativeType>();
    TypesLibrary typesLibrary = TypesLibraryUtil.getLogicalTypesLibrary(getResourceSet());
    for (Iterator<EObject> it = typesLibrary.eAllContents(); it.hasNext(); ) {
        EObject object = it.next();
        if (object instanceof NativeType) {
            NativeType type = (NativeType) object;
            types.put(type.getName(), type);
        }
    }
    return types;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EObject(org.eclipse.emf.ecore.EObject) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypesLibrary(org.obeonetwork.dsl.typeslibrary.TypesLibrary)

Example 4 with TypesLibrary

use of org.obeonetwork.dsl.typeslibrary.TypesLibrary in project InformationSystem by ObeoNetwork.

the class DatabaseModelWizard method performFinish.

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public boolean performFinish() {
    try {
        // Remember the file.
        // 
        final IFile modelFile = getModelFile();
        // Do the work within an operation.
        // 
        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor progressMonitor) {
                try {
                    // Create a resource set
                    // 
                    ResourceSet resourceSet = new ResourceSetImpl();
                    // Get the URI of the model file.
                    // 
                    URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
                    // Create a resource for this file.
                    // 
                    Resource resource = resourceSet.createResource(fileURI);
                    // Add the initial model object to the contents.
                    // 
                    EObject rootObject = createInitialModel();
                    // Set a default name on the root object
                    if (rootObject instanceof NamedElement) {
                        // Compute default name from model file path
                        String defaultName = modelFile.getName();
                        defaultName = defaultName.substring(0, defaultName.length() - modelFile.getFileExtension().length() - 1);
                        ((NamedElement) rootObject).setName(defaultName);
                    }
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                    }
                    // Set the types library
                    if (rootObject instanceof DataBase) {
                        Resource typesLibraryResource = null;
                        // We set the types library
                        String dbVendor = initialObjectCreationPage.dbVendorField.getText();
                        if (DB_MYSQL_5.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(MYSQL_PATHMAP), true);
                        } else if (DB_ORACLE_11G.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(ORACLE_PATHMAP), true);
                        } else if (DB_H2_13.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(H2_PATHMAP), true);
                        } else if (DB_POSTGRES_9.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(POSTGRES_PATHMAP), true);
                        } else if (DB_SQLSERVER_2008.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(SQLSERVER_PATHMAP), true);
                        } else if (DB_LOGICAL_TYPES.equals(dbVendor)) {
                            typesLibraryResource = resourceSet.getResource(URI.createURI(LOGICAL_PATHMAP), true);
                        }
                        if (typesLibraryResource != null) {
                            EObject typesRoot = typesLibraryResource.getContents().get(0);
                            if (typesRoot instanceof TypesLibrary) {
                                ((DataBase) rootObject).getUsedLibraries().add((TypesLibrary) typesRoot);
                            }
                        }
                    }
                    // Save the contents of the resource to the file system.
                    // 
                    Map<Object, Object> options = new HashMap<Object, Object>();
                    options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
                    resource.save(options);
                } catch (Exception exception) {
                    DatabaseEditorPlugin.INSTANCE.log(exception);
                } finally {
                    progressMonitor.done();
                }
            }
        };
        getContainer().run(false, false, operation);
        // Select the new file resource in the current view.
        // 
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(modelFile);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
        // 
        try {
            page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
        } catch (PartInitException exception) {
            MessageDialog.openError(workbenchWindow.getShell(), DatabaseEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
            return false;
        }
        return true;
    } catch (Exception exception) {
        DatabaseEditorPlugin.INSTANCE.log(exception);
        return false;
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) URI(org.eclipse.emf.common.util.URI) DataBase(org.obeonetwork.dsl.database.DataBase) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) EObject(org.eclipse.emf.ecore.EObject) ISelection(org.eclipse.jface.viewers.ISelection) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) IResource(org.eclipse.core.resources.IResource) TypesLibrary(org.obeonetwork.dsl.typeslibrary.TypesLibrary) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PartInitException(org.eclipse.ui.PartInitException) MissingResourceException(java.util.MissingResourceException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.obeonetwork.dsl.database.NamedElement)

Example 5 with TypesLibrary

use of org.obeonetwork.dsl.typeslibrary.TypesLibrary in project InformationSystem by ObeoNetwork.

the class DatabaseEditLabelServices method caseColumn.

@Override
public DatabaseElement caseColumn(Column column) {
    // the label can be in the form "attributeName : typeName (precision, length)"
    int pos = editedLabelContent.indexOf(':');
    if (pos != -1) {
        String attributeName = editedLabelContent.substring(0, pos).trim();
        column.setName(attributeName);
        String typeDef = editedLabelContent.substring(pos + 1).trim();
        // Retrieve types libraries
        DataBase database = getDataBase(column);
        if (database != null) {
            Collection<NativeTypesLibrary> nativeTypesLibraries = new ArrayList<NativeTypesLibrary>();
            for (TypesLibrary library : database.getUsedLibraries()) {
                if (library instanceof NativeTypesLibrary) {
                    nativeTypesLibraries.add((NativeTypesLibrary) library);
                }
            }
            setType(column, typeDef, nativeTypesLibraries);
        }
    } else {
        // there is only a name
        return super.caseNamedElement(column);
    }
    return column;
}
Also used : NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) ArrayList(java.util.ArrayList) NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) TypesLibrary(org.obeonetwork.dsl.typeslibrary.TypesLibrary) DataBase(org.obeonetwork.dsl.database.DataBase)

Aggregations

TypesLibrary (org.obeonetwork.dsl.typeslibrary.TypesLibrary)6 EObject (org.eclipse.emf.ecore.EObject)3 DataBase (org.obeonetwork.dsl.database.DataBase)3 NativeTypesLibrary (org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TypesLibraryUser (org.obeonetwork.dsl.typeslibrary.TypesLibraryUser)2 File (java.io.File)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 MissingResourceException (java.util.MissingResourceException)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1