|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectvelosurf.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 | |
|---|---|
static int |
CASE_SENSITIVE
case-sensitive policy |
static int |
LOWERCASE
|
protected int |
mCaseSensivity
case-sensivity |
protected ConnectionPool |
mConnectionPool
Pool of connections |
private Cryptograph |
mCryptograph
cryptograph used to encrypt/decrypt database ids |
protected int |
mDefaultCaching
default caching mode |
protected boolean |
mDefaultReadOnly
default access mode |
protected DriverInfo |
mDriverInfo
driver infos (database vendor specific) |
protected java.util.Map |
mEntities
map name->entity |
protected java.util.Map |
mEntitiesByTableName
|
protected java.lang.String |
mError
error string for the last error |
protected int |
mMaxConnections
|
protected int |
mMinConnections
|
protected java.lang.String |
mPassword
database user's password |
protected PreparedStatementPool |
mPreparedStatementPool
pool of prepared statements |
protected int |
mReverseMode
|
protected Entity |
mRootEntity
root entity that contains all root attributes and actions |
protected java.lang.String |
mSchema
schema |
private java.lang.String |
mSeed
random seed used to initialize the cryptograph |
protected StatementPool |
mStatementPool
pool of statements |
protected ConnectionPool |
mTransactionConnectionPool
Pool of connections for transactions |
protected PreparedStatementPool |
mTransactionPreparedStatementPool
pool of prepared statements for transactions |
protected StatementPool |
mTransactionStatementPool
pool of statements for transactions |
protected java.lang.String |
mUrl
database url |
protected java.lang.String |
mUser
database user |
static int |
REVERSE_FULL
|
static int |
REVERSE_NONE
reverse-enginering modes |
static int |
REVERSE_PARTIAL
|
private static java.util.Map |
sConnectionsByConfigFile
map config files -> instances |
private static java.util.Map |
sConnectionsByParams
map parameters -> instances |
private static java.util.Map |
sSharedCatalog
Shared catalog, to share entities among instances. |
static int |
UPPERCASE
|
| Constructor Summary | |
|---|---|
protected |
Database()
builds a new connection |
protected |
Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl)
builds a new connection |
protected |
Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
builds a new connection |
protected |
Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
builds a new connection |
| Method Summary | |
|---|---|
java.lang.String |
adaptCase(java.lang.String identifier)
changes to lowercase or uppercase if needed |
protected boolean |
checkSyntax(java.lang.String inParamName,
java.lang.String inParamValue,
java.lang.String[] inPossibleValues)
check the syntax of a parameter in the config file |
void |
close()
close the connection |
protected void |
connect()
|
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 inQuery)
evaluate a query to a scalar |
Action |
getAction(java.lang.String inName)
get a named action |
Attribute |
getAttribute(java.lang.String inName)
get a named attribute |
int |
getCaseSensivity()
get database case-sensivity |
java.sql.Connection |
getConnection()
get a jdbc connection |
DriverInfo |
getDriverInfo()
get database vendor |
Entity |
getEntity(java.lang.String inName)
get an existing entity |
Entity |
getEntityCreate(java.lang.String name)
get a named entity or creeate it if it doesn't exist |
java.lang.String |
getError()
get the error string |
static Database |
getInstance(java.io.InputStream inConfig)
get a new connection |
static Database |
getInstance(java.lang.String inConfigFilename)
get a unique Database from config filename |
static Database |
getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl)
get a unique Database from connection params |
static Database |
getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
get a unique Database from connection params |
static Database |
getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
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 |
java.lang.String |
getSchema()
get the schema |
java.sql.Connection |
getTransactionConnection()
get the underlying jdbc connection used for transactions |
protected void |
initCryptograph()
|
protected static DriverInfo |
loadDriver(java.lang.String inUrl,
java.lang.String inDriver)
loads the appropriate driver |
java.lang.String |
obfuscate(java.lang.Object value)
obfuscate the given value |
protected void |
open(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
open the connection |
protected void |
open(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
open the connection |
private static int |
parseCaching(java.lang.String caching)
parse a caching value |
PooledPreparedStatement |
prepare(java.lang.String inQuery)
prepare a query |
RowIterator |
query(java.lang.String inQuery)
issue a query |
RowIterator |
query(java.lang.String inQuery,
Entity inEntity)
issue a query, knowing the resulting entity |
void |
readConfigFile(java.io.InputStream inConfig)
read configuration from the given input stream |
void |
readConfigFile(java.lang.String inConfigFile)
read the given config file |
protected void |
readMetaData()
read the meta data from the database : reverse engeenering |
protected void |
readTableMetaData(java.sql.DatabaseMetaData meta,
Entity entity,
java.lang.String tableName)
|
void |
setError(java.lang.String inError)
set the error string |
PooledPreparedStatement |
transactionPrepare(java.lang.String inQuery)
prepare a query which is part of a transaction |
int |
transactionUpdate(java.lang.String inQuery)
issue an update query that is part of a transaction |
int |
update(java.lang.String inQuery)
issues an update query |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String mUser
protected java.lang.String mPassword
protected java.lang.String mUrl
protected java.lang.String mSchema
protected ConnectionPool mConnectionPool
protected int mMinConnections
protected int mMaxConnections
protected ConnectionPool mTransactionConnectionPool
protected StatementPool mStatementPool
protected StatementPool mTransactionStatementPool
protected PreparedStatementPool mPreparedStatementPool
protected PreparedStatementPool mTransactionPreparedStatementPool
protected boolean mDefaultReadOnly
protected int mDefaultCaching
protected java.lang.String mError
protected java.util.Map mEntities
protected java.util.Map mEntitiesByTableName
protected Entity mRootEntity
protected DriverInfo mDriverInfo
private java.lang.String mSeed
private Cryptograph mCryptograph
public static final int CASE_SENSITIVE
public static final int UPPERCASE
public static final int LOWERCASE
protected int mCaseSensivity
public static final int REVERSE_NONE
public static final int REVERSE_PARTIAL
public static final int REVERSE_FULL
protected int mReverseMode
private static java.util.Map sConnectionsByParams
private static java.util.Map sConnectionsByConfigFile
private static java.util.Map sSharedCatalog
| Constructor Detail |
|---|
protected Database()
throws java.sql.SQLException
java.sql.SQLException - thrown by the database engine
protected Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database url
² * @exception SQLException thrown by the database engine
java.sql.SQLException
protected Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class name
java.sql.SQLException - thrown by the database engine
protected Database(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class nameinSchema - schema name to use
java.sql.SQLException - thrown by the database engine| Method Detail |
|---|
protected void open(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class name
java.sql.SQLException - thrown by the database engine
protected void open(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class nameinSchema - schema name
java.sql.SQLException - thrown by the database engine
protected void connect()
throws java.sql.SQLException
java.sql.SQLException
protected static DriverInfo loadDriver(java.lang.String inUrl,
java.lang.String inDriver)
inUrl - database urlinDriver - driver java class name
protected void initCryptograph()
public static Database getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database url
java.sql.SQLException - thrown by the database engine
public static Database getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class name
java.sql.SQLException - thrown by the database engine
public static Database getInstance(java.lang.String inUser,
java.lang.String inPassword,
java.lang.String inUrl,
java.lang.String inDriver,
java.lang.String inSchema)
throws java.sql.SQLException
inUser - user nameinPassword - passwordinUrl - database urlinDriver - driver java class nameinSchema - schema
java.sql.SQLException - thrown by the database engine
public static Database getInstance(java.lang.String inConfigFilename)
throws java.sql.SQLException,
java.io.FileNotFoundException
inConfigFilename - config filename
java.sql.SQLException - thrown by the database engine
java.io.FileNotFoundException
public static Database getInstance(java.io.InputStream inConfig)
throws java.sql.SQLException
inConfig - config filename
java.sql.SQLException - thrown by the database enginepublic RowIterator query(java.lang.String inQuery)
inQuery - an SQL query
public RowIterator query(java.lang.String inQuery,
Entity inEntity)
inQuery - an SQL queryinEntity - the resulting entity
public java.lang.Object evaluate(java.lang.String inQuery)
inQuery - an sql query
public PooledPreparedStatement prepare(java.lang.String inQuery)
inQuery - an sql query
public PooledPreparedStatement transactionPrepare(java.lang.String inQuery)
inQuery - an sql query
public int update(java.lang.String inQuery)
inQuery - an sql query
public int transactionUpdate(java.lang.String inQuery)
inQuery - an sql query
public void close()
throws java.sql.SQLException
java.sql.SQLException - thrown by the database enginepublic void displayStats()
public java.sql.Connection getConnection()
throws java.sql.SQLException
java.sql.SQLException
public java.sql.Connection getTransactionConnection()
throws java.sql.SQLException
java.sql.SQLException
protected void readMetaData()
throws java.sql.SQLException
java.sql.SQLException - thrown by the database engine
protected void readTableMetaData(java.sql.DatabaseMetaData meta,
Entity entity,
java.lang.String tableName)
throws java.sql.SQLException
java.sql.SQLException
public void readConfigFile(java.lang.String inConfigFile)
throws java.sql.SQLException
inConfigFile - config file pathname
java.sql.SQLException - thrown by the database engine
public void readConfigFile(java.io.InputStream inConfig)
throws java.sql.SQLException
inConfig - input stream on the config file
java.sql.SQLException - thrown by the database enginepublic java.lang.String adaptCase(java.lang.String identifier)
identifier -
private static int parseCaching(java.lang.String caching)
caching - string describing the type of caching
protected boolean checkSyntax(java.lang.String inParamName,
java.lang.String inParamValue,
java.lang.String[] inPossibleValues)
inParamName - name of the parameterinParamValue - value of the parameterinPossibleValues - possible values for the parameter
public Entity getEntityCreate(java.lang.String name)
name - name of an entity
public Entity getEntity(java.lang.String inName)
inName - the name of an entity
public Attribute getAttribute(java.lang.String inName)
inName - name of an attribute
public Action getAction(java.lang.String inName)
inName - name of an attribute
public void setError(java.lang.String inError)
inError - error stringpublic java.lang.String getError()
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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||