Permalink
Please sign in to comment.
Showing
with
116 additions
and 5 deletions.
@@ -0,0 +1,111 @@ | ||
+package org.chardev.cjt.util; | ||
+ | ||
+import java.sql.Connection; | ||
+import java.sql.ResultSet; | ||
+import java.sql.SQLException; | ||
+import java.sql.Statement; | ||
+ | ||
+/** | ||
+ * Java port of php/tools/update_items.php | ||
+ * | ||
+ * Updates <code>chardev_cataclysm.item_sparse</code> with the currently | ||
+ * available and up to date items and sets additional cached item data in | ||
+ * <code>chardev_cataclysm_static.chardev_item_stats</code> | ||
+ * | ||
+ * @author LeMartin | ||
+ * | ||
+ */ | ||
+public class UpdateCachedItemSetTables { | ||
+ | ||
+ public static void main(String[] args) { | ||
+ Connection connectionLocaleDB = Database | ||
+ .connectToDatabase(Database.CHARDEV_CATACLYSM); | ||
+ Connection connectionStaticDB = Database | ||
+ .connectToDatabase(Database.CHARDEV_CATACLYSM_STATIC); | ||
+ new UpdateCachedItemSetTables(connectionStaticDB, connectionLocaleDB); | ||
+ } | ||
+ | ||
+ protected final Connection connectionStaticDB, connectionLocaleDB; | ||
+ | ||
+ /** | ||
+ * Updates <code>chardev_cataclysm.item_sparse</code> with the currently | ||
+ * available and up to date items. | ||
+ * | ||
+ * @param connectionStaticDB | ||
+ * @param connectionLocaleDB | ||
+ */ | ||
+ public UpdateCachedItemSetTables(Connection connectionStaticDB, | ||
+ Connection connectionLocaleDB) { | ||
+ // | ||
+ this.connectionStaticDB = connectionStaticDB; | ||
+ this.connectionLocaleDB = connectionLocaleDB; | ||
+ // | ||
+ try { | ||
+ // | ||
+ Statement stmt = connectionLocaleDB.createStatement(); | ||
+ ResultSet result = stmt.executeQuery("SELECT * FROM `itemset`"); | ||
+ // | ||
+ | ||
+ while (result.next()) { | ||
+ int minItemLevel = Integer.MAX_VALUE, maxItemLevel = 0, minReqLevel = 85, maxReqLevel = 0, items = 0, minQuality = Integer.MAX_VALUE, maxQuality = 0; | ||
+ | ||
+ System.out.println(result.getString("Name")); | ||
+ for( int i=1; i<= 10; i++ ) { | ||
+ if( result.getInt("ItemID"+i) <= 0 ) { | ||
+ continue; | ||
+ } | ||
+ Statement itemStmt = connectionLocaleDB.createStatement(); | ||
+ ResultSet itemResult = itemStmt.executeQuery("SELECT * FROM `item_sparse` WHERE `ID`="+result.getInt("ItemID"+i)); | ||
+ | ||
+ if (itemResult.next()) { | ||
+ System.out.println("\t"+itemResult.getString("Name")); | ||
+ | ||
+ int ilvl = itemResult.getInt("Level"); | ||
+ int clvl = itemResult.getInt("RequiredCharacterLevel"); | ||
+ int qua = itemResult.getInt("Quality"); | ||
+ | ||
+ if( ilvl < minItemLevel ) { | ||
+ minItemLevel = ilvl; | ||
+ } | ||
+ if( ilvl > maxItemLevel ) { | ||
+ maxItemLevel = ilvl; | ||
+ } | ||
+ if( clvl < minReqLevel ) { | ||
+ minReqLevel = clvl; | ||
+ } | ||
+ if( clvl > maxReqLevel ) { | ||
+ maxReqLevel = clvl; | ||
+ } | ||
+ if( qua < minQuality ) { | ||
+ minQuality = qua; | ||
+ } | ||
+ if( qua > maxQuality ) { | ||
+ maxQuality = qua; | ||
+ } | ||
+ items ++; | ||
+ } | ||
+ itemStmt.close(); | ||
+ } | ||
+ | ||
+ if( items > 0 ) { | ||
+ Statement insert = connectionStaticDB.createStatement(); | ||
+ insert.execute("REPLACE INTO `chardev_itemset_stats` values ( "+ | ||
+ result.getInt("ID")+ | ||
+ ", "+minItemLevel+ | ||
+ ", "+maxItemLevel+ | ||
+ ", "+minReqLevel+ | ||
+ ", "+maxReqLevel+ | ||
+ ", "+minQuality+ | ||
+ ", "+maxQuality+ | ||
+ ")" | ||
+ ); | ||
+ insert.close(); | ||
+ } | ||
+ } | ||
+ stmt.close(); | ||
+ } catch (SQLException e) { | ||
+ System.out.println(e); | ||
+ throw new RuntimeException(); | ||
+ } | ||
+ } | ||
+} |
0 comments on commit
47963f9