|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.drupal.project.async_command.DrupalConnection
public class DrupalConnection
Handles database connection to a Drupal site. Uses DBCP for connection pooling and DbUtils for simplified JDBC calls.
| Nested Class Summary | |
|---|---|
static class |
DrupalConnection.DatabaseType
|
| Field Summary | |
|---|---|
protected java.util.Properties |
config
Database configuration. |
protected org.apache.commons.dbcp.BasicDataSource |
dataSource
JDBC datasource for this Drupal connection. |
protected static java.util.logging.Logger |
logger
Default logger for the whole package. |
| Constructor Summary | |
|---|---|
DrupalConnection(java.io.File configFile)
Initializes database connection properties. |
|
DrupalConnection(java.util.Properties config)
Initializes database connection properties, set default properties if not given. |
|
DrupalConnection(java.lang.String configString)
Initializes database connection properties. |
|
| Method Summary | |
|---|---|
int[] |
batch(java.lang.String sql,
java.lang.Object[][] params)
Run batch database update. |
boolean |
checkConnection()
Check if the DataSource connection is still valid or not. |
void |
close()
|
void |
connect()
Equivalent to this.connect(false) |
void |
connect(boolean reconnect)
Initialize connection pooling and connect to the Drupal database. |
static DrupalConnection |
create()
|
java.lang.String |
d(java.lang.String sql)
"Decorates" the SQL statement for Drupal. |
java.sql.Connection |
getConnection()
Get a Drupal database connection from the pool. |
DrupalConnection.DatabaseType |
getDatabaseType()
|
javax.sql.DataSource |
getDataSource()
|
int |
getMaxBatchSize()
|
long |
insertAutoIncrement(java.lang.String sql,
java.lang.Object... params)
Insert one record and get the auto-increment ID. |
long |
insertCommandRecord(java.util.Map<java.lang.String,java.lang.Object> fields)
NOT SUPPORTED YET! Insert a command record into the database using fields. |
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
query(java.lang.String sql,
java.lang.Object... params)
Simply run Drupal database queries e.g., query("SELECT nid, title FROM {node} WHERE type=?", "forum"); |
java.util.List<java.lang.Object[]> |
queryArray(java.lang.String sql,
java.lang.Object... params)
Simply run Drupal database queries, returning a list of arrays instead of maps. |
java.lang.Object |
queryValue(java.lang.String sql,
java.lang.Object... params)
Simply run Drupal database queries, returning one value. |
java.util.List<CommandRecord> |
retrieveAnyCommandRecord(java.lang.String sqlWhere)
Retrieve any records in the {async_command} table given the "where" SQL clause. |
CommandRecord |
retrieveCommandRecord(long id)
Load a record from database . |
java.util.List<CommandRecord> |
retrievePendingCommandRecord(java.lang.String appName)
Retrieve a list of pending commands for the given app. |
void |
testConnection()
Test if the Drupal connection is working or not. |
int |
update(java.lang.String sql,
java.lang.Object... params)
Run Drupal database update queries (UPDATE, DELETE, INSERT) without using d(). |
java.lang.Object |
variableGet(java.lang.String varName)
Java version of Drupal function variable_get(). |
void |
variableSet(java.lang.String varName,
java.lang.Object varValue)
Java version of Drupal function variable_set(). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Properties config
protected static java.util.logging.Logger logger
protected org.apache.commons.dbcp.BasicDataSource dataSource
| Constructor Detail |
|---|
public DrupalConnection(java.util.Properties config)
config - Database configurationpublic DrupalConnection(java.lang.String configString)
configString - Properties string.public DrupalConnection(java.io.File configFile)
configFile - Properties file to config database connection.| Method Detail |
|---|
public javax.sql.DataSource getDataSource()
public DrupalConnection.DatabaseType getDatabaseType()
public static DrupalConnection create()
public void connect()
public void connect(boolean reconnect)
reconnect - Whether to force recreate dataSource.public void testConnection()
DrupalDatabaseException if error occurs. Otherwise do nothing.
public void close()
public boolean checkConnection()
public java.lang.String d(java.lang.String sql)
sql - the original SQL statement to be decorated.
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> query(java.lang.String sql,
java.lang.Object... params)
throws java.sql.SQLException
sql - SQL query to be executed, use {} for table namesparams - Parameters to complete the SQL query
java.sql.SQLException
public java.lang.Object queryValue(java.lang.String sql,
java.lang.Object... params)
throws java.sql.SQLException
sql - SQL query to be executed, use {} for table namesparams - Parameters to complete the SQL query
java.sql.SQLException
public java.util.List<java.lang.Object[]> queryArray(java.lang.String sql,
java.lang.Object... params)
throws java.sql.SQLException
sql - SQL query to be executed, use {} for table namesparams - Parameters to complete the SQL query
java.sql.SQLException
public int update(java.lang.String sql,
java.lang.Object... params)
throws java.sql.SQLException
sql - SQL update query to be executed, use {} for table names.params - parameters to complete the SQL query
java.sql.SQLException
public long insertAutoIncrement(java.lang.String sql,
java.lang.Object... params)
throws java.sql.SQLException
sql - SQL INSERT statement.params - Parameters to complete INSERT
java.sql.SQLException
public int[] batch(java.lang.String sql,
java.lang.Object[][] params)
throws java.sql.SQLException
sql - SQL update query to be executed, use {} for table names.params - params parameters to complete the SQL query
java.sql.SQLExceptionpublic java.lang.Object variableGet(java.lang.String varName)
varName - Drupal variable name
SerializedPhpParser
public void variableSet(java.lang.String varName,
java.lang.Object varValue)
varName - the variable name.varValue - the variable value in PHP code string. MessageFormatpublic java.util.List<CommandRecord> retrieveAnyCommandRecord(java.lang.String sqlWhere)
sqlWhere - Starts with "WHERE". If null, then returns all records.
public java.util.List<CommandRecord> retrievePendingCommandRecord(java.lang.String appName)
appName -
public long insertCommandRecord(java.util.Map<java.lang.String,java.lang.Object> fields)
fields - fields data eg field=>value.
public CommandRecord retrieveCommandRecord(long id)
id - Record id from the database.
public java.sql.Connection getConnection()
throws java.sql.SQLException
java.sql.SQLExceptionpublic int getMaxBatchSize()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||