Ejemplo n.º 1
1
  public static boolean deleteLumberLog(LumberLog lumberLog) {
    Logger logger = Logger.getLogger("dao");
    boolean status = false;
    StringBuilder delete =
        new StringBuilder("delete from lumberlog where id = " + lumberLog.getId());

    Connection con = null;
    Statement stm = null;

    try {
      con = DataAccess.getInstance().getDatabaseConnection();
      con.setAutoCommit(true);
      stm = con.createStatement();
      logger.info(delete.toString());
      int rez = stm.executeUpdate(delete.toString());
      if (rez > 0) {
        status = true;
        IDPlateManager.addAvailablePlate(lumberLog.getPlate());
      }
    } catch (Exception e) {
      logger.warning(e.getMessage());
      logger.log(Level.INFO, "Error", e);
    } finally {
      if (stm != null)
        try {
          stm.close();
        } catch (Exception e) {
        }
    }

    return status;
  }
Ejemplo n.º 2
1
  public boolean updateStatus(List<Long> lumberLogIds) {
    Logger logger = Logger.getLogger("dao");
    StringBuilder updateSql = new StringBuilder(" update lumberlog set Status = 0 ");
    updateSql.append(" where id in(");
    for (Long id : lumberLogIds) {
      updateSql.append(id).append(",");
    }
    updateSql.deleteCharAt(updateSql.length() - 1);
    updateSql.append(")");

    boolean status = true;

    Connection con = null;
    Statement stm = null;
    try {
      con = DataAccess.getInstance().getDatabaseConnection();
      con.setAutoCommit(true);
      stm = con.createStatement();
      logger.info(updateSql.toString());
      int count = stm.executeUpdate(updateSql.toString());

    } catch (Exception e) {
      status = false;
      logger.warning(e.getMessage());
      logger.log(Level.INFO, "Error", e);
    } finally {
      if (stm != null)
        try {
          stm.close();
        } catch (Exception e) {
        }
    }

    return status;
  }
Ejemplo n.º 3
1
  public static void refreshLumberLog(LumberLog lumberLog) {
    Logger logger = Logger.getLogger("dao");
    StringBuilder lumberLogData =
        new StringBuilder("select diameter, metric from lumberlog_diameter where lumberlog_id = ")
            .append(lumberLog.getId());

    Connection con = null;
    Statement stm = null;
    ResultSet rs = null;
    try {
      con = DataAccess.getInstance().getDatabaseConnection();
      con.setAutoCommit(true);
      stm = con.createStatement();
      logger.info(lumberLogData.toString());
      rs = stm.executeQuery(lumberLogData.toString());
      lumberLog.setMediumRadius(new ArrayList<Double>());
      while (rs.next()) {
        lumberLog.getMediumRadius().add(rs.getDouble(1));
      }
    } catch (Exception e) {
      logger.warning(e.getMessage());
      logger.log(Level.INFO, "Error", e);
    } finally {
      if (rs != null)
        try {
          rs.close();
        } catch (Exception e) {
        }
      if (stm != null)
        try {
          stm.close();
        } catch (Exception e) {
        }
    }
  }
Ejemplo n.º 4
0
  private static ArrayList<Application> select(String whereClause, String[] selectionArgs) {
    ArrayList<Application> applications = new ArrayList<>();
    DataAccess da = new DataAccess();
    SQLiteDatabase db = da.getReadableDB();
    Cursor cursor = null;

    try {
      String query = "Select * From " + TableName + " " + whereClause;
      cursor = db.rawQuery(query, selectionArgs);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          Application app =
              new Application(
                  cursor.getInt(cursor.getColumnIndex(Id)),
                  cursor.getInt(cursor.getColumnIndex(Uid)),
                  cursor.getString(cursor.getColumnIndex(AppName)),
                  cursor.getString(cursor.getColumnIndex(PackageName)),
                  cursor.getInt(cursor.getColumnIndex(Removed)) == 1);
          applications.add(app);
        } while (cursor.moveToNext());
      }
    } catch (MyRuntimeException e) {
      e.printStackTrace();
    } finally {
      if (cursor != null && !cursor.isClosed()) cursor.close();
      if (db != null && db.isOpen()) db.close();
    }
    return applications;
  }
