|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.util.DBUtil
public class DBUtil
This class provides a set of static methods which perform various utility operations on databases.
Field Summary | |
---|---|
static String |
REVISION
|
Constructor Summary | |
---|---|
DBUtil()
|
Method Summary | |
---|---|
static void |
addDataSource(String name,
DataSource dataSource)
Adds the given data source. |
static String |
buildSelectQuery(String dataSource,
String select,
String from,
String orderby,
String[] whereParams,
String[] whereValues,
boolean and)
This convenient method build an SQL Select query from the given parameters. |
static boolean |
checkDataSource(String dataSource)
Returns true if the given dataSource is available (i.e. |
static SQLQueryResult |
executeQuery(String dataSource,
String sqlQuery,
int maxRows)
This convient method performs a query and return a SQLQueryResult |
static void |
executeUpdate(String dataSource,
String sql)
This convenient method executes an update (insert/update/delete) in the given dataSource. |
static boolean[] |
getColumnsNumericsMetaData(String dataSource,
String tables,
String[] columns)
This method do a small request to the given database to extract metadata of given columns. |
static Connection |
getConnection(String dataSource)
Attempts to establish a connection with a given data source. |
static Connection |
getConnection(String dataSource,
String username,
String password)
Attempts to establish a connection with a given data source. |
static DataSource |
getDataSource(String dataSource)
Lookup for the given data source. |
static Map<String,DataSource> |
getDataSourceMap()
Lookup for all "java:com/env/jdbc/*" data sources declared in the AppServer. |
static Object |
getFirstValue(Connection conn,
String sqlQuery)
This convenient method performs a query then it returns the value of the first column of the first row of the result set. |
static Object |
getFirstValue(String dataSource,
String sqlQuery)
This convenient method performs a query then it returns the value of the first column of the first row of the result set. |
static Object |
getFirstValue(String dataSource,
String select,
String from,
String orderby,
String[] whereParams,
String[] whereValues,
boolean and)
This convenient method performs a query then it returns the value of the first column of the first row of the result set. |
static void |
initDataSourceMap(Set<String> includedDataSourceSet,
Set<String> excludedDataSourceSet)
This method must be called before any other methods accessing to the dataSourceMap. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
Constructor Detail |
---|
public DBUtil()
Method Detail |
---|
public static Map<String,DataSource> getDataSourceMap()
getDataSource(String)
public static void initDataSourceMap(Set<String> includedDataSourceSet, Set<String> excludedDataSourceSet)
includedDataSourceSet
- if not empty, only dataSource declared in this set will be used.excludedDataSourceSet
- if not empty, any dataSource declared in this set will be excluded.public static DataSource getDataSource(String dataSource)
dataSource
- the name of the data source (eg. "jdbc/TestDB")
getDataSourceMap()
public static Connection getConnection(String dataSource) throws SQLException
dataSource
- the name of the data source (eg. "jdbc/TestDB")
SQLException
public static Connection getConnection(String dataSource, String username, String password) throws SQLException
dataSource
- the name of the data source (eg. "jdbc/TestDB")username
- the database user on whose behalf the connection is being madepassword
- the user's password
SQLException
public static String buildSelectQuery(String dataSource, String select, String from, String orderby, String[] whereParams, String[] whereValues, boolean and) throws SQLException
dataSource
- the name of the data source (eg. "jdbc/TestDB")select
- the table filed to select or *from
- the table name to work with.orderby
- the order by parameterwhereParams
- an array of parameterswhereValues
- an array of parameters valueand
- should be 'AND' or 'OR' between parameters
SQLException
public static boolean[] getColumnsNumericsMetaData(String dataSource, String tables, String[] columns) throws SQLException
"numeric" means Types.BIGINT, Types.INTEGER, Types.SMALLINT, Types.NUMERIC
dataSource
- the name of the data source (eg. "jdbc/TestDB")tables
- the table namescolumns
- the column names
SQLException
public static Object getFirstValue(String dataSource, String select, String from, String orderby, String[] whereParams, String[] whereValues, boolean and) throws SQLException
dataSource
- the name of the data source (eg. "jdbc/TestDB")select
- the table filed to select or *from
- the table name to work with.orderby
- the order by parameterwhereParams
- an array of parameterswhereValues
- an array of parameters valueand
- should be 'AND' or 'OR' between parameters
SQLException
public static Object getFirstValue(String dataSource, String sqlQuery) throws SQLException
dataSource
- the name of the data source (eg. "jdbc/TestDB")sqlQuery
- the SQL query to be performed
SQLException
public static Object getFirstValue(Connection conn, String sqlQuery)
conn
- the JDBC connectionsqlQuery
- the SQL query to be performed
public static SQLQueryResult executeQuery(String dataSource, String sqlQuery, int maxRows)
dataSource
- the name of the data source (eg. "jdbc/TestDB")sqlQuery
- the SQL (SELECT) querymaxRows
- the max rows limit; zero means there is no limit
public static void executeUpdate(String dataSource, String sql)
dataSource
- the data sourcesql
- update querypublic static boolean checkDataSource(String dataSource)
dataSource
- the data source.
public static void addDataSource(String name, DataSource dataSource)
name
- the name of the data source.dataSource
- the data source.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |