@Override
  public List<QuotaUpdate> findLimited(int limit) throws StorageException {
    ArrayList<QuotaUpdate> resultList;
    try {
      Connection conn = mysqlConnector.obtainSession();
      PreparedStatement s = conn.prepareStatement(FIND_QUERY + limit);
      ResultSet result = s.executeQuery();
      resultList = new ArrayList<QuotaUpdate>();

      while (result.next()) {
        int id = result.getInt(ID);
        int inodeId = result.getInt(INODE_ID);
        int namespaceDelta = result.getInt(NAMESPACE_DELTA);
        long diskspaceDelta = result.getLong(DISKSPACE_DELTA);
        resultList.add(new QuotaUpdate(id, inodeId, namespaceDelta, diskspaceDelta));
      }
    } catch (SQLException ex) {
      throw HopsSQLExceptionHelper.wrap(ex);
    } finally {
      mysqlConnector.closeSession();
    }
    return resultList;
  }
public class QuotaUpdateClusterj
    implements TablesDef.QuotaUpdateTableDef, QuotaUpdateDataAccess<QuotaUpdate> {

  @PersistenceCapable(table = TABLE_NAME)
  public interface QuotaUpdateDTO {

    @PrimaryKey
    @Column(name = ID)
    int getId();

    void setId(int id);

    @PrimaryKey
    @Column(name = INODE_ID)
    int getInodeId();

    void setInodeId(int id);

    @Column(name = NAMESPACE_DELTA)
    long getNamespaceDelta();

    void setNamespaceDelta(long namespaceDelta);

    @Column(name = DISKSPACE_DELTA)
    long getDiskspaceDelta();

    void setDiskspaceDelta(long diskspaceDelta);
  }

  private ClusterjConnector connector = ClusterjConnector.getInstance();
  private MysqlServerConnector mysqlConnector = MysqlServerConnector.getInstance();

  @Override
  public void prepare(Collection<QuotaUpdate> added, Collection<QuotaUpdate> removed)
      throws StorageException {
    HopsSession session = connector.obtainSession();
    List<QuotaUpdateDTO> changes = new ArrayList<QuotaUpdateDTO>();
    List<QuotaUpdateDTO> deletions = new ArrayList<QuotaUpdateDTO>();
    if (removed != null) {
      for (QuotaUpdate update : removed) {
        QuotaUpdateDTO persistable = createPersistable(update, session);
        deletions.add(persistable);
      }
    }
    if (added != null) {
      for (QuotaUpdate update : added) {
        QuotaUpdateDTO persistable = createPersistable(update, session);
        changes.add(persistable);
      }
    }
    session.deletePersistentAll(deletions);
    session.savePersistentAll(changes);

    session.release(deletions);
    session.release(changes);
  }

  private static final String FIND_QUERY =
      "SELECT * FROM " + TABLE_NAME + " ORDER BY " + ID + " LIMIT ";

  @Override
  public List<QuotaUpdate> findLimited(int limit) throws StorageException {
    ArrayList<QuotaUpdate> resultList;
    try {
      Connection conn = mysqlConnector.obtainSession();
      PreparedStatement s = conn.prepareStatement(FIND_QUERY + limit);
      ResultSet result = s.executeQuery();
      resultList = new ArrayList<QuotaUpdate>();

      while (result.next()) {
        int id = result.getInt(ID);
        int inodeId = result.getInt(INODE_ID);
        int namespaceDelta = result.getInt(NAMESPACE_DELTA);
        long diskspaceDelta = result.getLong(DISKSPACE_DELTA);
        resultList.add(new QuotaUpdate(id, inodeId, namespaceDelta, diskspaceDelta));
      }
    } catch (SQLException ex) {
      throw HopsSQLExceptionHelper.wrap(ex);
    } finally {
      mysqlConnector.closeSession();
    }
    return resultList;
  }

  private QuotaUpdateDTO createPersistable(QuotaUpdate update, HopsSession session)
      throws StorageException {
    QuotaUpdateDTO dto = session.newInstance(QuotaUpdateDTO.class);
    dto.setId(update.getId());
    dto.setInodeId(update.getInodeId());
    dto.setNamespaceDelta(update.getNamespaceDelta());
    dto.setDiskspaceDelta(update.getDiskspaceDelta());
    return dto;
  }

  private List<QuotaUpdate> convertAndRelease(HopsSession session, List<QuotaUpdateDTO> list)
      throws StorageException {
    List<QuotaUpdate> result = new ArrayList<QuotaUpdate>();
    for (QuotaUpdateDTO dto : list) {
      result.add(
          new QuotaUpdate(
              dto.getId(), dto.getInodeId(), dto.getNamespaceDelta(), dto.getDiskspaceDelta()));
      session.release(dto);
    }
    return result;
  }

  private static final String INODE_ID_PARAM = "inodeId";

  @Override
  public List<QuotaUpdate> findByInodeId(int inodeId) throws StorageException {
    HopsSession session = connector.obtainSession();
    HopsQueryBuilder qb = session.getQueryBuilder();
    HopsQueryDomainType<QuotaUpdateDTO> dobj = qb.createQueryDefinition(QuotaUpdateDTO.class);
    HopsPredicate pred1 = dobj.get("inodeId").equal(dobj.param(INODE_ID_PARAM));
    dobj.where(pred1);
    HopsQuery<QuotaUpdateDTO> query = session.createQuery(dobj);
    query.setParameter(INODE_ID_PARAM, inodeId);

    List<QuotaUpdateDTO> results = query.getResultList();
    return convertAndRelease(session, results);
  }
}