Ejemplo n.º 5
0
 /** Closes and deletes the input files. */
 private void close() {
   str.close();
   dat.close();
   files.delete();
   filed.delete();
   sizes.delete();
 }
Ejemplo n.º 6
0
  private static ArrayList<SystemSetting> select(String whereClause, String[] selectionArgs) {
    ArrayList<SystemSetting> settings = new ArrayList<>();
    DataAccess da = new DataAccess();
    SQLiteDatabase db = da.getReadableDB();
    Cursor cursor = null;

    try {
      String query = "Select * From " + TableName + " " + whereClause;
      cursor = db.rawQuery(query, selectionArgs);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          SystemSetting systemSetting =
              new SystemSetting(
                  cursor.getInt(cursor.getColumnIndex(Id)),
                  cursor.getInt(cursor.getColumnIndex(Installed)) == 1,
                  cursor.getString(cursor.getColumnIndex(RingingToneUri)),
                  cursor.getString(cursor.getColumnIndex(AlarmRingingTone)),
                  cursor.getInt(cursor.getColumnIndex(VibrateInAlarms)) == 1,
                  cursor.getInt(cursor.getColumnIndex(SoundInAlarms)) == 1);
          settings.add(systemSetting);
        } while (cursor.moveToNext());
      }
    } catch (MyRuntimeException e) {
      e.printStackTrace();
    } finally {
      if (cursor != null && !cursor.isClosed()) cursor.close();
      if (db != null && db.isOpen()) db.close();
    }
    return settings;
  }
Ejemplo n.º 7
0
  public boolean setUpvote(int v) {
    StatementHandle hndl;
    String query;

    if (vote == 0) {
      query = "INSERT INTO votes (upvote, uid, sid) VALUES (?, ?, ?)";
      hndl = insert_vote;
    } else {
      query = "UPDATE votes SET upvote = ? WHERE uid = ? AND sid = ?";
      hndl = set_vote;
    }

    ArrayList<Object> args = new ArrayList<Object>();
    args.add(new Integer(v));
    args.add(new Integer(uid));
    args.add(new Integer(sid));

    boolean ret;
    if (vote == 0) ret = DataAccess.createEntry(hndl, query, "id", args) > 0;
    else ret = DataAccess.update(hndl, query, args);
    if (ret) {
      vote = v;
      Solution s = Solution.getSolution(sid);
      s.setScore();
    }

    return ret;
  }
Ejemplo n.º 8
0
  /**
   * Performs a wildcard search for the specified token.
   *
   * @param token token to look for
   * @return iterator
   */
  private synchronized IndexIterator wc(final byte[] token) {
    final FTIndexIterator it = FTIndexIterator.FTEMPTY;
    final FTWildcard wc = new FTWildcard(token);
    if (!wc.parse()) return it;

    final IntList pr = new IntList();
    final IntList ps = new IntList();
    final byte[] pref = wc.prefix();
    final int pl = pref.length, tl = tp.length;
    final int l = Math.min(tl - 1, wc.max());
    for (int ti = pl; ti <= l; ti++) {
      int i = tp[ti];
      if (i == -1) continue;
      int c = ti + 1;
      int e = -1;
      while (c < tl && e == -1) e = tp[c++];
      i = find(pref, i, e, ti);

      while (i < e) {
        final byte[] t = inY.readBytes(i, ti);
        if (!startsWith(t, pref)) break;
        if (wc.match(t)) {
          inZ.cursor(pointer(i, ti));
          final int s = size(i, ti);
          for (int d = 0; d < s; d++) {
            pr.add(inZ.readNum());
            ps.add(inZ.readNum());
          }
        }
        i += ti + ENTRY;
      }
    }
    return iter(new FTCache(pr, ps), token);
  }
