= Updated core documentation quickly
This commit is contained in:
@@ -8,8 +8,7 @@ import dataStructures.UserInput;
|
||||
|
||||
public class CommandThread extends Thread
|
||||
{
|
||||
// Pile of variables
|
||||
// TODO(wisp): Consider packaging this up into a thread arguments object potentially...?
|
||||
// Pile of variables. This may be packaged later as thread arguments.
|
||||
CommandManager manager;
|
||||
UserInput input;
|
||||
KittyGuild guild;
|
||||
|
||||
@@ -12,13 +12,13 @@ import utils.LogFilter;
|
||||
// This is where we put everything and swap out the moving parts,
|
||||
// ie MySQL, PostgreSQL, SQLite, etc...
|
||||
//
|
||||
// TODO(wisp): Right now this can be messed up with SQL injection stuff if users
|
||||
// are allowed to directly touch data. Leaving it like this temporarily.
|
||||
// Right now this can be messed up with SQL injection stuff if users
|
||||
// are allowed to directly touch data. Leaving it like this temporarily,
|
||||
// and is for prototyping only!
|
||||
public class DatabaseDriver
|
||||
{
|
||||
// Config and local varaibles
|
||||
private JDBCDriver driver;
|
||||
|
||||
// Note: Changing these values can mess up the database...
|
||||
private final String globalTableName = "kitty_globals";
|
||||
private final String globalKeyName = "GlobalKey";
|
||||
private final String globalValueName = "GlobalValue";
|
||||
@@ -28,6 +28,7 @@ public class DatabaseDriver
|
||||
driver = null;
|
||||
}
|
||||
|
||||
// Set up and create a table in the database
|
||||
public boolean Connect()
|
||||
{
|
||||
driver = new JDBCDriverSQLite();
|
||||
@@ -54,7 +55,7 @@ public class DatabaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
// the key will be created if it doesn't exist, and the default value returned.
|
||||
// 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, "CreateGeyKey: key-" + key);
|
||||
@@ -71,41 +72,38 @@ public class DatabaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
// Prototype formatting for key updating
|
||||
private void UpdateKey(String key, String value)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Update key " + key);
|
||||
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
driver.ExecuteStatement(command);
|
||||
}
|
||||
|
||||
// Protoype updating for seeing if a key exists
|
||||
private boolean HasKey(String key)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Has key " + key);
|
||||
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||
String out = ResultAsString(set, "count");
|
||||
return out.charAt(0) == '1';
|
||||
}
|
||||
|
||||
// Prototype for getting a key
|
||||
private String GetKey(String key)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Getting key " + key);
|
||||
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||
return ResultAsString(set, "searchedKey");
|
||||
}
|
||||
|
||||
// Prototype for creating a key
|
||||
private void CreateKey(String key, String value)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Creating Key " + key);
|
||||
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
driver.ExecuteStatement(command);
|
||||
}
|
||||
|
||||
// Transforms a result into a string if possible.
|
||||
private String ResultAsString(ResultSet rs, String key)
|
||||
{
|
||||
if(rs == null)
|
||||
|
||||
@@ -31,10 +31,8 @@ public class DatabaseManager
|
||||
driver.Connect();
|
||||
}
|
||||
|
||||
// Thumbs through registered objects and syncs them with the database.
|
||||
// TODO(wisp) Right now this just syncs on the main thread, but we will
|
||||
// want to have upkeep commands queue up for a dedicated database thread
|
||||
// in the future to offload the wait times.
|
||||
// Thumbs through registered objects and syncs them with the database.
|
||||
// Consider moving this operation to a separate thread.
|
||||
public void Upkeep()
|
||||
{
|
||||
for(int i = 0 ; i < trackedObjects.size(); ++i)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package core;
|
||||
|
||||
// Objects inheriting from this are capable of being stored in and
|
||||
// have their data populated from database entries.
|
||||
public abstract class DatabaseTrackedObject
|
||||
{
|
||||
private boolean isDirty;
|
||||
@@ -26,10 +28,8 @@ public abstract class DatabaseTrackedObject
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
// TODO(wisp): Not the best way to handle this, potentially consider
|
||||
// using an object factory that looks up how to serialize and
|
||||
// deserialize based on the type of the thing being tracked.
|
||||
// For now, this is fine.
|
||||
// Consider an object factory instead of dedicated serialization methods
|
||||
// if this starts to become impractical. For now, it works.
|
||||
public abstract String Serialize();
|
||||
public abstract void DeSerialzie(String string);
|
||||
}
|
||||
|
||||
@@ -31,13 +31,10 @@ public class ObjectBuilderFactory
|
||||
// Stats tracking and whatnot... for setting stats too internally potentially
|
||||
private static Stats stats;
|
||||
|
||||
//RPManger for tracking RP system
|
||||
// RPManger for tracking RP system
|
||||
private static RPManager rpManager;
|
||||
|
||||
// NOTE(wisp): This is designed to initialize at the last possible second.
|
||||
// The idea behind this is that there may be other things that may need
|
||||
// time to initialize before the factory can use them, and this guarantees
|
||||
// they get the time they need.
|
||||
// Lazy initialization style for
|
||||
private static boolean hasInitialized;
|
||||
private static Semaphore initMutex = new Semaphore(1);
|
||||
private static void LazyInit()
|
||||
@@ -50,8 +47,7 @@ public class ObjectBuilderFactory
|
||||
initMutex.acquire();
|
||||
try
|
||||
{
|
||||
// NOTE(wisp): Actually put all the init code here.
|
||||
// In the future, this is where we would read from something external.
|
||||
// Initialization here. This is where we could read from something external.
|
||||
guildCache = new HashMap<String, KittyGuild>();
|
||||
userCache = new HashMap<String, KittyUser>();
|
||||
channelCache = new HashMap<String, KittyChannel>();
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ import core.CommandManager.ThreadData;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
// NOTE(wisp): This is a class designed to be asked about various kittybot stats
|
||||
// This is a class designed to be asked about various kittybot stats.
|
||||
// It follows a singleton pattern, and is accessable from anywhere internally.
|
||||
public class Stats
|
||||
{
|
||||
public static String botName = "KittyBot";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package core;
|
||||
package dataStructures;
|
||||
|
||||
// This is a structure representing an image reponse for handing around.
|
||||
public class GenericImage
|
||||
{
|
||||
private String artist;
|
||||
|
||||
@@ -2,6 +2,7 @@ package network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import core.*;
|
||||
import dataStructures.GenericImage;
|
||||
import offline.*;
|
||||
import utils.*;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import core.*;
|
||||
import dataStructures.GenericImage;
|
||||
import utils.*;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user