Search in sources :

Example 11 with Result

use of org.jooq.Result in project jOOQ by jOOQ.

the class AbstractResultQuery method execute.

@Override
protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException {
    listener.executeStart(ctx);
    // [#4511] [#4753] PostgreSQL doesn't like fetchSize with autoCommit == true
    int f = SettingsTools.getFetchSize(fetchSize, ctx.settings());
    if (REPORT_FETCH_SIZE_WITH_AUTOCOMMIT.contains(ctx.dialect()) && f != 0 && ctx.connection().getAutoCommit())
        log.info("Fetch Size", "A fetch size of " + f + " was set on a auto-commit PostgreSQL connection, which is not recommended. See http://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor");
    SQLException e = executeStatementAndGetFirstResultSet(ctx, rendered.skipUpdateCounts);
    listener.executeEnd(ctx);
    // Fetch a single result set
    notManyIf: if (!many) {
        // and that exception is not thrown because of Settings.throwExceptions == THROW_NONE, we can stop
        if (e != null)
            break notManyIf;
        // not a result set.
        if (ctx.resultSet() == null) {
            DSLContext dsl = DSL.using(ctx.configuration());
            Field<Integer> c = DSL.field(name("UPDATE_COUNT"), int.class);
            Result<Record1<Integer>> r = dsl.newResult(c);
            r.add(dsl.newRecord(c).values(ctx.rows()));
            ctx.resultSet(new MockResultSet(r));
        }
        Field<?>[] fields = getFields(ctx.resultSet().getMetaData());
        cursor = new CursorImpl<>(ctx, listener, fields, intern.internIndexes(fields), keepStatement(), keepResultSet(), getRecordType(), SettingsTools.getMaxRows(maxRows, ctx.settings()), autoclosing);
        if (!lazy) {
            result = cursor.fetch();
            cursor = null;
        }
    } else // Fetch several result sets
    {
        results = new ResultsImpl(ctx.configuration());
        consumeResultSets(ctx, listener, results, intern, e);
    }
    return result != null ? result.size() : 0;
}
Also used : Field(org.jooq.Field) SQLException(java.sql.SQLException) DSLContext(org.jooq.DSLContext) MockResultSet(org.jooq.tools.jdbc.MockResultSet) Result(org.jooq.Result)

Example 12 with Result

use of org.jooq.Result in project textdb by TextDB.

the class KeywordDictionaryResource method listUserDictionaries.

@GET
@Path("/list")
public List<KeywordDictionary> listUserDictionaries(@Session HttpSession session) {
    UInteger userID = UserResource.getUser(session).getUserID();
    Result<Record4<UInteger, String, byte[], String>> result = getUserDictionaryRecord(userID);
    if (result == null)
        return new ArrayList<>();
    List<KeywordDictionary> dictionaryList = result.stream().map(record -> new KeywordDictionary(record.get(KEYWORD_DICTIONARY.KID), record.get(KEYWORD_DICTIONARY.NAME), convertContentToList(record.get(KEYWORD_DICTIONARY.CONTENT)), record.get(KEYWORD_DICTIONARY.DESCRIPTION))).collect(Collectors.toList());
    return dictionaryList;
}
Also used : HttpSession(javax.servlet.http.HttpSession) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) SqlServer(edu.uci.ics.texera.dataflow.sqlServerInfo.SqlServer) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) KEYWORD_DICTIONARY(edu.uci.ics.texera.dataflow.jooq.generated.Tables.KEYWORD_DICTIONARY) Result(org.jooq.Result) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Record4(org.jooq.Record4) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) Stream(java.util.stream.Stream) DSL.defaultValue(org.jooq.impl.DSL.defaultValue) Pair(org.apache.commons.lang3.tuple.Pair) javax.ws.rs(javax.ws.rs) java.io(java.io) UInteger(org.jooq.types.UInteger) Session(io.dropwizard.jersey.sessions.Session) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse) UInteger(org.jooq.types.UInteger) Record4(org.jooq.Record4)

Example 13 with Result

use of org.jooq.Result 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);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) FilterRegistry(com.almuradev.almura.shared.feature.filter.FilterRegistry) Results(org.jooq.Results) Item(net.minecraft.item.Item) Inject(com.google.inject.Inject) StoreQueries(com.almuradev.almura.feature.store.database.StoreQueries) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DatabaseManager(com.almuradev.almura.shared.database.DatabaseManager) BigDecimal(java.math.BigDecimal) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StoreBuyingItem(com.almuradev.generated.store.tables.StoreBuyingItem) BasicBuyingItem(com.almuradev.almura.feature.store.basic.listing.BasicBuyingItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EconomyService(org.spongepowered.api.service.economy.EconomyService) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) Timestamp(java.sql.Timestamp) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) Sponge(org.spongepowered.api.Sponge) DatabaseQueue(com.almuradev.almura.shared.database.DatabaseQueue) ServiceManager(org.spongepowered.api.service.ServiceManager) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) Result(org.jooq.Result) Instant(java.time.Instant) StoreSellingItemDataRecord(com.almuradev.generated.store.tables.records.StoreSellingItemDataRecord) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) List(java.util.List) Stream(java.util.stream.Stream) StoreSellingItemData(com.almuradev.generated.store.tables.StoreSellingItemData) ClientboundStoreGuiResponsePacket(com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) StoreSellingItemRecord(com.almuradev.generated.store.tables.records.StoreSellingItemRecord) ChannelId(org.spongepowered.api.network.ChannelId) IngameFeature(com.almuradev.almura.shared.feature.IngameFeature) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Query(org.jooq.Query) Almura(com.almuradev.almura.Almura) Getter(org.spongepowered.api.event.filter.Getter) StoreBuyingItemData(com.almuradev.generated.store.tables.StoreBuyingItemData) BasicSellingItem(com.almuradev.almura.feature.store.basic.listing.BasicSellingItem) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Text(org.spongepowered.api.text.Text) StoreBuyingItemRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemRecord) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) StoreSellingItem(com.almuradev.generated.store.tables.StoreSellingItem) GameState(org.spongepowered.api.GameState) CauseStackManager(org.spongepowered.api.event.CauseStackManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) Record(org.jooq.Record) StoreBuyingItemDataRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemDataRecord) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Scheduler(org.spongepowered.api.scheduler.Scheduler) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) SerializationUtil(com.almuradev.almura.shared.util.SerializationUtil) Witness(com.almuradev.core.event.Witness) ClientboundStoresRegistryPacket(com.almuradev.almura.feature.store.network.ClientboundStoresRegistryPacket) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Listener(org.spongepowered.api.event.Listener) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) Comparator(java.util.Comparator) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) SQLException(java.sql.SQLException) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) DSLContext(org.jooq.DSLContext) Results(org.jooq.Results) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) StoreBuyingItem(com.almuradev.generated.store.tables.StoreBuyingItem) BasicBuyingItem(com.almuradev.almura.feature.store.basic.listing.BasicBuyingItem) List(java.util.List) ArrayList(java.util.ArrayList)

Example 14 with Result

use of org.jooq.Result 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);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) FilterRegistry(com.almuradev.almura.shared.feature.filter.FilterRegistry) Results(org.jooq.Results) Item(net.minecraft.item.Item) Inject(com.google.inject.Inject) StoreQueries(com.almuradev.almura.feature.store.database.StoreQueries) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DatabaseManager(com.almuradev.almura.shared.database.DatabaseManager) BigDecimal(java.math.BigDecimal) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StoreBuyingItem(com.almuradev.generated.store.tables.StoreBuyingItem) BasicBuyingItem(com.almuradev.almura.feature.store.basic.listing.BasicBuyingItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EconomyService(org.spongepowered.api.service.economy.EconomyService) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) Timestamp(java.sql.Timestamp) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) Sponge(org.spongepowered.api.Sponge) DatabaseQueue(com.almuradev.almura.shared.database.DatabaseQueue) ServiceManager(org.spongepowered.api.service.ServiceManager) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) Result(org.jooq.Result) Instant(java.time.Instant) StoreSellingItemDataRecord(com.almuradev.generated.store.tables.records.StoreSellingItemDataRecord) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) List(java.util.List) Stream(java.util.stream.Stream) StoreSellingItemData(com.almuradev.generated.store.tables.StoreSellingItemData) ClientboundStoreGuiResponsePacket(com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) StoreSellingItemRecord(com.almuradev.generated.store.tables.records.StoreSellingItemRecord) ChannelId(org.spongepowered.api.network.ChannelId) IngameFeature(com.almuradev.almura.shared.feature.IngameFeature) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Query(org.jooq.Query) Almura(com.almuradev.almura.Almura) Getter(org.spongepowered.api.event.filter.Getter) StoreBuyingItemData(com.almuradev.generated.store.tables.StoreBuyingItemData) BasicSellingItem(com.almuradev.almura.feature.store.basic.listing.BasicSellingItem) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Text(org.spongepowered.api.text.Text) StoreBuyingItemRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemRecord) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) StoreSellingItem(com.almuradev.generated.store.tables.StoreSellingItem) GameState(org.spongepowered.api.GameState) CauseStackManager(org.spongepowered.api.event.CauseStackManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) Record(org.jooq.Record) StoreBuyingItemDataRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemDataRecord) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Scheduler(org.spongepowered.api.scheduler.Scheduler) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) SerializationUtil(com.almuradev.almura.shared.util.SerializationUtil) Witness(com.almuradev.core.event.Witness) ClientboundStoresRegistryPacket(com.almuradev.almura.feature.store.network.ClientboundStoresRegistryPacket) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Listener(org.spongepowered.api.event.Listener) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) Comparator(java.util.Comparator) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) SQLException(java.sql.SQLException) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) DSLContext(org.jooq.DSLContext) BasicSellingItem(com.almuradev.almura.feature.store.basic.listing.BasicSellingItem) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreSellingItem(com.almuradev.generated.store.tables.StoreSellingItem) Results(org.jooq.Results) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with Result