Ejemplo n.º 9
0
  /**
   * Determines the pointer on a token.
   *
   * @param token token looking for
   * @return int pointer or {@code -1} if token was not found
   */
  private int token(final byte[] token) {
    final int tl = token.length;
    // left limit
    int l = tp[tl];
    if (l == -1) return -1;

    int i = 1;
    int r;
    // find right limit
    do r = tp[tl + i++];
    while (r == -1);
    final int x = r;

    // binary search
    final int o = tl + ENTRY;
    while (l < r) {
      final int m = l + (r - l >> 1) / o * o;
      final int c = diff(inY.readBytes(m, tl), token);
      if (c == 0) return m;
      if (c < 0) l = m + o;
      else r = m - o;
    }
    // accept entry if pointer is inside relevant tokens
    return r != x && l == r && eq(inY.readBytes(l, tl), token) ? l : -1;
  }
Ejemplo n.º 10
0
  @Override
  protected long index(final int pre, final int id, final byte[] value, final int kind) {
    final DataAccess store;
    final TokenObjMap<IntList> map;
    if (kind == ATTR) {
      store = values;
      map = meta.attrindex ? atvBuffer : null;
    } else {
      store = texts;
      // don't index document names
      map = meta.textindex && kind != DOC ? txtBuffer : null;
    }

    // add text to map to index later
    if (meta.updindex && map != null && value.length <= meta.maxlen) {
      IntList ids = map.get(value);
      if (ids == null) {
        ids = new IntList(1);
        map.put(value, ids);
      }
      ids.add(id);
    }

    // add text to text file
    // inline integer value...
    final long v = toSimpleInt(value);
    if (v != Integer.MIN_VALUE) return v | IO.OFFNUM;

    // store text
    final long off = store.length();
    final byte[] val = COMP.get().pack(value);
    store.writeToken(off, val);
    return val == value ? off : off | IO.OFFCOMP;
  }
Ejemplo n.º 11
0
 @Test
 public void testSegmentSize() {
   DataAccess da = createDataAccess(name);
   da.setSegmentSize(20);
   assertEquals(128, da.getSegmentSize());
   da.close();
 }
Ejemplo n.º 12
0
 void ensureTurnCostsIndex(int nodeIndex) {
   long deltaCap = ((long) nodeIndex + 4) * turnCostsEntryBytes - turnCosts.getCapacity();
   if (deltaCap <= 0) {
     return;
   }
   turnCosts.incCapacity(deltaCap);
 }
Ejemplo n.º 13
0
 @Override
 public Type load(IdType id) {
   log.entering(delegate.getClass().getName(), "load", id);
   try {
     return delegate.load(id);
   } finally {
     log.exiting(delegate.getClass().getName(), "load", id);
   }
 }
Ejemplo n.º 14
0
 @Override
 public int textLen(final int pre, final boolean text) {
   final long o = textOff(pre);
   if (number(o)) return numDigits((int) o);
   final DataAccess da = text ? texts : values;
   final int l = da.readNum(o & IO.OFFCOMP - 1);
   // compressed: next number contains number of compressed bytes
   return compressed(o) ? da.readNum() : l;
 }
Ejemplo n.º 15
0
 @Override
 public void delete(Type entity) {
   log.entering(delegate.getClass().getName(), "delete", entity);
   try {
     delegate.delete(entity);
   } finally {
     log.exiting(delegate.getClass().getName(), "delete", entity);
   }
 }
Ejemplo n.º 16
0
 public static void main(String[] args) {
   TestData td = new TestData();
   td.bookData();
   // td.libraryMemberData();
   td.userData();
   DataAccess da = new DataAccessFacade();
   System.out.println(da.readBooksMap());
   System.out.println(da.readUserMap());
 }
