use of com.iCo6.IO.Database 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.IO.Database 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;
}
use of com.iCo6.IO.Database in project Core by iConomy.
the class Transactions method insert.
/**
* Insert a balance transaction change or update.
*
* @param data Transaction class
*/
public static void insert(Transaction data) {
if (!Constants.Nodes.Logging.getBoolean())
return;
if (Common.matches(iConomy.Database.getType().toString(), "inventorydb", "minidb", "orbdb")) {
Mini database = iConomy.Database.getTransactionDatabase();
if (database == null)
return;
Arguments entry = new Arguments(data.time);
entry.setValue("where", data.where);
entry.setValue("from", data.from);
entry.setValue("to", data.to);
entry.setValue("from_balance", data.fromBalance);
entry.setValue("to_balance", data.toBalance);
entry.setValue("gain", data.gain);
entry.setValue("loss", data.loss);
entry.setValue("set", data.set);
database.addIndex(entry);
database.update();
return;
}
}
Aggregations