mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-18 02:27:42 +00:00
Addressed review comments and Codacy comments.
This commit is contained in:
parent
b78aa977c2
commit
088cfaae6a
@ -3195,24 +3195,17 @@ abstract class RdbmsCentralRepo implements CentralRepository {
|
|||||||
// clear out the cache
|
// clear out the cache
|
||||||
typeCache.invalidateAll();
|
typeCache.invalidateAll();
|
||||||
|
|
||||||
Connection conn = connect();
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
String sql = "SELECT * FROM correlation_types";
|
String sql = "SELECT * FROM correlation_types";
|
||||||
try {
|
try ( Connection conn = connect();
|
||||||
preparedStatement = conn.prepareStatement(sql);
|
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||||
resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();) {
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
CorrelationAttributeInstance.Type aType = getCorrelationTypeFromResultSet(resultSet);
|
CorrelationAttributeInstance.Type aType = getCorrelationTypeFromResultSet(resultSet);
|
||||||
typeCache.put(aType.getId(), aType);
|
typeCache.put(aType.getId(), aType);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new CentralRepoException("Error getting correlation types.", ex); // NON-NLS
|
throw new CentralRepoException("Error getting correlation types.", ex); // NON-NLS
|
||||||
} finally {
|
|
||||||
CentralRepoDbUtil.closeStatement(preparedStatement);
|
|
||||||
CentralRepoDbUtil.closeResultSet(resultSet);
|
|
||||||
CentralRepoDbUtil.closeConnection(conn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,16 +92,14 @@ public class RdbmsCentralRepoFactory {
|
|||||||
|
|
||||||
// NOTE: the db_info table currenly only has 1 row, so having an index
|
// NOTE: the db_info table currenly only has 1 row, so having an index
|
||||||
// provides no benefit.
|
// provides no benefit.
|
||||||
Connection conn = null;
|
try (Connection conn = this.getEphemeralConnection();) {
|
||||||
Statement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getEphemeralConnection();
|
|
||||||
if (null == conn) {
|
if (null == conn) {
|
||||||
LOGGER.log(Level.SEVERE, "Cannot initialize CR database, don't have a valid connection."); // NON-NLS
|
LOGGER.log(Level.SEVERE, "Cannot initialize CR database, don't have a valid connection."); // NON-NLS
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = conn.createStatement();
|
try (Statement stmt = conn.createStatement();) {
|
||||||
|
|
||||||
// these setting PRAGMAs are SQLIte spcific
|
// these setting PRAGMAs are SQLIte spcific
|
||||||
if (selectedPlatform == CentralRepoPlatforms.SQLITE) {
|
if (selectedPlatform == CentralRepoPlatforms.SQLITE) {
|
||||||
@ -163,7 +161,6 @@ public class RdbmsCentralRepoFactory {
|
|||||||
stmt.execute(String.format(getReferenceTypeValueKnownstatusIndexTemplate(), reference_type_dbname, reference_type_dbname));
|
stmt.execute(String.format(getReferenceTypeValueKnownstatusIndexTemplate(), reference_type_dbname, reference_type_dbname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createPersonaTables(stmt);
|
createPersonaTables(stmt);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
|
LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
|
||||||
@ -171,16 +168,12 @@ public class RdbmsCentralRepoFactory {
|
|||||||
} catch (CentralRepoException ex) {
|
} catch (CentralRepoException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "Error getting default correlation types. Likely due to one or more Type's with an invalid db table name."); // NON-NLS
|
LOGGER.log(Level.SEVERE, "Error getting default correlation types. Likely due to one or more Type's with an invalid db table name."); // NON-NLS
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
if (stmt != null) {
|
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException ex2) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Error closing statement.", ex2);
|
|
||||||
}
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Error connecting to database.", ex); // NON-NLS
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
CentralRepoDbUtil.closeConnection(conn);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,17 +183,22 @@ public class RdbmsCentralRepoFactory {
|
|||||||
* @return True if success, False otherwise.
|
* @return True if success, False otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean insertDefaultDatabaseContent() {
|
public boolean insertDefaultDatabaseContent() {
|
||||||
Connection conn = this.getEphemeralConnection();
|
|
||||||
|
boolean result;
|
||||||
|
try (Connection conn = this.getEphemeralConnection();) {
|
||||||
if (null == conn) {
|
if (null == conn) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = CentralRepoDbUtil.insertDefaultCorrelationTypes(conn)
|
result = CentralRepoDbUtil.insertDefaultCorrelationTypes(conn)
|
||||||
&& CentralRepoDbUtil.insertDefaultOrganization(conn)
|
&& CentralRepoDbUtil.insertDefaultOrganization(conn)
|
||||||
&& insertDefaultPersonaTablesContent(conn);
|
&& insertDefaultPersonaTablesContent(conn);
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
LOGGER.log(Level.SEVERE, String.format("Failed to populate default data in CR tables."), ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CentralRepoDbUtil.closeConnection(conn);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,23 +847,16 @@ public class RdbmsCentralRepoFactory {
|
|||||||
} else if (accountType == Account.Type.PHONE) {
|
} else if (accountType == Account.Type.PHONE) {
|
||||||
typeId = CorrelationAttributeInstance.PHONE_TYPE_ID;
|
typeId = CorrelationAttributeInstance.PHONE_TYPE_ID;
|
||||||
} else {
|
} else {
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
PreparedStatement preparedStatementQuery = null;
|
|
||||||
String querySql = "SELECT * FROM correlation_types WHERE display_name=?";
|
String querySql = "SELECT * FROM correlation_types WHERE display_name=?";
|
||||||
try {
|
try ( PreparedStatement preparedStatementQuery = conn.prepareStatement(querySql)) {
|
||||||
preparedStatementQuery = conn.prepareStatement(querySql);
|
|
||||||
preparedStatementQuery.setString(1, accountType.getDisplayName());
|
preparedStatementQuery.setString(1, accountType.getDisplayName());
|
||||||
|
try (ResultSet resultSet = preparedStatementQuery.executeQuery();) {
|
||||||
resultSet = preparedStatementQuery.executeQuery();
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
typeId = resultSet.getInt("id");
|
typeId = resultSet.getInt("id");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.log(Level.SEVERE, String.format("Failed to get correlation typeId for account type %s.", accountType.getTypeName()), ex);
|
LOGGER.log(Level.SEVERE, String.format("Failed to get correlation typeId for account type %s.", accountType.getTypeName()), ex);
|
||||||
} finally {
|
|
||||||
CentralRepoDbUtil.closeStatement(preparedStatementQuery);
|
|
||||||
CentralRepoDbUtil.closeResultSet(resultSet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user