Ejemplo n.º 17
0
  public static long insert(Application application) {
    ContentValues values = new ContentValues();
    values.put(Uid, application.getUid());
    values.put(AppName, application.getAppName());
    values.put(PackageName, application.getPackageName());
    values.put(Removed, application.getRemoved());

    DataAccess da = new DataAccess();
    return da.insert(TableName, values);
  }
Ejemplo n.º 18
0
  @Override
  public boolean loadExisting() {
    if (!turnCosts.loadExisting())
      throw new IllegalStateException(
          "cannot load node costs. corrupt file or directory? " + graph.getDirectory());

    turnCostsEntryBytes = turnCosts.getHeader(0);
    turnCostsCount = turnCosts.getHeader(4);
    return true;
  }
Ejemplo n.º 19
0
 @Test
 public void testExceptionIfNoEnsureCapacityWasCalled() {
   DataAccess da = createDataAccess(name);
   assertFalse(da.loadExisting());
   // throw some undefined exception if no ensureCapacity was called
   try {
     da.setInt(2 * 4, 321);
     assertTrue(false);
   } catch (Exception ex) {
   }
 }
Ejemplo n.º 20
0
 /**
  * Returns an iterator for an index entry.
  *
  * @param off offset on entries
  * @param size number of id/pos entries
  * @param da data source
  * @param token index token
  * @return iterator
  */
 private static FTIndexIterator iter(
     final long off, final int size, final DataAccess da, final byte[] token) {
   da.cursor(off);
   final IntList pr = new IntList(size);
   final IntList ps = new IntList(size);
   for (int c = 0; c < size; c++) {
     pr.add(da.readNum());
     ps.add(da.readNum());
   }
   return iter(new FTCache(pr, ps), token);
 }
Ejemplo n.º 21
0
  public static long update(Application application) {
    ContentValues values = new ContentValues();
    values.put(Uid, application.getUid());
    values.put(AppName, application.getAppName());
    values.put(PackageName, application.getPackageName());
    values.put(Removed, application.getRemoved());

    DataAccess da = new DataAccess();
    return da.update(
        TableName, values, Id + " =? ", new String[] {String.valueOf(application.getId())});
  }
Ejemplo n.º 22
0
 @Test
 public void testRenameNoFlush() {
   DataAccess da = createDataAccess(name);
   da.create(100);
   da.setInt(17 * 4, 17);
   try {
     da.rename(name + "wow");
     assertTrue(false);
   } catch (Exception ex) {
   }
   da.close();
 }
Ejemplo n.º 23
0
 @Override
 public DataAccess copyTo(DataAccess da) {
   for (int h = 0; h < header.length; h++) {
     da.setHeader(h, getHeader(h));
   }
   da.ensureCapacity(capacity());
   long max = capacity() / 4;
   for (long l = 0; l < max; l++) {
     da.setInt(l, getInt(l));
   }
   return da;
 }
Ejemplo n.º 24
0
  @Override
  public synchronized byte[] info(final MainOptions options) {
    final TokenBuilder tb = new TokenBuilder();
    final long l = inX.length() + inY.length() + inZ.length();
    tb.add(LI_NAMES).add(data.meta.ftinclude).add(NL);
    tb.add(LI_SIZE + Performance.format(l, true) + NL);

    final IndexStats stats = new IndexStats(options.get(MainOptions.MAXSTAT));
    addOccs(stats);
    stats.print(tb);
    return tb.finish();
  }
Ejemplo n.º 25
0
  public static long update(SystemSetting setting) {
    ContentValues values = new ContentValues();

    values.put(Installed, setting.getInstalled() ? 1 : 0);
    values.put(RingingToneUri, setting.getRingingToneUri());
    values.put(AlarmRingingTone, setting.getAlarmRingingTone());
    values.put(VibrateInAlarms, setting.getVibrateInAlarms() ? 1 : 0);
    values.put(SoundInAlarms, setting.getSoundInAlarms() ? 1 : 0);

    DataAccess da = new DataAccess();
    return da.update(
        TableName, values, Id + " = ? ", new String[] {String.valueOf(setting.getId())});
  }
