Search in sources :

Example 1 with Sequence

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

the class SequencePropertiesEditionComponent 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 Sequence sequence = (Sequence) elt;
        final SequencePropertiesEditionPart sequencePart = (SequencePropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.name))
            sequencePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, sequence.getName()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.StartIncrement.start))
            sequencePart.setStart(EEFConverterUtil.convertToString(EcorePackage.Literals.EBIG_INTEGER, sequence.getStart()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.StartIncrement.increment))
            sequencePart.setIncrement(EEFConverterUtil.convertToString(EcorePackage.Literals.EBIG_INTEGER, sequence.getIncrement()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.MinMax.minValue))
            sequencePart.setMinValue(EEFConverterUtil.convertToString(EcorePackage.Literals.EBIG_INTEGER, sequence.getMinValue()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.MinMax.maxValue))
            sequencePart.setMaxValue(EEFConverterUtil.convertToString(EcorePackage.Literals.EBIG_INTEGER, sequence.getMaxValue()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.CycleCacheSize.cycle)) {
            sequencePart.setCycle(sequence.isCycle());
        }
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.CycleCacheSize.cacheSize))
            sequencePart.setCacheSize(EEFConverterUtil.convertToString(EcorePackage.Literals.EBIG_INTEGER, sequence.getCacheSize()));
        if (isAccessible(DatabaseViewsRepository.Sequence.Properties.comments))
            sequencePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, sequence.getComments()));
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : SequencePropertiesEditionPart(org.obeonetwork.dsl.database.parts.SequencePropertiesEditionPart) Sequence(org.obeonetwork.dsl.database.Sequence)

Example 2 with Sequence

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

the class H2DataBaseBuilder method buildSequences.

private void buildSequences(DatabaseMetaData metaData, TableContainer owner) {
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        // TODO récupérer cycle avec IS_CYCLE
        // TODO récupérer Cache
        PreparedStatement psmt = metaData.getConnection().prepareStatement("SELECT SEQUENCE_NAME, INCREMENT, MIN_VALUE, MAX_VALUE, CURRENT_VALUE " + "FROM INFORMATION_SCHEMA.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);
            Sequence sequence = CreationUtils.createSequence(owner, name, increment, minValue, maxValue, start, false, null);
            // 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 3 with Sequence

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

the class PostGresDataBaseBuilder method buildSequences.

private void buildSequences(TableContainer owner) {
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        PreparedStatement psmt = metaData.getConnection().prepareStatement("SELECT s.SEQUENCE_NAME, s.INCREMENT, s.MINIMUM_VALUE, s.MAXIMUM_VALUE, s.START_VALUE, s.CYCLE_OPTION , pg_catalog.obj_description(c.oid) " + "FROM INFORMATION_SCHEMA.SEQUENCES s " + "LEFT JOIN PG_CATALOG.pg_class c " + "ON c.relname = s.SEQUENCE_NAME " + "AND c.relkind = 'S' " + "WHERE s.SEQUENCE_SCHEMA = '" + schemaName + "'");
        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 = "YES".equals(cycleAsString);
            String comment = rs.getString(7);
            // Retrieve CACHE value
            BigInteger cacheValue = null;
            PreparedStatement psmtCache = metaData.getConnection().prepareStatement("SELECT CACHE_VALUE FROM " + schemaName + "." + name);
            ResultSet rsCache = psmtCache.executeQuery();
            if (rsCache.next()) {
                cacheValue = getBigIntValueForColumn(rsCache, 1);
            }
            Sequence sequence = CreationUtils.createSequence(owner, name, increment, minValue, maxValue, start, cycle, cacheValue);
            sequence.setComments(comment);
            // 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 4 with Sequence

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

the class SQLServerDataBaseBuilder method buildSequences.

private void buildSequences(DatabaseMetaData metaData, TableContainer owner) {
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        String query = "SELECT			CAST(seq.name AS NVARCHAR(128)), " + "				CAST(seq.increment AS NVARCHAR(128)), " + "				CAST(seq.minimum_value AS NVARCHAR(128)), " + "				CAST(seq.maximum_value AS NVARCHAR(128)), " + "				CAST(seq.start_value AS NVARCHAR(128)), " + "				CAST(seq.is_cycling AS NVARCHAR(128)), " + "				CAST(seq.cache_size AS NVARCHAR(128)) " + "FROM			sys.sequences AS seq " + "INNER JOIN		sys.schemas AS sch " + "ON				seq.schema_id = sch.schema_id " + "WHERE			sch.name = ?";
        pstmt = metaData.getConnection().prepareStatement(query);
        pstmt.setString(1, schemaName);
        rs = pstmt.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);
            boolean cycle = rs.getBoolean(6);
            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 5 with Sequence

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

the class DataBaseServices method allSequences.

/**
 * Returns all the sequences contained and referenced by the database (including the sequences associated to tables of external
 * databases referenced through foreign
 * keys).
 *
 * @param database
 * @return the set of all sequences contained and referenced by the database.
 */
public Set<Sequence> allSequences(DataBase database) {
    Set<Sequence> result = new HashSet<Sequence>();
    result.addAll(database.getSequences());
    Set<Table> tables = allTables(database);
    for (Table table : tables) {
        if (table.eContainer() instanceof TableContainer) {
            result.addAll(((TableContainer) table.eContainer()).getSequences());
        }
    }
    return result;
}
Also used : Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) TableContainer(org.obeonetwork.dsl.database.TableContainer) Sequence(org.obeonetwork.dsl.database.Sequence) HashSet(java.util.HashSet)

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