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;
});
}
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);
}
}
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;
}
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);
}
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;
});
}
Aggregations