= Core subsystem formatting update
This commit is contained in:
@@ -35,14 +35,14 @@ public class DatabaseDriverKeyValue
|
||||
|
||||
// Makes sure a table exists with the specified name.
|
||||
// The keyName specifies the key column label, and the valueName specifies the value column label.
|
||||
public void EnsureTableExists(String tableName, String keyName, String valueName)
|
||||
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);
|
||||
}
|
||||
|
||||
// Set up and create a table in the database
|
||||
public boolean Connect()
|
||||
public boolean connect()
|
||||
{
|
||||
driver = new JDBCDriverSQLite();
|
||||
if(driver.Connect() == false)
|
||||
@@ -51,45 +51,45 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Verify tables we want to use exist
|
||||
EnsureTableExists(tableName, keyColumnName, valueColumnName); // General table. Do not remove.
|
||||
ensureTableExists(tableName, keyColumnName, valueColumnName); // General table. Do not remove.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// The key will be created if it doesn't exist and the value specified will be stored.
|
||||
public void CreateSetKey(String key, String value)
|
||||
public void createSetKey(String key, String value)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
|
||||
|
||||
if(HasKey(key))
|
||||
if(hasKey(key))
|
||||
{
|
||||
UpdateKey(key, value);
|
||||
updateKey(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateKey(key, value);
|
||||
createKey(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||
public String CreateGetKey(String key)
|
||||
public String createGetKey(String key)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
|
||||
|
||||
if(HasKey(key))
|
||||
if(hasKey(key))
|
||||
{
|
||||
return GetKey(key);
|
||||
return getKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
String newValue = "";
|
||||
CreateKey(key, newValue);
|
||||
createKey(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Prototype formatting for key updating
|
||||
private void UpdateKey(String key, String value)
|
||||
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 });
|
||||
@@ -97,24 +97,24 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Protoype updating for seeing if a key exists
|
||||
private boolean HasKey(String key)
|
||||
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 });
|
||||
String out = ResultAsString(set, "count");
|
||||
String out = resultAsString(set, "count");
|
||||
return out.charAt(0) == '1';
|
||||
}
|
||||
|
||||
// Prototype for getting a key
|
||||
private String GetKey(String key)
|
||||
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 });
|
||||
return ResultAsString(set, "searchedKey");
|
||||
return resultAsString(set, "searchedKey");
|
||||
}
|
||||
|
||||
// Prototype for creating a key
|
||||
private void CreateKey(String key, String value)
|
||||
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 });
|
||||
@@ -122,7 +122,7 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Get all keys containing a substring
|
||||
public List<String> GetKeysWith(String keySubstring)
|
||||
public List<String> getKeysWith(String keySubstring)
|
||||
{
|
||||
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
|
||||
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
|
||||
@@ -146,7 +146,7 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Transforms a result into a string if possible.
|
||||
private String ResultAsString(ResultSet rs, String key)
|
||||
private String resultAsString(ResultSet rs, String key)
|
||||
{
|
||||
if(rs == null)
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user