コード例 #1
0
ファイル: SqliteDirTreeDb.java プロジェクト: n-i-e/dirtreedb
  @Override
  public void insert(DbPathEntry basedir, PathEntry newentry)
      throws SQLException, InterruptedException {
    String sql = null;
    try {
      if (basedir == null) { // root folder
        PreparedStatement ps;
        sql =
            "INSERT INTO directory (parentid, datelastmodified, size, compressedsize, path, type, status, duplicate, dedupablesize) VALUES (0, ?, 0, 0, ?, 0, 1, 0, 0)";
        ps = conn.prepareStatement(sql);
        ps.setTimestamp(1, new Timestamp(new Date().getTime()));
        ps.setString(2, newentry.getPath());
        ps.executeUpdate();

        sql = "UPDATE directory SET rootid=pathid WHERE rootid IS NULL AND pathid IS NOT NULL";
        ps = conn.prepareStatement(sql);
        ps.executeUpdate();
        ps.close();
      } else {
        assert (basedir
            .getPath()
            .equals(newentry.getPath().substring(0, basedir.getPath().length())));
        PreparedStatement ps;
        if (newentry.isCsumNull()) {
          sql =
              "INSERT INTO directory (parentid, rootid, datelastmodified, size, compressedsize, path, type, status, duplicate, dedupablesize) VALUES (?, ?, ?, ?, ?, ?, ?, 1, 0, 0)";
          ps = conn.prepareStatement(sql);
        } else {
          sql =
              "INSERT INTO directory (parentid, rootid, datelastmodified, size, compressedsize, path, type, status, duplicate, dedupablesize, csum) VALUES (?, ?, ?, ?, ?, ?, ?, 1, 0, 0, ?)";
          ps = conn.prepareStatement(sql);
          ps.setInt(8, newentry.getCsum());
        }
        ps.setLong(1, basedir.getPathId());
        ps.setLong(2, basedir.getRootId());
        Date d = new Date(newentry.getDateLastModified());
        ps.setString(3, sdf.format(d));
        ps.setLong(4, newentry.getSize());
        ps.setLong(5, newentry.getCompressedSize());
        ps.setString(6, newentry.getPath());
        ps.setInt(7, newentry.getType());
        ps.executeUpdate();
        ps.close();
      }
    } catch (SQLException e) {
      if (sql != null) {
        Debug.writelog("!! SQL insert failed at CommonSqlDirTreeDB for: " + sql);
        Debug.writelog("newentry.path = " + newentry.getPath());
        if (basedir != null) {
          Debug.writelog("basedir.path = " + basedir.getPath());
        }
      }
      throw e;
    }
  }
コード例 #2
0
ファイル: SqliteDirTreeDb.java プロジェクト: n-i-e/dirtreedb
 @Override
 public void insertEquality(long pathid1, long pathid2, long size, int csum)
     throws SQLException, InterruptedException {
   PreparedStatement ps =
       prepareStatement(
           "INSERT INTO equality (pathid1, pathid2, size, csum, datelasttested) VALUES (?, ?, ?, ?, ?)");
   try {
     if (pathid1 > pathid2) {
       ps.setLong(1, pathid1);
       ps.setLong(2, pathid2);
     } else {
       ps.setLong(1, pathid2);
       ps.setLong(2, pathid1);
     }
     ps.setLong(3, size);
     ps.setInt(4, csum);
     Date d = new Date();
     ps.setString(5, sdf.format(d));
     ps.executeUpdate();
   } catch (SQLException e) {
     Debug.writelog("SQLException at addEquality: pathid1=" + pathid1 + ", pathid2=" + pathid2);
     throw e;
   } finally {
     ps.close();
   }
 }