Search in sources :

Example 1 with NativeTypesLibrary

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

the class TypesLibraryUtil method getLogicalTypesLibrary.

public static NativeTypesLibrary getLogicalTypesLibrary(ResourceSet resourceSet) {
    URI typeslibraryURI = URI.createURI(LOGICAL_PATHMAP);
    Resource resource = resourceSet.getResource(typeslibraryURI, true);
    NativeTypesLibrary nativeTypesLibrary = (NativeTypesLibrary) resource.getContents().get(0);
    return nativeTypesLibrary;
}
Also used : NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 2 with NativeTypesLibrary

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

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

the class NativeTypesLibraryPropertiesEditionComponent 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 NativeTypesLibrary nativeTypesLibrary = (NativeTypesLibrary) elt;
        final NativeTypesLibraryPropertiesEditionPart nativeTypesLibraryPart = (NativeTypesLibraryPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.name))
            nativeTypesLibraryPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, nativeTypesLibrary.getName()));
        if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.nativeTypes)) {
            nativeTypesSettings = new ReferencesTableSettings(nativeTypesLibrary, TypesLibraryPackage.eINSTANCE.getNativeTypesLibrary_NativeTypes());
            nativeTypesLibraryPart.initNativeTypes(nativeTypesSettings);
        }
        if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.nativeTypes)) {
            nativeTypesLibraryPart.addFilterToNativeTypes(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) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof NativeType);
                }
            });
        // Start of user code for additional businessfilters for nativeTypes
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) NativeTypesLibraryPropertiesEditionPart(org.obeonetwork.dsl.typeslibrary.parts.NativeTypesLibraryPropertiesEditionPart) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with NativeTypesLibrary

use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary 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)

Example 5 with NativeTypesLibrary

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

the class DatabaseEditLabelServices method setType.

private void setType(Column column, String typeName, Collection<NativeTypesLibrary> typesLibraries) {
    for (NativeTypesLibrary nativeTypesLibrary : typesLibraries) {
        for (NativeType nativeType : nativeTypesLibrary.getNativeTypes()) {
            String typePattern = getNativeTypePattern(nativeType);
            String typeRegexPattern = null;
            if (nativeType.getSpec() == NativeTypeKind.ENUM) {
                typeRegexPattern = typePattern;
            } else {
                typeRegexPattern = typePattern.replace("%n", "(.*)");
                typeRegexPattern = typeRegexPattern.replace("%p", "(.*)");
            }
            if (typeRegexPattern != null) {
                Pattern ptn = null;
                try {
                    ptn = Pattern.compile(typeRegexPattern, Pattern.CASE_INSENSITIVE);
                } catch (Exception e) {
                // Do nothing, the loop will try the other types
                }
                if (ptn != null) {
                    Matcher matcher = ptn.matcher(typeName);
                    if (matcher.matches()) {
                        // Ensure there is a type instance
                        if (column.getType() == null || (column.getType() instanceof TypeInstance == false)) {
                            TypeInstance type = TypesLibraryFactory.eINSTANCE.createTypeInstance();
                            type.setNativeType(nativeType);
                            column.setType(type);
                        }
                        TypeInstance columnType = ((TypeInstance) column.getType());
                        columnType.setNativeType(nativeType);
                        switch(nativeType.getSpec()) {
                            case SIMPLE:
                                // Nothing special to do
                                return;
                            case LENGTH:
                                // Retrieve length
                                String lengthString = matcher.group(1).trim();
                                // Ensure its a string representing an int
                                int length = getIntValue(lengthString);
                                columnType.setLength(length);
                                return;
                            case LENGTH_AND_PRECISION:
                                int nPos = typePattern.indexOf("%n");
                                int pPos = typePattern.indexOf("%p");
                                String nString = null;
                                String pString = null;
                                if (nPos < pPos) {
                                    nString = matcher.group(1).trim();
                                    nString = matcher.group(2).trim();
                                } else {
                                    nString = matcher.group(2).trim();
                                    pString = matcher.group(1).trim();
                                }
                                int nValue = getIntValue(nString);
                                int pValue = getIntValue(pString);
                                columnType.setLength(nValue);
                                columnType.setPrecision(pValue);
                                break;
                            case ENUM:
                                // Retrieves values
                                columnType.getLiterals().clear();
                                String valuesString = matcher.group(1).trim();
                                for (String value : valuesString.split(",")) {
                                    columnType.getLiterals().add(value.trim());
                                }
                                return;
                        }
                    }
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NativeTypesLibrary(org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Aggregations

NativeTypesLibrary (org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary)7 EObject (org.eclipse.emf.ecore.EObject)3 NativeType (org.obeonetwork.dsl.typeslibrary.NativeType)3 TypesLibrary (org.obeonetwork.dsl.typeslibrary.TypesLibrary)3 ArrayList (java.util.ArrayList)2 DataBase (org.obeonetwork.dsl.database.DataBase)2 File (java.io.File)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1