Package com.almworks.sqlite4java

Examples of com.almworks.sqlite4java.SQLiteStatement


   * Grab details on a schema.
   */
  public SchemaSummaryData getSchemaSummaryData(final long schemaid) {
    return dbQueue.execute(new SQLiteJob<SchemaSummaryData>() {
        protected SchemaSummaryData job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("SELECT schemarepr, schemasrcdescription FROM Schemas WHERE schemaid = ?");
          try {
            stmt.bind(1, schemaid);
            if (stmt.step()) {
              return new SchemaSummaryData(schemaid, stmt.columnString(0), stmt.columnString(1));
            } else {
              return null;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
  }
View Full Code Here


  static String precachedSchemaQuery = "SELECT Schemas.schemaid, Schemas.schemarepr, Schemas.schemasrcdescription, SchemaGuesses.fid, TypeGuesses.typeid, Files.crawlid, Files.fname, Files.owner, Files.groupowner, Files.permissions, Files.size, Files.modified, Files.path FROM Schemas, SchemaGuesses, TypeGuesses, Files WHERE SchemaGuesses.schemaid = Schemas.schemaid AND TypeGuesses.fid = SchemaGuesses.fid AND Files.fid = SchemaGuesses.fid ORDER BY Schemas.schemaid"
  public List<SchemaSummary> getPrecachedSchemaSummaries() {
    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(precachedSchemaQuery);
         
          try {
            SchemaSummaryData ssd = null;
            SchemaSummary ss = null;
            long lastSchemaId = -1L;
            List<TypeGuessSummary> tgslist = null;
            while (stmt.step()) {
              long schemaid = stmt.columnLong(0);
              String schemarepr = stmt.columnString(1);
              String schemasrcdescription = stmt.columnString(2);
              long fid = stmt.columnLong(3);
              long typeid = stmt.columnLong(4);
              long crawlid = stmt.columnLong(5);
              String fname = stmt.columnString(6);
              String owner = stmt.columnString(7);
              String groupowner = stmt.columnString(8);
              String permissions = stmt.columnString(9);
              long size = stmt.columnLong(10);
              String modified = stmt.columnString(11);
              String path = stmt.columnString(12)

              TypeGuessSummary tgs = new TypeGuessSummary(FSAnalyzer.this, fid, typeid, schemaid);
              FileSummary fs = new FileSummary(FSAnalyzer.this, fid);
              FileSummaryData fsd = new FileSummaryData(FSAnalyzer.this, true, fid, crawlid, fname, owner, groupowner, permissions, size, modified, path);
              fs.addCachedData(fsd);
              tgs.addCachedData(fs);
             
              if (schemaid != lastSchemaId) {
                if (ss != null) {
                  ss.addCachedData(tgslist);
                  output.add(ss);
                }
                ssd = new SchemaSummaryData(schemaid, schemarepr, schemasrcdescription);
                ss = new SchemaSummary(FSAnalyzer.this, schemaid);
                ss.addCachedData(ssd);
                tgslist = new ArrayList<TypeGuessSummary>();
              }
              tgslist.add(tgs);
              lastSchemaId = schemaid;
            }
            if (ss != null) {
              ss.addCachedData(tgslist);
              output.add(ss);
            }
          } catch (SQLiteException se) {
            se.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return output;
        }}).complete();
  }
View Full Code Here

  static String subpathFilesQuery = "SELECT fid from Files WHERE path LIKE ?";
  public List<Long> getFidUnderPath(final String pathPrefix) throws SQLiteException {
    List<Long> finalResults = dbQueue.execute(new SQLiteJob<List<Long>>() {
        protected List<Long> job(SQLiteConnection db) throws SQLiteException {
          List<Long> results = new ArrayList<Long>();         
          SQLiteStatement stmt = db.prepare(subpathFilesQuery);
          try {
            stmt.bind(1, pathPrefix + "%");
            while (stmt.step()) {
              long resultId = stmt.columnLong(0);
              results.add(resultId);
            }
            return results;
          } finally {
            stmt.dispose();
          }
        }
      }).complete();
    return finalResults;
  }
View Full Code Here

  static String fileInfoQueryWithPrefix = "SELECT fid FROM Files WHERE isDir = ? AND path = ?";
  public List<FileSummary> getFileSummariesInDir(final boolean isDir, final String prefix) {
    return dbQueue.execute(new SQLiteJob<List<FileSummary>>() {
        protected List<FileSummary> job(SQLiteConnection db) throws SQLiteException {
          List<FileSummary> output = new ArrayList<FileSummary>();
          SQLiteStatement stmt;
          if (prefix == null) {
            stmt = db.prepare(fileInfoQueryWithoutPrefix);
            stmt.bind(1, isDir ? "True" : "False");           
          } else {
            stmt = db.prepare(fileInfoQueryWithPrefix);
            String prefixStr = prefix;
            if (! prefixStr.endsWith("/")) {
              prefixStr += "/";
            }
            stmt.bind(1, isDir ? "True" : "False").bind(2, prefixStr);           
          }
          try {
            while (stmt.step()) {
              long fid = stmt.columnLong(0);
              output.add(new FileSummary(FSAnalyzer.this, fid));
            }
          } catch (SQLiteException se) {
            se.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return output;
        }}).complete();
  }
View Full Code Here

  static String precachedFileInfoQueryWithPrefix = precachedFileInfoQueryWithoutPrefix + " AND Files.path = ?";
  public List<FileSummary> getPrecachedFileSummariesInDir(final boolean isDir, final String prefix) {
    return dbQueue.execute(new SQLiteJob<List<FileSummary>>() {
        protected List<FileSummary> job(SQLiteConnection db) throws SQLiteException {
          List<FileSummary> output = new ArrayList<FileSummary>();
          SQLiteStatement stmt;
          if (prefix == null) {
            stmt = db.prepare(precachedFileInfoQueryWithoutPrefix);
            stmt.bind(1, isDir ? "True" : "False");           
          } else {
            stmt = db.prepare(precachedFileInfoQueryWithPrefix);
            String prefixStr = prefix;
            if (! prefixStr.endsWith("/")) {
              prefixStr += "/";
            }
            stmt.bind(1, isDir ? "True" : "False").bind(2, prefixStr);           
          }
          try {
            FileSummary fs = null;
            FileSummaryData fsd = null;
            long lastFid = -1L;
            List<TypeGuessSummary> tgslist = null;
            while (stmt.step()) {
              long fid = stmt.columnLong(0);
              long crawlid = stmt.columnLong(1);
              String fname = stmt.columnString(2);
              String owner = stmt.columnString(3);
              String groupowner = stmt.columnString(4);
              String permissions = stmt.columnString(5);
              long size = stmt.columnLong(6);
              String modified = stmt.columnString(7);
              String path = stmt.columnString(8);
              long schemaid = stmt.columnLong(9);
              long typeid = stmt.columnLong(10);

              // We get a tuple for every typeguess.
              // There could be more than one typeguess for each unique file
              TypeGuessSummary tgs = new TypeGuessSummary(FSAnalyzer.this, fid, typeid, schemaid);
              tgs.addCachedData(fs);
               
              if (fid != lastFid) {
                if (fs != null) {
                  fs.addCachedData(tgslist);
                  output.add(fs);
                }
                fs = new FileSummary(FSAnalyzer.this, fid);             
                fsd = new FileSummaryData(FSAnalyzer.this, isDir, fid, crawlid, fname, owner, groupowner, permissions, size, modified, path);
                fs.addCachedData(fsd);
                tgslist = new ArrayList<TypeGuessSummary>();
              }
              tgslist.add(tgs);
              lastFid = fid;
            }
            if (fs != null) {
              fs.addCachedData(tgslist);
              output.add(fs);
            }
          } catch (SQLiteException sqe) {
            sqe.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return output;
        }}).complete();
  }
View Full Code Here

  static String singletonFileInfoQuery = "SELECT fid FROM Files WHERE path||fname = ?"
  public FileSummary getSingleFileSummary(final String fullName) {
    return dbQueue.execute(new SQLiteJob<FileSummary>() {
        protected FileSummary job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare(singletonFileInfoQuery);
          stmt.bind(1, fullName);           
          try {
            if (stmt.step()) {
              long fid = stmt.columnLong(0);
              return new FileSummary(FSAnalyzer.this, fid);
            }
          } catch (SQLiteException se) {
            se.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return null;
        }}).complete();
  }   
View Full Code Here

  static String filenameForCrawlQuery = "SELECT path, fname FROM Files WHERE crawlid=? AND isDir = ?";       
  private List<Path> getFileEntriesForCrawl(final long crawlid, final String isDir) {
    return dbQueue.execute(new SQLiteJob<List<Path>>() {
        protected List<Path> job(SQLiteConnection db) throws SQLiteException {
          List<Path> output = new ArrayList<Path>();         
          SQLiteStatement stmt = db.prepare(filenameForCrawlQuery);
          try {
            stmt.bind(1, crawlid).bind(2, isDir);
            while (stmt.step()) {
              output.add(new Path(stmt.columnString(0), stmt.columnString(1)));
            }
          } catch (SQLiteException se) {
            se.printStackTrace();
          } finally {
            stmt.dispose();
          }
          return output;
        }}).complete();
  }
View Full Code Here

    return dbQueue.execute(new SQLiteJob<DataDescriptor>() {
        protected DataDescriptor job(SQLiteConnection db) throws SQLiteException {
          String identifier = null;
          String path = null;
          String fname = null;
          SQLiteStatement stmt = db.prepare("SELECT Types.typelabel, Files.path, Files.fname FROM Types, TypeGuesses, Files WHERE TypeGuesses.fid = ? AND Files.fid = TypeGuesses.fid AND Types.typeid = TypeGuesses.typeid");
          try {
            stmt.bind(1, fid);
            if (stmt.step()) {
              identifier = stmt.columnString(0);
              path = stmt.columnString(1);
              fname = stmt.columnString(2);
            }
          } finally {
            stmt.dispose();
          }
          stmt = db.prepare("SELECT Schemas.schemaid, Schemas.schemarepr, Schemas.schemasrcdescription, Schemas.schemapayload FROM Schemas, SchemaGuesses WHERE SchemaGuesses.fid = ? AND SchemaGuesses.schemaid = Schemas.schemaid");
          try {
            List<String> schemaReprs = new ArrayList<String>();
            List<String> schemaDescs = new ArrayList<String>();
            List<byte[]> schemaBlobs = new ArrayList<byte[]>();
             
            stmt.bind(1, fid);
            while (stmt.step()) {
              schemaReprs.add(stmt.columnString(1));
              schemaDescs.add(stmt.columnString(2));
              schemaBlobs.add(stmt.columnBlob(3));
            }

            try {
              return formatAnalyzer.loadDataDescriptor(fs, new Path(path + fname), identifier, schemaReprs, schemaDescs, schemaBlobs);
            } catch (IOException ioex) {
              return null;
            }
          } finally {
            stmt.dispose();
          }
        }}).complete();
  }
View Full Code Here

          long size = 0L;
          String modified = null;
          String path = null;
          String identifier = null;         

          SQLiteStatement stmt = db.prepare("SELECT isDir, crawlid, fname, owner, groupowner, permissions, size, modified, path FROM Files WHERE Files.fid = ?");
          try {
            stmt.bind(1, fid);
            if (stmt.step()) {
              isDir = "True".equals(stmt.columnString(0));
              crawlid = stmt.columnLong(1);
              fname = stmt.columnString(2);
              owner = stmt.columnString(3);
              groupowner = stmt.columnString(4);
              permissions = stmt.columnString(5);
              size = stmt.columnLong(6);
              modified = stmt.columnString(7);
              path = stmt.columnString(8);
            }
          } finally {
            stmt.dispose();
          }

          if (! isDir) {
            stmt = db.prepare("SELECT typelabel FROM Types, TypeGuesses WHERE TypeGuesses.fid = ? AND Types.typeid = TypeGuesses.typeid");
            try {
              stmt.bind(1, fid);
              if (stmt.step()) {
                identifier = stmt.columnString(0);
              }
            } finally {
              stmt.dispose();
            }
           
            stmt = db.prepare("SELECT Schemas.schemaid, Schemas.schemarepr, Schemas.schemasrcdescription, Schemas.schemapayload FROM Schemas, SchemaGuesses WHERE SchemaGuesses.fid = ? AND SchemaGuesses.schemaid = Schemas.schemaid");
            try {
              List<String> schemaReprs = new ArrayList<String>();
              List<String> schemaDescs = new ArrayList<String>();
              List<byte[]> schemaBlobs = new ArrayList<byte[]>();
             
              stmt.bind(1, fid);
              while (stmt.step()) {
                schemaReprs.add(stmt.columnString(1));
                schemaDescs.add(stmt.columnString(2));
                schemaBlobs.add(stmt.columnBlob(3));
              }

              try {
                DataDescriptor dd = formatAnalyzer.loadDataDescriptor(fs, new Path(path + fname), identifier, schemaReprs, schemaDescs, schemaBlobs);
                fsd = new FileSummaryData(FSAnalyzer.this, true, fid, crawlid, fname, owner, groupowner, permissions, size, modified, path);
                fsd.addCachedData(dd);
              } catch (IOException iex) {
                iex.printStackTrace();
                return null;
              }
            } finally {
              stmt.dispose();
            }
          } else {
            fsd = new FileSummaryData(FSAnalyzer.this, false, fid, crawlid, fname, owner, groupowner, permissions, size, modified, path);           
          }
          return fsd;
View Full Code Here

   * Get the top-level directory from a given crawl
   */
  public Path getTopDir(final long crawlid)  {
    return dbQueue.execute(new SQLiteJob<Path>() {
        protected Path job(SQLiteConnection db) throws SQLiteException {
          SQLiteStatement stmt = db.prepare("SELECT path, fname FROM Files WHERE crawlid = ? AND isDir = 'True' ORDER BY length(path||fname) ASC LIMIT 1");
          try {
            stmt.bind(1, crawlid);
            if (stmt.step()) {
              return new Path(stmt.columnString(0) + stmt.columnString(1));
            } else {
              return null;
            }
          } finally {
            stmt.dispose();
          }
        }
      }).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.