public class Database
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.OidChunk
A class to represent a range of allocated oids.
|
static class |
Database.StringEscaper |
static class |
Database.XMLExceptionListener
Logs the error encountered during de-serialization.
|
| Constructor and Description |
|---|
Database()
Constructor starts the keepalive thread
|
Database(java.lang.String sDriver)
General database connection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
characterNameTaken(java.lang.String name)
Get user name.
|
void |
close()
Close the database connection.
|
void |
connect(java.lang.String url,
java.lang.String username,
java.lang.String password)
Connect to the database at the host given by the url, using the
given username and password
|
void |
createCharacter(java.lang.String worldName,
OID aoid,
AOObject user,
Namespace namespace)
Creates this character as an entry in the database.
|
Namespace |
createNamespace(java.lang.String nsString)
Store the mapping between the given namespace string and
integer in the namespaces table.
|
boolean |
databaseContainsTable(java.lang.String dbName,
java.lang.String tableName)
Tests to see if the table of the given name is present in a
database.
|
boolean |
databaseTableContainsColumn(java.lang.String dbName,
java.lang.String tableName,
java.lang.String columnName)
Tests to see if the table of the given name contain the given
row in the current database.
|
void |
deleteObjectData(OID oid)
Delete object and all its sub-objects from the
objstore table
|
void |
deleteObjectData(OID oid,
Namespace namespace)
Delete a sub-object from the objstore table
|
void |
deletePlayerCharacter(OID oid)
Delete the user with the given oid from the player_character
table.
|
void |
encacheNamespaceMapping()
Encache the mapping between namespace strings and namespace
integers.
|
protected void |
encodeEntity(java.io.ByteArrayOutputStream ba,
Entity entity)
Write the representation of the entity into the
ByteArrayOutputStream.
|
void |
executeBatch(java.util.List<java.lang.String> statements)
Run the series of SQL statements in the list argument.
|
int |
executeUpdate(java.lang.String update)
Run the update statement in the string arg.
|
Namespace |
findExistingNamespace(java.lang.Integer nsInt)
Find an existing namespace int in the database.
|
Namespace |
findExistingNamespace(java.lang.String nsString)
Find an existing namespace string in the database.
|
int |
getAccountCount(java.lang.String worldName) |
OID |
getAccountOid(OID playerOid) |
java.sql.Connection |
getConnection()
returns the connection object -- you must lock around this.
|
java.util.List<OID> |
getGameIDs(java.lang.String worldName,
OID atavismID)
Each Atavism account may have more than 1 character for a
given world.
|
java.util.List<OID> |
getInstanceContent(OID instanceOid,
ObjectType exclusion) |
OID |
getLocation(OID oid,
Namespace ns,
Point location)
Get object location.
|
java.util.concurrent.locks.Lock |
getLock() |
java.lang.String |
getObjectName(OID oid,
Namespace namespace)
Get object name.
|
java.util.List<java.lang.String> |
getObjectNames(java.util.List<OID> inputOids,
Namespace namespace,
java.lang.String unknownName)
Get object names for the given oids.
|
java.util.List<Namespace> |
getObjectNamespaces(OID oid) |
OID |
getOidByName(java.lang.String name,
Namespace namespace) |
OID |
getOidByName(java.lang.String name,
Namespace namespace,
OID instanceOid) |
Database.OidChunk |
getOidChunk(int chunkSize)
Returns a block of oids, and record the fact that they have
been allocated in the database.
|
java.util.List<java.lang.Object> |
getOidsAndNamesMatchingName(java.lang.String playerName,
boolean exactMatch)
Get the oids and names matching the name supplied, base on the
name string to match, and whether to return based on a starting
match of an exact match.
|
java.util.Set<OID> |
getPersistedObjects(Namespace namespace,
Geometry g)
Returns the set of oid's for objects managed by the namespace
that are persisted in the geometry passed in, and all objects
that have no geometry.
|
java.util.List<PluginStatus> |
getPluginStatus(java.lang.String pluginType)
Get the contents of the database row into a PluginStatus
instance.
|
java.lang.String |
getUserName(OID uid)
Get user name.
|
Entity |
loadEntity(OID oid,
Namespace namespace)
Retrieves the user - returns null if user with OID does not
exist.
|
Entity |
loadEntity(java.lang.String persistenceKey)
Load the entity with the given key.
|
Entity |
LoadItemObject(int templateID,
boolean persistent,
OID oid,
long inv_backref,
int stackSize,
int enchantLevel,
int durability) |
static java.lang.String |
makeNameCollectionString(java.util.Collection<java.lang.String> names) |
static java.lang.String |
makeOidCollectionString(java.util.List<OID> oids) |
void |
mapAtavismID(java.lang.String worldName,
OID atavismID,
OID objID)
Adds a atavism ID -> player OID mapping to the player_character table.
|
void |
ping()
Runs a select statement to make sure we can still talk to the
database.
|
boolean |
registerStatusReportingPlugin(EnginePlugin plugin,
long runId)
Register a plugin
|
java.io.InputStream |
retrieveEntityDataByOidAndNamespace(OID oid,
Namespace namespace)
Loads an object's serialization data from the database.
|
java.io.InputStream |
retrieveEntityDataByPersistenceKey(java.lang.String persistenceKey)
Loads the object with the given persistence key from the
database.
|
void |
saveObject(Entity entity,
Namespace namespace)
Save the entity in the given namespace
|
void |
saveObject(java.lang.String persistenceKey,
byte[] data,
Namespace namespace)
Helper method.
|
void |
saveObject(java.lang.String persistenceKey,
Entity entity,
Namespace namespace)
FIXME: This happens on the object manager- we dont need to lock the quad
tree anymore saves object and all objects owned by this object into the
database. if the object already exists, it will overwrite with a newer
version. if the object is new, will create a new row and also set the
dbid into the obj itself (obj.getDBid() will return the new id).
|
void |
saveObjectHelper(java.lang.String persistenceKey,
Entity entity,
Namespace namespace,
byte[] data)
A helper method that saves the byte array in the namespace with
the oid supplied by the entity.
|
boolean |
unregisterStatusReportingPlugin(EnginePlugin plugin)
Unregister the plugin for status reporting
|
boolean |
updatePluginStatus(EnginePlugin plugin,
long nextUpdateTime)
Update the status of a plugin
|
protected static final Logger log
public Database()
public Database(java.lang.String sDriver)
public java.sql.Connection getConnection()
public java.util.concurrent.locks.Lock getLock()
public void connect(java.lang.String url,
java.lang.String username,
java.lang.String password)
url - Specifies the host to connect to.username - The account name used to log into the database.password - The password to use to log in.public int executeUpdate(java.lang.String update)
update - An SQL update statement, or any other statement
that does not return values.public void executeBatch(java.util.List<java.lang.String> statements)
statements - A list of SQL statements to be executed.public boolean databaseTableContainsColumn(java.lang.String dbName,
java.lang.String tableName,
java.lang.String columnName)
tableName - The name of the table.columnName - The name of the column.public boolean databaseContainsTable(java.lang.String dbName,
java.lang.String tableName)
dbName - The name of the database.tableName - The name of the table.public void close()
public void encacheNamespaceMapping()
public Namespace findExistingNamespace(java.lang.String nsString)
nsString - The string name of the namespace.public Namespace findExistingNamespace(java.lang.Integer nsInt)
nsInt - The int associated with the namespace.public Namespace createNamespace(java.lang.String nsString)
nsString - The namespace string for the new namespace.public void createCharacter(java.lang.String worldName,
OID aoid,
AOObject user,
Namespace namespace)
worldName - The string name of the world in which to create the character.aoid - The Atavism account id for the user.user - The Entity representing the user characternamespace - The namespace into which to save the created
character object.public void mapAtavismID(java.lang.String worldName,
OID atavismID,
OID objID)
worldName - The string name of the world in which to create the character.atavismID - The Atavism account id for the user.objID - The oid of the Entity representing the user characterpublic java.util.Set<OID> getPersistedObjects(Namespace namespace, Geometry g)
namespace - The namespace containing the object to be
returned.g - The geometry containing the locations of objects to be
returned.public Entity loadEntity(OID oid, Namespace namespace)
oid - The oid of the of user character.namespace - The namespace containing entity to be
returned.public Entity loadEntity(java.lang.String persistenceKey)
persistenceKey - The string key, which provides a "handle"
by which the object to be loaded is named.public Entity LoadItemObject(int templateID, boolean persistent, OID oid, long inv_backref, int stackSize, int enchantLevel, int durability)
public java.io.InputStream retrieveEntityDataByOidAndNamespace(OID oid, Namespace namespace)
oid - The object oid of the object to be loaded.namespace - The namespace containing the object.public java.io.InputStream retrieveEntityDataByPersistenceKey(java.lang.String persistenceKey)
persistenceKey - The string key used to locate the object
in the objstore table.public java.lang.String getObjectName(OID oid, Namespace namespace)
public java.util.List<java.lang.Object> getOidsAndNamesMatchingName(java.lang.String playerName,
boolean exactMatch)
playerName - The name string to match.exactMatch - If true, the names returned must be an exact
match. If false, the names returned must start with the
playerName.public java.util.List<java.lang.String> getObjectNames(java.util.List<OID> inputOids, Namespace namespace, java.lang.String unknownName)
inputOids. The value of
unknownName is returned for non-existent objects.inputOids - The oids for which to get names.namespace - The sub-object namespace.unknownName - Value returned for non-existent objects.inputOids.public boolean characterNameTaken(java.lang.String name)
uid - The user oid.public static java.lang.String makeOidCollectionString(java.util.List<OID> oids)
public static java.lang.String makeNameCollectionString(java.util.Collection<java.lang.String> names)
public java.util.List<OID> getInstanceContent(OID instanceOid, ObjectType exclusion)
public void deleteObjectData(OID oid)
oid - The object oid to be deleted.public void deleteObjectData(OID oid, Namespace namespace)
oid - The object oid to delete.namespace - The sub-object namespace to delete.public void deletePlayerCharacter(OID oid)
oid - The oid of the player to be deleted.public void saveObject(Entity entity, Namespace namespace)
entity - The Entity object to be saved.namespace - The namespace in which to save the entity.public void saveObject(java.lang.String persistenceKey,
byte[] data,
Namespace namespace)
persistenceKey - The key under which to save the object.data - The bytes of data to be saved. They represent an
Entity, and the Entity contains its own oid.namespace - The namespace into which to save the
reconstructed entity.public void saveObject(java.lang.String persistenceKey,
Entity entity,
Namespace namespace)
protected void encodeEntity(java.io.ByteArrayOutputStream ba,
Entity entity)
ba - The ByteArrayOutputStream to which the entity will be
serialized.entity - The entity to be serialized.public void saveObjectHelper(java.lang.String persistenceKey,
Entity entity,
Namespace namespace,
byte[] data)
persistenceKey - The string key to associate with the
object. For most objects, this is null.entity - The entity whose state is represented by the data.namespace - The namespace into which to save the object state.data - The serialized state of the entity.public java.util.List<OID> getGameIDs(java.lang.String worldName, OID atavismID)
worldName - The name of the world containing the
characters.atavismID - The Atavism account id of the user.public int getAccountCount(java.lang.String worldName)
public java.lang.String getUserName(OID uid)
uid - The user oid.public OID getLocation(OID oid, Namespace ns, Point location)
oid - Object oid.ns - Namespace from which to get location.location - Returns the object location.public Database.OidChunk getOidChunk(int chunkSize)
chunkSize - The number oids to return.public boolean registerStatusReportingPlugin(EnginePlugin plugin, long runId)
public boolean unregisterStatusReportingPlugin(EnginePlugin plugin)
public boolean updatePluginStatus(EnginePlugin plugin, long nextUpdateTime)
public java.util.List<PluginStatus> getPluginStatus(java.lang.String pluginType)
public void ping()