Package com.almworks.sqlite4java

Examples of com.almworks.sqlite4java.SQLiteStatement


      }).complete();
  }
  public void addHiveSupport(final Path fpath, final String tablename) {
    dbQueue.execute(new SQLiteJob<Object>() {
        protected Object job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("INSERT into HiveTables VALUES(?, ?)");
          try {
            stmt.bind(1, fpath.toString());
            stmt.bind(2, tablename);
            stmt.step();
            return null;
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here


    // REMIND -- must check to make sure FS is valid before accepting it.
    // (E.g., for HDFS see if we can contact it)
   
    long fsid = dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("SELECT fsid FROM Filesystems WHERE fsname = ?");
          try {
            stmt.bind(1, fsuri.toString());
            if (stmt.step()) {
              long resultId = stmt.columnLong(0);
              return resultId;
            } else {
              return -1L;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
    if (fsid >= 0) {
      return fsid;
    }

    // It wasn't there, so create it!
    if (canCreate) {
      return dbQueue.execute(new SQLiteJob<Long>() {
          protected Long job(SQLiteConnection db) throws SQLiteException {
            SQLiteStatement stmt = db.prepare("INSERT into Filesystems VALUES(null, ?)");
            try {
              stmt.bind(1, fsuri.toString());
              stmt.step();
              return db.getLastInsertId();
            } finally {
              stmt.dispose();
            }
          }
        }).complete();
    } else {
      return -1L;
View Full Code Here

   * If no crawl is pending, a new one is created.
   */
  public long getCreatePendingCrawl(final long fsid, boolean shouldCreate)  {
      long crawlid = dbQueue.execute(new SQLiteJob<Long>() {
          protected Long job(SQLiteConnection db) throws SQLiteException {
            SQLiteStatement stmt = db.prepare("SELECT crawlid from Crawls WHERE fsid = ? AND inprogress = 'True'");
            try {
              stmt.bind(1, fsid);
              if (stmt.step()) {
                return stmt.columnLong(0);
              } else {
                return -1L;
              }
            } finally {
              stmt.dispose();
            }
          }
        }).complete();

      if (crawlid >= 0) {
        return crawlid;
      }
   
      // Time to insert
      if (shouldCreate) {
        return dbQueue.execute(new SQLiteJob<Long>() {
            protected Long job(SQLiteConnection db) throws SQLiteException {
              Date now = new Date(System.currentTimeMillis());
              String dateCreated = fileDateFormat.format(now);
              String syntheticDateFinished = fileDateFormat.format(new Date(0));
              String inprogress = "True";
              SQLiteStatement stmt = db.prepare("INSERT into Crawls VALUES(null, ?, ?, ?, ?)");
              try {
                stmt.bind(1, dateCreated).bind(2, syntheticDateFinished).bind(3, inprogress).bind(4, fsid);
                stmt.step();
                return db.getLastInsertId();
              } finally {
                stmt.dispose();
              }
            }
          }).complete();
      }
    return -1L;
View Full Code Here

  }
 
  public void completeCrawl(final long crawlid) throws SQLiteException {
    dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("UPDATE Crawls SET inprogress='False', crawlfinished=? WHERE crawlid = ?");
          try {
            Date now = new Date(System.currentTimeMillis());
            String dateFinished = fileDateFormat.format(now);
            stmt.bind(1, dateFinished).bind(2, crawlid);
            if (stmt.step()) {
              return crawlid;
            } else {
              return -1L;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here

  }

  public long getLatestCompleteCrawl(final long fsid) {
    return dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("SELECT crawlid from Crawls WHERE fsid = ? AND inprogress = 'False' ORDER BY crawlid DESC LIMIT 1");
          try {
            stmt.bind(1, fsid);
            if (stmt.step()) {
              return stmt.columnLong(0);
            } else {
              return -1L;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here

   * The row is created, if necessary.
   */
  long getCreateType(final String typeLabel) throws SQLiteException {
    long typeid = dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("SELECT typeid FROM Types WHERE typelabel = ?");
          try {
            stmt.bind(1, typeLabel);
            if (stmt.step()) {
              long resultId = stmt.columnLong(0);
              return resultId;
            } else {
              return -1L;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();

    if (typeid >= 0) {
      return typeid;
    }
   
    // Time to insert
    return dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("INSERT into Types VALUES(null, ?)");
          try {
            stmt.bind(1, typeLabel);
            stmt.step();
            return db.getLastInsertId();
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here

    final String schemaIdentifier = (sd == null) ? "" : sd.getSchemaIdentifier();
    final String schemaDesc = (sd == null) ? "no schema" : sd.getSchemaSourceDescription();
    final byte[] payload = (sd == null) ? new byte[0] : sd.getPayload();
    long schemaid = dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          final SQLiteStatement stmt = db.prepare("SELECT schemaid FROM Schemas WHERE schemarepr = ? AND schemasrcdescription = ?");
          try {
            stmt.bind(1, schemaIdentifier).bind(2, schemaDesc);
            if (stmt.step()) {
              long resultId = stmt.columnLong(0);
              return resultId;
            } else {
              return -1L;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();

    if (schemaid >= 0) {
      return schemaid;
    }
   
    // Time to insert
    return dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          final SQLiteStatement stmt = db.prepare("INSERT into Schemas VALUES(null, ?, ?, ?)");
          try {
            stmt.bind(1, schemaIdentifier).bind(2, schemaDesc).bind(3, payload);
            stmt.step();
            return db.getLastInsertId();     
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here

            for (int i = 0; i < typeGuesses.size(); i+=3) {
              long typeId = typeGuesses.get(i);
              long fileId = typeGuesses.get(i+1);             
              long schemaId = typeGuesses.get(i+2);           

              SQLiteStatement stmt = db.prepare("INSERT into TypeGuesses VALUES(?, ?)");
              try {
                stmt.bind(1, fileId).bind(2, typeId);
                stmt.step();
              } finally {
                stmt.dispose();
              }
            }
            return null;
          }
        }).complete();

      dbQueue.execute(new SQLiteJob<Object>() {
          protected Long job(SQLiteConnection db) throws SQLiteException {
            for (int i = 0; i < typeGuesses.size(); i+=3) {
              long typeId = typeGuesses.get(i);
              long fileId = typeGuesses.get(i+1);             
              long schemaId = typeGuesses.get(i+2);           

              SQLiteStatement stmt = db.prepare("INSERT into SchemaGuesses VALUES(?, ?)");
              try {
                stmt.bind(1, fileId).bind(2, schemaId);
                stmt.step();
              } finally {
                stmt.dispose();
              }
            }
            return null;
          }
        }).complete();
View Full Code Here

    }
    final String parentPath = parentPathString;
    final String fName = fnameString;
    final long fileId = dbQueue.execute(new SQLiteJob<Long>() {
        protected Long job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("INSERT into Files VALUES(null, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
          try {
            stmt.bind(1, isDir ? "True" : "False").bind(2, crawlId).bind(3, fName).bind(4, fstatus.getOwner()).bind(5, fstatus.getGroup()).bind(6, permissions).bind(7, fstatus.getLen()).bind(8, fileDateFormat.format(new Date(fstatus.getModificationTime()))).bind(9, parentPath);
            stmt.step();
            return db.getLastInsertId();
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here

  static String schemaInfoQuery = "SELECT schemaid FROM Schemas";   
  public List<SchemaSummary> getSchemaSummaries() {
    return dbQueue.execute(new SQLiteJob<List<SchemaSummary>>() {
        protected List<SchemaSummary> job(SQLiteConnection db) throws SQLiteException {
          List<SchemaSummary> output = new ArrayList<SchemaSummary>();         
          SQLiteStatement stmt = db.prepare(schemaInfoQuery);
         
          try {
            while (stmt.step()) {
              long schemaId = stmt.columnLong(0);
              output.add(new SchemaSummary(FSAnalyzer.this, schemaId));
            }
          } catch (SQLiteException se) {
            se.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return output;
        }}).complete();
  }
View Full Code Here

TOP

Related Classes of com.almworks.sqlite4java.SQLiteStatement

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.