public int updateEntry(
      int id, String key, String value, String uris, String files, double[] location) {
    int retval;

    if (mDatabase == null) {
      retval = -1;
    } else {
      ContentValues values = new ContentValues();

      try {
        values.put(Database.C_KEY, Encryption.encrypt(mPassword, key));
        values.put(Database.C_VALUE, Encryption.encrypt(mPassword, value));
        values.put(Database.C_IMG_URI, Encryption.encrypt(mPassword, uris));
        values.put(Database.C_FILES, Encryption.encrypt(mPassword, files));
        values.put(Database.C_LAT, Encryption.encrypt(mPassword, Double.toString(location[0])));
        values.put(Database.C_LONG, Encryption.encrypt(mPassword, Double.toString(location[1])));
        values.put(Database.C_DATE, String.valueOf(System.currentTimeMillis()));
      } catch (Exception e) {
        return -1;
      }

      retval = mDatabase.update(Database.TABLE_NAME, id, values);
    }

    return retval;
  }
Example #2
0
  public void true_insert() throws Exception {
    // synchronized(variavel) {

    Database db = new Database();
    db.connect();
    // BEGIN WORK -> stored procedure
    db.update(
        "insert into tbNews (tmsp, headline, body, email) values ('"
            + this.tmsp
            + "', '"
            + this.headline
            + "', '"
            + this.body
            + "', '"
            + this.email
            + "')");
    ResultSet rs = db.query("select max(id) as id from tbNews");
    if (rs.next()) {
      this.id = rs.getInt("id");
    }
    // COMMIT

    db.close();

    // }
  }
Example #3
0
  public void remove() throws Exception {
    Database db = new Database();
    db.connect();

    db.update("delete from page where url = '" + url + "'");

    db.close();
  }
Example #4
0
  public void update() throws Exception {
    Database db = new Database();
    db.connect();

    db.update(
        "update page set tmsp = '" + tmsp + "', body = '" + body + "' where url = '" + url + "'");
    // URLEncoder.encode(url, "UTF-8")+"'");
    // URLEncoder.encode(url, "ISO-8859-1")+"'");

    db.close();
  }
Example #5
0
  // sqllers
  public void insert() throws Exception {
    Database db = new Database();
    db.connect();

    db.update(
        "insert into page (tmsp, url, body) values ('"
            + tmsp
            + "', '"
            + url
            + "', '"
            + body
            + "')");

    db.close();
  }
Example #6
0
 private static Connection createConnection() {
   Connection con = new ConnectionNonClosing(DatabaseCreator.nextConnection());
   Database db = Database.from(con);
   // insert another 1000 people
   db.update("insert into person(name, score) values(?,?)")
       .parameters(
           Observable.range(1, 1000)
               .concatMap(
                   new Func1<Integer, Observable<Object>>() {
                     @Override
                     public Observable<Object> call(Integer n) {
                       return Observable.<Object>just("person" + n, n);
                     }
                   }));
   return con;
 }
