ItemAuctionInstance.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.itemauction;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.sql.SQLException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.Collection;
  28. import java.util.Comparator;
  29. import java.util.Date;
  30. import java.util.HashMap;
  31. import java.util.Map;
  32. import java.util.concurrent.ScheduledFuture;
  33. import java.util.concurrent.TimeUnit;
  34. import java.util.concurrent.atomic.AtomicInteger;
  35. import java.util.logging.Level;
  36. import java.util.logging.Logger;
  37. import org.w3c.dom.NamedNodeMap;
  38. import org.w3c.dom.Node;
  39. import com.l2jserver.Config;
  40. import com.l2jserver.L2DatabaseFactory;
  41. import com.l2jserver.gameserver.ThreadPoolManager;
  42. import com.l2jserver.gameserver.datatables.CharNameTable;
  43. import com.l2jserver.gameserver.enums.ItemLocation;
  44. import com.l2jserver.gameserver.instancemanager.ItemAuctionManager;
  45. import com.l2jserver.gameserver.model.L2World;
  46. import com.l2jserver.gameserver.model.StatsSet;
  47. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  48. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  49. import com.l2jserver.gameserver.network.SystemMessageId;
  50. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  51. import com.l2jserver.util.Rnd;
  52. public final class ItemAuctionInstance
  53. {
  54. protected static final Logger _log = Logger.getLogger(ItemAuctionInstance.class.getName());
  55. private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss dd.MM.yy");
  56. private static final long START_TIME_SPACE = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
  57. private static final long FINISH_TIME_SPACE = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
  58. // SQL queries
  59. private static final String SELECT_AUCTION_ID_BY_INSTANCE_ID = "SELECT auctionId FROM item_auction WHERE instanceId = ?";
  60. private static final String SELECT_AUCTION_INFO = "SELECT auctionItemId, startingTime, endingTime, auctionStateId FROM item_auction WHERE auctionId = ? ";
  61. private static final String DELETE_AUCTION_INFO_BY_AUCTION_ID = "DELETE FROM item_auction WHERE auctionId = ?";
  62. private static final String DELETE_AUCTION_BID_INFO_BY_AUCTION_ID = "DELETE FROM item_auction_bid WHERE auctionId = ?";
  63. private static final String SELECT_PLAYERS_ID_BY_AUCTION_ID = "SELECT playerObjId, playerBid FROM item_auction_bid WHERE auctionId = ?";
  64. private final int _instanceId;
  65. private final AtomicInteger _auctionIds;
  66. private final Map<Integer, ItemAuction> _auctions;
  67. private final ArrayList<AuctionItem> _items;
  68. private final AuctionDateGenerator _dateGenerator;
  69. private ItemAuction _currentAuction;
  70. private ItemAuction _nextAuction;
  71. private ScheduledFuture<?> _stateTask;
  72. public ItemAuctionInstance(final int instanceId, final AtomicInteger auctionIds, final Node node) throws Exception
  73. {
  74. _instanceId = instanceId;
  75. _auctionIds = auctionIds;
  76. _auctions = new HashMap<>();
  77. _items = new ArrayList<>();
  78. final NamedNodeMap nanode = node.getAttributes();
  79. final StatsSet generatorConfig = new StatsSet();
  80. for (int i = nanode.getLength(); i-- > 0;)
  81. {
  82. final Node n = nanode.item(i);
  83. if (n != null)
  84. {
  85. generatorConfig.set(n.getNodeName(), n.getNodeValue());
  86. }
  87. }
  88. _dateGenerator = new AuctionDateGenerator(generatorConfig);
  89. for (Node na = node.getFirstChild(); na != null; na = na.getNextSibling())
  90. {
  91. try
  92. {
  93. if ("item".equalsIgnoreCase(na.getNodeName()))
  94. {
  95. final NamedNodeMap naa = na.getAttributes();
  96. final int auctionItemId = Integer.parseInt(naa.getNamedItem("auctionItemId").getNodeValue());
  97. final int auctionLenght = Integer.parseInt(naa.getNamedItem("auctionLenght").getNodeValue());
  98. final long auctionInitBid = Integer.parseInt(naa.getNamedItem("auctionInitBid").getNodeValue());
  99. final int itemId = Integer.parseInt(naa.getNamedItem("itemId").getNodeValue());
  100. final int itemCount = Integer.parseInt(naa.getNamedItem("itemCount").getNodeValue());
  101. if (auctionLenght < 1)
  102. {
  103. throw new IllegalArgumentException("auctionLenght < 1 for instanceId: " + _instanceId + ", itemId " + itemId);
  104. }
  105. final StatsSet itemExtra = new StatsSet();
  106. final AuctionItem item = new AuctionItem(auctionItemId, auctionLenght, auctionInitBid, itemId, itemCount, itemExtra);
  107. if (!item.checkItemExists())
  108. {
  109. throw new IllegalArgumentException("Item with id " + itemId + " not found");
  110. }
  111. for (final AuctionItem tmp : _items)
  112. {
  113. if (tmp.getAuctionItemId() == auctionItemId)
  114. {
  115. throw new IllegalArgumentException("Dublicated auction item id " + auctionItemId);
  116. }
  117. }
  118. _items.add(item);
  119. for (Node nb = na.getFirstChild(); nb != null; nb = nb.getNextSibling())
  120. {
  121. if ("extra".equalsIgnoreCase(nb.getNodeName()))
  122. {
  123. final NamedNodeMap nab = nb.getAttributes();
  124. for (int i = nab.getLength(); i-- > 0;)
  125. {
  126. final Node n = nab.item(i);
  127. if (n != null)
  128. {
  129. itemExtra.set(n.getNodeName(), n.getNodeValue());
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. catch (final IllegalArgumentException e)
  137. {
  138. _log.log(Level.WARNING, getClass().getSimpleName() + ": Failed loading auction item", e);
  139. }
  140. }
  141. if (_items.isEmpty())
  142. {
  143. throw new IllegalArgumentException("No items defined");
  144. }
  145. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  146. PreparedStatement ps = con.prepareStatement(SELECT_AUCTION_ID_BY_INSTANCE_ID))
  147. {
  148. ps.setInt(1, _instanceId);
  149. try (ResultSet rset = ps.executeQuery())
  150. {
  151. while (rset.next())
  152. {
  153. final int auctionId = rset.getInt(1);
  154. try
  155. {
  156. final ItemAuction auction = loadAuction(auctionId);
  157. if (auction != null)
  158. {
  159. _auctions.put(auctionId, auction);
  160. }
  161. else
  162. {
  163. ItemAuctionManager.deleteAuction(auctionId);
  164. }
  165. }
  166. catch (final SQLException e)
  167. {
  168. _log.log(Level.WARNING, getClass().getSimpleName() + ": Failed loading auction: " + auctionId, e);
  169. }
  170. }
  171. }
  172. }
  173. catch (final SQLException e)
  174. {
  175. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed loading auctions.", e);
  176. return;
  177. }
  178. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + _items.size() + " item(s) and registered " + _auctions.size() + " auction(s) for instance " + _instanceId + ".");
  179. checkAndSetCurrentAndNextAuction();
  180. }
  181. public final ItemAuction getCurrentAuction()
  182. {
  183. return _currentAuction;
  184. }
  185. public final ItemAuction getNextAuction()
  186. {
  187. return _nextAuction;
  188. }
  189. public final void shutdown()
  190. {
  191. final ScheduledFuture<?> stateTask = _stateTask;
  192. if (stateTask != null)
  193. {
  194. stateTask.cancel(false);
  195. }
  196. }
  197. private final AuctionItem getAuctionItem(final int auctionItemId)
  198. {
  199. for (int i = _items.size(); i-- > 0;)
  200. {
  201. final AuctionItem item = _items.get(i);
  202. if (item.getAuctionItemId() == auctionItemId)
  203. {
  204. return item;
  205. }
  206. }
  207. return null;
  208. }
  209. final void checkAndSetCurrentAndNextAuction()
  210. {
  211. final ItemAuction[] auctions = _auctions.values().toArray(new ItemAuction[_auctions.size()]);
  212. ItemAuction currentAuction = null;
  213. ItemAuction nextAuction = null;
  214. switch (auctions.length)
  215. {
  216. case 0:
  217. {
  218. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  219. break;
  220. }
  221. case 1:
  222. {
  223. switch (auctions[0].getAuctionState())
  224. {
  225. case CREATED:
  226. {
  227. if (auctions[0].getStartingTime() < (System.currentTimeMillis() + START_TIME_SPACE))
  228. {
  229. currentAuction = auctions[0];
  230. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  231. }
  232. else
  233. {
  234. nextAuction = auctions[0];
  235. }
  236. break;
  237. }
  238. case STARTED:
  239. {
  240. currentAuction = auctions[0];
  241. nextAuction = createAuction(Math.max(currentAuction.getEndingTime() + FINISH_TIME_SPACE, System.currentTimeMillis() + START_TIME_SPACE));
  242. break;
  243. }
  244. case FINISHED:
  245. {
  246. currentAuction = auctions[0];
  247. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  248. break;
  249. }
  250. default:
  251. throw new IllegalArgumentException();
  252. }
  253. break;
  254. }
  255. default:
  256. {
  257. Arrays.sort(auctions, Comparator.comparingLong(ItemAuction::getStartingTime));
  258. // just to make sure we won't skip any auction because of little different times
  259. final long currentTime = System.currentTimeMillis();
  260. for (final ItemAuction auction : auctions)
  261. {
  262. if (auction.getAuctionState() == ItemAuctionState.STARTED)
  263. {
  264. currentAuction = auction;
  265. break;
  266. }
  267. else if (auction.getStartingTime() <= currentTime)
  268. {
  269. currentAuction = auction;
  270. break; // only first
  271. }
  272. }
  273. for (final ItemAuction auction : auctions)
  274. {
  275. if ((auction.getStartingTime() > currentTime) && (currentAuction != auction))
  276. {
  277. nextAuction = auction;
  278. break;
  279. }
  280. }
  281. if (nextAuction == null)
  282. {
  283. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  284. }
  285. break;
  286. }
  287. }
  288. _auctions.put(nextAuction.getAuctionId(), nextAuction);
  289. _currentAuction = currentAuction;
  290. _nextAuction = nextAuction;
  291. if ((currentAuction != null) && (currentAuction.getAuctionState() != ItemAuctionState.FINISHED))
  292. {
  293. if (currentAuction.getAuctionState() == ItemAuctionState.STARTED)
  294. {
  295. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(currentAuction), Math.max(currentAuction.getEndingTime() - System.currentTimeMillis(), 0L)));
  296. }
  297. else
  298. {
  299. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(currentAuction), Math.max(currentAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
  300. }
  301. _log.log(Level.INFO, getClass().getSimpleName() + ": Schedule current auction " + currentAuction.getAuctionId() + " for instance " + _instanceId);
  302. }
  303. else
  304. {
  305. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(nextAuction), Math.max(nextAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
  306. _log.log(Level.INFO, getClass().getSimpleName() + ": Schedule next auction " + nextAuction.getAuctionId() + " on " + DATE_FORMAT.format(new Date(nextAuction.getStartingTime())) + " for instance " + _instanceId);
  307. }
  308. }
  309. public final ItemAuction getAuction(final int auctionId)
  310. {
  311. return _auctions.get(auctionId);
  312. }
  313. public final ItemAuction[] getAuctionsByBidder(final int bidderObjId)
  314. {
  315. final Collection<ItemAuction> auctions = getAuctions();
  316. final ArrayList<ItemAuction> stack = new ArrayList<>(auctions.size());
  317. for (final ItemAuction auction : getAuctions())
  318. {
  319. if (auction.getAuctionState() != ItemAuctionState.CREATED)
  320. {
  321. final ItemAuctionBid bid = auction.getBidFor(bidderObjId);
  322. if (bid != null)
  323. {
  324. stack.add(auction);
  325. }
  326. }
  327. }
  328. return stack.toArray(new ItemAuction[stack.size()]);
  329. }
  330. public final Collection<ItemAuction> getAuctions()
  331. {
  332. final Collection<ItemAuction> auctions;
  333. synchronized (_auctions)
  334. {
  335. auctions = _auctions.values();
  336. }
  337. return auctions;
  338. }
  339. private final class ScheduleAuctionTask implements Runnable
  340. {
  341. private final ItemAuction _auction;
  342. public ScheduleAuctionTask(final ItemAuction auction)
  343. {
  344. _auction = auction;
  345. }
  346. @Override
  347. public final void run()
  348. {
  349. try
  350. {
  351. runImpl();
  352. }
  353. catch (final Exception e)
  354. {
  355. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed scheduling auction " + _auction.getAuctionId(), e);
  356. }
  357. }
  358. private final void runImpl() throws Exception
  359. {
  360. final ItemAuctionState state = _auction.getAuctionState();
  361. switch (state)
  362. {
  363. case CREATED:
  364. {
  365. if (!_auction.setAuctionState(state, ItemAuctionState.STARTED))
  366. {
  367. throw new IllegalStateException("Could not set auction state: " + ItemAuctionState.STARTED.toString() + ", expected: " + state.toString());
  368. }
  369. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + _auction.getAuctionId() + " has started for instance " + _auction.getInstanceId());
  370. checkAndSetCurrentAndNextAuction();
  371. break;
  372. }
  373. case STARTED:
  374. {
  375. switch (_auction.getAuctionEndingExtendState())
  376. {
  377. case EXTEND_BY_5_MIN:
  378. {
  379. if (_auction.getScheduledAuctionEndingExtendState() == ItemAuctionExtendState.INITIAL)
  380. {
  381. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_5_MIN);
  382. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  383. return;
  384. }
  385. break;
  386. }
  387. case EXTEND_BY_3_MIN:
  388. {
  389. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_3_MIN)
  390. {
  391. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_3_MIN);
  392. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  393. return;
  394. }
  395. break;
  396. }
  397. case EXTEND_BY_CONFIG_PHASE_A:
  398. {
  399. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_B)
  400. {
  401. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_B);
  402. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  403. return;
  404. }
  405. break;
  406. }
  407. case EXTEND_BY_CONFIG_PHASE_B:
  408. {
  409. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_A)
  410. {
  411. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_A);
  412. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  413. return;
  414. }
  415. }
  416. }
  417. if (!_auction.setAuctionState(state, ItemAuctionState.FINISHED))
  418. {
  419. throw new IllegalStateException("Could not set auction state: " + ItemAuctionState.FINISHED.toString() + ", expected: " + state.toString());
  420. }
  421. onAuctionFinished(_auction);
  422. checkAndSetCurrentAndNextAuction();
  423. break;
  424. }
  425. default:
  426. throw new IllegalStateException("Invalid state: " + state);
  427. }
  428. }
  429. }
  430. final void onAuctionFinished(final ItemAuction auction)
  431. {
  432. auction.broadcastToAllBiddersInternal(SystemMessage.getSystemMessage(SystemMessageId.S1_AUCTION_ENDED).addInt(auction.getAuctionId()));
  433. final ItemAuctionBid bid = auction.getHighestBid();
  434. if (bid != null)
  435. {
  436. final L2ItemInstance item = auction.createNewItemInstance();
  437. final L2PcInstance player = bid.getPlayer();
  438. if (player != null)
  439. {
  440. player.getWarehouse().addItem("ItemAuction", item, null, null);
  441. player.sendPacket(SystemMessageId.WON_BID_ITEM_CAN_BE_FOUND_IN_WAREHOUSE);
  442. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. Highest bid by " + player.getName() + " for instance " + _instanceId);
  443. }
  444. else
  445. {
  446. item.setOwnerId(bid.getPlayerObjId());
  447. item.setItemLocation(ItemLocation.WAREHOUSE);
  448. item.updateDatabase();
  449. L2World.getInstance().removeObject(item);
  450. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. Highest bid by " + CharNameTable.getInstance().getNameById(bid.getPlayerObjId()) + " for instance " + _instanceId);
  451. }
  452. // Clean all canceled bids
  453. auction.clearCanceledBids();
  454. }
  455. else
  456. {
  457. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. There have not been any bid for instance " + _instanceId);
  458. }
  459. }
  460. final void setStateTask(final ScheduledFuture<?> future)
  461. {
  462. final ScheduledFuture<?> stateTask = _stateTask;
  463. if (stateTask != null)
  464. {
  465. stateTask.cancel(false);
  466. }
  467. _stateTask = future;
  468. }
  469. private final ItemAuction createAuction(final long after)
  470. {
  471. final AuctionItem auctionItem = _items.get(Rnd.get(_items.size()));
  472. final long startingTime = _dateGenerator.nextDate(after);
  473. final long endingTime = startingTime + TimeUnit.MILLISECONDS.convert(auctionItem.getAuctionLength(), TimeUnit.MINUTES);
  474. final ItemAuction auction = new ItemAuction(_auctionIds.getAndIncrement(), _instanceId, startingTime, endingTime, auctionItem);
  475. auction.storeMe();
  476. return auction;
  477. }
  478. private final ItemAuction loadAuction(final int auctionId) throws SQLException
  479. {
  480. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  481. {
  482. int auctionItemId = 0;
  483. long startingTime = 0;
  484. long endingTime = 0;
  485. byte auctionStateId = 0;
  486. try (PreparedStatement ps = con.prepareStatement(SELECT_AUCTION_INFO))
  487. {
  488. ps.setInt(1, auctionId);
  489. try (ResultSet rset = ps.executeQuery())
  490. {
  491. if (!rset.next())
  492. {
  493. _log.log(Level.WARNING, getClass().getSimpleName() + ": Auction data not found for auction: " + auctionId);
  494. return null;
  495. }
  496. auctionItemId = rset.getInt(1);
  497. startingTime = rset.getLong(2);
  498. endingTime = rset.getLong(3);
  499. auctionStateId = rset.getByte(4);
  500. }
  501. }
  502. if (startingTime >= endingTime)
  503. {
  504. _log.log(Level.WARNING, getClass().getSimpleName() + ": Invalid starting/ending paramaters for auction: " + auctionId);
  505. return null;
  506. }
  507. final AuctionItem auctionItem = getAuctionItem(auctionItemId);
  508. if (auctionItem == null)
  509. {
  510. _log.log(Level.WARNING, getClass().getSimpleName() + ": AuctionItem: " + auctionItemId + ", not found for auction: " + auctionId);
  511. return null;
  512. }
  513. final ItemAuctionState auctionState = ItemAuctionState.stateForStateId(auctionStateId);
  514. if (auctionState == null)
  515. {
  516. _log.log(Level.WARNING, getClass().getSimpleName() + ": Invalid auctionStateId: " + auctionStateId + ", for auction: " + auctionId);
  517. return null;
  518. }
  519. if ((auctionState == ItemAuctionState.FINISHED) && (startingTime < (System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(Config.ALT_ITEM_AUCTION_EXPIRED_AFTER, TimeUnit.DAYS))))
  520. {
  521. _log.log(Level.INFO, getClass().getSimpleName() + ": Clearing expired auction: " + auctionId);
  522. try (PreparedStatement ps = con.prepareStatement(DELETE_AUCTION_INFO_BY_AUCTION_ID))
  523. {
  524. ps.setInt(1, auctionId);
  525. ps.execute();
  526. }
  527. try (PreparedStatement ps = con.prepareStatement(DELETE_AUCTION_BID_INFO_BY_AUCTION_ID))
  528. {
  529. ps.setInt(1, auctionId);
  530. ps.execute();
  531. }
  532. return null;
  533. }
  534. final ArrayList<ItemAuctionBid> auctionBids = new ArrayList<>();
  535. try (PreparedStatement ps = con.prepareStatement(SELECT_PLAYERS_ID_BY_AUCTION_ID))
  536. {
  537. ps.setInt(1, auctionId);
  538. try (ResultSet rs = ps.executeQuery())
  539. {
  540. while (rs.next())
  541. {
  542. final int playerObjId = rs.getInt(1);
  543. final long playerBid = rs.getLong(2);
  544. final ItemAuctionBid bid = new ItemAuctionBid(playerObjId, playerBid);
  545. auctionBids.add(bid);
  546. }
  547. }
  548. }
  549. return new ItemAuction(auctionId, _instanceId, startingTime, endingTime, auctionItem, auctionBids, auctionState);
  550. }
  551. }
  552. }