use of org.jooq.Result 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);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) FilterRegistry(com.almuradev.almura.shared.feature.filter.FilterRegistry) Results(org.jooq.Results) Item(net.minecraft.item.Item) Inject(com.google.inject.Inject) StoreQueries(com.almuradev.almura.feature.store.database.StoreQueries) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DatabaseManager(com.almuradev.almura.shared.database.DatabaseManager) BigDecimal(java.math.BigDecimal) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StoreBuyingItem(com.almuradev.generated.store.tables.StoreBuyingItem) BasicBuyingItem(com.almuradev.almura.feature.store.basic.listing.BasicBuyingItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EconomyService(org.spongepowered.api.service.economy.EconomyService) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) Timestamp(java.sql.Timestamp) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) Sponge(org.spongepowered.api.Sponge) DatabaseQueue(com.almuradev.almura.shared.database.DatabaseQueue) ServiceManager(org.spongepowered.api.service.ServiceManager) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) Result(org.jooq.Result) Instant(java.time.Instant) StoreSellingItemDataRecord(com.almuradev.generated.store.tables.records.StoreSellingItemDataRecord) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) List(java.util.List) Stream(java.util.stream.Stream) StoreSellingItemData(com.almuradev.generated.store.tables.StoreSellingItemData) ClientboundStoreGuiResponsePacket(com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) StoreSellingItemRecord(com.almuradev.generated.store.tables.records.StoreSellingItemRecord) ChannelId(org.spongepowered.api.network.ChannelId) IngameFeature(com.almuradev.almura.shared.feature.IngameFeature) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Query(org.jooq.Query) Almura(com.almuradev.almura.Almura) Getter(org.spongepowered.api.event.filter.Getter) StoreBuyingItemData(com.almuradev.generated.store.tables.StoreBuyingItemData) BasicSellingItem(com.almuradev.almura.feature.store.basic.listing.BasicSellingItem) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Text(org.spongepowered.api.text.Text) StoreBuyingItemRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemRecord) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) StoreSellingItem(com.almuradev.generated.store.tables.StoreSellingItem) GameState(org.spongepowered.api.GameState) CauseStackManager(org.spongepowered.api.event.CauseStackManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) Record(org.jooq.Record) StoreBuyingItemDataRecord(com.almuradev.generated.store.tables.records.StoreBuyingItemDataRecord) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Scheduler(org.spongepowered.api.scheduler.Scheduler) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) SerializationUtil(com.almuradev.almura.shared.util.SerializationUtil) Witness(com.almuradev.core.event.Witness) ClientboundStoresRegistryPacket(com.almuradev.almura.feature.store.network.ClientboundStoresRegistryPacket) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Listener(org.spongepowered.api.event.Listener) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) Comparator(java.util.Comparator) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) SQLException(java.sql.SQLException) BasicStore(com.almuradev.almura.feature.store.basic.BasicStore) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) DSLContext(org.jooq.DSLContext) Results(org.jooq.Results) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) StoreBuyingItem(com.almuradev.generated.store.tables.StoreBuyingItem) BasicBuyingItem(com.almuradev.almura.feature.store.basic.listing.BasicBuyingItem) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Result (org.jooq.Result)31 Record (org.jooq.Record)24 ArrayList (java.util.ArrayList)23 List (java.util.List)22 Collectors (java.util.stream.Collectors)17 DSLContext (org.jooq.DSLContext)17 BigDecimal (java.math.BigDecimal)13 SQLException (java.sql.SQLException)13 Map (java.util.Map)13 Timestamp (java.sql.Timestamp)12 Optional (java.util.Optional)12 Stream (java.util.stream.Stream)12 Lists (com.google.common.collect.Lists)11 HashMap (java.util.HashMap)11 UUID (java.util.UUID)11 IOException (java.io.IOException)10 Iterator (java.util.Iterator)10 Singleton (javax.inject.Singleton)10 Almura (com.almuradev.almura.Almura)9 ServerNotificationManager (com.almuradev.almura.feature.notification.ServerNotificationManager)9