|
|||||||||
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
Deprecated. |
protected org.apache.commons.dbcp.BasicDataSource |
dataSource
JDBC datasource for this Drupal connection. |
protected DrupletConfig |
drupletConfig
Configuration for Druplet, including config about the database. |
protected static java.util.logging.Logger |
logger
Default logger for the whole package. |
Constructor Summary | |
---|---|
DrupalConnection(DrupletConfig drupletConfig)
|
|
DrupalConnection(java.io.File configFile)
Deprecated. |
|
DrupalConnection(java.util.Properties config)
Deprecated. |
|
DrupalConnection(java.lang.String configString)
Deprecated. |
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()
Deprecated. |
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()
|
java.lang.String |
getEncryptedFieldSecretKey()
|
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. |
long |
issueAsyncCommand(java.lang.String app,
java.lang.String command,
java.lang.String description,
java.util.Map<java.lang.String,java.lang.Object> options)
|
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> |
retrieveNewCommandRecord(java.lang.String appName)
Retrieve a list of new and unhandled 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 |
---|
@Deprecated protected java.util.Properties config
protected DrupletConfig drupletConfig
protected static java.util.logging.Logger logger
protected org.apache.commons.dbcp.BasicDataSource dataSource
Constructor Detail |
---|
@Deprecated public DrupalConnection(java.util.Properties config)
config
- Database configurationpublic DrupalConnection(DrupletConfig drupletConfig)
@Deprecated public DrupalConnection(java.lang.String configString)
configString
- Properties string.@Deprecated public DrupalConnection(java.io.File configFile)
configFile
- Properties file to config database connection.Method Detail |
---|
public javax.sql.DataSource getDataSource()
public DrupalConnection.DatabaseType getDatabaseType()
@Deprecated 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.SQLException
public 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. MessageFormat
public java.util.List<CommandRecord> retrieveAnyCommandRecord(java.lang.String sqlWhere)
sqlWhere
- Starts with "WHERE". If null, then returns all records.
public java.util.List<CommandRecord> retrieveNewCommandRecord(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 long issueAsyncCommand(java.lang.String app, java.lang.String command, java.lang.String description, java.util.Map<java.lang.String,java.lang.Object> options)
public CommandRecord retrieveCommandRecord(long id)
id
- Record id from the database.
public java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException
public int getMaxBatchSize()
public java.lang.String getEncryptedFieldSecretKey()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |