|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object velosurf.sql.Database
public class Database
This class encapsulates a connection to the database and contains all the stuff relative to it.
To get a new instance, client classes should call one of the getInstance static methods.
Field Summary | |
---|---|
private int |
caching
Default caching mode. |
static int |
CASE_SENSITIVE
'sensitive' case-sensitive policy. |
static int |
CASE_UNKNOWN
'unknown' case-sensitive policy. |
private int |
caseSensivity
Case-sensivity. |
private boolean |
checkConnections
Default connections checking |
private long |
checkInterval
Default check interval |
private ConnectionPool |
connectionPool
Pool of connections. |
private static java.util.Map<java.lang.Integer,Database> |
connectionsByConfigFile
Map config files -> instances. |
private static java.util.Map<java.lang.Integer,Database> |
connectionsByParams
Map parameters -> instances. |
private static int |
contextCase
Case-sensivity for context. |
private Cryptograph |
cryptograph
Cryptograph used to encrypt/decrypt database ids. |
private java.lang.String |
driverClass
Driver class name, if provided in the config file. |
private DriverInfo |
driverInfo
Driver infos (database vendor specific). |
private boolean |
driverLoaded
Whether the JDBC driver has been loaded. |
private java.util.Map<java.lang.String,Entity> |
entities
Map name->entity. |
static int |
LOWERCASE
'lowercase' case-sensitive policy. |
private int |
maxConnections
Max connections. |
private int |
minConnections
Min connections. |
private java.lang.String |
password
Database user's password. |
private PreparedStatementPool |
preparedStatementPool
Pool of prepared statements. |
private boolean |
readOnly
Default access mode. |
private ReverseEngineer |
reverseEngineer
Reverse engineer. |
private Entity |
rootEntity
Root entity that contains all root attributes and actions. |
private java.lang.String |
schema
Schema. |
private java.lang.String |
seed
Random seed used to initialize the cryptograph. |
private static java.util.Map<java.lang.Integer,java.util.Map<java.lang.String,Entity>> |
sharedCatalog
Shared catalog, to share entities among instances. |
private StatementPool |
statementPool
Pool of statements. |
private ConnectionPool |
transactionConnectionPool
Pool of connections for transactions. |
private PreparedStatementPool |
transactionPreparedStatementPool
Pool of prepared statements for transactions. |
private StatementPool |
transactionStatementPool
Pool of statements for transactions. |
static int |
UPPERCASE
'uppercase' case-sensitive policy. |
private java.lang.String |
url
Database url. |
private java.lang.String |
user
Database user. |
private java.lang.ThreadLocal<UserContext> |
userContext
Thread-local user context. |
Constructor Summary | |
---|---|
private |
Database()
Builds a new connection. |
private |
Database(java.lang.String user,
java.lang.String password,
java.lang.String url,
java.lang.String driver,
java.lang.String schema)
Builds a new connection. |
Method Summary | |
---|---|
java.lang.String |
adaptCase(java.lang.String identifier)
Changes to lowercase or uppercase if needed. |
static java.lang.String |
adaptContextCase(java.lang.String str)
Adapt a string to the context case. |
void |
addEntity(Entity entity)
Add a new entity. |
void |
close()
Close the connection. |
private void |
connect()
Connect the database. |
java.lang.String |
deobfuscate(java.lang.Object value)
De-obfuscate the given value. |
void |
displayStats()
Display statistics about the statements pools. |
java.lang.Object |
evaluate(java.lang.String query)
Evaluate a query to a scalar. |
java.lang.Object |
filterParam(java.lang.Object value)
Driver specific value filter |
Action |
getAction(java.lang.String name)
Get a root action. |
Attribute |
getAttribute(java.lang.String name)
Get a root attribute. |
int |
getCaseSensivity()
Get database case-sensivity policy. |
ConnectionWrapper |
getConnection()
Get a jdbc connection. |
DriverInfo |
getDriverInfo()
Get database driver infos. |
java.util.Map<java.lang.String,Entity> |
getEntities()
Entities map getter. |
Entity |
getEntity(java.lang.String name)
Get an existing entity. |
Entity |
getEntityCreate(java.lang.String name)
Get a named entity or creeate it if it doesn't exist |
static Database |
getInstance(java.io.InputStream config)
Get a new connection. |
static Database |
getInstance(java.io.InputStream config,
XIncludeResolver xincludeResolver)
Get a new connection. |
static Database |
getInstance(java.lang.String configFilename)
Get a unique Database from config filename. |
static Database |
getInstance(java.lang.String user,
java.lang.String password,
java.lang.String url)
Get a unique Database from connection params. |
static Database |
getInstance(java.lang.String user,
java.lang.String password,
java.lang.String url,
java.lang.String driver)
Get a unique Database from connection params. |
static Database |
getInstance(java.lang.String user,
java.lang.String password,
java.lang.String url,
java.lang.String driver,
java.lang.String schema)
Get a unique Database from connection params. |
private java.lang.Integer |
getMagicNumber(java.lang.String schema)
Get the integer key used to share schema entities among instances. |
ReverseEngineer |
getReverseEngineer()
Get reverse engineer. |
Entity |
getRootEntity()
Get root entity. |
java.lang.String |
getSchema()
Get the schema. |
ConnectionWrapper |
getTransactionConnection()
Get the underlying jdbc connection used for transactions, and mark it right away as busy. |
UserContext |
getUserContext()
Get this database user context (thread local) |
protected void |
initCryptograph()
Init cryptograph. |
protected void |
loadDriver()
oad the appropriate driver. |
java.lang.String |
obfuscate(java.lang.Object value)
Obfuscate the given value. |
private void |
open(java.lang.String user,
java.lang.String password,
java.lang.String url,
java.lang.String driver,
java.lang.String schema)
Open the connection. |
PooledPreparedStatement |
prepare(java.lang.String query)
Prepare a query. |
RowIterator |
query(java.lang.String query)
Issue a query. |
RowIterator |
query(java.lang.String query,
Entity entity)
Issue a query, knowing the resulting entity. |
private void |
readConfigFile(java.io.InputStream config,
XIncludeResolver xincludeResolver)
Read model configuration from the given input stream. |
void |
setCaching(int cachingMethod)
Set the caching method. |
void |
setCase(int caseSensivity)
Set the case policy. |
void |
setCheckConnections(boolean checkConnections)
Set whether or not connections are to be checked or not |
void |
setCheckInterval(long checkInterval)
Set the minimum check interval (in milliseconds) - connections are only checked when their last use is older than this interval. |
void |
setDriver(java.lang.String driverClass)
Set driver class. |
void |
setError(java.lang.String errormsg)
Set error message. |
void |
setMaxConnections(int maxConnections)
Set the maximum number of connections. |
void |
setMinConnections(int minConnections)
Set minimum number of connections. |
void |
setPassword(java.lang.String password)
Set the database password. |
void |
setReadOnly(boolean readOnly)
Set the read-only state. |
void |
setSchema(java.lang.String schema)
Set schema name. |
void |
setSeed(java.lang.String seed)
Set the encryption seed. |
void |
setURL(java.lang.String url)
Set the database URL. |
void |
setUser(java.lang.String user)
Set the database user. |
void |
setUserContext(UserContext userContext)
Set this database user context (thread local) |
PooledPreparedStatement |
transactionPrepare(java.lang.String query)
Prepare a query which is part of a transaction. |
int |
transactionUpdate(java.lang.String query)
Issue an update query that is part of a transaction. |
int |
update(java.lang.String query)
Issue an update query. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String user
private java.lang.String password
private java.lang.String url
private java.lang.String schema
private boolean driverLoaded
private java.lang.String driverClass
private ConnectionPool connectionPool
private int minConnections
private int maxConnections
private ConnectionPool transactionConnectionPool
private StatementPool statementPool
private StatementPool transactionStatementPool
private PreparedStatementPool preparedStatementPool
private PreparedStatementPool transactionPreparedStatementPool
private boolean readOnly
private boolean checkConnections
private long checkInterval
private int caching
private java.util.Map<java.lang.String,Entity> entities
private Entity rootEntity
private DriverInfo driverInfo
private java.lang.String seed
private Cryptograph cryptograph
public static final int CASE_UNKNOWN
public static final int CASE_SENSITIVE
public static final int UPPERCASE
public static final int LOWERCASE
private int caseSensivity
private static int contextCase
private static java.util.Map<java.lang.Integer,Database> connectionsByParams
private static java.util.Map<java.lang.Integer,Database> connectionsByConfigFile
private static java.util.Map<java.lang.Integer,java.util.Map<java.lang.String,Entity>> sharedCatalog
Shared catalog, to share entities among instances.
Key is hashcode of (name+password+url+schema), value is an entities map.
private ReverseEngineer reverseEngineer
private java.lang.ThreadLocal<UserContext> userContext
Constructor Detail |
---|
private Database()
private Database(java.lang.String user, java.lang.String password, java.lang.String url, java.lang.String driver, java.lang.String schema) throws java.sql.SQLException
user
- user namepassword
- passwordurl
- database urldriver
- driver java class nameschema
- schema name to use
java.sql.SQLException
- thrown by the database engineMethod Detail |
---|
public static Database getInstance(java.lang.String user, java.lang.String password, java.lang.String url) throws java.sql.SQLException
user
- user namepassword
- passwordurl
- database url
java.sql.SQLException
- thrown by the database enginepublic static Database getInstance(java.lang.String user, java.lang.String password, java.lang.String url, java.lang.String driver) throws java.sql.SQLException
user
- user namepassword
- passwordurl
- database urldriver
- driver java class name
java.sql.SQLException
- thrown by the database enginepublic static Database getInstance(java.lang.String user, java.lang.String password, java.lang.String url, java.lang.String driver, java.lang.String schema) throws java.sql.SQLException
user
- user namepassword
- passwordurl
- database urldriver
- driver java class nameschema
- schema
java.sql.SQLException
- thrown by the database enginepublic static Database getInstance(java.lang.String configFilename) throws java.sql.SQLException, java.io.FileNotFoundException, java.io.IOException
configFilename
- config filename
java.sql.SQLException
- thrown by the database engine
java.io.FileNotFoundException
java.io.IOException
public static Database getInstance(java.io.InputStream config) throws java.sql.SQLException
config
- config filename
java.sql.SQLException
- thrown by the database enginepublic static Database getInstance(java.io.InputStream config, XIncludeResolver xincludeResolver) throws java.sql.SQLException
config
- config filename
java.sql.SQLException
- thrown by the database engineprivate void open(java.lang.String user, java.lang.String password, java.lang.String url, java.lang.String driver, java.lang.String schema) throws java.sql.SQLException
user
- user namepassword
- passwordurl
- database urldriver
- driver java class nameschema
- schema name
java.sql.SQLException
- thrown by the database engineprivate void connect() throws java.sql.SQLException
java.sql.SQLException
public void setReadOnly(boolean readOnly)
readOnly
- read-only statepublic void setCaching(int cachingMethod)
cachingMethod
- caching methodpublic void setUser(java.lang.String user)
user
- user name.public void setPassword(java.lang.String password)
password
- passwordpublic void setURL(java.lang.String url)
url
- database urlpublic void setDriver(java.lang.String driverClass)
driverClass
- driver classpublic void setSchema(java.lang.String schema)
schema
- schema namepublic void setMinConnections(int minConnections)
minConnections
- minimum number of connectionspublic void setMaxConnections(int maxConnections)
maxConnections
- maximum number of connectionspublic void setSeed(java.lang.String seed)
seed
- encryption seedpublic void setCase(int caseSensivity)
caseSensivity
- case policypublic void setCheckConnections(boolean checkConnections)
checkConnections
- read-only check or notpublic void setCheckInterval(long checkInterval)
checkInterval
- protected void loadDriver()
protected void initCryptograph()
public ReverseEngineer getReverseEngineer()
public RowIterator query(java.lang.String query) throws java.sql.SQLException
query
- an SQL query
java.sql.SQLException
public RowIterator query(java.lang.String query, Entity entity) throws java.sql.SQLException
query
- an SQL queryentity
- the resulting entity
java.sql.SQLException
public java.lang.Object evaluate(java.lang.String query)
query
- an sql query
public PooledPreparedStatement prepare(java.lang.String query)
query
- an sql query
public PooledPreparedStatement transactionPrepare(java.lang.String query)
query
- an sql query
public int update(java.lang.String query)
query
- an sql query
public int transactionUpdate(java.lang.String query)
query
- an sql query
public void close() throws java.sql.SQLException
java.sql.SQLException
- thrown by the database enginepublic void displayStats()
public ConnectionWrapper getConnection() throws java.sql.SQLException
java.sql.SQLException
public ConnectionWrapper getTransactionConnection() throws java.sql.SQLException
java.sql.SQLException
private void readConfigFile(java.io.InputStream config, XIncludeResolver xincludeResolver)
config
- input stream on the config filepublic java.lang.String adaptCase(java.lang.String identifier)
identifier
-
public void addEntity(Entity entity)
entity
- entity to addpublic Entity getRootEntity()
public Entity getEntityCreate(java.lang.String name)
name
- name of an entity
public Entity getEntity(java.lang.String name)
name
- the name of an entity
public java.util.Map<java.lang.String,Entity> getEntities()
public Attribute getAttribute(java.lang.String name)
name
- name of an attribute
public Action getAction(java.lang.String name)
name
- name of an attribute
public java.lang.String obfuscate(java.lang.Object value)
value
- value to obfuscate
public java.lang.String deobfuscate(java.lang.Object value)
value
- value to de-obfuscate
public DriverInfo getDriverInfo()
public int getCaseSensivity()
private java.lang.Integer getMagicNumber(java.lang.String schema)
public java.lang.String getSchema()
public static java.lang.String adaptContextCase(java.lang.String str)
str
- string to adapt
public void setUserContext(UserContext userContext)
userContext
- user contextpublic UserContext getUserContext()
public void setError(java.lang.String errormsg)
public java.lang.Object filterParam(java.lang.Object value)
value
- value to be filtered
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |