From: <wol...@us...> - 2004-03-08 11:45:38
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22257/src/org/exist/xmlrpc Modified Files: RpcConnection.java RpcServer.java RpcAPI.java Log Message: * class BrokerPool now detects if a thread does already hold a broker object and increments a reference count instead of returning a new object. Otherwise, deadlock situations could occurr. * documentCache in RpcConnection should be cleared if changes have been made to the database. * implemented missing getMembersAsResource method in RemoteResourceSet. Index: RpcConnection.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc/RpcConnection.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** RpcConnection.java 5 Mar 2004 11:15:28 -0000 1.47 --- RpcConnection.java 8 Mar 2004 11:21:21 -0000 1.48 *************** *** 50,53 **** --- 50,55 ---- import org.exist.util.serializer.DOMSerializer; import org.exist.util.serializer.DOMSerializerPool; + import org.exist.util.serializer.SAXSerializer; + import org.exist.util.serializer.SAXSerializerPool; import org.exist.xquery.PathExpr; import org.exist.xquery.XPathException; *************** *** 69,72 **** --- 71,75 ---- import org.xml.sax.InputSource; import org.xml.sax.SAXException; + import org.xml.sax.helpers.AttributesImpl; import antlr.collections.AST; *************** *** 802,805 **** --- 805,809 ---- LOG.debug("parsing " + docName + " took " + (System.currentTimeMillis() - startTime) + "ms."); + documentCache.clear(); return doc != null; } catch (Exception e) { *************** *** 852,855 **** --- 856,860 ---- } file.delete(); + documentCache.clear(); return doc != null; } *************** *** 861,866 **** try { broker = brokerPool.get(user); - } finally { - brokerPool.release(broker); int p = docName.lastIndexOf('/'); if (p < 0 || p == docName.length() - 1) --- 866,869 ---- *************** *** 879,883 **** --- 882,889 ---- } doc = collection.addBinaryResource(broker, docName, data); + } finally { + brokerPool.release(broker); } + documentCache.clear(); return doc != null; } *************** *** 1052,1055 **** --- 1058,1062 ---- public void releaseQueryResult(int handle) { connectionPool.resultSets.remove(handle); + documentCache.clear(); LOG.debug("removed query result with handle " + handle); } *************** *** 1075,1078 **** --- 1082,1086 ---- else collection.removeDocument(broker, docName); + documentCache.clear(); } finally { brokerPool.release(broker); *************** *** 1087,1090 **** --- 1095,1099 ---- return false; LOG.debug("removing collection " + name); + documentCache.clear(); return broker.removeCollection(name); } finally { *************** *** 1112,1115 **** --- 1121,1125 ---- DocumentImpl doc; if (!documentCache.containsKey(docName)) { + LOG.debug("loading doc " + docName); doc = (DocumentImpl) broker.getDocument(docName); documentCache.put(docName, doc); *************** *** 1129,1134 **** public String retrieve(User user, int resultId, int num, Hashtable parameters) throws Exception { ! DBBroker broker = brokerPool.get(user); try { QueryResult qr = (QueryResult) connectionPool.resultSets .get(resultId); --- 1139,1145 ---- public String retrieve(User user, int resultId, int num, Hashtable parameters) throws Exception { ! DBBroker broker = null; try { + broker = brokerPool.get(user); QueryResult qr = (QueryResult) connectionPool.resultSets .get(resultId); *************** *** 1164,1167 **** --- 1175,1232 ---- } + public String retrieveAll(User user, int resultId, Hashtable parameters) throws Exception { + DBBroker broker = null; + try { + broker = brokerPool.get(user); + QueryResult qr = (QueryResult) connectionPool.resultSets + .get(resultId); + if (qr == null) + throw new EXistException("result set unknown or timed out"); + qr.timestamp = System.currentTimeMillis(); + + Serializer serializer = broker.getSerializer(); + serializer.reset(); + serializer.setProperties(parameters); + + SAXSerializer handler = SAXSerializerPool.getInstance().borrowSAXSerializer(); + handler.setOutputProperties(getProperties(parameters)); + StringWriter writer = new StringWriter(); + handler.setWriter(writer); + + // serialize results + handler.startDocument(); + handler.startPrefixMapping("exist", Serializer.EXIST_NS); + AttributesImpl attribs = new AttributesImpl(); + attribs.addAttribute( + "", + "hitCount", + "hitCount", + "CDATA", + Integer.toString(qr.result.getLength())); + handler.startElement( + Serializer.EXIST_NS, + "result", + "exist:result", + attribs); + Item current; + char[] value; + for(SequenceIterator i = qr.result.iterate(); i.hasNext(); ) { + current = i.nextItem(); + if(Type.subTypeOf(current.getType(), Type.NODE)) + ((NodeValue)current).toSAX(broker, handler); + else { + value = current.toString().toCharArray(); + handler.characters(value, 0, value.length); + } + } + handler.endElement(Serializer.EXIST_NS, "result", "exist:result"); + handler.endPrefixMapping("exist"); + handler.endDocument(); + return writer.toString(); + } finally { + brokerPool.release(broker); + } + } + public void run() { synchronized (this) { Index: RpcServer.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc/RpcServer.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** RpcServer.java 3 Feb 2004 13:14:48 -0000 1.29 --- RpcServer.java 8 Mar 2004 11:21:21 -0000 1.30 *************** *** 958,961 **** --- 958,985 ---- } } + + /* (non-Javadoc) + * @see org.exist.xmlrpc.RpcAPI#retrieveAll(org.exist.security.User, int, java.util.Hashtable) + */ + public byte[] retrieveAll(User user, int resultId, Hashtable parameters) throws EXistException, PermissionDeniedException { + RpcConnection con = null; + try { + con = pool.get(); + String xml = con.retrieveAll(user, resultId, parameters); + String encoding = (String)parameters.get(OutputKeys.ENCODING); + if(encoding == null) + encoding = "UTF-8"; + try { + return xml.getBytes(encoding); + } catch (UnsupportedEncodingException uee) { + return xml.getBytes(); + } + } catch (Exception e) { + handleException(e); + return null; + } finally { + pool.release(con); + } + } /** Index: RpcAPI.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc/RpcAPI.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** RpcAPI.java 3 Feb 2004 13:14:48 -0000 1.23 --- RpcAPI.java 8 Mar 2004 11:21:21 -0000 1.24 *************** *** 231,234 **** --- 231,237 ---- throws EXistException, PermissionDeniedException; + public byte[] retrieveAll(User user, int resultId, Hashtable parameters) + throws EXistException, PermissionDeniedException; + Hashtable queryP(User user, byte[] xpath, Hashtable parameters) throws EXistException, PermissionDeniedException; |