|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectlazyj.DBFunctions
public class DBFunctions
Wrapper for JDBC connections and collection of useful functions related to database connections. It is also a connection pool, recycling previously established sessions and closing the idle ones.
| Nested Class Summary | |
|---|---|
static class |
DBFunctions.DBConnection
Wrapper around a raw database connection. |
| Field Summary | |
|---|---|
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger> |
chmQueryCount
For statistics: how many queries were executed on each connection. |
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.atomic.AtomicLong> |
chmQueryTime
For statistics: total time to execute the queries on each of the connections. |
| Constructor Summary | |
|---|---|
DBFunctions(ExtProperties configProperties)
Create a connection to the database using the parameters in this properties file. |
|
DBFunctions(ExtProperties configProperties,
java.lang.String sQuery)
Create a connection to the database using the parameters in this properties file, then execute the given query. |
|
DBFunctions(java.util.Properties configProperties)
|
|
DBFunctions(java.util.Properties configProperties,
java.lang.String sQuery)
Create a connection to the database using the parameters in this properties file, then execute the given query. |
|
DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL)
If you already have the full JDBC connection URL, connect like this. |
|
DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL,
java.util.Properties configProperties)
If you already have the full JDBC connection URL, connect like this |
|
DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL,
java.util.Properties configProperties,
java.lang.String sQuery)
If you already have the full JDBC connection URL, connect like this. |
|
| Method Summary | |
|---|---|
boolean |
absolute(int position)
Jump to an absolute position in the result set |
int |
count()
Get the number of rows that were selected by the previous query. |
static java.lang.String |
encodeArray(java.util.Collection<?> array)
Generate a PostgreSQL array representation of the given one-dimensional collection. |
protected void |
finalize()
Override the default destructor to properly close any resources in use. |
static java.util.HashMap<java.lang.String,java.lang.Integer> |
getActiveConnections()
Statistics : get the number of connections per each unique key |
static long |
getActiveConnectionsCount()
Statistics : get the number of connections currently established |
boolean |
getb(int iColumn,
boolean bDefault)
Get the boolean value of a column |
boolean |
getb(java.lang.String sColumn,
boolean bDefault)
Get the boolean value of a column |
static long |
getClosedConnectionsCount()
Statistics : the total number of closed connection to the databases until now. |
static long |
getClosedOnFinalizeConnectionsCount()
Statistics : the total number of closed connection to the databases executed when the object is deallocated. |
java.lang.String[] |
getColumnNames()
A shortcut to find out the column names for this query |
java.lang.String |
getConnectFailReason()
Get the reason why the last connect() attempt has failed. |
DBFunctions.DBConnection |
getConnection()
Get a raw database connection wrapper. |
double |
getd(int iColumn)
Get the double value of a column. |
double |
getd(int iColumn,
double dDefault)
Get the double value of a column. |
double |
getd(java.lang.String sColumnName)
Get the double value of a column. |
double |
getd(java.lang.String sColumnName,
double dDefault)
Get the double value of a column. |
java.util.Date |
getDate(int iColumn)
Get the column contents converted to Date. |
java.util.Date |
getDate(int iColumn,
java.util.Date dDefault)
Get the value of a column as a Date object. |
java.util.Date |
getDate(java.lang.String sColumnName)
Get the column contents converted to Date. |
java.util.Date |
getDate(java.lang.String sColumnName,
java.util.Date dDefault)
Get the column contents converted to Date. |
float |
getf(int iColumn)
Get the float value of a column. |
float |
getf(int iColumn,
float fDefault)
Get the float value of a column. |
float |
getf(java.lang.String sColumnName)
Get the float value of a column. |
float |
getf(java.lang.String sColumnName,
float fDefault)
Get the float value of a column. |
int |
geti(int iColumn)
Get the value of this column as int, returning the default value of 0 if the conversion is not possible. |
int |
geti(int iColumn,
int iDefault)
Get the integer value of a column. |
int |
geti(java.lang.String sColumnName)
Get the value of this column as int. |
int |
geti(java.lang.String sColumnName,
int iDefault)
Get the value of this column as int, returning the default value if the conversion is not possible. |
java.util.Collection<java.lang.Integer> |
getIntArray(int iColumn)
Extract a PostgreSQL array into a Collection of Integer objects |
java.util.Collection<java.lang.Integer> |
getIntArray(java.lang.String sColumn)
Extract a PostgreSQL array into a Collection of Integer objects |
long |
getl(int iColCount)
Get the long value of a column. |
long |
getl(int iColCount,
long lDefault)
Get the long value of a column. |
long |
getl(java.lang.String sColumnName)
Get the long value of a column. |
long |
getl(java.lang.String sColumnName,
long lDefault)
Get the long value of a column. |
java.sql.ResultSetMetaData |
getMetaData()
Get the meta information for the current query. |
static long |
getOpenedConnectionsCount()
Statistics : the total number of opened connection to the databases until now. |
int |
getPosition()
Get the current position in the result set |
static long |
getQueryCount()
Statistics : get the total number of executed queries. |
java.lang.String |
gets(int iColumn)
Get the contents of a column from the current row based on its position |
java.lang.String |
gets(int iColumn,
java.lang.String sDefault)
Get the contents of a column from the current row based on its position. |
java.lang.String |
gets(java.lang.String sColumnName)
Get the contents of a column from the current row based on its name. |
java.lang.String |
gets(java.lang.String sColumnName,
java.lang.String sDefault)
Get the contents of a column from the current row based on its name. |
java.util.Collection<java.lang.String> |
getStringArray(int iColumn)
Extract a PostgreSQL array into a Collection of String objects |
java.util.Collection<java.lang.String> |
getStringArray(java.lang.String sColumn)
Extract a PostgreSQL array into a Collection of String objects |
int |
getUpdateCount()
Get the number of rows affected by the last SQL update query. |
boolean |
isMySQL()
Check if this connection is done to a MySQL database (if we are using the MySQL JDBC driver) |
boolean |
isPostgreSQL()
Check if this connection is done to a PostgreSQL database (if we are using the PG JDBC driver) |
boolean |
moveNext()
Jump to the next row in the result |
static java.lang.String |
propToJDBC(java.util.Properties prop)
Build a JDBC URL connection string for a bunch of parameters |
boolean |
query(java.lang.String sQuery)
Execute a query. |
boolean |
query(java.lang.String sQuery,
boolean bIgnoreErrors)
Execute an error and as an option you can force to ignore any errors, no to log them if you expect a query to fail. |
boolean |
relative(int count)
Jump an arbitrary number of rows. |
static void |
startThread()
Start the cleanup thread. |
static void |
stopThread()
Signal the thread that it's time to stop. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger> chmQueryCount
public static final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.atomic.AtomicLong> chmQueryTime
| Constructor Detail |
|---|
public DBFunctions(ExtProperties configProperties)
configProperties - connection optionspublic DBFunctions(java.util.Properties configProperties)
configProperties - DBFunctions(ExtProperties)
public DBFunctions(java.util.Properties configProperties,
java.lang.String sQuery)
configProperties - connection parameterssQuery - query to execute after connectingDBFunctions(ExtProperties)
public DBFunctions(ExtProperties configProperties,
java.lang.String sQuery)
configProperties - connection parameterssQuery - query to execute after connectingDBFunctions(ExtProperties)
public DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL)
driverClass - JDBC driver class namejdbcURL - JDBC connection URLDBFunctions(String, String, Properties)
public DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL,
java.util.Properties configProperties)
driverClass - JDBC driver class namejdbcURL - full JDBC connection URLconfigProperties - extra configuration options. Can be null if the URL has everything in itDBFunctions(ExtProperties)
public DBFunctions(java.lang.String driverClass,
java.lang.String jdbcURL,
java.util.Properties configProperties,
java.lang.String sQuery)
driverClass - JDBC driver class namejdbcURL - full JDBC connection URLconfigProperties - extra configuration optionssQuery - query to executeDBFunctions(ExtProperties)| Method Detail |
|---|
public boolean isPostgreSQL()
public boolean isMySQL()
public java.lang.String getConnectFailReason()
null if the connection actually workedpublic final DBFunctions.DBConnection getConnection()
DBFunctions.DBConnection.free() or DBFunctions.DBConnection.close() at the end of the section where you use it!
null if a connection cannot be establishedDBFunctions.DBConnectionpublic static final java.lang.String propToJDBC(java.util.Properties prop)
prop -
null if for any reason it cannot be built (unknown driver?)public static final void startThread()
public static final void stopThread()
public final int getUpdateCount()
protected void finalize()
finalize in class java.lang.Objectpublic boolean query(java.lang.String sQuery)
sQuery - SQL query to execute
true if the query succeeded, false if there was an error (connection or syntax).query(String, boolean)
public final boolean query(java.lang.String sQuery,
boolean bIgnoreErrors)
sQuery - query to executebIgnoreErrors - true if you want to hide any errors
public final int count()
public final int getPosition()
ResultSet.getRow()public final boolean relative(int count)
count - can be positive or negative
ResultSet.relative(int)public final boolean absolute(int position)
position - new position
ResultSet.absolute(int)public final boolean moveNext()
public final java.lang.String gets(java.lang.String sColumnName)
sColumnName - column name
gets(String, String),
gets(int),
gets(int, String)
public final java.lang.String gets(java.lang.String sColumnName,
java.lang.String sDefault)
sColumnName - column namesDefault - default value to return if the column doesn't exist or is null
gets(String),
gets(int),
gets(int, String)public final java.lang.String gets(int iColumn)
iColumn - column count
gets(String),
gets(String, String),
gets(int, String)
public final java.lang.String gets(int iColumn,
java.lang.String sDefault)
iColumn - position (1 = first column of the result set)sDefault - default value to return if the column doesn't exist or is null
gets(String),
gets(String, String),
gets(int)public final java.util.Date getDate(java.lang.String sColumnName)
sColumnName - column name
null but maybe the current time if the contents cannot be converted to DateFormat.parseDate(String),
getDate(String, Date),
getDate(int),
getDate(int, Date)
public final java.util.Date getDate(java.lang.String sColumnName,
java.util.Date dDefault)
sColumnName - column namedDefault - default value to return if the contents in db cannot be parsed to Date
Format.parseDate(String),
getDate(String),
getDate(int),
getDate(int, Date)public final java.util.Date getDate(int iColumn)
iColumn - column number ( 1 = first column of the result set )
Format.parseDate(String),
getDate(String),
getDate(String, Date),
getDate(int, Date)
public final java.util.Date getDate(int iColumn,
java.util.Date dDefault)
iColumn - column number ( 1 = first column of the result set )dDefault - default value to return in case of an error at parsing
Format.parseDate(String),
getDate(String),
getDate(String, Date),
getDate(int)public final int geti(java.lang.String sColumnName)
sColumnName - column
geti(String, int),
geti(int),
geti(int, int)
public final int geti(java.lang.String sColumnName,
int iDefault)
sColumnName - column nameiDefault - default value to return
geti(String),
geti(int),
geti(int, int)public final int geti(int iColumn)
iColumn - column position
geti(String, int),
geti(String),
geti(int, int)
public final int geti(int iColumn,
int iDefault)
iColumn - column numberiDefault - default value to return in case of a parsing error
geti(String, int),
geti(int),
geti(String)public final long getl(java.lang.String sColumnName)
sColumnName - column name
getl(String, long),
getl(int),
getl(int, long)
public final long getl(java.lang.String sColumnName,
long lDefault)
sColumnName - column namelDefault - default value to return in case of a parsing error
getl(String),
getl(int),
getl(int, long)public final long getl(int iColCount)
iColCount - column count
getl(String, long),
getl(String),
getl(int, long)
public final long getl(int iColCount,
long lDefault)
iColCount - column countlDefault - default value to return in case of a parsing error
getl(String, long),
getl(int),
getl(String)public final float getf(java.lang.String sColumnName)
sColumnName - column name
public final float getf(java.lang.String sColumnName,
float fDefault)
sColumnName - column namefDefault - default value to return in case of a parsing error
public final float getf(int iColumn)
iColumn - column position
public final float getf(int iColumn,
float fDefault)
iColumn - column positionfDefault - default value to return in case of a parsing error
public final double getd(java.lang.String sColumnName)
sColumnName - column name
public final double getd(java.lang.String sColumnName,
double dDefault)
sColumnName - column namedDefault - default value to return in case of a parsing error
public final double getd(int iColumn)
iColumn - column position
public final double getd(int iColumn,
double dDefault)
iColumn - column positiondDefault - default value to return in case of a parsing error
public final boolean getb(java.lang.String sColumn,
boolean bDefault)
sColumn - column namebDefault - default value
Utils.stringToBool(String, boolean),
getb(int, boolean)
public final boolean getb(int iColumn,
boolean bDefault)
iColumn - column indexbDefault - default value
Utils.stringToBool(String, boolean),
getb(String, boolean)public final java.util.Collection<java.lang.String> getStringArray(java.lang.String sColumn)
sColumn - column name
public final java.util.Collection<java.lang.String> getStringArray(int iColumn)
iColumn - column index
public final java.util.Collection<java.lang.Integer> getIntArray(java.lang.String sColumn)
sColumn - column name
public final java.util.Collection<java.lang.Integer> getIntArray(int iColumn)
iColumn - column index
public static java.lang.String encodeArray(java.util.Collection<?> array)
array -
public final java.sql.ResultSetMetaData getMetaData()
public final java.lang.String[] getColumnNames()
public static final long getOpenedConnectionsCount()
public static final long getClosedConnectionsCount()
public static final long getClosedOnFinalizeConnectionsCount()
public static final long getQueryCount()
public static final long getActiveConnectionsCount()
public static final java.util.HashMap<java.lang.String,java.lang.Integer> getActiveConnections()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||