From: <th...@us...> - 2004-01-12 18:18:58
|
Update of /cvsroot/jaxme/JaxMe/src/runtime/de/ispsoft/jaxme/tamino In directory sc8-pr-cvs1:/tmp/cvs-serv6940/src/runtime/de/ispsoft/jaxme/tamino Modified Files: InoResponseHandlerNoNs.java InoManagerNoNs.java Added Files: InoSession.java Log Message: tamino session handling added --- NEW FILE: InoSession.java --- /* * Created on 07.01.2004 * */ package de.ispsoft.jaxme.tamino; /** * @author Thomas Haenel, ATC GmbH * @version $Id: InoSession.java,v 1.1 2004/01/12 18:18:55 thaenel Exp $ */ public class InoSession { private String sessionid = null; private String sessionkey = null; /** * @return */ public String getSessionid() { return sessionid; } /** * @return */ public String getSessionkey() { return sessionkey; } /** * @param string */ public void setSessionid(String string) { sessionid = string; } /** * @param string */ public void setSessionkey(String string) { sessionkey = string; } } Index: InoResponseHandlerNoNs.java =================================================================== RCS file: /cvsroot/jaxme/JaxMe/src/runtime/de/ispsoft/jaxme/tamino/InoResponseHandlerNoNs.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- InoResponseHandlerNoNs.java 7 Jan 2004 10:59:28 -0000 1.2 +++ InoResponseHandlerNoNs.java 12 Jan 2004 18:18:55 -0000 1.3 @@ -53,6 +53,9 @@ private int i; private ResultInfo resultInfo = null; + + private String sessionid = null; + private String sessionkey = null; /** Creates a new InoResponseHandler */ public InoResponseHandlerNoNs() {} @@ -131,6 +134,23 @@ inInoMessageText = true; } } + } else if (level == 0) { + if (resultInfo != null && INO_RESPONSE2_URI.equals(namespaceUri) && + "response".equals(localName)) { + cat.debug("Level 0 is response element"); + String sid = attr.getValue(INO_RESPONSE2_URI, "sessionid"); + if(sid != null && sid.length() > 0) { + sessionid = sid; + resultInfo.putResultInfo("sessionid", sessionid); + } + cat.debug("sessionid: " + sessionid); + String sk = attr.getValue(INO_RESPONSE2_URI, "sessionkey"); + if(sk != null && sk.length() > 0) { + sessionkey = sk; + resultInfo.putResultInfo("sessionkey", sessionkey); + } + cat.debug("sessionkey: " + sessionkey); + } } else if (level == 1) { if (XQL_URI.equals(namespaceUri) && "result".equals(localName)) { inXqlResult = true; @@ -147,7 +167,7 @@ } if ("cursor".equals(localName)) { String cc = attr.getValue(INO_RESPONSE2_URI, "count"); if(resultInfo != null && cc != null && cc.length() > 0) - resultInfo.setCursorCount(Integer.parseInt(cc)); + resultInfo.putResultInfo("cursorCount", cc); } } } @@ -299,6 +319,34 @@ */ public void setResultInfo(ResultInfo info) { resultInfo = info; + } + + /** + * @return + */ + public String getSessionid() { + return sessionid; + } + + /** + * @return + */ + public String getSessionkey() { + return sessionkey; + } + + /** + * @param string + */ + public void setSessionid(String string) { + sessionid = string; + } + + /** + * @param string + */ + public void setSessionkey(String string) { + sessionkey = string; } } Index: InoManagerNoNs.java =================================================================== RCS file: /cvsroot/jaxme/JaxMe/src/runtime/de/ispsoft/jaxme/tamino/InoManagerNoNs.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- InoManagerNoNs.java 7 Jan 2004 10:59:28 -0000 1.2 +++ InoManagerNoNs.java 12 Jan 2004 18:18:55 -0000 1.3 @@ -93,6 +93,12 @@ private String idAttributeNS = null; private String targetNamespaceIn = null; private boolean useCursoring = false; + + private String isolationLevel = "stableDocument"; + private String lockMode = "protected"; + private String lockWait = "no"; + private String transactionTimeout = "30"; + private String nonActivityTimeout = "60"; /** <p>Name of our private configuration node (<samp>InoManager</samp> in * namespace <code>JMManagerFactoryImpl.NAMESPACE_URI</code>)</p> @@ -130,6 +136,47 @@ */ public static final String USE_CURSORING = "Use-Cursoring"; + /** <p>Use the request param _isolationLevel for special cursoring as described above.</p> + * <p>Possible values are: + * - uncommittedDocument + * - committedCommand + * - stableCursor + * - stableDocument + * - serializable + * </p> + */ + public static final String ISOLATION_LEVEL = "ISOLATION-LEVEL"; + + /** <p>Use the request param _lockMode for special cursoring as described above.</p> + * <p>Possible values are: + * - unprotected + * - shared + * - protected + * </p> + */ + public static final String LOCK_MODE = "LOCK-MODE"; + + /** <p>Use the request param _lockWait for special cursoring as described above.</p> + * <p>Possible values are: + * - yes/no + * </p> + */ + public static final String LOCK_WAIT = "LOCK-WAIT"; + + /** <p>Use the request param _transactionTimeout for special cursoring as described above.</p> + * <p>Possible values are: + * - seconds as a number value + * </p> + */ + public static final String TRANSACTION_TIMEOUT = "TRANSACTION-TIMEOUT"; + + /** <p>Use the request param _nonActivityTimeout for special cursoring as described above.</p> + * <p>Possible values are: + * - seconds as a number value + * </p> + */ + public static final String NONACTIVITY_TIMEOUT = "NONACTIVITY-TIMEOUT"; + /** * @return */ @@ -169,24 +216,29 @@ throw new IllegalArgumentException( "Invalid database URL: " + url); } - } else if ( - USER_NODE_NAME.equals(child.getLocalName())) { + } else if (USER_NODE_NAME.equals(child.getLocalName())) { user = JMManagerFactoryImpl.getNodeText(child); - } else if ( - PASSWORD_NODE_NAME.equals(child.getLocalName())) { + } else if (PASSWORD_NODE_NAME.equals(child.getLocalName())) { password = JMManagerFactoryImpl.getNodeText(child); - } else if ( - ID_ATTRIBUTE.equals(child.getLocalName())) { + } else if (ID_ATTRIBUTE.equals(child.getLocalName())) { idAttribute = JMManagerFactoryImpl.getNodeText(child); - } else if ( - ID_ATTRIBUTE_NS.equals(child.getLocalName())) { + } else if (ID_ATTRIBUTE_NS.equals(child.getLocalName())) { idAttributeNS = JMManagerFactoryImpl.getNodeText(child); - } else if ( - TARGETNAMESPACE_IN.equals(child.getLocalName())) { + } else if (TARGETNAMESPACE_IN.equals(child.getLocalName())) { targetNamespaceIn = JMManagerFactoryImpl.getNodeText(child); } else if (USE_CURSORING.equals(child.getLocalName())) { String uc = JMManagerFactoryImpl.getNodeText(child); useCursoring = (uc != null && "yes".equals(uc)); + } else if (ISOLATION_LEVEL.equals(child.getLocalName())) { + isolationLevel = JMManagerFactoryImpl.getNodeText(child); + } else if (LOCK_MODE.equals(child.getLocalName())) { + lockMode = JMManagerFactoryImpl.getNodeText(child); + } else if (LOCK_WAIT.equals(child.getLocalName())) { + lockWait = JMManagerFactoryImpl.getNodeText(child); + } else if (TRANSACTION_TIMEOUT.equals(child.getLocalName())) { + transactionTimeout = JMManagerFactoryImpl.getNodeText(child); + } else if (NONACTIVITY_TIMEOUT.equals(child.getLocalName())) { + nonActivityTimeout = JMManagerFactoryImpl.getNodeText(child); } } } @@ -204,6 +256,13 @@ spf.setValidating(false); } + /** <p>Deletes the given document from the database using the given session.</p> + */ + public void deleteUseSession(JMAnyElement pElement, InoSession pInoSession) throws SAXException { + String query = getDeleteQuery(pElement); + performQueryUseSession(query, (List) null, pInoSession); + } + /** <p>Deletes the given document from the database.</p> */ public void delete(JMAnyElement pElement) throws SAXException { @@ -213,6 +272,18 @@ /** <p>Inserts the given document into the database.</p> */ + public void insertUseSession(JMAnyElement pElement, InoSession pInoSession) throws SAXException { + String query = getInsertQuery(pElement); + List idList = new ArrayList(); + InoResponseHandlerNoNs irh = performQueryUseSession(query, idList, pInoSession); + if (idList.size() == 0) { + throw new SAXException("Query did not return an ino:id"); + } + setElementId(pElement, (String) idList.get(0)); + } + + /** <p>Inserts the given document into the database.</p> + */ public void insert(JMAnyElement pElement) throws SAXException { String query = getInsertQuery(pElement); List idList = new ArrayList(); @@ -225,6 +296,13 @@ /** <p>Updates the given document in the database.</p> */ + public void updateUseSession(JMAnyElement pElement, InoSession pInoSession) throws SAXException { + String query = getUpdateQuery(pElement); + performQueryUseSession(query, (List) null, pInoSession); + } + + /** <p>Updates the given document in the database.</p> + */ public void update(JMAnyElement pElement) throws SAXException { String query = getUpdateQuery(pElement); performQuery(query, (List) null); @@ -270,6 +348,17 @@ /* (non-Javadoc) * @see de.ispsoft.jaxme.JMManager#select(java.lang.String, java.lang.Object[], int, int, de.ispsoft.jaxme.ResultInfo) */ + public Iterator selectUseSession(String pQuery, Object[] pPlaceHolderArgs, + int pStart, int pMax, ResultInfo pResultInfo, + InoSession pInoSession) throws SAXException { + MyObserver o = new MyObserver(); + selectUseSession(o, pQuery, pPlaceHolderArgs, pStart, pMax, pResultInfo, pInoSession); + return o.resultList.iterator(); + } + + /* (non-Javadoc) + * @see de.ispsoft.jaxme.JMManager#select(java.lang.String, java.lang.Object[], int, int, de.ispsoft.jaxme.ResultInfo) + */ public Iterator select(String pQuery, Object[] pPlaceHolderArgs, int pStart, int pMax, ResultInfo pResultInfo) throws SAXException { MyObserver o = new MyObserver(); @@ -280,29 +369,30 @@ /* (non-Javadoc) * @see de.ispsoft.jaxme.JMManager#select(de.ispsoft.jaxme.Observer, java.lang.String, java.lang.Object[], int, int, de.ispsoft.jaxme.ResultInfo) */ + public void selectUseSession(Observer pObserver, String pQuery, Object[] pPlaceHolderArgs, + int pStart, int pMax, ResultInfo pResultInfo, + InoSession pInoSession) throws SAXException { + if (pPlaceHolderArgs != null && pPlaceHolderArgs.length > 0) { + throw new SAXException("Placeholders are not yet supported"); + } + String q = getSelectQuery(pQuery, pStart, pMax); + InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); + irh.setResultInfo(pResultInfo); + JMContentHandler ch = getJMContentHandler(); + ch.setObserver(pObserver); + irh.setResultHandler(ch); + performQueryUseSession(q, irh, pInoSession); + } + + /* (non-Javadoc) + * @see de.ispsoft.jaxme.JMManager#select(de.ispsoft.jaxme.Observer, java.lang.String, java.lang.Object[], int, int, de.ispsoft.jaxme.ResultInfo) + */ public void select(Observer pObserver, String pQuery, Object[] pPlaceHolderArgs, int pStart, int pMax, ResultInfo pResultInfo) throws SAXException { if (pPlaceHolderArgs != null && pPlaceHolderArgs.length > 0) { throw new SAXException("Placeholders are not yet supported"); } - String q; - if (useCursoring) { - if(pStart == 0 && pMax == 0) { - q = "_xql(1,0)=" + URLEncoder.encode(pQuery); - } else { - q = "_cursor=open&_count=cheap&_xql=" + URLEncoder.encode(pQuery); - if (pStart != 0 || pMax != 0) { - q += "&_position=" + (pStart + 1) + "&_quantity=" + pMax; - } - } - } else { - if (pStart != 0 || pMax != 0) { - q = "_xql(" + (pStart + 1) + "," + pMax + ")="; - } else { - q = "_xql="; - } - q += URLEncoder.encode(pQuery); - } + String q = getSelectQuery(pQuery, pStart, pMax); InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); irh.setResultInfo(pResultInfo); JMContentHandler ch = getJMContentHandler(); @@ -311,6 +401,46 @@ performQuery(q, irh); } + /** + * Creates a new tamino session. The _connect request is called using the + * session parameters. + * @return a new inoSession containing sessionid and sessionkey + * @throws SAXException + */ + public InoSession createInoSession() throws SAXException { + StringBuffer q = new StringBuffer("_connect=*"); + q.append("&_isolationLevel="+isolationLevel); + q.append("&_lockMode="+lockMode); + q.append("&_lockWait="+lockWait); + q.append("&_transactionTimeout="+transactionTimeout); + q.append("&_nonActivityTimeout="+nonActivityTimeout); + ResultInfo ri = new ResultInfo(); + InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); + irh.setResultInfo(ri); + JMContentHandler ch = getJMContentHandler(); + ch.setObserver(null); + irh.setResultHandler(ch); + performQuery(q.toString(), irh); + InoSession is = new InoSession(); + is.setSessionid(ri.getResultInfo("sessionid")); + is.setSessionkey(ri.getResultInfo("sessionkey")); + return is; + } + + /** + * Closes the tamino session of sessionid given in InoSession. + * @param inoSession + * @throws SAXException + */ + public void closeInoSession(InoSession inoSession) throws SAXException { + String q = "_disconnect=*&_sessionid="+inoSession.getSessionid(); + InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); + JMContentHandler ch = getJMContentHandler(); + ch.setObserver(null); + irh.setResultHandler(ch); + performQuery(q, irh); + } + /** <p>Returns the element ID. The default implementation * returns * <code>getAttribute(InoResponseHandler.INO_RESPONSE2_URI, "id")</code>. @@ -409,6 +539,18 @@ /** <p>Performs a single database query.</p> */ + protected InoResponseHandlerNoNs performQueryUseSession(String pQuery, + List pList, InoSession pInoSession) throws SAXException { + InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); + if (pList != null) { + irh.setInoObjectIdList(pList); + } + performQueryUseSession(pQuery, irh, pInoSession); + return irh; + } + + /** <p>Performs a single database query.</p> + */ protected InoResponseHandlerNoNs performQuery(String pQuery, List pList) throws SAXException { InoResponseHandlerNoNs irh = new InoResponseHandlerNoNs(); @@ -419,6 +561,23 @@ return irh; } + /** <p>Starts session based db query. First append the sessionid and sessionkey + * params at the query, then calls performQuery(pQuery, pHandler) and finally + * put the sessionid and sessionkey from InoResponseHandlerNoNs into InoSession + * (this is because of the new returned sessionkey from the tamino response during + * an active session).</p> + * @param String pQuery + * @param InoResponseHandlerNoNs pHandler + * @throws SAXException + */ + protected void performQueryUseSession(String pQuery, InoResponseHandlerNoNs pHandler, + InoSession pInoSession) throws SAXException { + pQuery = appendSession(pQuery, pInoSession); + performQuery(pQuery, pHandler); + pInoSession.setSessionid(pHandler.getSessionid()); + pInoSession.setSessionkey(pHandler.getSessionkey()); + } + /** <p>Parses a single INO response document.</p> */ protected void performQuery(String pQuery, InoResponseHandlerNoNs pHandler) @@ -437,12 +596,39 @@ xr.setContentHandler(pHandler); xr.parse(isource); } catch (ParserConfigurationException e) { - throw new SAXException( - "ParserConfigurationException: " + e.getMessage(), - e); + throw new SAXException("ParserConfigurationException: " + e.getMessage(), e); } catch (IOException e) { throw new SAXException("I/O Exception: " + e.getMessage(), e); } } + + protected String getSelectQuery(String pQuery, int pStart, int pMax) { + String q = null; + if (useCursoring) { + if(pStart == 0 && pMax == 0) { + q = "_xql(1,0)=" + URLEncoder.encode(pQuery); + } else { + q = "_cursor=open&_count=cheap&_xql=" + URLEncoder.encode(pQuery); + if (pStart != 0 || pMax != 0) { + q += "&_position=" + (pStart + 1) + "&_quantity=" + pMax; + } + } + } else { + if (pStart != 0 || pMax != 0) { + q = "_xql(" + (pStart + 1) + "," + pMax + ")="; + } else { + q = "_xql="; + } + q += URLEncoder.encode(pQuery); + } + return q; + } + + protected String appendSession(String query, InoSession pInoSession) { + query += "&_sessionid="+pInoSession.getSessionid(); + query += "&_sessionkey="+pInoSession.getSessionkey(); + return query; + } + } |