Author: jochen Date: Thu Oct 27 12:57:38 2005 New Revision: 328942 URL: http://svn.apache.org/viewcvs?rev=328942&view=rev Log: Added support for the TaminoAPI4J without the resource adapter. In other words, this is usable in the absence of an EJB container.
Modified: webservices/jaxme/branches/b0_5/src/pm/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JPm.java Modified: webservices/jaxme/branches/b0_5/src/pm/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JPm.java URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/pm/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JPm.java?rev=328942&r1=328941&r2=328942&view=diff ============================================================================== --- webservices/jaxme/branches/b0_5/src/pm/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JPm.java (original) +++ webservices/jaxme/branches/b0_5/src/pm/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JPm.java Thu Oct 27 12:57:38 2005 @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.ws.jaxme.pm.ino.api4j; -import javax.naming.InitialContext; -import javax.naming.NamingException; import javax.xml.bind.Element; import javax.xml.bind.JAXBException; @@ -38,8 +35,6 @@ import com.softwareag.tamino.db.api.accessor.TUpdateException; import com.softwareag.tamino.db.api.accessor.TXMLObjectAccessor; import com.softwareag.tamino.db.api.connection.TConnection; -import com.softwareag.tamino.db.api.connection.TServerNotAvailableException; -import com.softwareag.tamino.db.api.connector.TaminoDataSource; import com.softwareag.tamino.db.api.objectModel.TIteratorException; import com.softwareag.tamino.db.api.objectModel.TNoSuchXMLObjectException; import com.softwareag.tamino.db.api.objectModel.TXMLObject; @@ -48,13 +43,16 @@ import com.softwareag.tamino.db.api.objectModel.sax.TSAXObjectModel; import com.softwareag.tamino.db.api.response.TResponse; -/** - * @author <a href="mailto:[EMAIL PROTECTED]">Jochen Wiedmann</a> + +/** Common base class for + * [EMAIL PROTECTED] org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JRaPm}, and + * [EMAIL PROTECTED] org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JDbPm}. */ -public class TaminoAPI4JPm extends PMImpl { +public abstract class TaminoAPI4JPm extends PMImpl { private static final ThreadLocal context = new ThreadLocal(); - private static TSAXObjectModel model; + private String collection; private static boolean isInitialized; + private static TSAXObjectModel model; static JAXBContextImpl getJAXBContext() { return (JAXBContextImpl) context.get(); @@ -64,32 +62,12 @@ context.set(pContext); } - private String collection; - private String jndiReference; - - public String getCollection() { - return collection; - } - - public void setCollection(String pCollection) { - collection = pCollection; - } - - public String getJndiReference() { - return jndiReference; - } - - public void setJndiReference(String pJndiReference) { - jndiReference = pJndiReference; - } - public void init(JMManager pManager) throws JAXBException { super.init(pManager); if (!isInitialized) { - synchronized(TaminoAPI4JPm.class) { + synchronized(TaminoAPI4JRaPm.class) { if (!isInitialized) { - System.err.println("Registering object model in class " + TXMLObjectModel.class + " with class loader " + TXMLObjectModel.class.getClassLoader()); - TSAXObjectModel m = new TSAXObjectModel(TaminoAPI4JPm.class.getName(), + TSAXObjectModel m = new TSAXObjectModel(TaminoAPI4JRaPm.class.getName(), TJMElement.class, TJMElement.class, new DocumentDefaultHandler(), new ElementDefaultHandler()); @@ -103,12 +81,20 @@ if (collection == null || collection.length() == 0) { throw new JAXBException("The property 'collection' must be set."); } - jndiReference = pManager.getProperty("jndiReference"); - if (jndiReference == null || jndiReference.length() == 0) { - throw new JAXBException("The property 'jndiReference' must be set."); - } } - + + /** Returns the Tamino database collection. + */ + public String getCollection() { + return collection; + } + + /** Sets the Tamino database collection. + */ + public void setCollection(String pCollection) { + collection = pCollection; + } + protected TXMLObject getTXMLObject(InoObject pElement) { return TXMLObject.newInstance(new TJMElement(pElement)); } @@ -117,17 +103,12 @@ return model; } - protected TConnection getTConnection() throws NamingException, TServerNotAvailableException { - InitialContext ic = new InitialContext(); - TaminoDataSource tds = (TaminoDataSource) ic.lookup(jndiReference); - TConnection con = tds.getConnection(); - return con; - } + protected abstract TConnection getTConnection() throws PMException; public void select(Observer pObserver, String pQuery, PMParams pParams) throws PMException { TConnection conn = null; try { - JAXBContextImpl c = getManager().getFactory(); + JAXBContextImpl c = getManager().getFactory(); setJAXBContext(c); JMUnmarshallerHandlerImpl h = (JMUnmarshallerHandlerImpl) c.createUnmarshaller().getUnmarshallerHandler(); DocumentDefaultHandler.setUnmarshallerHandler(h); @@ -140,10 +121,6 @@ TXMLObject object = iter.next(); pObserver.notify(((TJMElement) object.getElement()).getJMElement()); } - } catch (TServerNotAvailableException e) { - throw new PMException(e); - } catch (NamingException e) { - throw new PMException(e); } catch (TQueryException e) { throw new PMException(e); } catch (TNoSuchXMLObjectException e) { @@ -167,10 +144,6 @@ conn = getTConnection(); TXMLObjectAccessor accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), model); accessor.insert(getTXMLObject((InoObject) pElement)); - } catch (TServerNotAvailableException e) { - throw new PMException(e); - } catch (NamingException e) { - throw new PMException(e); } catch (TInsertException e) { throw new PMException(e); } finally { @@ -186,10 +159,6 @@ conn = getTConnection(); TXMLObjectAccessor accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), model); accessor.update(getTXMLObject((InoObject) pElement)); - } catch (TServerNotAvailableException e) { - throw new PMException(e); - } catch (NamingException e) { - throw new PMException(e); } catch (TUpdateException e) { throw new PMException(e); } finally { @@ -205,10 +174,6 @@ conn = getTConnection(); TXMLObjectAccessor accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), model); accessor.delete(getTXMLObject((InoObject) pElement)); - } catch (TServerNotAvailableException e) { - throw new PMException(e); - } catch (NamingException e) { - throw new PMException(e); } catch (TDeleteException e) { throw new PMException(e); } finally { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]