Ejemplo n.º 1
0
    /**
     * Find the record with the specified primary keys
     *
     * @return DataPoint or null if no record is found
     */
    public DataPoint find(int id) {
      DataPoint rec = new DataPoint();

      // Create temp object and look in cache for it
      ((DataPoint_base) rec).initialize(id);
      rec = (DataPoint) GenOrmDataSource.getGenOrmConnection().getCachedRecord(rec.getRecordKey());

      java.sql.PreparedStatement genorm_statement = null;
      java.sql.ResultSet genorm_rs = null;

      if (rec == null) {
        try {
          // No cached object so look in db
          genorm_statement = GenOrmDataSource.prepareStatement(SELECT + FROM + KEY_WHERE);
          genorm_statement.setInt(1, id);

          s_logger.debug(genorm_statement.toString());

          genorm_rs = genorm_statement.executeQuery();
          if (genorm_rs.next()) rec = newDataPoint(genorm_rs);
        } catch (java.sql.SQLException sqle) {
          throw new GenOrmException(sqle);
        } finally {
          try {
            if (genorm_rs != null) genorm_rs.close();

            if (genorm_statement != null) genorm_statement.close();
          } catch (java.sql.SQLException sqle2) {
            throw new GenOrmException(sqle2);
          }
        }
      }

      return (rec);
    }
Ejemplo n.º 2
0
    /** Creates a new entry with the specified primary keys. */
    public DataPoint create(int id) {
      DataPoint rec = new DataPoint();
      rec.m_isNewRecord = true;

      ((DataPoint_base) rec).setId(id);

      return ((DataPoint) GenOrmDataSource.getGenOrmConnection().getUniqueRecord(rec));
    }
Ejemplo n.º 3
0
    /**
     * If the table has a primary key that has a key generator this method will return a new table
     * entry with a generated primary key.
     *
     * @return DataPoint with generated primary key
     */
    public DataPoint createWithGeneratedKey() {
      DataPoint rec = new DataPoint();

      rec.m_isNewRecord = true;

      GenOrmKeyGenerator keyGen = GenOrmDataSource.getKeyGenerator("data_point");
      if (keyGen != null) {
        rec.setId((Integer) keyGen.generateKey());
      }

      return ((DataPoint) GenOrmDataSource.getGenOrmConnection().getUniqueRecord(rec));
    }
Ejemplo n.º 4
0
    /**
     * Deletes the record with the specified primary keys. The point of this api is to prevent a hit
     * on the db to see if the record is there. This call will add a record to the next transaction
     * that is marked for delete.
     *
     * @return Returns true if the record was previous created and existed either in the transaction
     *     cache or the db.
     */
    public boolean delete(int id) {
      boolean ret = false;
      DataPoint rec = new DataPoint();

      ((DataPoint_base) rec).initialize(id);
      GenOrmConnection con = GenOrmDataSource.getGenOrmConnection();
      DataPoint cachedRec = (DataPoint) con.getCachedRecord(rec.getRecordKey());

      if (cachedRec != null) {
        ret = true;
        cachedRec.delete();
      } else {
        rec = (DataPoint) con.getUniqueRecord(rec); // This adds the record to the cache
        rec.delete();
        ret = rec.flush();
        rec.setIgnored(true); // So the system does not try to delete it again at commmit
      }

      return (ret);
    }
Ejemplo n.º 5
0
    /** Creates a new entry that is empty */
    public DataPoint createRecord() {
      DataPoint rec = new DataPoint();
      rec.m_isNewRecord = true;

      return ((DataPoint) GenOrmDataSource.getGenOrmConnection().getUniqueRecord(rec));
    }