Package com.jbidwatcher.util

Examples of com.jbidwatcher.util.Record


  public void testInsertData() throws Exception {
    Table t = new Table("categories");
    mSavepoint = t.getDB().getConnection().setSavepoint();
    assert(t.execute("DELETE FROM categories"));
    Record r = new Record();
    r.put("id", "1");
    r.put("name", "zarf");
    t.storeMap(r);
    List<Record> recs = t.findAll();
    for(Record rec : recs) {
      HashBacked h = new HashBacked(rec);
      System.err.println(h.dumpRecord());
View Full Code Here


  private static Database dbMigrate() throws IllegalAccessException, SQLException, ClassNotFoundException, InstantiationException {
    Table schemaInfo = new Table("schema_info");
    List<Record> info = schemaInfo.findAll();
    if(info != null) {
      Record first = info.get(0);
      HashBacked record = new HashBacked(first);
      int version = record.getInteger("version", -1);
      if(version != -1) {
        int last_version = version;
        version++;
View Full Code Here

  protected static ActiveRecord findFirstBySQL(Class klass, String query) {
    if(sDBDisabled) return null;
    ActiveRecord found = getExemplar(klass);
    Table t = getTable(found);
    Record result = t.findFirstBy(query);
    if (result != null && !result.isEmpty()) {
      found.setBacking(result);
    } else {
      found = null;
    }
    return found;
View Full Code Here

  protected static ActiveRecord findFirstByUncached(Class klass, String key, String value) {
    if(sDBDisabled) return null;
    ActiveRecord found = getExemplar(klass);
    Table t = getTable(found);
    Record result = t.findFirstBy(key, value);
    if (result != null && !result.isEmpty()) {
      found.setBacking(result);
    } else {
      found = null;
    }
    return found;
View Full Code Here

  private ResultSet execute(PreparedStatement ps) throws SQLException {
    return ps.executeQuery();
  }

  private Record getFirstResult(ResultSet rs) throws SQLException {
    Record rval = new Record();
    ResultSetMetaData rsm = rs.getMetaData();
    if (rsm != null) {
      if (rs.next()) {
        for (int i = 1; i <= rsm.getColumnCount(); i++) {
          rval.put(rs.getMetaData().getColumnName(i).toLowerCase(), rs.getString(i));
        }
      }
    }
    rs.close();
    return rval;
View Full Code Here

  private List<Record> getAllResults(ResultSet rs) throws SQLException {
    ArrayList<Record> rval = new ArrayList<Record>();
    ResultSetMetaData rsm = rs.getMetaData();
    if (rsm != null) {
      while(rs.next()) {
        Record row = new Record();
        for (int i = 1; i <= rsm.getColumnCount(); i++) {
          row.put(rs.getMetaData().getColumnName(i).toLowerCase(), rs.getString(i));
        }
        rval.add(row);
      }
    }
    rs.close();
View Full Code Here

    if(value != null && value.length() == 0) value = null;
    return updateMap(mTableName, "id", value, row);
  }

  public String updateMap(String tableName, String columnKey, String value, Record newRow) {
    Record oldRow = null;
    if(value != null) {
      oldRow = getRow(tableName, columnKey, value, true);
    }
    newRow = cleanRow(newRow);
View Full Code Here

    }
    return null;
  }

  private Record cleanRow(Record newRow) {
    Record cleanedNewRow = new Record();
    for(String column : newRow.keySet()) {
      if(hasColumn(column)) {
        cleanedNewRow.put(column, newRow.get(column));
      }
    }
    newRow = cleanedNewRow;
    return newRow;
  }
View Full Code Here

  public Record findByColumn(String columnKey, String value, boolean forUpdate) {
    return getRow(mTableName, columnKey, value, forUpdate);
  }

  private Record getRow(String tableName, String columnKey, String value, boolean forUpdate) {
    Record oldRow = null;

    try {
      String statement = "SELECT * FROM " + tableName;
      statement += " WHERE " + columnKey + " = ?";
      if (forUpdate) statement += " FOR UPDATE";
View Full Code Here

  }

  private String findKeys(PreparedStatement ps) throws SQLException {
    ResultSet rs = ps.getGeneratedKeys();
    if(rs != null) {
      Record insertMap = getFirstResult(rs);
      if (insertMap.containsKey("1")) {
        return insertMap.get("1");
      } else if(insertMap.containsKey("generated_key")) {
        return insertMap.get("generated_key");
      } else if(insertMap.values().size() == 1) {
        return insertMap.values().toArray()[0].toString();
      }
    }
    return "";
  }
View Full Code Here

TOP

Related Classes of com.jbidwatcher.util.Record

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.