Ejemplo n.º 26
0
  @Test
  public void testSet_GetBytes() {
    DataAccess da = createDataAccess(name);
    da.create(300);
    assertEquals(128, da.getSegmentSize());
    byte[] bytes = BitUtil.BIG.fromInt(Integer.MAX_VALUE / 3);
    da.setBytes(8, bytes, bytes.length);
    bytes = new byte[4];
    da.getBytes(8, bytes, bytes.length);
    assertEquals(Integer.MAX_VALUE / 3, BitUtil.BIG.toInt(bytes));

    da.setBytes(127, bytes, bytes.length);
    da.getBytes(127, bytes, bytes.length);
    assertEquals(Integer.MAX_VALUE / 3, BitUtil.BIG.toInt(bytes));

    da.close();

    long bytePos = 4294967296L + 11111;
    int segmentSizePower = 24;
    int segmentSizeInBytes = 1 << segmentSizePower;
    int indexDivisor = segmentSizeInBytes - 1;
    int bufferIndex = (int) (bytePos >>> segmentSizePower);
    int index = (int) (bytePos & indexDivisor);
    assertEquals(256, bufferIndex);
    assertEquals(11111, index);
  }
Ejemplo n.º 27
0
 @Override
 public synchronized void flush(final boolean all) {
   try {
     table.flush(all);
     if (all) {
       write();
       texts.flush();
       values.flush();
       if (textIndex != null) ((DiskValues) textIndex).flush();
       if (attrIndex != null) ((DiskValues) attrIndex).flush();
     }
   } catch (final IOException ex) {
     Util.stack(ex);
   }
 }
Ejemplo n.º 28
0
 @Override
 public synchronized void close() {
   if (closed) return;
   closed = true;
   try {
     write();
     table.close();
     texts.close();
     values.close();
     close(IndexType.TEXT);
     close(IndexType.ATTRIBUTE);
     close(IndexType.FULLTEXT);
   } catch (final IOException ex) {
     Util.stack(ex);
   }
 }
 @Override
 public Skill getById(int id, DataAccess da) throws PersistenceFailureException {
   PreparedStatement statement = null;
   ResultSet resultSet = null;
   Skill skill = null;
   Department department = null;
   String sql =
       "SELECT s.id, s.name, s.department_id, d.name AS department_name, d.parent_id "
           + "FROM skills AS s INNER JOIN departments AS d ON s.department_id = d.id "
           + "WHERE id = 1";
   try {
     statement = da.getConnection().prepareStatement(sql);
     statement.setInt(1, id);
     resultSet = statement.executeQuery();
     if (resultSet.next()) {
       skill = new Skill(resultSet.getInt("id"), resultSet.getString("name"));
       department =
           new Department(
               resultSet.getInt("id"),
               resultSet.getString("department_name"),
               resultSet.getInt("parent_id"));
       skill.setDepartment(department);
     }
     resultSet.close();
     statement.close();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new PersistenceFailureException("Query has failed!");
   }
   return skill;
 }
Ejemplo n.º 30
0
  /**
   * Returns next token.
   *
   * @return byte[] token
   */
  private byte[] token() {
    if (tp[tp.length - 1] == ptok) return EMPTY;
    if (tp[ntl] == ptok || ntl == 0) {
      ++ctl;
      while (tp[ctl] == -1) ++ctl;
      ntl = ctl + 1;
      while (tp[ntl] == -1) ++ntl;
    }
    if (ctl == tp.length) return EMPTY;

    final byte[] t = str.readBytes(ptok, ctl);
    // skip pointer
    size = str.read4(str.cursor() + 5);
    // position will always fit in an integer...
    ptok = (int) str.cursor();
    return t;
  }