Note that there are some explanatory texts on larger screens.

plurals
  1. POJava error when caching
    primarykey
    data
    text
    <p>I have a game and when I cache items with this method it works fine when I first get in-game</p> <pre><code>public void add(IItem item, int priceId, int priceAmount) { try { MapleInventoryManipulator.removeFromSlot(c, MapleItemInformationProvider.getInstance().getInventoryType(item.getItemId()), item.getPosition(), item.getQuantity(), true); MarketItem m = new MarketItem(getPlayer().getName(), (IItem)item, priceId, priceAmount); MarketItem s = new MarketItem(getPlayer().getName(), (IItem)item); //Market.add(m); Market.add(s); } catch (Exception e) { e.printStackTrace(); } System.out.println(Market.getItems().get(0).getItem() == null ? "Item is null" : "Item is not null."); } public static void add(MarketItem item) { lock.writeLock().lock(); try { try { itemCache.add(item); //try save directly to db see if i get stuck still System.out.println("Added item " + item.getName()); } finally { lock.writeLock().unlock(); } } catch (Exception e) { e.printStackTrace(); } } </code></pre> <p>I can cache new items unlimited times but then when I save with this method</p> <pre><code>public static void save() { try { PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM market_items"); ps.execute(); ps.close(); //After purging the table, insert updated values... List&lt;MarketItem&gt; equips = new LinkedList&lt;MarketItem&gt;(); List&lt;MarketItem&gt; notEquips = new LinkedList&lt;MarketItem&gt;(); lock.readLock().lock(); try { for (MarketItem item : itemCache) { item.setType((byte)0); if (item.getInventoryType() == 1) { equips.add(item); } else { notEquips.add(item); } } } finally { lock.readLock().lock(); } sLock.readLock().lock(); try { for (String keySet : storage.keySet()) { for (MarketItem item : storage.get(keySet)) { item.setType((byte)1); if (item.getInventoryType() == 1) { equips.add(item); } else { notEquips.add(item); } } } } finally { sLock.readLock().unlock(); } ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO market_items (`itemid`, `ownername`, `priceItem`, `priceAmount`, `itemname`, `inventorytype`, `type`) VALUES (?, ?, ?, ?, ?, ?, ?)"); for (MarketItem notEquip : notEquips) { ps.setInt(1, notEquip.getItem().getItemId()); ps.setString(2, notEquip.getOwner()); ps.setInt(3, notEquip.getPriceItem()); ps.setInt(4, notEquip.getPriceAmount()); ps.setString(5, notEquip.getName()); ps.setByte(6, notEquip.getInventoryType()); ps.setByte(7, notEquip.getType()); ps.execute(); } ps.close(); ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO market_items (`itemid`, `ownername`, `priceItem`, `priceAmount`, `itemname`, `inventorytype`, `type`, `acc`, `avoid`, `dex`, `flag`, `hands`, `hp`, `int`, `itemexp`, `jump`, `level`, `luk`, `matk`, `mdef`, `mp`, `owner`, `speed`, `str`, `vicious`, `watk`, `wdef`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); for (MarketItem equip : equips) { Equip eq = (Equip)equip.getItem(); ps.setInt(1, equip.getItem().getItemId()); ps.setString(2, equip.getOwner()); ps.setInt(3, equip.getPriceItem()); ps.setInt(4, equip.getPriceAmount()); ps.setString(5, equip.getName()); ps.setByte(6, equip.getInventoryType()); ps.setByte(7, equip.getType()); ps.setShort(8, eq.getAcc()); ps.setShort(9, eq.getAvoid()); ps.setShort(10, eq.getDex()); ps.setShort(11, eq.getFlag()); ps.setShort(12, eq.getHands()); ps.setShort(13, eq.getHp()); ps.setShort(14, eq.getInt()); ps.setInt(15, eq.getItemExp()); ps.setShort(16, eq.getJump()); ps.setShort(17, eq.getLevel()); ps.setShort(18, eq.getLuk()); ps.setShort(19, eq.getMatk()); ps.setShort(20, eq.getMdef()); ps.setShort(21, eq.getMp()); ps.setString(22, eq.getOwner()); ps.setShort(23, eq.getSpeed()); ps.setShort(24, eq.getStr()); ps.setShort(25, eq.getVicious()); ps.setShort(26, eq.getWatk()); ps.setShort(27, eq.getWdef()); ps.execute(); } ps.close(); } catch (SQLException e) { System.out.println("Exception caught saving market items: "); e.printStackTrace(); } } </code></pre> <p>It works fine when saving into the database, but now when I'm trying to cache an item with the <code>add</code> command, my code gets stuck.</p> <p>Should I be disposing the cache or doing something else?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload