Search in sources :

Example 1 with TLongLongIterator

use of gnu.trove.iterator.TLongLongIterator in project olca-modules by GreenDelta.

the class ProcessImport method switchDefaultProviders.

private void switchDefaultProviders() {
    log.trace("update default providers");
    dest.getEntityFactory().getCache().evictAll();
    TLongArrayList exchangeIds = new TLongArrayList();
    TLongArrayList providerIds = new TLongArrayList();
    TLongLongIterator it = oldProviderMap.iterator();
    while (it.hasNext()) {
        it.advance();
        long exchangeId = it.key();
        long newId = srcDestIdMap.get(it.value());
        exchangeIds.add(exchangeId);
        providerIds.add(newId);
    }
    updateDefaultProviders(exchangeIds, providerIds);
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongLongIterator(gnu.trove.iterator.TLongLongIterator)

Example 2 with TLongLongIterator

use of gnu.trove.iterator.TLongLongIterator in project olca-modules by GreenDelta.

the class Upgrade10 method addParameterSets.

private void addParameterSets(DbUtil u) {
    if (u.tableExists("tbl_parameter_redef_sets"))
        return;
    u.createTable("tbl_parameter_redef_sets", "CREATE TABLE tbl_parameter_redef_sets (" + " id BIGINT NOT NULL," + " name VARCHAR(2048)," + " description CLOB(64 K)," + " is_baseline SMALLINT default 0," + " f_product_system BIGINT)");
    u.createColumn("tbl_parameter_redefs", "description CLOB(64 K)");
    // move parameter redefinitions that were attached
    // to a product system into a baseline parameter set
    // of that product system
    AtomicLong seq = new AtomicLong(u.getLastID() + 5);
    try {
        // 1) collect the product system IDs
        TLongHashSet systemIDs = new TLongHashSet();
        String sql = "select id from tbl_product_systems";
        NativeSql.on(u.db).query(sql, r -> {
            systemIDs.add(r.getLong(1));
            return true;
        });
        // 2) move possible parameter redefinitions into parameter sets
        var systemSets = new TLongLongHashMap();
        sql = "select f_owner from tbl_parameter_redefs";
        NativeSql.on(u.db).updateRows(sql, rs -> {
            long owner = rs.getLong(1);
            if (!systemIDs.contains(owner))
                return true;
            long paramSet = systemSets.get(owner);
            if (paramSet == 0) {
                paramSet = seq.incrementAndGet();
                systemSets.put(owner, paramSet);
            }
            rs.updateLong(1, paramSet);
            rs.updateRow();
            return true;
        });
        // 3) create the allocated parameter sets
        TLongLongIterator it = systemSets.iterator();
        while (it.hasNext()) {
            it.advance();
            long systemID = it.key();
            long setID = it.value();
            String stmt = "insert into tbl_parameter_redef_sets " + "(id, name, is_baseline, f_product_system) " + "values (" + setID + ", 'Baseline', 1, " + systemID + ")";
            NativeSql.on(u.db).runUpdate(stmt);
        }
        // finally update the ID sequence
        u.setLastID(seq.get() + 1);
    } catch (Exception e) {
        throw new RuntimeException("failed create parameter sets", e);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TLongHashSet(gnu.trove.set.hash.TLongHashSet) TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) TLongLongIterator(gnu.trove.iterator.TLongLongIterator) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 3 with TLongLongIterator

use of gnu.trove.iterator.TLongLongIterator in project deephaven-core by deephaven.

the class TestLongLongMap method emptyMapHelper.

private void emptyMapHelper(TLongLongMap map) {
    TLongLongIterator it = map.iterator();
    TestCase.assertFalse(it.hasNext());
    try {
        it.setValue(12345);
        TestCase.fail();
    } catch (Exception e) {
    // do nothing
    }
    try {
        it.advance();
        TestCase.fail();
    } catch (Exception e) {
    // do nothing
    }
    try {
        it.remove();
        TestCase.fail();
    } catch (Exception e) {
    // do nothing
    }
}
Also used : TLongLongIterator(gnu.trove.iterator.TLongLongIterator)

Example 4 with TLongLongIterator

use of gnu.trove.iterator.TLongLongIterator in project deephaven-core by deephaven.

the class WritableRowRedirectionLockFree method commitUpdates.

/**
 * Commits the 'updates' map into the 'baseline' map, then resets the 'updates' map to empty. The only caller should
 * be Writer@Idle, via the TerminalNotification.
 */
private static void commitUpdates(@NotNull final WritableRowRedirectionLockFree instance) {
    // This only gets called by the UpdateCommitter, and only as a result of a terminal listener notification (which
    // in turn can only happen once prev tracking has been turned on). We copy updates to baseline and reset the
    // updates map.
    final TNullableLongLongMap updates = instance.updates;
    final TNullableLongLongMap baseline = instance.baseline;
    Assert.neq(baseline, "baseline", updates, "updates");
    for (final TLongLongIterator it = updates.iterator(); it.hasNext(); ) {
        it.advance();
        if (it.value() == BASELINE_KEY_NOT_FOUND) {
            baseline.remove(it.key());
        } else {
            baseline.put(it.key(), it.value());
        }
    }
    updates.resetToNull();
}
Also used : TNullableLongLongMap(io.deephaven.util.datastructures.hash.TNullableLongLongMap) TLongLongIterator(gnu.trove.iterator.TLongLongIterator)

Aggregations

TLongLongIterator (gnu.trove.iterator.TLongLongIterator)4 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 TNullableLongLongMap (io.deephaven.util.datastructures.hash.TNullableLongLongMap)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1