Bug fixes and file rename

This commit is contained in:
U-BASIS\dsmyda 2018-11-07 11:28:38 -05:00
parent 91b4842e0b
commit d3f6678f8b
2 changed files with 28 additions and 27 deletions

View File

@ -181,9 +181,9 @@ public class SQLiteTableReader implements AutoCloseable {
private final Consumer<Object> forAllAction; private final Consumer<Object> forAllAction;
//Iteration state variables //Iteration state variables
private Integer currRowColumnIndex = 1; private Integer currRowColumnIndex;
private boolean unfinishedRowState = false; private boolean unfinishedRowState;
private Integer columnNameIndex = 1; private Integer columnNameIndex;
private Integer currentColumnCount; private Integer currentColumnCount;
private ResultSetMetaData currentMetadata; private ResultSetMetaData currentMetadata;
@ -224,10 +224,10 @@ public class SQLiteTableReader implements AutoCloseable {
* Get table names from database * Get table names from database
* *
* @return * @return
* @throws org.sleuthkit.autopsy.coreutils.AutopsySQLiteException * @throws org.sleuthkit.autopsy.coreutils.SQLiteTableReaderException
* *
*/ */
public List<String> getTableNames() throws AutopsySQLiteException { public List<String> getTableNames() throws SQLiteTableReaderException {
ensureOpen(); ensureOpen();
List<String> tableNames = new ArrayList<>(); List<String> tableNames = new ArrayList<>();
@ -239,7 +239,7 @@ public class SQLiteTableReader implements AutoCloseable {
tableNames.add(tableNameResult.getString("name")); //NON-NLS tableNames.add(tableNameResult.getString("name")); //NON-NLS
} }
} catch (SQLException ex) { } catch (SQLException ex) {
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
return tableNames; return tableNames;
@ -249,9 +249,9 @@ public class SQLiteTableReader implements AutoCloseable {
* *
* @param tableName * @param tableName
* @return * @return
* @throws org.sleuthkit.autopsy.coreutils.AutopsySQLiteException * @throws org.sleuthkit.autopsy.coreutils.SQLiteTableReaderException
*/ */
public int getRowCount(String tableName) throws AutopsySQLiteException { public int getRowCount(String tableName) throws SQLiteTableReaderException {
ensureOpen(); ensureOpen();
try (ResultSet countResult = conn.createStatement() try (ResultSet countResult = conn.createStatement()
@ -259,11 +259,11 @@ public class SQLiteTableReader implements AutoCloseable {
"\"" + tableName + "\"")) { "\"" + tableName + "\"")) {
return countResult.getInt("count"); return countResult.getInt("count");
} catch (SQLException ex) { } catch (SQLException ex) {
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
} }
public int getColumnCount(String tableName) throws AutopsySQLiteException { public int getColumnCount(String tableName) throws SQLiteTableReaderException {
ensureOpen(); ensureOpen();
try (ResultSet columnCount = conn.createStatement() try (ResultSet columnCount = conn.createStatement()
@ -271,16 +271,16 @@ public class SQLiteTableReader implements AutoCloseable {
"\"" + tableName + "\"")) { "\"" + tableName + "\"")) {
return columnCount.getMetaData().getColumnCount(); return columnCount.getMetaData().getColumnCount();
} catch (SQLException ex) { } catch (SQLException ex) {
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
} }
/** /**
* *
* @param tableName * @param tableName
* @throws org.sleuthkit.autopsy.coreutils.AutopsySQLiteException * @throws org.sleuthkit.autopsy.coreutils.SQLiteTableReaderException
*/ */
public void read(String tableName) throws AutopsySQLiteException { public void read(String tableName) throws SQLiteTableReaderException {
readHelper("SELECT * FROM \"" + tableName +"\"", alwaysFalseCondition); readHelper("SELECT * FROM \"" + tableName +"\"", alwaysFalseCondition);
} }
@ -291,10 +291,10 @@ public class SQLiteTableReader implements AutoCloseable {
* @param tableName * @param tableName
* @param limit * @param limit
* @param offset * @param offset
* @throws org.sleuthkit.autopsy.coreutils.AutopsySQLiteException * @throws org.sleuthkit.autopsy.coreutils.SQLiteTableReaderException
* *
*/ */
public void read(String tableName, int limit, int offset) throws AutopsySQLiteException { public void read(String tableName, int limit, int offset) throws SQLiteTableReaderException {
readHelper("SELECT * FROM \"" + tableName +"\" LIMIT " + limit readHelper("SELECT * FROM \"" + tableName +"\" LIMIT " + limit
+ " OFFSET " + offset, alwaysFalseCondition); + " OFFSET " + offset, alwaysFalseCondition);
} }
@ -305,10 +305,10 @@ public class SQLiteTableReader implements AutoCloseable {
* *
* @param tableName * @param tableName
* @param condition * @param condition
* @throws org.sleuthkit.autopsy.coreutils.AutopsySQLiteException * @throws org.sleuthkit.autopsy.coreutils.SQLiteTableReaderException
* *
*/ */
public void read(String tableName, BooleanSupplier condition) throws AutopsySQLiteException { public void read(String tableName, BooleanSupplier condition) throws SQLiteTableReaderException {
if(Objects.nonNull(prevTableName) && prevTableName.equals(tableName)) { if(Objects.nonNull(prevTableName) && prevTableName.equals(tableName)) {
readHelper("SELECT * FROM \"" + tableName + "\"", condition); readHelper("SELECT * FROM \"" + tableName + "\"", condition);
} else { } else {
@ -327,12 +327,13 @@ public class SQLiteTableReader implements AutoCloseable {
* *
* @throws org.sleuthkit.autopsy.core.AutopsySQLiteException * @throws org.sleuthkit.autopsy.core.AutopsySQLiteException
*/ */
private void readHelper(String query, BooleanSupplier condition) throws AutopsySQLiteException { private void readHelper(String query, BooleanSupplier condition) throws SQLiteTableReaderException {
try { try {
if(!hasOpened) { if(!hasOpened) {
openResultSet(query); openResultSet(query);
currentMetadata = queryResults.getMetaData(); currentMetadata = queryResults.getMetaData();
currentColumnCount = currentMetadata.getColumnCount(); currentColumnCount = currentMetadata.getColumnCount();
columnNameIndex = 1;
} }
isFinished = false; isFinished = false;
@ -367,7 +368,7 @@ public class SQLiteTableReader implements AutoCloseable {
this.onBlobAction.accept((byte[]) item); this.onBlobAction.accept((byte[]) item);
} }
this.forAllAction.accept((Object) item); this.forAllAction.accept(item);
} }
unfinishedRowState = false; unfinishedRowState = false;
@ -378,7 +379,7 @@ public class SQLiteTableReader implements AutoCloseable {
} catch (SQLException ex) { } catch (SQLException ex) {
closeResultSet(); closeResultSet();
isFinished = true; isFinished = true;
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
} }
@ -386,7 +387,7 @@ public class SQLiteTableReader implements AutoCloseable {
* *
* @throws org.sleuthkit.autopsy.core.AutopsySQLiteException * @throws org.sleuthkit.autopsy.core.AutopsySQLiteException
*/ */
private void ensureOpen() throws AutopsySQLiteException { private void ensureOpen() throws SQLiteTableReaderException {
if (Objects.isNull(conn)) { if (Objects.isNull(conn)) {
try { try {
Class.forName("org.sqlite.JDBC"); //NON-NLS Class.forName("org.sqlite.JDBC"); //NON-NLS
@ -395,7 +396,7 @@ public class SQLiteTableReader implements AutoCloseable {
conn = DriverManager.getConnection("jdbc:sqlite:" + localDiskPath); conn = DriverManager.getConnection("jdbc:sqlite:" + localDiskPath);
} catch (NoCurrentCaseException | TskCoreException | IOException | } catch (NoCurrentCaseException | TskCoreException | IOException |
ClassNotFoundException | SQLException ex) { ClassNotFoundException | SQLException ex) {
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
} }
} }
@ -479,7 +480,7 @@ public class SQLiteTableReader implements AutoCloseable {
* @param query * @param query
* @throws SQLException * @throws SQLException
*/ */
private void openResultSet(String query) throws AutopsySQLiteException { private void openResultSet(String query) throws SQLiteTableReaderException {
ensureOpen(); ensureOpen();
try { try {
@ -488,7 +489,7 @@ public class SQLiteTableReader implements AutoCloseable {
queryResults = statement.executeQuery(); queryResults = statement.executeQuery();
hasOpened = true; hasOpened = true;
} catch (SQLException ex) { } catch (SQLException ex) {
throw new AutopsySQLiteException(ex); throw new SQLiteTableReaderException(ex);
} }
} }

View File

@ -9,13 +9,13 @@ package org.sleuthkit.autopsy.coreutils;
* *
* @author dsmyda * @author dsmyda
*/ */
public class AutopsySQLiteException extends Exception { public class SQLiteTableReaderException extends Exception {
public AutopsySQLiteException(String msg, Throwable ex) { public SQLiteTableReaderException(String msg, Throwable ex) {
super(msg, ex); super(msg, ex);
} }
public AutopsySQLiteException(Throwable ex) { public SQLiteTableReaderException(Throwable ex) {
super(ex); super(ex);
} }
} }