Search in sources :

Example 6 with Sequence

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

the class AddSequenceItemProvider method getText.

/**
 * This returns the label text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public String getText(Object object) {
    AddSequence addSequence = (AddSequence) object;
    Sequence sequence = addSequence.getSequence();
    return getString("_UI_AddSequence_type") + " " + sequence.getName();
}
Also used : AddSequence(org.obeonetwork.dsl.database.dbevolution.AddSequence) AddSequence(org.obeonetwork.dsl.database.dbevolution.AddSequence) Sequence(org.obeonetwork.dsl.database.Sequence)

Example 7 with Sequence

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

the class SequenceChangeImpl method setSequence.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setSequence(Sequence newSequence) {
    Sequence oldSequence = sequence;
    sequence = newSequence;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, DbevolutionPackage.SEQUENCE_CHANGE__SEQUENCE, oldSequence, sequence));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Sequence(org.obeonetwork.dsl.database.Sequence)

Example 8 with Sequence

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

the class SequenceServicesTest method sequenceColumnsTest.

@Test
public void sequenceColumnsTest() {
    Sequence sequence = getGSSerieSequence();
    assertEquals(1, new SequenceServices().columns(sequence).size());
}
Also used : Sequence(org.obeonetwork.dsl.database.Sequence) AbstractTest(org.obeonetwork.database.m2doc.services.common.AbstractTest) Test(org.junit.Test)

Example 9 with Sequence

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

the class MpdToMldBidiRules method createOrUpdateSequences.

/**
 * Create needed new sequences or update existing ones
 * @param sourceTableContainer
 * @return list of sequences processed so that all other sequences (now useless) could be removed
 */
/**
 * @param sourceTableContainer
 * @return
 */
private Collection<Sequence> createOrUpdateSequences(TableContainer sourceTableContainer) {
    Collection<Sequence> sequences = new ArrayList<Sequence>();
    // for each non-composite PK we create a sequence and associate it with the PK column
    for (AbstractTable sourceAbstractTable : sourceTableContainer.getTables()) {
        if (sourceAbstractTable instanceof Table) {
            Table sourceTable = (Table) sourceAbstractTable;
            // Get associated table
            Table targetTable = getFromOutputTraceabilityMap(sourceTable, DatabasePackage.Literals.TABLE);
            if (targetTable != null) {
                PrimaryKey pk = targetTable.getPrimaryKey();
                // Only for non-composite PK
                if (pk != null && pk.getColumns().size() == 1) {
                    Column targetColumn = pk.getColumns().get(0);
                    // Retrieve the potentially existing sequence
                    Sequence existingSequence = targetColumn.getSequence();
                    String sequenceName = targetTable.getName() + "_SEQ";
                    if (existingSequence != null) {
                        // Update name
                        existingSequence.setName(sequenceName);
                        // Ensure the sequence is in the right container
                        if (!targetTable.getOwner().getSequences().contains(existingSequence)) {
                            targetTable.getOwner().getSequences().add(existingSequence);
                        }
                        sequences.add(existingSequence);
                    } else {
                        // Create a new sequence
                        Sequence newSequence = DatabaseFactory.eINSTANCE.createSequence();
                        newSequence.setName(sequenceName);
                        newSequence.setIncrement(new BigInteger("1"));
                        newSequence.setStart(new BigInteger("1"));
                        newSequence.setComments(String.format(SEQUENCE_INITIAL_COMMENTS, targetTable.getName()));
                        targetTable.getOwner().getSequences().add(newSequence);
                        // Retrieve the associated column and associate it with the sequence
                        targetColumn.setSequence(newSequence);
                        sequences.add(newSequence);
                    }
                }
            }
        }
    }
    if (sourceTableContainer instanceof DataBase) {
        DataBase sourceDataBase = (DataBase) sourceTableContainer;
        for (Schema sourceSchema : sourceDataBase.getSchemas()) {
            sequences.addAll(createOrUpdateSequences(sourceSchema));
        }
    }
    return sequences;
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Column(org.obeonetwork.dsl.database.Column) Schema(org.obeonetwork.dsl.database.Schema) ArrayList(java.util.ArrayList) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) BigInteger(java.math.BigInteger) Sequence(org.obeonetwork.dsl.database.Sequence) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 10 with Sequence

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

the class ColumnPropertiesEditionComponent 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);
        if (editingPart instanceof CompositePropertiesEditionPart) {
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(typeSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(lengthSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(precisionSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(literalsSettings);
        }
        final Column column = (Column) elt;
        final ColumnPropertiesEditionPart columnPart = (ColumnPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Column.Properties.name))
            columnPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, column.getName()));
        if (isAccessible(DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.nullable)) {
            columnPart.setNullable(column.isNullable());
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.primaryKey)) {
            columnPart.setPrimaryKey(column.isInPrimaryKey());
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.unique)) {
            columnPart.setUnique(column.isUnique());
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.Sequence.autoincrement)) {
            columnPart.setAutoincrement(column.isAutoincrement());
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.Sequence.sequence_)) {
            // init part
            sequenceSettings = new EObjectFlatComboSettings(column, DatabasePackage.eINSTANCE.getColumn_Sequence());
            columnPart.initSequence(sequenceSettings);
            // set the button mode
            columnPart.setSequenceButtonMode(ButtonsModeEnum.BROWSE);
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.defaultValue))
            columnPart.setDefaultValue(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, column.getDefaultValue()));
        if (isAccessible(DatabaseViewsRepository.Column.Properties.comments))
            columnPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, column.getComments()));
        if (typeSettings.getSignificantObject() != null && isAccessible(DatabaseViewsRepository.Column.Properties.type)) {
            columnPart.initType(EEFUtils.choiceOfValues(typeSettings.getSignificantObject(), TypesLibraryPackage.eINSTANCE.getTypeInstance_NativeType()), typeSettings.getValue());
        }
        if (lengthSettings.getValue() != null && isAccessible(DatabaseViewsRepository.Column.Properties.TypeAttributes.length))
            columnPart.setLength(EEFConverterUtil.convertToString(EcorePackage.Literals.EINTEGER_OBJECT, lengthSettings.getValue()));
        if (precisionSettings.getValue() != null && isAccessible(DatabaseViewsRepository.Column.Properties.TypeAttributes.precision))
            columnPart.setPrecision(EEFConverterUtil.convertToString(EcorePackage.Literals.EINTEGER_OBJECT, precisionSettings.getValue()));
        if (literalsSettings.getSignificantObject() != null && isAccessible(DatabaseViewsRepository.Column.Properties.literals)) {
            columnPart.setLiterals((EList<?>) literalsSettings.getValue());
        }
        if (isAccessible(DatabaseViewsRepository.Column.Properties.Sequence.sequence_)) {
            columnPart.addFilterToSequence(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 Sequence);
                }
            });
        // Start of user code for additional businessfilters for sequence
        // End of user code
        }
    // Start of user code for additional businessfilters for type
    // End of user code
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Column(org.obeonetwork.dsl.database.Column) CompositePropertiesEditionPart(org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings) Sequence(org.obeonetwork.dsl.database.Sequence) ColumnPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ColumnPropertiesEditionPart)

Aggregations

Sequence (org.obeonetwork.dsl.database.Sequence)15 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)6 Column (org.obeonetwork.dsl.database.Column)6 Table (org.obeonetwork.dsl.database.Table)6 BigInteger (java.math.BigInteger)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 UpdateSequence (org.obeonetwork.dsl.database.dbevolution.UpdateSequence)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 CompositePropertiesEditionPart (org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Test (org.junit.Test)1 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)1 DataBase (org.obeonetwork.dsl.database.DataBase)1