Search in sources :

Example 11 with Database

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) QueryRunner(com.iCo6.util.org.apache.commons.dbutils.QueryRunner)

Example 12 with Database

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) QueryRunner(com.iCo6.util.org.apache.commons.dbutils.QueryRunner)

Example 13 with Database

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;
    }
}
Also used : Mini(com.iCo6.IO.mini.Mini) Arguments(com.iCo6.IO.mini.Arguments)

Aggregations

QueryRunner (com.iCo6.util.org.apache.commons.dbutils.QueryRunner)12 Connection (java.sql.Connection)12 SQLException (java.sql.SQLException)12 Player (org.bukkit.entity.Player)4 Arguments (com.iCo6.IO.mini.Arguments)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Drivers (com.iCo6.Constants.Drivers)1 Database (com.iCo6.IO.Database)1 Type (com.iCo6.IO.Database.Type)1 MissingDriver (com.iCo6.IO.exceptions.MissingDriver)1 Mini (com.iCo6.IO.mini.Mini)1 com.iCo6.listeners.players (com.iCo6.listeners.players)1 Account (com.iCo6.system.Account)1 Interest (com.iCo6.system.Interest)1 Template (com.iCo6.util.Template)1 ResultSetHandler (com.iCo6.util.org.apache.commons.dbutils.ResultSetHandler)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1