Merge branch 'develop'
This commit is contained in:
@@ -35,7 +35,7 @@ public class DatabaseDriver
|
|||||||
driver.Connect();
|
driver.Connect();
|
||||||
|
|
||||||
// Require a global table if it doesn't exist already
|
// Require a global table if it doesn't exist already
|
||||||
driver.ExecuteStatement("CREATE TABLE IF NOT EXISTS " + globalTableName + " (" + globalKeyName + " text PRIMARY KEY, " + globalValueName + " text);");
|
driver.ExecuteStatement("CREATE TABLE IF NOT EXISTS " + globalTableName + " (" + globalKeyName + " text PRIMARY KEY, " + globalValueName + " text);", null);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -75,15 +75,15 @@ public class DatabaseDriver
|
|||||||
// Prototype formatting for key updating
|
// Prototype formatting for key updating
|
||||||
private void UpdateKey(String key, String value)
|
private void UpdateKey(String key, String value)
|
||||||
{
|
{
|
||||||
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
|
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = ? WHERE " + globalKeyName + " = ?;";
|
||||||
driver.ExecuteStatement(command);
|
driver.ExecuteStatement(command, new String[] { key, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protoype updating for seeing if a key exists
|
// 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 " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
|
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = ?;";
|
||||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
ResultSet set = driver.ExecuteReturningStatement(command, new String[] { key });
|
||||||
String out = ResultAsString(set, "count");
|
String out = ResultAsString(set, "count");
|
||||||
return out.charAt(0) == '1';
|
return out.charAt(0) == '1';
|
||||||
}
|
}
|
||||||
@@ -91,16 +91,16 @@ public class DatabaseDriver
|
|||||||
// Prototype for getting a key
|
// Prototype for getting a key
|
||||||
private String GetKey(String key)
|
private String GetKey(String key)
|
||||||
{
|
{
|
||||||
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
|
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + " = ?;";
|
||||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
ResultSet set = driver.ExecuteReturningStatement(command, new String[] { key });
|
||||||
return ResultAsString(set, "searchedKey");
|
return ResultAsString(set, "searchedKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prototype for creating a key
|
// Prototype for creating a key
|
||||||
private void CreateKey(String key, String value)
|
private void CreateKey(String key, String value)
|
||||||
{
|
{
|
||||||
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
|
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES (?, ?);";
|
||||||
driver.ExecuteStatement(command);
|
driver.ExecuteStatement(command, new String[] { key, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transforms a result into a string if possible.
|
// Transforms a result into a string if possible.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import core.DatabaseTrackedObject;
|
import core.DatabaseTrackedObject;
|
||||||
@@ -23,15 +24,30 @@ public class KittyTrackedVector extends DatabaseTrackedObject
|
|||||||
databaseID = differentiator + readableName + UniqueID;
|
databaseID = differentiator + readableName + UniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirrored behavior
|
|
||||||
public boolean contains(String role)
|
// See if the string is contined in the vector, regardless of case.
|
||||||
|
public boolean containsIgnoreCase(String str)
|
||||||
{
|
{
|
||||||
return allowedRole.contains(role);
|
Iterator<String> value = allowedRole.iterator();
|
||||||
|
|
||||||
|
while (value.hasNext())
|
||||||
|
{
|
||||||
|
if(value.next().equalsIgnoreCase(str))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String role)
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mirrored behavior
|
||||||
|
public boolean contains(String str)
|
||||||
{
|
{
|
||||||
allowedRole.add(role);
|
return allowedRole.contains(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String str)
|
||||||
|
{
|
||||||
|
allowedRole.add(str);
|
||||||
this.MarkDirty();
|
this.MarkDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,9 +66,9 @@ public class KittyTrackedVector extends DatabaseTrackedObject
|
|||||||
return allowedRole.get(index);
|
return allowedRole.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(String role)
|
public void remove(String str)
|
||||||
{
|
{
|
||||||
allowedRole.remove(role);
|
allowedRole.remove(str);
|
||||||
this.MarkDirty();
|
this.MarkDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ public abstract class JDBCDriver
|
|||||||
public abstract boolean Disconnect();
|
public abstract boolean Disconnect();
|
||||||
|
|
||||||
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
|
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
|
||||||
// case of the returning statement, returns the ResultSet.
|
// case of the returning statement, returns the ResultSet. Args are placed into the prepared statement
|
||||||
public abstract boolean ExecuteStatement(String statement);
|
// in place of each '?' places into it.
|
||||||
public abstract ResultSet ExecuteReturningStatement(String statement);
|
public abstract boolean ExecuteStatement(String command, String[] args);
|
||||||
|
public abstract ResultSet ExecuteReturningStatement(String command, String[] args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ public class JDBCDriverMySQL extends JDBCDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ExecuteStatement(String statement) {
|
public boolean ExecuteStatement(String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(String statement) {
|
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ public class JDBCDriverPostgreSQL extends JDBCDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ExecuteStatement(String statement) {
|
public boolean ExecuteStatement(String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(String statement) {
|
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package network;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@@ -63,54 +64,86 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(String sql)
|
public ResultSet ExecuteReturningStatement(String command, String[] args)
|
||||||
{
|
{
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if(sql == null || sql.length() == 0)
|
if(command == null || command.length() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Statement statement = connection.createStatement();
|
if(args != null && args.length > 0)
|
||||||
ResultSet set = statement.executeQuery(sql);
|
{
|
||||||
|
PreparedStatement statement = connection.prepareStatement(command);
|
||||||
|
|
||||||
|
for(int i = 0; i < args.length; ++i)
|
||||||
|
statement.setString(i + 1, args[i]);
|
||||||
|
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
ResultSet set = statement.executeQuery(command);
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
GlobalLog.Fatal(e.getMessage());
|
GlobalLog.Fatal(e.getMessage());
|
||||||
} catch (Exception e1) {
|
}
|
||||||
// TODO Auto-generated catch block
|
catch (Exception e1)
|
||||||
|
{
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ExecuteStatement(String sql)
|
public boolean ExecuteStatement(String command, String[] args)
|
||||||
{
|
{
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(sql == null || sql.length() == 0)
|
if(command == null || command.length() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Statement statement = connection.createStatement();
|
if(args != null && args.length > 0)
|
||||||
boolean executed = statement.execute(sql);
|
{
|
||||||
|
PreparedStatement statement = connection.prepareStatement(command);
|
||||||
|
|
||||||
|
for(int i = 0; i < args.length; ++i)
|
||||||
|
statement.setString(i + 1, args[i]);
|
||||||
|
|
||||||
|
boolean executed = statement.execute();
|
||||||
return executed;
|
return executed;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
boolean executed = statement.execute(command);
|
||||||
|
return executed;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
GlobalLog.Fatal(e.getMessage());
|
GlobalLog.Fatal(e.getMessage());
|
||||||
} catch (Exception e1) {
|
}
|
||||||
// TODO Auto-generated catch block
|
catch (Exception e1)
|
||||||
|
{
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user