use of org.jooq.Query in project waltz by khartec.
the class UserRoleDao method updateRoles.
public boolean updateRoles(String userName, Set<String> newRoles) {
try {
dsl.transaction(config -> {
LOG.info("Removing existing roles for: " + userName);
DSL.using(config).delete(USER_ROLE).where(USER_ROLE.USER_NAME.eq(userName)).execute();
LOG.info("Inserting roles for " + userName + " / " + newRoles);
DSLContext batcher = DSL.using(config);
Set<Query> inserts = map(newRoles, r -> batcher.insertInto(USER_ROLE, USER_ROLE.USER_NAME, USER_ROLE.ROLE).values(userName, r));
batcher.batch(inserts).execute();
});
return true;
} catch (Exception e) {
return false;
}
}
use of org.jooq.Query in project Almura by AlmuraDev.
the class ServerStoreManager method handleDelistBuyingItems.
public void handleDelistBuyingItems(final Player player, final String id, final List<Integer> recNos) {
checkNotNull(player);
checkNotNull(id);
checkNotNull(recNos);
checkState(!recNos.isEmpty());
if (!player.hasPermission(Almura.ID + ".store.admin")) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to unlist items!"), 5);
return;
}
final Store store = this.getStore(id).orElse(null);
if (store == null) {
this.logger.error("Player '{}' attempted to de-list buying items for store '{}' but the server has no knowledge of it. Syncing " + "store registry...", player.getName(), id);
this.syncStoreRegistryTo(player);
return;
}
final List<BuyingItem> buyingItems = store.getBuyingItems();
if (buyingItems.isEmpty()) {
this.logger.error("Player '{}' attempted to de-list buying items for store '{}' but the server knows of no " + " buying items for it. This could be a de-sync or an exploit.", player.getName(), store.getId());
this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.BUYING, buyingItems));
return;
}
final List<Integer> copyRecNos = Lists.newArrayList(recNos);
final Iterator<Integer> iter = copyRecNos.iterator();
while (iter.hasNext()) {
final Integer recNo = iter.next();
final BuyingItem found = buyingItems.stream().filter(v -> v.getRecord() == recNo).findAny().orElse(null);
if (found == null) {
this.logger.error("Player '{}' attempted to de-list buying item '{}' for store '{}' but the server knows of no knowledge of it. " + "This could be a de-sync or an exploit. Discarding...", player.getName(), recNo, store.getId());
iter.remove();
}
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final List<Query> toUpdate = new ArrayList<>();
for (final Integer recNo : recNos) {
toUpdate.add(StoreQueries.createUpdateBuyingItemIsHidden(recNo, true).build(context));
}
context.batch(toUpdate).execute();
final Results results = StoreQueries.createFetchBuyingItemsAndDataFor(store.getId(), false).build(context).fetchMany();
final List<BuyingItem> finalBuyingItems = new ArrayList<>();
results.forEach(result -> finalBuyingItems.addAll(this.parseBuyingItemsFor(result)));
this.scheduler.createTaskBuilder().execute(() -> {
store.putBuyingItems(finalBuyingItems);
this.network.sendToAll(new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.BUYING, finalBuyingItems));
}).submit(this.container);
} catch (final SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of org.jooq.Query in project Almura by AlmuraDev.
the class ServerStoreManager method handleModifySellingItems.
public void handleModifySellingItems(final Player player, final String id, final List<ServerboundModifyItemsPacket.ModifyCandidate> candidates) {
checkNotNull(player);
checkNotNull(id);
checkNotNull(candidates);
if (!player.hasPermission(Almura.ID + ".store.admin")) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to modify listed items!"), 5);
return;
}
final Store store = this.getStore(id).orElse(null);
if (store == null) {
this.logger.error("Player '{}' attempted to modify selling items for store '{}' but the server has no knowledge of it. Syncing " + "store registry...", player.getName(), id);
this.syncStoreRegistryTo(player);
return;
}
final List<SellingItem> sellingItems = store.getSellingItems();
if (sellingItems.isEmpty()) {
this.logger.error("Player '{}' attempted to modify selling items for store '{}' but the server knows of no " + " selling items for it. This could be a de-sync or an exploit.", player.getName(), store.getId());
this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, sellingItems));
return;
}
final List<ServerboundModifyItemsPacket.ModifyCandidate> copyCandidates = Lists.newArrayList(candidates);
final Iterator<ServerboundModifyItemsPacket.ModifyCandidate> iter = copyCandidates.iterator();
while (iter.hasNext()) {
final ServerboundModifyItemsPacket.ModifyCandidate candidate = iter.next();
final SellingItem found = sellingItems.stream().filter(v -> v.getRecord() == candidate.recNo).findAny().orElse(null);
if (found == null) {
this.logger.error("Player '{}' attempted to modify selling item '{}' for store '{}' but the server knows of no knowledge of it. " + "This could be a de-sync or an exploit. Discarding...", player.getName(), candidate.recNo, store.getId());
iter.remove();
}
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final List<Query> toUpdate = new ArrayList<>();
for (final ServerboundModifyItemsPacket.ModifyCandidate candidate : copyCandidates) {
toUpdate.add(StoreQueries.createUpdateSellingItem(candidate.recNo, candidate.quantity, candidate.index, candidate.price).build(context));
}
context.batch(toUpdate).execute();
final Results results = StoreQueries.createFetchSellingItemsAndDataFor(store.getId(), false).build(context).fetchMany();
final List<SellingItem> finalSellingItems = new ArrayList<>();
results.forEach(result -> finalSellingItems.addAll(this.parseSellingItemsFrom(result)));
this.scheduler.createTaskBuilder().execute(() -> {
store.putSellingItems(finalSellingItems);
this.network.sendToAll(new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, finalSellingItems));
}).submit(this.container);
} catch (final SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of org.jooq.Query in project Almura by AlmuraDev.
the class ServerStoreManager method handleModifyBuyingItems.
public void handleModifyBuyingItems(final Player player, final String id, final List<ServerboundModifyItemsPacket.ModifyCandidate> candidates) {
checkNotNull(player);
checkNotNull(id);
checkNotNull(candidates);
if (!player.hasPermission(Almura.ID + ".store.admin")) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to modify listed items!"), 5);
return;
}
final Store store = this.getStore(id).orElse(null);
if (store == null) {
this.logger.error("Player '{}' attempted to modify buying items for store '{}' but the server has no knowledge of it. Syncing " + "store registry...", player.getName(), id);
this.syncStoreRegistryTo(player);
return;
}
final List<BuyingItem> buyingItems = store.getBuyingItems();
if (buyingItems.isEmpty()) {
this.logger.error("Player '{}' attempted to modify buying items for store '{}' but the server knows of no " + " buying items for it. This could be a de-sync or an exploit.", player.getName(), store.getId());
this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, buyingItems));
return;
}
final List<ServerboundModifyItemsPacket.ModifyCandidate> copyCandidates = Lists.newArrayList(candidates);
final Iterator<ServerboundModifyItemsPacket.ModifyCandidate> iter = copyCandidates.iterator();
while (iter.hasNext()) {
final ServerboundModifyItemsPacket.ModifyCandidate candidate = iter.next();
final BuyingItem found = buyingItems.stream().filter(v -> v.getRecord() == candidate.recNo).findAny().orElse(null);
if (found == null) {
this.logger.error("Player '{}' attempted to modify buying item '{}' for store '{}' but the server knows of no knowledge of it. " + "This could be a de-sync or an exploit. Discarding...", player.getName(), candidate.recNo, store.getId());
iter.remove();
}
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final List<Query> toUpdate = new ArrayList<>();
for (final ServerboundModifyItemsPacket.ModifyCandidate candidate : copyCandidates) {
toUpdate.add(StoreQueries.createUpdateBuyingItem(candidate.recNo, candidate.quantity, candidate.index, candidate.price).build(context));
}
context.batch(toUpdate).execute();
final Results results = StoreQueries.createFetchBuyingItemsAndDataFor(store.getId(), false).build(context).fetchMany();
final List<BuyingItem> finalBuyingItems = new ArrayList<>();
results.forEach(result -> finalBuyingItems.addAll(this.parseBuyingItemsFor(result)));
this.scheduler.createTaskBuilder().execute(() -> {
store.putBuyingItems(finalBuyingItems);
this.network.sendToAll(new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.BUYING, finalBuyingItems));
}).submit(this.container);
} catch (final SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of org.jooq.Query in project kork by spinnaker.
the class SqlTestUtil method cleanupDb.
public static void cleanupDb(DSLContext context) {
String schema = context.select(currentSchema()).fetch().getValue(0, 0).toString();
GlobalConfiguration configuration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
List<Query> commands = new ArrayList<>();
if (context.dialect() == SQLDialect.MYSQL) {
commands.add(query("set foreign_key_checks=0"));
}
context.meta().getTables().stream().filter(table -> table.getType().isTable() && table.getSchema().getName().equals(schema) && !table.getName().equals(configuration.getDatabaseChangeLogTableName()) && !table.getName().equals(configuration.getDatabaseChangeLogLockTableName())).forEach(table -> {
switch(context.dialect()) {
case POSTGRES:
commands.add(truncateTable(table).cascade());
break;
default:
commands.add(truncateTable(table));
break;
}
});
if (context.dialect() == SQLDialect.MYSQL) {
commands.add(query("set foreign_key_checks=1"));
}
context.batch(commands).execute();
}
Aggregations