Example #7
0
 public void update() throws Exception {
   Database db = new Database();
   db.connect();
   db.update(
       "update tbNews set tmsp = '"
           + this.tmsp
           + "', headline = '"
           + this.headline
           + "', body = '"
           + this.body
           + "', email = '"
           + this.email
           + "' where id = "
           + this.id);
   db.close();
 }
  @Override
  public void init(Database db, int size) throws SQLException {
    this.database = db;
    transactions = size * 6;

    int scale = 2;
    accounts = size * 30;
    tellers = Math.max(accounts / 10, 1);
    branches = Math.max(tellers / 10, 1);

    db.start(this, "Init");

    db.openConnection();

    db.dropTable("BRANCHES");
    db.dropTable("TELLERS");
    db.dropTable("ACCOUNTS");
    db.dropTable("HISTORY");

    String[] create = {
      "CREATE TABLE BRANCHES(BID INT NOT NULL PRIMARY KEY, "
          + "BBALANCE DECIMAL(15,2), FILLER VARCHAR(88))",
      "CREATE TABLE TELLERS(TID INT NOT NULL PRIMARY KEY, "
          + "BID INT, TBALANCE DECIMAL(15,2), FILLER VARCHAR(84))",
      "CREATE TABLE ACCOUNTS(AID INT NOT NULL PRIMARY KEY, "
          + "BID INT, ABALANCE DECIMAL(15,2), FILLER VARCHAR(84))",
      "CREATE TABLE HISTORY(TID INT, "
          + "BID INT, AID INT, DELTA DECIMAL(15,2), HTIME DATETIME, "
          + "FILLER VARCHAR(40))"
    };

    for (String sql : create) {
      db.update(sql);
    }

    PreparedStatement prep;
    db.setAutoCommit(false);
    int commitEvery = 1000;
    prep =
        db.prepare(
            "INSERT INTO BRANCHES(BID, BBALANCE, FILLER) "
                + "VALUES(?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < branches * scale; i++) {
      prep.setInt(1, i);
      db.update(prep, "insertBranches");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    prep =
        db.prepare(
            "INSERT INTO TELLERS(TID, BID, TBALANCE, FILLER) "
                + "VALUES(?, ?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < tellers * scale; i++) {
      prep.setInt(1, i);
      prep.setInt(2, i / tellers);
      db.update(prep, "insertTellers");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    int len = accounts * scale;
    prep =
        db.prepare(
            "INSERT INTO ACCOUNTS(AID, BID, ABALANCE, FILLER) "
                + "VALUES(?, ?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < len; i++) {
      prep.setInt(1, i);
      prep.setInt(2, i / accounts);
      db.update(prep, "insertAccounts");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    db.closeConnection();
    db.end();

    //        db.start(this, "Open/Close");
    //        db.openConnection();
    //        db.closeConnection();
    //        db.end();
  }
  private void processTransactions() throws SQLException {
    Random random = database.getRandom();
    int branch = random.nextInt(branches);
    int teller = random.nextInt(tellers);

    PreparedStatement updateAccount =
        database.prepare("UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
    PreparedStatement selectBalance = database.prepare("SELECT ABALANCE FROM ACCOUNTS WHERE AID=?");
    PreparedStatement updateTeller =
        database.prepare("UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?");
    PreparedStatement updateBranch =
        database.prepare("UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?");
    PreparedStatement insertHistory =
        database.prepare(
            "INSERT INTO HISTORY(AID, TID, BID, DELTA, HTIME, FILLER) "
                + "VALUES(?, ?, ?, ?, ?, ?)");
    int accountsPerBranch = accounts / branches;
    database.setAutoCommit(false);

    for (int i = 0; i < transactions; i++) {
      int account;
      if (random.nextInt(100) < 85) {
        account = random.nextInt(accountsPerBranch) + branch * accountsPerBranch;
      } else {
        account = random.nextInt(accounts);
      }
      int max = BenchA.DELTA;
      // delta: -max .. +max

      BigDecimal delta = BigDecimal.valueOf(random.nextInt(max * 2) - max);
      long current = System.currentTimeMillis();

      updateAccount.setBigDecimal(1, delta);
      updateAccount.setInt(2, account);
      database.update(updateAccount, "updateAccount");

      updateTeller.setBigDecimal(1, delta);
      updateTeller.setInt(2, teller);
      database.update(updateTeller, "updateTeller");

      updateBranch.setBigDecimal(1, delta);
      updateBranch.setInt(2, branch);
      database.update(updateBranch, "updateBranch");

      selectBalance.setInt(1, account);
      database.queryReadResult(selectBalance);

      insertHistory.setInt(1, account);
      insertHistory.setInt(2, teller);
      insertHistory.setInt(3, branch);
      insertHistory.setBigDecimal(4, delta);
      // TODO convert: should be able to convert date to timestamp
      // (by using 0 for remaining fields)
      // insertHistory.setDate(5, new java.sql.Date(current));
      insertHistory.setTimestamp(5, new java.sql.Timestamp(current));
      insertHistory.setString(6, BenchA.FILLER);
      database.update(insertHistory, "insertHistory");

      database.commit();
    }
    updateAccount.close();
    selectBalance.close();
    updateTeller.close();
    updateBranch.close();
    insertHistory.close();
  }
 /**
  * Update this entity in the database.
  *
  * @return The number of rows affected
  * @throws NoSuchFieldException
  */
 public int update() throws ActiveRecordException {
   ContentValues values = createContentValues();
   int r =
       m_Database.update(getTableName(), values, "_id = ?", new String[] {String.valueOf(_id)});
   return r;
 }
Example #11
0
 public void remove() throws Exception {
   Database db = new Database();
   db.connect();
   db.update("delete from tbNews where id = " + this.id);
   db.close();
 }