use of com.iCo6.util.org.apache.commons.dbutils.QueryRunner in project Core by iConomy.
the class MoneyComparator method topAccounts.
static List<Account> topAccounts(int amount) {
Accounts Accounts = new Accounts();
List<Account> accounts = new ArrayList<Account>();
List<Account> finals = new ArrayList<Account>();
List<String> total = new ArrayList<String>();
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
if (useInventoryDB())
total.addAll(inventory.getAllPlayers());
if (useOrbDB())
for (Player p : iConomy.Server.getOnlinePlayers()) total.add(p.getName());
total.addAll(database.getIndices().keySet());
} else {
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
total = run.query(c, "SELECT username FROM " + t + " WHERE status <> 1 ORDER BY balance DESC LIMIT " + amount, returnList);
} catch (SQLException ex) {
System.out.println("[iConomy] Error issueing SQL query: " + ex);
} finally {
DbUtils.close(c);
}
} catch (SQLException ex) {
System.out.println("[iConomy] Database Error: " + ex);
}
}
for (Iterator<String> it = total.iterator(); it.hasNext(); ) {
String player = it.next();
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
accounts.add(Accounts.get(player));
} else {
finals.add(new Account(player));
}
}
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
Collections.sort(accounts, new MoneyComparator());
if (amount > accounts.size())
amount = accounts.size();
for (int i = 0; i < amount; i++) {
if (accounts.get(i).getStatus() == 1) {
i--;
continue;
}
finals.add(accounts.get(i));
}
}
return finals;
}
use of com.iCo6.util.org.apache.commons.dbutils.QueryRunner in project Core by iConomy.
the class MoneyComparator method getBalance.
static double getBalance(String name) {
Double balance = Constants.Nodes.Balance.getDouble();
if (!hasAccount(name))
return balance;
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
if (useInventoryDB())
if (inventory.dataExists(name))
return inventory.getBalance(name);
if (useOrbDB())
if (iConomy.Server.getPlayer(name) != null)
return iConomy.Server.getPlayer(name).getTotalExperience();
if (database.hasIndex(name))
return database.getArguments(name).getDouble("balance");
return balance;
}
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
balance = run.query(c, "SELECT balance FROM " + t + " WHERE username=?", returnBalance, name.toLowerCase());
} catch (SQLException ex) {
System.out.println("[iConomy] Error issueing SQL query: " + ex);
} finally {
DbUtils.close(c);
}
} catch (SQLException ex) {
System.out.println("[iConomy] Database Error: " + ex);
}
return balance;
}
use of com.iCo6.util.org.apache.commons.dbutils.QueryRunner in project Core by iConomy.
the class MoneyComparator method hasAccount.
static boolean hasAccount(String name) {
Boolean exists = false;
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
if (useInventoryDB())
if (inventory.dataExists(name))
return true;
if (useOrbDB())
if (iConomy.Server.getPlayer(name) != null)
return true;
return database.hasIndex(name);
}
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
exists = run.query(c, "SELECT id FROM " + t + " WHERE username=?", returnBoolean, name.toLowerCase());
} catch (SQLException ex) {
System.out.println("[iConomy] Error issueing SQL query: " + ex);
} finally {
DbUtils.close(c);
}
} catch (SQLException ex) {
System.out.println("[iConomy] Database Error: " + ex);
}
return exists;
}
Aggregations