use of com.iCo6.IO.Database in project Core by iConomy.
the class MoneyComparator method accountList.
static List<String> accountList() {
List<String> accounts = new ArrayList<String>();
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
if (useInventoryDB())
accounts.addAll(inventory.getAllPlayers());
if (useOrbDB())
for (Player p : iConomy.Server.getOnlinePlayers()) accounts.add(p.getName());
accounts.addAll(database.getIndices().keySet());
return accounts;
}
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
accounts = run.query(c, "SELECT username FROM " + t, 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);
}
return accounts;
}
use of com.iCo6.IO.Database in project Core by iConomy.
the class MoneyComparator method doInterest.
static void doInterest(final String query, LinkedHashMap<String, HashMap<String, Object>> queries) {
final Object[][] parameters = new Object[queries.size()][2];
int i = 0;
for (String name : queries.keySet()) {
double balance = (Double) queries.get(name).get("balance");
double original = 0.0, gain = 0.0, loss = 0.0;
if (Constants.Nodes.Logging.getBoolean()) {
original = getBalance(name);
gain = balance - original;
loss = original - balance;
}
// We are using a query for MySQL
if (!useInventoryDB() && !useMiniDB() && !useOrbDB()) {
parameters[i][0] = balance;
parameters[i][1] = name;
i++;
} else if (useMiniDB()) {
if (!hasAccount(name))
continue;
database.setArgument(name, "balance", balance);
database.update();
} else if (useInventoryDB()) {
if (inventory.dataExists(name))
inventory.setBalance(name, balance);
else if (database.hasIndex(name)) {
database.setArgument(name, "balance", balance);
database.update();
}
} else if (useOrbDB()) {
if (!hasAccount(name))
continue;
Player gainer = iConomy.Server.getPlayer(name);
if (gainer != null)
setBalance(name, balance);
}
if (Constants.Nodes.Logging.getBoolean()) {
if (gain < 0.0)
gain = 0.0;
if (loss < 0.0)
loss = 0.0;
Transactions.insert(new Transaction("Interest", "System", name).setFromBalance(original).setToBalance(balance).setGain(gain).setLoss(loss).setSet(balance));
}
}
if (!useInventoryDB() && !useMiniDB() && !useOrbDB())
Thrun.init(new Runnable() {
public void run() {
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
run.batch(c, query, parameters);
} catch (SQLException ex) {
System.out.println("[iConomy] Error with batching: " + ex);
} finally {
DbUtils.close(c);
}
} catch (SQLException ex) {
System.out.println("[iConomy] Database Error: " + ex);
}
}
});
}
use of com.iCo6.IO.Database in project Core by iConomy.
the class MoneyComparator method removeAccount.
static boolean removeAccount(String name) {
Boolean removed = false;
if (useMiniDB() || useInventoryDB() || useOrbDB()) {
if (database.hasIndex(name)) {
database.removeIndex(name);
database.update();
return true;
}
return false;
}
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
Integer amount = run.update(c, "DELETE FROM " + t + " WHERE username=?", name.toLowerCase());
if (amount > 0)
removed = true;
} 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 removed;
}
use of com.iCo6.IO.Database in project Core by iConomy.
the class MoneyComparator method getStatus.
static Integer getStatus(String name) {
int status = 0;
if (!hasAccount(name))
return -1;
if (useMiniDB())
return database.getArguments(name).getInteger("status");
if (useInventoryDB())
return (inventory.dataExists(name)) ? 1 : (database.hasIndex(name)) ? database.getArguments(name).getInteger("status") : 0;
if (useOrbDB())
return (iConomy.Server.getPlayer(name) != null) ? 1 : (database.hasIndex(name)) ? database.getArguments(name).getInteger("status") : 0;
try {
QueryRunner run = new QueryRunner();
Connection c = iConomy.Database.getConnection();
try {
String t = Constants.Nodes.DatabaseTable.toString();
status = run.query(c, "SELECT status FROM " + t + " WHERE username=?", returnStatus, 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 status;
}
use of com.iCo6.IO.Database 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;
}
Aggregations