use of com.iCo6.util.org.apache.commons.dbutils.QueryRunner 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.util.org.apache.commons.dbutils.QueryRunner in project Core by iConomy.
the class Database method tableExists.
public boolean tableExists(String table) {
boolean exists = false;
try {
Connection conn = getConnection();
QueryRunner run = new QueryRunner();
try {
String t = Constants.Nodes.DatabaseTable.toString();
exists = run.query(conn, "SELECT id FROM " + table, returnBoolean);
} finally {
DbUtils.close(conn);
}
} catch (SQLException e) {
exists = false;
}
return exists;
}
use of com.iCo6.util.org.apache.commons.dbutils.QueryRunner 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.util.org.apache.commons.dbutils.QueryRunner 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.util.org.apache.commons.dbutils.QueryRunner 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;
}
Aggregations