Search in sources :

Example 1 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project SkyBot by duncte123.

the class GuildSettingsUtils method loadVcAutoRoles.

public static void loadVcAutoRoles(Variables variables) {
    final DatabaseAdapter adapter = variables.getDatabaseAdapter();
    final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
    LOGGER.info("Loading vc auto roles.");
    adapter.getVcAutoRoles((items) -> {
        items.forEach((item) -> {
            final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
                // This returns the old value which was null
                vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
                return vcAutoRoleCache.get(item.getGuildId());
            });
            cache.put(item.getVoiceChannelId(), item.getRoleId());
        });
        LOGGER.info("Loaded " + items.size() + " vc auto roles.");
        return null;
    });
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) TLongLongMap(gnu.trove.map.TLongLongMap) DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Example 2 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap 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 TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project olca-modules by GreenDelta.

the class ProductSystemWriter method exchangeIDs.

/**
 * Creates a map exchangeID -> internalID of the exchanges used in the
 * product system links.
 */
private TLongLongHashMap exchangeIDs(ProductSystem system) {
    var map = new TLongLongHashMap();
    if (system.referenceExchange != null) {
        map.put(system.referenceExchange.id, -1);
    }
    for (ProcessLink link : system.processLinks) {
        map.put(link.exchangeId, -1L);
    }
    try {
        String sql = "select id, internal_id from tbl_exchanges";
        NativeSql.on(exp.db).query(sql, r -> {
            long id = r.getLong(1);
            long internal = r.getLong(2);
            if (map.containsKey(id)) {
                map.put(id, internal);
            }
            return true;
        });
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(getClass());
        log.error("Failed to query exchange IDs", e);
    }
    return map;
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) Logger(org.slf4j.Logger)

Example 4 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project deephaven-core by deephaven.

the class ContiguousWritableRowRedirection method startTrackingPrevValues.

public synchronized void startTrackingPrevValues() {
    Assert.eqNull(updateCommitter, "updateCommitter");
    checkpoint = new TLongLongHashMap(Math.min(size, 1024 * 1024), 0.75f, UPDATES_KEY_NOT_FOUND, UPDATES_KEY_NOT_FOUND);
    updateCommitter = new UpdateCommitter<>(this, ContiguousWritableRowRedirection::commitUpdates);
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap)

Example 5 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project SkyBot by DuncteBot.

the class GuildSettingsUtils method loadVcAutoRoles.

public static void loadVcAutoRoles(Variables variables) {
    final DatabaseAdapter adapter = variables.getDatabaseAdapter();
    final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
    LOGGER.info("Loading vc auto roles.");
    adapter.getVcAutoRoles((items) -> {
        items.forEach((item) -> {
            final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
                // This returns the old value which was null
                vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
                return vcAutoRoleCache.get(item.getGuildId());
            });
            cache.put(item.getVoiceChannelId(), item.getRoleId());
        });
        LOGGER.info("Loaded " + items.size() + " vc auto roles.");
        return null;
    });
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) TLongLongMap(gnu.trove.map.TLongLongMap) DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Aggregations

TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)7 TLongLongMap (gnu.trove.map.TLongLongMap)2 DatabaseAdapter (ml.duncte123.skybot.adapters.DatabaseAdapter)2 JsonObject (com.google.gson.JsonObject)1 TLongLongIterator (gnu.trove.iterator.TLongLongIterator)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ParameterDao (org.openlca.core.database.ParameterDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 FlowProperty (org.openlca.core.model.FlowProperty)1 ProcessLink (org.openlca.core.model.ProcessLink)1 Logger (org.slf4j.Logger)1