= Updated utils and logging subsystem formatting

This commit is contained in:
Matthew Cech
2019-06-19 22:14:13 -07:00
parent 5e531a19b7
commit 06317a4528
58 changed files with 205 additions and 202 deletions
+12 -12
View File
@@ -38,14 +38,14 @@ public class DatabaseDriverKeyValue
public void ensureTableExists(String tableName, String keyName, String valueName)
{
// Require a global table if it doesn't exist already
driver.ExecuteStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
driver.executeStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
}
// Set up and create a table in the database
public boolean connect()
{
driver = new JDBCDriverSQLite();
if(driver.Connect() == false)
if(driver.connect() == false)
{
return false;
}
@@ -59,7 +59,7 @@ public class DatabaseDriverKeyValue
// The key will be created if it doesn't exist and the value specified will be stored.
public void createSetKey(String key, String value)
{
GlobalLog.Log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
GlobalLog.log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
if(hasKey(key))
{
@@ -74,7 +74,7 @@ public class DatabaseDriverKeyValue
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
public String createGetKey(String key)
{
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
GlobalLog.log(LogFilter.Database, "CreateGetKey: " + key);
if(hasKey(key))
{
@@ -92,15 +92,15 @@ public class DatabaseDriverKeyValue
private void updateKey(String key, String value)
{
String command = "UPDATE " + tableName + " SET " + valueColumnName + " = ? WHERE " + keyColumnName + " = ?";
boolean status = driver.ExecuteStatement(JDBCStatementType.Update, command, new String[] { value, key });
GlobalLog.Log(LogFilter.Database, "UpdateKey status: " + status);
boolean status = driver.executeStatement(JDBCStatementType.Update, command, new String[] { value, key });
GlobalLog.log(LogFilter.Database, "UpdateKey status: " + status);
}
// Protoype updating for seeing if a key exists
private boolean hasKey(String key)
{
String command = "SELECT COUNT(1) as count FROM " + tableName + " WHERE " + keyColumnName + " = ?";
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
String out = resultAsString(set, "count");
return out.charAt(0) == '1';
}
@@ -109,7 +109,7 @@ public class DatabaseDriverKeyValue
private String getKey(String key)
{
String command = "SELECT " + valueColumnName + " as searchedKey FROM " + tableName +" WHERE " + keyColumnName + " = ?";
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
return resultAsString(set, "searchedKey");
}
@@ -117,15 +117,15 @@ public class DatabaseDriverKeyValue
private void createKey(String key, String value)
{
String command = "INSERT INTO " + tableName + " (GlobalKey, GlobalValue) VALUES (?, ?)";
boolean status = driver.ExecuteStatement(JDBCStatementType.Insert, command, new String[] { key, value });
GlobalLog.Log(LogFilter.Database, "CreateKey status: " + status);
boolean status = driver.executeStatement(JDBCStatementType.Insert, command, new String[] { key, value });
GlobalLog.log(LogFilter.Database, "CreateKey status: " + status);
}
// Get all keys containing a substring
public List<String> getKeysWith(String keySubstring)
{
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
ResultSet result = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
List<String> keys = new ArrayList<String>();
@@ -165,7 +165,7 @@ public class DatabaseDriverKeyValue
}
catch (SQLException e)
{
GlobalLog.Error(LogFilter.Database, e.toString());
GlobalLog.error(LogFilter.Database, e.toString());
return null;
}
}