Search in sources :

Example 11 with Sequence

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

the class OracleDataBaseBuilder method buildSequences.

private void buildSequences(DatabaseMetaData metaData, TableContainer owner) {
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        PreparedStatement psmt = metaData.getConnection().prepareStatement("SELECT SEQUENCE_NAME, INCREMENT_BY, MIN_VALUE, MAX_VALUE, LAST_NUMBER, CYCLE_FLAG, CACHE_SIZE " + "FROM user_sequences");
        rs = psmt.executeQuery();
        while (rs.next()) {
            String name = rs.getString(1);
            BigInteger increment = getBigIntValueForColumn(rs, 2);
            BigInteger minValue = getBigIntValueForColumn(rs, 3);
            BigInteger maxValue = getBigIntValueForColumn(rs, 4);
            BigInteger start = getBigIntValueForColumn(rs, 5);
            String cycleAsString = rs.getString(6);
            boolean cycle = "Y".equals(cycleAsString);
            BigInteger cacheSize = getBigIntValueForColumn(rs, 7);
            Sequence sequence = CreationUtils.createSequence(owner, name, increment, minValue, maxValue, start, cycle, cacheSize);
            // Look for a table that could correspond to the sequence
            if (name.endsWith("_SEQ")) {
                String tableName = name.substring(0, name.length() - "_SEQ".length());
                AbstractTable abstractTable = queries.getTable(tableName);
                if (abstractTable != null && abstractTable instanceof Table) {
                    Table table = (Table) abstractTable;
                    if (table.getPrimaryKey() != null && table.getPrimaryKey().getColumns().size() == 1) {
                        Column column = table.getPrimaryKey().getColumns().get(0);
                        column.setSequence(sequence);
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        JdbcUtils.closeStatement(pstmt);
        JdbcUtils.closeResultSet(rs);
    }
}
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) ResultSet(java.sql.ResultSet) BigInteger(java.math.BigInteger) PreparedStatement(java.sql.PreparedStatement) Sequence(org.obeonetwork.dsl.database.Sequence) SQLException(java.sql.SQLException)

Example 12 with Sequence

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

the class CreationUtils method createSequence.

public static Sequence createSequence(TableContainer owner, String name, BigInteger increment, BigInteger minValue, BigInteger maxValue, BigInteger start, boolean cycle, BigInteger cache) {
    Sequence sequence = DatabaseFactory.eINSTANCE.createSequence();
    sequence.setName(name);
    sequence.setIncrement(increment);
    sequence.setMinValue(minValue);
    sequence.setMaxValue(maxValue);
    sequence.setStart(start);
    sequence.setCycle(cycle);
    sequence.setCacheSize(cache);
    owner.getSequences().add(sequence);
    return sequence;
}
Also used : Sequence(org.obeonetwork.dsl.database.Sequence)

Example 13 with Sequence

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

the class UpdateSequenceImpl method setNewSequence.

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

Example 14 with Sequence

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

the class RemoveSequenceItemProvider 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) {
    RemoveSequence removeSequence = (RemoveSequence) object;
    Sequence sequence = removeSequence.getSequence();
    return getString("_UI_RemoveSequence_type") + " " + sequence.getName();
}
Also used : RemoveSequence(org.obeonetwork.dsl.database.dbevolution.RemoveSequence) RemoveSequence(org.obeonetwork.dsl.database.dbevolution.RemoveSequence) Sequence(org.obeonetwork.dsl.database.Sequence)

Example 15 with Sequence

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

the class UpdateSequenceItemProvider 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) {
    UpdateSequence updateSequence = (UpdateSequence) object;
    Sequence sequence = updateSequence.getSequence();
    return getString("_UI_UpdateSequence_type") + " " + sequence.getName();
}
Also used : Sequence(org.obeonetwork.dsl.database.Sequence) UpdateSequence(org.obeonetwork.dsl.database.dbevolution.UpdateSequence) UpdateSequence(org.obeonetwork.dsl.database.dbevolution.UpdateSequence)

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