|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.ispsoft.jaxme.JMManagerImpl de.ispsoft.jaxme.JMJdbcManager
A Manager implementation for XML documents read from or written to an SQL database.
Nested Class Summary |
Nested classes inherited from class de.ispsoft.jaxme.JMManagerImpl |
JMManagerImpl.MyObserver |
Field Summary | |
static java.lang.String |
CONFIGURATION_NODE_NAME
Name of our private configuration node (JMJdbcManager in namespace JMManagerFactoryImpl.NAMESPACE_URI ) |
protected static int |
CREATE_KEY_DONT
Constant for not creating a primary key as part of the INSERT operation. |
protected static int |
CREATE_KEY_POST_INSERT
Constant for creating a primary key after the INSERT operation. |
protected static int |
CREATE_KEY_PRE_INSERT
Constant for creating a primary key before the INSERT operation. |
protected java.lang.String |
datasource
|
static java.lang.String |
DATASOURCE_NODE_NAME
Name of the DataSource node, used by subclasses only |
protected java.lang.String |
driver
|
static java.lang.String |
DRIVER_NODE_NAME
Name of the Driver node |
protected java.lang.String |
password
|
static java.lang.String |
PASSWORD_NODE_NAME
Name of the Password node |
protected java.lang.String |
url
|
static java.lang.String |
URL_NODE_NAME
Name of the Url node |
protected boolean |
useDataSource
|
protected java.lang.String |
user
|
static java.lang.String |
USER_NODE_NAME
Name of the User node |
Fields inherited from class de.ispsoft.jaxme.JMManagerImpl |
ELEMENT_CLASS_NAME, HANDLER_CLASS_NAME, jmAnyElementClass, jmContentHandlerClass |
Fields inherited from interface de.ispsoft.jaxme.JMManager |
BIGINT, BIT, BLOB, BOOLEAN, CLOB, DECIMAL, DOUBLE, FLOAT, INTEGER, SMALLINT, TIMESTAMP, TINYINT, VARBINARY, VARCHAR |
Constructor Summary | |
JMJdbcManager()
Creates a new instance of JMJdbcManager |
Method Summary | |
void |
delete(JMAnyElement pElement)
Deletes the given element in the database. |
protected void |
executeQueries(java.sql.Connection pConn,
java.sql.PreparedStatement[] pStmt)
|
void |
executeStatement(java.lang.String pQuery,
java.lang.Object[] pPlaceHolderArgs)
Executes the given statement. |
java.sql.Connection |
getConnection()
Returns an open JDBC connection |
protected java.sql.PreparedStatement[] |
getDeleteQueries(java.sql.Connection pConn,
JMJdbcElement pElement)
Returns an array of prepared statements, that are being performed to delete the element in the database. |
protected java.lang.String |
getFieldList()
Returns the field list to build an SQL SELECT statement. |
protected int |
getInsertCreatesPrimaryKey()
Returns whether a primary key should be created before the insert (CREATE_KEY_PRE_INSERT), after the insert (CREATE_KEY_POST_INSERT) or not at all (CREATE_KEY_DONT). |
protected java.sql.PreparedStatement[] |
getInsertQueries(java.sql.Connection pConn,
JMJdbcElement pElement)
Returns an array of prepared statements, that are being performed to insert the element into the database. |
protected java.sql.PreparedStatement |
getPreparedStatement(java.sql.Connection pConn,
java.lang.String pQuery,
java.lang.Object[] pPlaceHolderArgs)
Prepares the placeholders of the given statement. |
protected java.lang.String |
getQuery(java.lang.String pQuery)
Parses and converts the query. |
protected java.lang.String |
getTableList()
Returns the table list to build an SQL SELECT statement. |
protected java.sql.PreparedStatement[] |
getUpdateQueries(java.sql.Connection pConn,
JMJdbcElement pElement)
Returns an array of prepared statements, that are being performed to update the element in the database. |
protected java.lang.String |
getWhere()
Returns an additional filter for the WHERE clause. |
void |
init(JMManagerFactory pFactory,
java.lang.String pNamespaceURI,
java.lang.String pLocalName)
Initializes the manager. |
protected abstract void |
init(java.sql.ResultSet rs,
JMJdbcElement pElement)
Initializes the element from the resultset. |
void |
insert(JMAnyElement pElement)
Calls newPrimaryKey() and inserts the given
element into the database. |
protected void |
newPrimaryKey(java.sql.Connection pConn,
JMAnyElement pElement)
Creates a new primary key for the element. |
void |
parseConfiguration(org.w3c.dom.Element pElement)
Parses a configuration element. |
void |
select(Observer pObserver,
java.lang.String pQuery,
java.lang.Object[] pPlaceHolderArgs,
int pStart,
int pMax)
Reads documents matching the given query. |
void |
update(JMAnyElement pElement)
Inserts the given element into the database. |
Methods inherited from class de.ispsoft.jaxme.JMManagerImpl |
create, getJMAnyElementClass, getJMContentHandler, getLocalName, getNamespaceSupport, getNamespaceURI, select, select, select, select, select, select, select, toSAX, toWriter, toXML |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String CONFIGURATION_NODE_NAME
Name of our private configuration node (JMJdbcManager in
namespace JMManagerFactoryImpl.NAMESPACE_URI
)
public static final java.lang.String DRIVER_NODE_NAME
Name of the Driver node
public static final java.lang.String URL_NODE_NAME
Name of the Url node
public static final java.lang.String USER_NODE_NAME
Name of the User node
public static final java.lang.String PASSWORD_NODE_NAME
Name of the Password node
public static final java.lang.String DATASOURCE_NODE_NAME
Name of the DataSource node, used by subclasses only
protected java.lang.String driver
protected java.lang.String url
protected java.lang.String user
protected java.lang.String password
protected java.lang.String datasource
protected boolean useDataSource
protected static final int CREATE_KEY_DONT
Constant for not creating a primary key as part of the INSERT operation.
protected static final int CREATE_KEY_PRE_INSERT
Constant for creating a primary key before the INSERT operation.
protected static final int CREATE_KEY_POST_INSERT
Constant for creating a primary key after the INSERT operation.
Constructor Detail |
public JMJdbcManager()
Method Detail |
public void parseConfiguration(org.w3c.dom.Element pElement)
Parses a configuration element. This method is called twice: Once for the default configuration and once for the specific configuration.
parseConfiguration
in class JMManagerImpl
public void init(JMManagerFactory pFactory, java.lang.String pNamespaceURI, java.lang.String pLocalName) throws org.xml.sax.SAXException
init
in interface JMManager
init
in class JMManagerImpl
pFactory
- The factory that created this Manager.pNamespaceURI
- The document types namespace URIpLocalName
- The document types local name
org.xml.sax.SAXException
public java.sql.Connection getConnection() throws java.sql.SQLException, org.xml.sax.SAXException
Returns an open JDBC connection
java.sql.SQLException
org.xml.sax.SAXException
protected void executeQueries(java.sql.Connection pConn, java.sql.PreparedStatement[] pStmt) throws java.sql.SQLException
java.sql.SQLException
protected int getInsertCreatesPrimaryKey()
Returns whether a primary key should be created before the insert (CREATE_KEY_PRE_INSERT), after the insert (CREATE_KEY_POST_INSERT) or not at all (CREATE_KEY_DONT).
protected void newPrimaryKey(java.sql.Connection pConn, JMAnyElement pElement) throws java.sql.SQLException
Creates a new primary key for the element. Does nothing, to be overwritten by subclasses.
java.sql.SQLException
public void insert(JMAnyElement pElement) throws org.xml.sax.SAXException
Calls newPrimaryKey()
and inserts the given
element into the database.
insert
in interface JMManager
insert
in class JMManagerImpl
org.xml.sax.SAXException
public void update(JMAnyElement pElement) throws org.xml.sax.SAXException
Inserts the given element into the database.
update
in interface JMManager
update
in class JMManagerImpl
org.xml.sax.SAXException
public void delete(JMAnyElement pElement) throws org.xml.sax.SAXException
Deletes the given element in the database.
delete
in interface JMManager
delete
in class JMManagerImpl
org.xml.sax.SAXException
public void select(Observer pObserver, java.lang.String pQuery, java.lang.Object[] pPlaceHolderArgs, int pStart, int pMax) throws org.xml.sax.SAXException
Reads documents matching the given query. For any document matching, the Observer's notify method is executed with the matching document as an argument.
The query may contain placeholders. If it does, you have to supply an object array with two elements per placeholder: An Integer with a java.sql.Types type and the actual placeholder value. Example:
manager.select("Name = ? and Id = ?", new Object[]{JMManager.VARCHAR, "Someone", JMManager.INTEGER, 4}, 0, 0);
select
in interface JMManager
select
in class JMManagerImpl
pObserver
- This Observer is notified for any matching document.
The document is added as an argument.pQuery
- The query to perform. May contain placeholders.pPlaceHolderArgs
- An array of objects or null, if the
query doesn't contain any placeholders.pStart
- Ignore the given number of result documents at the
beginning. A value of zero will return all documents.pMax
- Return at most the given number of documents. A value
of zero will return all documents.
org.xml.sax.SAXException
protected java.lang.String getQuery(java.lang.String pQuery) throws org.xml.sax.SAXException
Parses and converts the query.
org.xml.sax.SAXException
protected abstract void init(java.sql.ResultSet rs, JMJdbcElement pElement) throws java.sql.SQLException, org.xml.sax.SAXException
Initializes the element from the resultset. In other words, reads one row from the result set.
java.sql.SQLException
org.xml.sax.SAXException
protected java.lang.String getFieldList() throws org.xml.sax.SAXException
Returns the field list to build an SQL SELECT statement.
org.xml.sax.SAXException
protected java.lang.String getTableList() throws org.xml.sax.SAXException
Returns the table list to build an SQL SELECT statement.
org.xml.sax.SAXException
protected java.sql.PreparedStatement[] getInsertQueries(java.sql.Connection pConn, JMJdbcElement pElement) throws org.xml.sax.SAXException, java.sql.SQLException
Returns an array of prepared statements, that are being performed to insert the element into the database.
org.xml.sax.SAXException
java.sql.SQLException
protected java.sql.PreparedStatement[] getUpdateQueries(java.sql.Connection pConn, JMJdbcElement pElement) throws org.xml.sax.SAXException, java.sql.SQLException
Returns an array of prepared statements, that are being performed to update the element in the database.
org.xml.sax.SAXException
java.sql.SQLException
protected java.sql.PreparedStatement[] getDeleteQueries(java.sql.Connection pConn, JMJdbcElement pElement) throws org.xml.sax.SAXException, java.sql.SQLException
Returns an array of prepared statements, that are being performed to delete the element in the database.
org.xml.sax.SAXException
java.sql.SQLException
protected java.lang.String getWhere() throws org.xml.sax.SAXException
Returns an additional filter for the WHERE clause. You should probably not use this, as it requires heavy parsing of the query to support sorting and the like. It is only there for databases not supporting the "a JOIN b ON a.foo=b.bar WHERE ..." syntax, in which case we need to write "a, b WHERE (a.foo=b.bar) AND (...)".
org.xml.sax.SAXException
public void executeStatement(java.lang.String pQuery, java.lang.Object[] pPlaceHolderArgs) throws org.xml.sax.SAXException
Executes the given statement.
org.xml.sax.SAXException
protected java.sql.PreparedStatement getPreparedStatement(java.sql.Connection pConn, java.lang.String pQuery, java.lang.Object[] pPlaceHolderArgs) throws java.sql.SQLException
Prepares the placeholders of the given statement.
java.sql.SQLException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |