Skip to content

Commit

Permalink
🚀 save/insert items with priority data
Browse files Browse the repository at this point in the history
Took 6 minutes
  • Loading branch information
kiranhart committed Aug 19, 2024
1 parent 22dc21e commit 4aefe04
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void updateItems(Collection<AuctionedItem> items, UpdateCallback callback
connection.setAutoCommit(false);
SQLException err = null;

PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ?, item = ?, serialize_version = ?, itemstack = ? WHERE id = ?");
PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ?, item = ?, serialize_version = ?, itemstack = ?, priority_listing = ?, priority_expires_at = ? WHERE id = ?");
for (AuctionedItem item : items) {
try {
statement.setString(1, item.getOwner().toString());
Expand All @@ -259,7 +259,12 @@ public void updateItems(Collection<AuctionedItem> items, UpdateCallback callback
statement.setString(13, null);
}

statement.setString(14, item.getId().toString());
statement.setBoolean(14, item.isHasListingPriority());
statement.setLong(15, item.getPriorityExpiresAt());

statement.setString(16, item.getId().toString());


statement.addBatch();
} catch (SQLException e) {
err = e;
Expand Down Expand Up @@ -340,7 +345,7 @@ public void getItems(Callback<ArrayList<AuctionedItem>> callback) {

public void insertAuction(AuctionedItem item, Callback<AuctionedItem> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys, server_auction, is_request, request_count, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys, server_auction, is_request, request_count, serialize_version, itemstack, priority_listing, priority_expires_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
final AuctionAPI api = AuctionAPI.getInstance();
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions WHERE id = ?");

Expand Down Expand Up @@ -377,6 +382,9 @@ public void insertAuction(AuctionedItem item, Callback<AuctionedItem> callback)
statement.setString(25, null);
}

statement.setBoolean(26, item.isHasListingPriority());
statement.setLong(27, item.getPriorityExpiresAt());

statement.executeUpdate();

if (callback != null) {
Expand Down Expand Up @@ -427,7 +435,6 @@ private AuctionedItem extractAuctionedItem(ResultSet resultSet) throws SQLExcept
auctionItem.setHasListingPriority(resultSet.getBoolean("listing_priority"));
auctionItem.setPriorityExpiresAt(resultSet.getLong("priority_expires_at"));


return auctionItem;
}

Expand Down

0 comments on commit 4aefe04

Please sign in to comment.