zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #12985
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
Rodolfo Ochoa has proposed merging lp:~zorba-coders/zorba/bug938320 into lp:zorba.
Requested reviews:
Cezar Andrei (cezar-andrei)
Related bugs:
Bug #938320 in Zorba: "Improve XQJ Streaming"
https://bugs.launchpad.net/zorba/+bug/938320
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug938320/+merge/118194
--
https://code.launchpad.net/~zorba-coders/zorba/bug938320/+merge/118194
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'swig/DiagnosticHandler.h'
--- swig/DiagnosticHandler.h 2012-07-24 08:48:48 +0000
+++ swig/DiagnosticHandler.h 2012-08-03 20:31:44 +0000
@@ -27,6 +27,7 @@
void error (const zorba::ZorbaException &ze);
void warning (const zorba::XQueryException &xw);
public:
+ DiagnosticHandler() {};
virtual ~DiagnosticHandler();
/**
=== modified file 'swig/Item.h'
--- swig/Item.h 2012-07-24 08:48:48 +0000
+++ swig/Item.h 2012-08-03 20:31:44 +0000
@@ -199,7 +199,7 @@
* Note that this function is only available for node Items.
*
* @return bool if the name of the node was retrieved successfully
- * @return aNodeName the name of the node
+ * @param aNodeName the name of the node
* @throw ZorbaException if an error occured (e.g. the Item is not of type node).
*/
bool getNodeName (Item &aNodeName) const;
@@ -298,6 +298,27 @@
* Also note that this function is available for all types of Items.
*/
void close();
+
+ /** \brief Serializes the object
+ *
+ * Returns a string with the value of the object serialized
+ *
+ * @param aStream The stream to write the value of the Item.
+ * @throw ZorbaException if an error occured.
+ */
+ void serializeToStream(ZorbaStream& aStream) const;
+
+ /** \brief Serializes the object
+ *
+ * Returns a string with the value of the object serialized
+ *
+ * @param aStream The stream to write the value of the Item.
+ * @param serOptions The serialization options for this Item
+ * @return The string value of the Item.
+ * @throw ZorbaException if an error occured.
+ */
+ void serializeToStream(ZorbaStream& aStream, SerializationOptions serOptions) const;
+
}; // class Item
#endif
=== modified file 'swig/Item.i'
--- swig/Item.i 2012-07-24 08:48:48 +0000
+++ swig/Item.i 2012-08-03 20:31:44 +0000
@@ -122,6 +122,31 @@
void Item::close()
{ theItem.close(); }
+ void Item::serializeToStream(ZorbaStream& aStream) const
+ {
+ ZorbaBuffer buffer(aStream);
+ std::ostream lStream(&buffer);
+
+ Zorba_SerializerOptions_t lOptions;
+ lOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+ zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(lOptions);
+ zorba::SingletonItemSequence lSequence(theItem);
+ lSerializer->serialize(&lSequence, lStream);
+ return;
+ }
+ void Item::serializeToStream(ZorbaStream& aStream, SerializationOptions serOptions) const
+ {
+ ZorbaBuffer buffer(aStream);
+ std::ostream lStream(&buffer);
+
+ Zorba_SerializerOptions_t lOptions;
+ serOptions.lOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+ zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(serOptions.lOptions);
+ zorba::SingletonItemSequence lSequence(theItem);
+ lSerializer->serialize(&lSequence, lStream);
+ return;
+ }
+
%} // end Implementation
=== modified file 'swig/XQuery.h'
--- swig/XQuery.h 2012-07-24 08:48:48 +0000
+++ swig/XQuery.h 2012-08-03 20:31:44 +0000
@@ -156,6 +156,14 @@
* @throw ZorbaException if an error occured.
*/
void getExternalVariables(Iterator& vars) const;
+
+ /** \brief Execute the query and write the result to the given output stream.
+ * The query only has a result if it's a non-updating query.
+ *
+ * @stream The output stream on which the result is written.
+ */
+ void execute( ZorbaStream& stream );
+
}; // class XQuery
#endif
\ No newline at end of file
=== modified file 'swig/XQuery.i'
--- swig/XQuery.i 2012-07-24 08:48:48 +0000
+++ swig/XQuery.i 2012-08-03 20:31:44 +0000
@@ -15,11 +15,11 @@
*/
%{ // start Implementation
-
+
std::string XQuery::execute()
{
Zorba_SerializerOptions_t lSerOptions;
- lSerOptions.indent = ZORBA_INDENT_YES;
+ lSerOptions.indent = ZORBA_INDENT_NO;
lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
std::stringstream lStream;
lStream << theQuery;
@@ -78,6 +78,17 @@
void XQuery::destroy() { theQuery = 0; }
Iterator XQuery::iterator() { return Iterator(theQuery->iterator()); }
+ void XQuery::execute( ZorbaStream& stream )
+ {
+ Zorba_SerializerOptions_t lSerOptions;
+ lSerOptions.indent = ZORBA_INDENT_NO;
+ lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+ ZorbaBuffer buffer(stream);
+ std::ostream lStream(&buffer);
+ theQuery->execute(lStream, &lSerOptions);
+ return;
+ }
+
%} // end Implementation
%include "XQuery.h"
=== modified file 'swig/XmlDataManager.h'
--- swig/XmlDataManager.h 2012-07-24 08:48:48 +0000
+++ swig/XmlDataManager.h 2012-08-03 20:31:44 +0000
@@ -66,8 +66,7 @@
* dynamic collections identified by a URI, i.e. those that are
* not declared in the prolog of a module or identified by a QName.
*
- * @return The collection manager responsible for managing
- * collections.
+ * @return The collection manager responsible for managing collections.
*
*/
CollectionManager getW3CCollectionManager();
@@ -84,5 +83,11 @@
*/
Item parseXMLtoItem(const std::string& aDoc);
+ /** \brief Parse an XML stream and return an Item.
+ *
+ * @param aStream the input string whose content should be parsed
+ */
+ Item parseXMLtoItem(ZorbaStream& aStream);
+
};
#endif
\ No newline at end of file
=== modified file 'swig/XmlDataManager.i'
--- swig/XmlDataManager.i 2012-07-24 08:48:48 +0000
+++ swig/XmlDataManager.i 2012-08-03 20:31:44 +0000
@@ -45,6 +45,13 @@
return Item(lItem);
}
+ Item XmlDataManager::parseXMLtoItem(ZorbaStream& aStream)
+ {
+ ZorbaBuffer streamBuffer(aStream);
+ std::istream stream = std::istream(&streamBuffer);
+ zorba::Item lItem = theManager->parseXML(stream);
+ return Item(lItem);
+ }
%} // end Implementation
=== modified file 'swig/Zorba.h'
--- swig/Zorba.h 2012-07-24 08:48:48 +0000
+++ swig/Zorba.h 2012-08-03 20:31:44 +0000
@@ -202,6 +202,28 @@
*/
bool isXQueryXSupported();
+ /** \brief Creates and compiles an XQuery object.
+ *
+ * This methods creates an XQuery object and compiles the query string
+ * passed to this method.
+ *
+ * @param stream the query stream, this object is an extension to stream data accross the API.
+ * @return XQuery the newly created and compiled XQuery object.
+ */
+ XQuery compileQuery(ZorbaStream& stream);
+
+ /** \brief Creates and compiles an XQuery object using a StaticContext.
+ *
+ * This methods creates an XQuery object and compiles the query string
+ * passed to this method. Compilation is done using the information
+ * contained in the StaticContext that is passed as parameter.
+ *
+ * @param stream the query stream, this object is an extension to stream data accross the API.
+ * @param aStaticContext the StaticContext that contains information used for compiling the query.
+ * @return XQuery the newly created and compiled XQuery object.
+ */
+ XQuery compileQuery(ZorbaStream& stream, StaticContext &aStaticContext );
+
}; // class Zorba
#endif
=== modified file 'swig/Zorba.i'
--- swig/Zorba.i 2012-07-24 08:48:48 +0000
+++ swig/Zorba.i 2012-08-03 20:31:44 +0000
@@ -53,21 +53,6 @@
);
}
- // XQuery Zorba::compileQuery(const ZIStreamHelper& aZorbaStream)
- // {
- // zorbabuffer *buffer = new zorbabuffer(&const_cast<ZIStreamHelper &> (aZorbaStream));
- // std::istream stream = std::istream(buffer);
- // zistream stream = zistream(buffer);
- // return XQuery(theZorba->compileQuery(stream));
- // }
-
- // XQuery Zorba::compileQuery(const ZIStreamHelper& aZorbaStream, StaticContext &aStaticContext )
- // {
- // zorbabuffer *buffer = new zorbabuffer(&const_cast<ZIStreamHelper &> (aZorbaStream));
- // std::istream stream = std::istream(buffer);
- // return XQuery(theZorba->compileQuery(stream, aStaticContext.theStaticContext));
- // }
-
XQuery Zorba::compileQuery(
const std::string& aStr,
DiagnosticHandler* aDiagnosticHandler
@@ -132,6 +117,20 @@
#endif //ZORBA_XQUERYX
}
+ XQuery Zorba::compileQuery(ZorbaStream& aStream)
+ {
+ ZorbaBuffer streamBuffer(aStream);
+ std::istream stream = std::istream(&streamBuffer);
+ return XQuery(theZorba->compileQuery(stream));
+ }
+
+ XQuery Zorba::compileQuery(ZorbaStream& aStream, StaticContext &aStaticContext )
+ {
+ ZorbaBuffer streamBuffer(aStream);
+ std::istream stream = std::istream(&streamBuffer);
+ return XQuery(theZorba->compileQuery(stream, aStaticContext.theStaticContext));
+ }
+
%} // end Implementation
%include "Zorba.h"
=== added file 'swig/ZorbaBuffer.h'
--- swig/ZorbaBuffer.h 1970-01-01 00:00:00 +0000
+++ swig/ZorbaBuffer.h 2012-08-03 20:31:44 +0000
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef API_ZORBA_BUFFER_H
+#define API_ZORBA_BUFFER_H
+
+#include <streambuf>
+#include <cstdio>
+#include <cstdlib>
+#include <vector>
+#include "ZorbaBuffer.h"
+
+
+class ZorbaBuffer :
+ public std::streambuf
+{
+public:
+ ZorbaBuffer(ZorbaStream &aStreamWrapper): bBegin(0), bEnd(0), bCurrent(0), buffer(0), streamWrapper(&aStreamWrapper) {};
+
+ // HELPER
+ // Function to return EOF character from other languages
+ static int getEOF();
+
+ // INPUT
+ // Get character in the case of underflow
+ int underflow();
+ // Get character in the case of underflow and advance get pointer
+ int uflow();
+ // Put character back in the case of backup underflow
+ int pbackfail(int ch);
+ // Get number of characters available in the sequence
+ std::streamsize showmanyc();
+
+ // OUTPUT
+ // Write sequence of characters <Inherited>
+ virtual std::streamsize xsputn ( const char * str, std::streamsize len );
+ // Write character in the case of overflow
+ virtual int overflow ( int c = EOF );
+
+
+
+
+private:
+ void checkBuffer();
+ // Copy contructor and assignment not allowed
+ ZorbaBuffer(const ZorbaBuffer &);
+ ZorbaBuffer &operator= (const ZorbaBuffer &);
+
+ //BUFFER
+ int * buffer;
+ int * bBegin;
+ int * bEnd;
+ int * bCurrent;
+ ZorbaStream *streamWrapper;
+
+ char * cBuffer;
+};
+
+#endif
=== added file 'swig/ZorbaBuffer.i'
--- swig/ZorbaBuffer.i 1970-01-01 00:00:00 +0000
+++ swig/ZorbaBuffer.i 2012-08-03 20:31:44 +0000
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%feature("director") ZorbaBuffer;
+
+%{ // start Implementation
+
+#include "ZorbaBuffer.h"
+#include <cassert>
+#include <iostream>
+
+void ZorbaBuffer::checkBuffer()
+{
+ if (buffer==0)
+ {
+ streamWrapper->fillStreamCallback();
+ if (streamWrapper->getLen() > 0) {
+ bBegin = bCurrent = buffer = streamWrapper->getStream();
+ bEnd = bBegin + streamWrapper->getLen();
+ }
+ } else if (bCurrent == bEnd)
+ {
+ if (streamWrapper->getLen()==1024)
+ {
+ streamWrapper->fillStreamCallback();
+ if (streamWrapper->getLen() > 0) {
+ bBegin = bCurrent = buffer = streamWrapper->getStream();
+ bEnd = bBegin + streamWrapper->getLen();
+ }
+ }
+ }
+
+}
+int ZorbaBuffer::getEOF()
+{
+ return traits_type::eof();
+}
+
+int ZorbaBuffer::underflow()
+{
+ checkBuffer();
+ if ((bCurrent == bEnd) || (buffer==0))
+ return traits_type::eof();
+ return traits_type::to_int_type(*bCurrent);
+}
+
+int ZorbaBuffer::uflow()
+{
+ checkBuffer();
+ if ((bCurrent == bEnd) || (buffer==0))
+ return traits_type::eof();
+ return traits_type::to_int_type(*bCurrent++);
+}
+
+int ZorbaBuffer::pbackfail(int ch)
+{
+ checkBuffer();
+ if (bCurrent == bBegin || (ch != traits_type::eof() && ch != bCurrent[-1]) || (buffer==0))
+ return traits_type::eof();
+
+ return traits_type::to_int_type(*--bCurrent);
+}
+
+std::streamsize ZorbaBuffer::showmanyc()
+{
+ checkBuffer();
+ return bEnd - bCurrent;
+}
+
+std::streamsize ZorbaBuffer::xsputn ( const char * str, std::streamsize len ) {
+ // Wrapping to virtual function
+ streamWrapper->write(str, len);
+ return len;
+}
+
+int ZorbaBuffer::overflow ( int c )
+{
+ streamWrapper->write((const char*)&c, 1);
+ return c;
+}
+
+
+%} // end Implementation
+
+%include "ZorbaBuffer.h"
\ No newline at end of file
=== added file 'swig/ZorbaStream.h'
--- swig/ZorbaStream.h 1970-01-01 00:00:00 +0000
+++ swig/ZorbaStream.h 2012-08-03 20:31:44 +0000
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef API_ZORBA_STREAM_H
+#define API_ZORBA_STREAM_H
+
+#include <streambuf>
+#include <cstdio>
+#include <cstdlib>
+#include <vector>
+
+class ZorbaStream
+{
+public:
+ ZorbaStream() {};
+
+ //STREAM TO ZORBA
+ virtual void fillStreamCallback();
+ void setStream(int *aStream, int aLen);
+ int * getStream();
+ int getLen();
+
+ //STREAM FROM ZORBA
+ virtual void write( const char * str, size_t len );
+
+private:
+ //FOR STREAM TO ZORBA
+ int buffer[1024];
+ int len;
+
+ // Copy contructor and assignment not allowed
+ ZorbaStream(const ZorbaStream &);
+ ZorbaStream &operator= (const ZorbaStream &);
+
+};
+
+#endif
=== added file 'swig/ZorbaStream.i'
--- swig/ZorbaStream.i 1970-01-01 00:00:00 +0000
+++ swig/ZorbaStream.i 2012-08-03 20:31:44 +0000
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%feature("director") ZorbaStream;
+
+%{ // start Implementation
+
+#include "ZorbaStream.h"
+#include <cassert>
+#include <iostream>
+#include <ios>
+
+void ZorbaStream::fillStreamCallback()
+{
+ // Local fill buffer
+ int len = 10;
+ int *buffer = (int*) malloc(sizeof(int)*(len));
+ int* p=buffer;
+ for (int i=0; i<(len); i++, *p++ = i+40)
+ ;
+ setStream(buffer, len);
+ return;
+}
+
+void ZorbaStream::setStream(int *aStream, int aLen)
+{
+ if (aLen > 0)
+ memcpy(buffer, aStream, aLen*sizeof(int));
+ len = aLen;
+ return;
+}
+
+int * ZorbaStream::getStream()
+{
+ return buffer;
+}
+
+int ZorbaStream::getLen()
+{
+ return len;
+}
+
+void ZorbaStream::write( const char * str, size_t len )
+{
+ return;
+}
+
+%} // end Implementation
+
+
+%include "ZorbaStream.h"
\ No newline at end of file
=== modified file 'swig/java/CMakeLists.txt'
--- swig/java/CMakeLists.txt 2012-07-24 08:48:48 +0000
+++ swig/java/CMakeLists.txt 2012-08-03 20:31:44 +0000
@@ -53,13 +53,19 @@
FOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}" "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}" COPYONLY)
ENDFOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
+
+ #STREAM WRAPPER
+ FILE(GLOB ZORBA_JAVA_EXTRAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "${CMAKE_CURRENT_SOURCE_DIR}/*.java")
+ FOREACH(ZORBA_JAVA_EXTRA ${ZORBA_JAVA_EXTRAS})
+ CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/${ZORBA_JAVA_EXTRA}" "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_JAVA_EXTRA}" COPYONLY)
+ ENDFOREACH(ZORBA_JAVA_EXTRA ${ZORBA_JAVA_EXTRAS})
ADD_CUSTOM_COMMAND(TARGET lib_zorba_java_api
POST_BUILD
COMMAND cmake -E echo "Compiling Java files..."
COMMAND ${Java_JAVAC_EXECUTABLE} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cmake -E echo "Creating jar file..."
- COMMAND ${Java_JAR_EXECUTABLE} cvf zorba_api.jar org
+ COMMAND ${Java_JAR_EXECUTABLE} cf zorba_api.jar org
)
# --- Install
=== added file 'swig/java/InputZorbaStream.java'
--- swig/java/InputZorbaStream.java 1970-01-01 00:00:00 +0000
+++ swig/java/InputZorbaStream.java 2012-08-03 20:31:44 +0000
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.zorbaxquery.api.intArray;
+
+public class InputZorbaStream extends org.zorbaxquery.api.ZorbaStream {
+ private InputStream input;
+
+ public InputZorbaStream(InputStream aInput) {
+ input= aInput;
+ }
+
+ @Override
+ public void fillStreamCallback() {
+ byte[] b = new byte[1024];
+ int total = 0;
+ try {
+ total = input.read(b, 0, 1024);
+ } catch (IOException ex) {
+ }
+ intArray lBuffer = null;
+ if (total>0) {
+ lBuffer = new intArray(total);
+ for (int i=0; i<total; i++) {
+ lBuffer.setitem(i, b[i]);
+ }
+ } else {
+ lBuffer = new intArray(1); // Can't be null
+ }
+ setStream(lBuffer.cast(), total);
+ }
+
+}
=== added file 'swig/java/OutputZorbaStream.java'
--- swig/java/OutputZorbaStream.java 1970-01-01 00:00:00 +0000
+++ swig/java/OutputZorbaStream.java 2012-08-03 20:31:44 +0000
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class OutputZorbaStream extends ZorbaStream {
+ private OutputStream output;
+
+ public OutputZorbaStream(OutputStream aOutput) {
+ output = aOutput;
+ }
+
+ @Override
+ public void write(String string, long l){
+ try {
+ output.write(string.getBytes());
+ } catch (IOException ex) {
+ System.out.println("Error writing on output stream" + ex.getLocalizedMessage());
+ }
+
+ }
+
+}
=== added file 'swig/java/ReaderZorbaStream.java'
--- swig/java/ReaderZorbaStream.java 1970-01-01 00:00:00 +0000
+++ swig/java/ReaderZorbaStream.java 2012-08-03 20:31:44 +0000
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.Reader;
+import org.zorbaxquery.api.intArray;
+
+public class ReaderZorbaStream extends org.zorbaxquery.api.ZorbaStream {
+
+ private Reader reader;
+
+ public ReaderZorbaStream(Reader aReader) {
+ reader= aReader;
+ }
+
+ @Override
+ public void fillStreamCallback() {
+ char[] b = new char[1024];
+ int total = 0;
+ try {
+ total = reader.read(b, 0, 1024);
+ } catch (IOException ex) {
+ }
+ intArray lBuffer = null;
+ if (total>0) {
+ lBuffer = new intArray(total);
+ for (int i=0; i<total; i++) {
+ lBuffer.setitem(i, b[i]);
+ }
+ } else {
+ lBuffer = new intArray(1); // Can't be null
+ }
+ setStream(lBuffer.cast(), total);
+
+ }
+}
=== added file 'swig/java/WriterZorbaStream.java'
--- swig/java/WriterZorbaStream.java 1970-01-01 00:00:00 +0000
+++ swig/java/WriterZorbaStream.java 2012-08-03 20:31:44 +0000
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.Writer;
+
+public class WriterZorbaStream extends org.zorbaxquery.api.ZorbaStream {
+ private Writer writer;
+
+ public WriterZorbaStream(Writer aWriter) {
+ writer = aWriter;
+ }
+
+ @Override
+ public void write(String string, long l){
+ try {
+ writer.append(string);
+ } catch (IOException ex) {
+ System.out.println("Error writing on output stream" + ex.getLocalizedMessage());
+ }
+
+ }
+
+}
=== modified file 'swig/java/zorba_api.i'
--- swig/java/zorba_api.i 2012-07-24 08:48:48 +0000
+++ swig/java/zorba_api.i 2012-08-03 20:31:44 +0000
@@ -20,6 +20,4 @@
// don't do a JNI call for constants and enums.
%javaconst(1);
-
-
%include ../zorba_api.i
=== modified file 'swig/php/tests/test11.php'
--- swig/php/tests/test11.php 2012-03-27 00:56:11 +0000
+++ swig/php/tests/test11.php 2012-08-03 20:31:44 +0000
@@ -15,38 +15,34 @@
* limitations under the License.
*/
-//require '@phpPath@/Zorba/zorba_api_wrapper.php';
-require 'C:/dev/zapi/build/swig/php/Zorba/zorba_api_wrapper.php';
-
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler):
- def error(self, *args):
- print "Error args: ", args
-
-def test(zorba):
- #Read and write result
- print 'Executing: compilerHints.xq'
- f = open('compilerHints.xq', 'r')
- lines = f.read()
- f.close()
+require '@phpPath@/Zorba/zorba_api_wrapper.php';
+
+class MyDiagnosticHandler(DiagnosticHandler handler) {
+ funtion error(self, *args) {
+ print "Error args: ", args;
+ }
+}
+
+function test(Zorba $aZorba)
+{
diagnosticHandler = MyDiagnosticHandler()
- compilerHints = zorba_api.CompilerHints()
- compilerHints.setOptimizationLevel(0)
- xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-
- result = xquery.execute()
- print result
+ try {
+ xquery = zorba.compileQuery("1 div 0", diagnosticHandler);
+ print xquery.execute()
+ } catch (Exception e) {
+ print "Caught error: ";
+ }
return
-
-
-store = zorba_api.InMemoryStore_getInstance()
-zorba = zorba_api.Zorba_getInstance(store)
-
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
-print "Success"
-
-
-zorba.shutdown()
-zorba_api.InMemoryStore_shutdown(store)
+}
+
+$store = InMemoryStore::getInstance();
+$zorba = Zorba::getInstance($store);
+
+print "Running: Compile query string using Diagnostic Handler"
+test($zorba);
+print "Success";
+
+$zorba->shutdown();
+InMemoryStore::shutdown($store);
?>
\ No newline at end of file
=== modified file 'swig/python/tests/CMakeLists.txt'
--- swig/python/tests/CMakeLists.txt 2012-07-24 08:48:48 +0000
+++ swig/python/tests/CMakeLists.txt 2012-08-03 20:31:44 +0000
@@ -60,9 +60,9 @@
ADD_TEST("python_test10" ${PYTHON_EXECUTABLE} test10.py)
SET_TESTS_PROPERTIES("python_test10" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.py.in ${CMAKE_CURRENT_BINARY_DIR}/test11.py)
-#ADD_TEST("python_test11" ${PYTHON_EXECUTABLE} test11.py)
-#SET_TESTS_PROPERTIES("python_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.py.in ${CMAKE_CURRENT_BINARY_DIR}/test11.py)
+ADD_TEST("python_test11" ${PYTHON_EXECUTABLE} test11.py)
+SET_TESTS_PROPERTIES("python_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test12.py.in ${CMAKE_CURRENT_BINARY_DIR}/test12.py)
#ADD_TEST("python_test12" ${PYTHON_EXECUTABLE} test12.py)
=== modified file 'swig/python/tests/test11.py.in'
--- swig/python/tests/test11.py.in 2012-07-24 08:48:48 +0000
+++ swig/python/tests/test11.py.in 2012-08-03 20:31:44 +0000
@@ -16,31 +16,24 @@
sys.path.insert(0, '@pythonPath@')
import zorba_api
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler):
- def error(self, *args):
- print "Error args: ", args
-
-def test(zorba):
- #Read and write result
- print 'Executing: compilerHints.xq'
- f = open('compilerHints.xq', 'r')
- lines = f.read()
- f.close()
- diagnosticHandler = MyDiagnosticHandler()
- compilerHints = zorba_api.CompilerHints()
- compilerHints.setOptimizationLevel(0)
- xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-
- result = xquery.execute()
- print result
- return
-
-
store = zorba_api.InMemoryStore_getInstance()
zorba = zorba_api.Zorba_getInstance(store)
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
+print "Running: CompileQuery CollectionManager"
+
+xmlManager = zorba.getXmlDataManager()
+collectionManager = xmlManager.getCollectionManager()
+itemFactory = zorba.getItemFactory()
+name = itemFactory.createQName("http://www.zorba-xquery.com/", "aaa")
+collectionManager.createCollection(name)
+isAdded = collectionManager.isAvailableCollection(name)
+
+if isAdded :
+ collection = collectionManager.getCollection(name);
+ data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
+ itemSequence = zorba_api.ItemSequence(data)
+ collection.insertNodesLast(itemSequence)
+
print "Success"
=== modified file 'swig/ruby/tests/CMakeLists.txt'
--- swig/ruby/tests/CMakeLists.txt 2012-07-24 08:48:48 +0000
+++ swig/ruby/tests/CMakeLists.txt 2012-08-03 20:31:44 +0000
@@ -29,9 +29,9 @@
ADD_TEST("ruby_test02" ${RUBY_EXECUTABLE} test02.rb)
SET_TESTS_PROPERTIES("ruby_test02" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test03.rb ${CMAKE_CURRENT_BINARY_DIR}/test03.rb)
-#ADD_TEST("ruby_test03" ${RUBY_EXECUTABLE} test03.rb)
-#SET_TESTS_PROPERTIES("ruby_test03" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test03.rb ${CMAKE_CURRENT_BINARY_DIR}/test03.rb)
+ADD_TEST("ruby_test03" ${RUBY_EXECUTABLE} test03.rb)
+SET_TESTS_PROPERTIES("ruby_test03" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test04.rb ${CMAKE_CURRENT_BINARY_DIR}/test04.rb)
ADD_TEST("ruby_test04" ${RUBY_EXECUTABLE} test04.rb)
@@ -64,9 +64,9 @@
ADD_TEST("ruby_test10" ${RUBY_EXECUTABLE} test10.rb)
SET_TESTS_PROPERTIES("ruby_test10" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.rb ${CMAKE_CURRENT_BINARY_DIR}/test11.rb)
-#ADD_TEST("ruby_test11" ${RUBY_EXECUTABLE} test11.rb)
-#SET_TESTS_PROPERTIES("ruby_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.rb ${CMAKE_CURRENT_BINARY_DIR}/test11.rb)
+ADD_TEST("ruby_test11" ${RUBY_EXECUTABLE} test11.rb)
+SET_TESTS_PROPERTIES("ruby_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test12.rb ${CMAKE_CURRENT_BINARY_DIR}/test12.rb)
#ADD_TEST("ruby_test12" ${RUBY_EXECUTABLE} test12.rb)
=== modified file 'swig/ruby/tests/test03.rb'
--- swig/ruby/tests/test03.rb 2012-03-27 00:56:11 +0000
+++ swig/ruby/tests/test03.rb 2012-08-03 20:31:44 +0000
@@ -14,13 +14,13 @@
require '@rubyPath@/zorba_api'
-class MyDiagnosticHandler < Zorba_api.DiagnosticHandler
- def error(self, *args)
- print "Error args: " + args
+class MyDiagnosticHandler < Zorba_api::DiagnosticHandler
+ def error(args)
+ print "Error args: " + args.getDescription() + "\n"
end
end
-def test(zorba):
+def test(zorba)
diagnosticHandler = MyDiagnosticHandler.new
begin
xquery = zorba.compileQuery("1 div 0", diagnosticHandler)
@@ -35,9 +35,9 @@
store = Zorba_api::InMemoryStore.getInstance()
zorba = Zorba_api::Zorba.getInstance(store)
-print "Running: Capturing error with DiagnosticHandler"
+print "Running: Capturing error with DiagnosticHandler\n"
test(zorba)
print "Success"
zorba.shutdown()
-Zorba_api::InMemoryStore.shutdown(store)
+Zorba_api::InMemoryStore.shutdown(store)
\ No newline at end of file
=== modified file 'swig/ruby/tests/test11.rb'
--- swig/ruby/tests/test11.rb 2012-03-27 00:56:11 +0000
+++ swig/ruby/tests/test11.rb 2012-08-03 20:31:44 +0000
@@ -12,38 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
-sys.path.insert(0, '@pythonPath@')
-import zorba_api
-
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler):
- def error(self, *args):
- print "Error args: ", args
-
-def test(zorba):
- #Read and write result
- print 'Executing: compilerHints.xq'
- f = open('compilerHints.xq', 'r')
- lines = f.read()
- f.close()
- diagnosticHandler = MyDiagnosticHandler()
- compilerHints = zorba_api.CompilerHints()
- compilerHints.setOptimizationLevel(0)
- xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-
- result = xquery.execute()
- print result
- return
-
-
-store = zorba_api.InMemoryStore_getInstance()
-zorba = zorba_api.Zorba_getInstance(store)
-
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
+require '@rubyPath@/zorba_api'
+
+store = Zorba_api::InMemoryStore.getInstance()
+zorba = Zorba_api::Zorba.getInstance(store)
+
+print "Running: CompileQuery CollectionManager\n"
+
+xmlManager = zorba.getXmlDataManager()
+collectionManager = xmlManager.getCollectionManager()
+itemFactory = zorba.getItemFactory()
+name = itemFactory.createQName("http://www.zorba-xquery.com/", "aaa")
+collectionManager.createCollection(name)
+isAdded = collectionManager.isAvailableCollection(name)
+
+if isAdded :
+ collection = collectionManager.getCollection(name)
+ data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>")
+ itemSequence = Zorba_api::ItemSequence.new(data)
+ collection.insertNodesLast(itemSequence)
+end
+
print "Success"
-
zorba.shutdown()
-zorba_api.InMemoryStore_shutdown(store)
-
+Zorba_api::InMemoryStore.shutdown(store)
=== modified file 'swig/xqj/CMakeLists.txt'
--- swig/xqj/CMakeLists.txt 2012-07-24 08:48:48 +0000
+++ swig/xqj/CMakeLists.txt 2012-08-03 20:31:44 +0000
@@ -100,7 +100,7 @@
COMMAND cmake -E echo "Compiling XQJ files..."
COMMAND ${Java_JAVAC_EXECUTABLE} -cp ${XQJ_CLASSPATH} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cmake -E echo "Creating jar file..."
- COMMAND ${Java_JAR_EXECUTABLE} cvf zorba_xqj.jar org
+ COMMAND ${Java_JAR_EXECUTABLE} cf zorba_xqj.jar org
)
ENDIF (${RESULT} GREATER -1)
=== modified file 'swig/xqj/ZorbaXQConnection.java'
--- swig/xqj/ZorbaXQConnection.java 2012-07-24 08:48:48 +0000
+++ swig/xqj/ZorbaXQConnection.java 2012-08-03 20:31:44 +0000
@@ -333,26 +333,11 @@
isClosedXQException();
isNullXQException(reader);
- StringBuffer string = new StringBuffer();
- CharBuffer buffer = CharBuffer.allocate(1024);
- Writer writer = new StringWriter();
-
- try {
- while( reader.read(buffer) >= 0 ) {
- buffer.flip();
- writer.append(buffer);
- buffer.clear();
- }
- reader.close();
- } catch (Exception ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
- }
-
XQPreparedExpression expression;
if (lStaticContext == null) {
- expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString());
+ expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader);
} else {
- expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString(), lStaticContext);
+ expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader, lStaticContext);
}
cPreparedExpression.add(expression);
return expression;
@@ -372,21 +357,8 @@
isClosedXQException();
isNullXQException(reader);
isNullXQException(xqsc);
- StringBuffer string = new StringBuffer();
- CharBuffer buffer = CharBuffer.allocate(1024);
- Writer writer = new StringWriter();
- try {
- while( reader.read(buffer) >= 0 ) {
- buffer.flip();
- writer.append(buffer);
- buffer.clear();
- }
- reader.close();
- } catch (Exception ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
- }
-
- XQPreparedExpression expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString(), xqsc);
+
+ XQPreparedExpression expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader, xqsc);
cPreparedExpression.add(expression);
return expression;
@@ -404,21 +376,12 @@
public XQPreparedExpression prepareExpression(InputStream in) throws XQException {
isClosedXQException();
isNullXQException(in);
- StringBuffer out = new StringBuffer ();
- try {
- byte[] b = new byte[4096];
- for (int n; (n = in.read(b)) != -1;) {
- out.append(new String(b, 0, n));
- }
- } catch (Exception ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
- }
-
+
XQPreparedExpression expression;
if (lStaticContext == null) {
- expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString());
+ expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in);
} else {
- expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString(), lStaticContext);
+ expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in, lStaticContext);
}
try {
cPreparedExpression.add(expression);
@@ -443,19 +406,10 @@
isClosedXQException();
isNullXQException(in);
isNullXQException(xqsc);
- StringBuffer out = new StringBuffer ();
- try {
- byte[] b = new byte[4096];
- for (int n; (n = in.read(b)) != -1;) {
- out.append(new String(b, 0, n));
- }
- } catch (IOException ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
- }
XQPreparedExpression expression = null;
try {
- expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString(), xqsc);
+ expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in, xqsc);
cPreparedExpression.add(expression);
} catch (Exception ex) {
throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
@@ -726,11 +680,7 @@
try {
dm = zorba.getXmlDataManager();
doc = new Item();
- org.zorbaxquery.api.Iterator iterator = dm.parseXML(value);
- iterator.open();
- iterator.next(doc);
- iterator.close();
- iterator.delete();
+ doc = dm.parseXMLtoItem(value);
item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
} catch (Exception e) {
throw new XQException("Error creating Item" + e.getLocalizedMessage());
@@ -756,23 +706,26 @@
public XQItem createItemFromDocument(Reader value, String baseURI, XQItemType type) throws XQException {
isClosedXQException();
isNullXQException(value);
-
- StringBuffer string = new StringBuffer();
- CharBuffer buffer = CharBuffer.allocate(1024);
- Writer writer = new StringWriter();
-
+ if (type!=null) {
+ if ( ! ((type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_ELEMENT)||(type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT)) ) {
+ throw new XQException("Invalid type");
+ }
+ } else {
+ type = this.createElementType(null, XQItemType.XQBASETYPE_UNTYPED);
+ }
+
+ XmlDataManager dm = null;
+ Item doc = null;
+ XQItem item = null;
try {
- while( value.read(buffer) >= 0 ) {
- buffer.flip();
- writer.append(buffer);
- buffer.clear();
- }
- value.close();
- } catch (Exception ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
+ dm = zorba.getXmlDataManager();
+ doc = new Item();
+ ReaderZorbaStream stream = new ReaderZorbaStream(value);
+ doc = dm.parseXMLtoItem(stream);
+ item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
+ } catch (Exception e) {
+ throw new XQException("Error creating Item" + e.getLocalizedMessage());
}
-
- XQItem item = createItemFromDocument(writer.toString(), baseURI, type);
return item;
}
@@ -794,17 +747,26 @@
public XQItem createItemFromDocument(InputStream value, String baseURI, XQItemType type) throws XQException {
isClosedXQException();
isNullXQException(value);
- // TODO: Rodolfo: optimize this, not good to have a string
- StringBuffer out = new StringBuffer ();
+ if (type!=null) {
+ if ( ! ((type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_ELEMENT)||(type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT)) ) {
+ throw new XQException("Invalid type");
+ }
+ } else {
+ type = this.createElementType(null, XQItemType.XQBASETYPE_UNTYPED);
+ }
+
+ XmlDataManager dm = null;
+ Item doc = null;
+ XQItem item = null;
try {
- byte[] b = new byte[4096];
- for (int n; (n = value.read(b)) != -1;) {
- out.append(new String(b, 0, n));
- }
- } catch (Exception ex) {
- throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
+ dm = zorba.getXmlDataManager();
+ doc = new Item();
+ InputZorbaStream stream = new InputZorbaStream(value);
+ doc = dm.parseXMLtoItem(stream);
+ item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
+ } catch (Exception e) {
+ throw new XQException("Error creating Item" + e.getLocalizedMessage());
}
- XQItem item = createItemFromDocument(out.toString(), baseURI, type);
return item;
}
@@ -1203,11 +1165,7 @@
Item tmpItem = new Item();
if (xmlString.length()>0) {
XmlDataManager dataManager = zorba.getXmlDataManager();
- org.zorbaxquery.api.Iterator iter = dataManager.parseXML(xmlString);
- iter.open();
- iter.next(tmpItem);
- iter.close();
- iter.delete();
+ tmpItem = dataManager.parseXMLtoItem(xmlString);
} else {
tmpItem = itemFactory.createDocumentNode("", "");
}
=== modified file 'swig/xqj/ZorbaXQItem.java'
--- swig/xqj/ZorbaXQItem.java 2012-07-24 08:48:48 +0000
+++ swig/xqj/ZorbaXQItem.java 2012-08-03 20:31:44 +0000
@@ -699,7 +699,8 @@
opts.setSerializerOption(key, value);
}
}
- out.write(item.serialize(opts).getBytes());
+ OutputZorbaStream OStream = new OutputZorbaStream(out);
+ item.serializeToStream(OStream);
} catch (Exception ex) {
throw new XQException("Error writing on stream: " + ex.getLocalizedMessage());
}
@@ -727,6 +728,8 @@
opts.setSerializerOption(key, value);
}
}
+ WriterZorbaStream OStream = new WriterZorbaStream(writer);
+ item.serializeToStream(OStream);
writer.write(item.serialize(opts));
} catch (Exception ex) {
throw new XQException("Error sending to writer: " + ex.getLocalizedMessage());
=== modified file 'swig/xqj/ZorbaXQPreparedExpression.java'
--- swig/xqj/ZorbaXQPreparedExpression.java 2012-07-24 08:48:48 +0000
+++ swig/xqj/ZorbaXQPreparedExpression.java 2012-08-03 20:31:44 +0000
@@ -15,10 +15,7 @@
*/
package org.zorbaxquery.api.xqj;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
+import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Collection;
@@ -112,6 +109,43 @@
}
}
+
+ public ZorbaXQPreparedExpression (XQConnection conn, Reader reader) throws XQException {
+ if (conn.isClosed()) {
+ throw new XQException ("Connection is closed");
+ }
+ closed = false;
+ connection = conn;
+ Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance();
+ try {
+ ReaderZorbaStream stream = new ReaderZorbaStream(reader);
+ query = zorba.compileQuery(stream);
+ dynamicContext = query.getDynamicContext();
+ xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+ } catch (Exception e) {
+ throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+
+ }
+ }
+
+ public ZorbaXQPreparedExpression (XQConnection conn, InputStream input) throws XQException {
+ if (conn.isClosed()) {
+ throw new XQException ("Connection is closed");
+ }
+ closed = false;
+ connection = conn;
+ Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance();
+ try {
+ InputZorbaStream stream = new InputZorbaStream(input);
+ query = zorba.compileQuery(stream);
+ dynamicContext = query.getDynamicContext();
+ xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+ } catch (Exception e) {
+ throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+
+ }
+ }
+
public ZorbaXQPreparedExpression (XQConnection conn, String string, XQStaticContext sc) throws XQException {
if (conn.isClosed()) {
throw new XQException ("Connection is closed");
@@ -129,6 +163,42 @@
}
}
+ public ZorbaXQPreparedExpression (XQConnection conn, Reader reader, XQStaticContext sc) throws XQException {
+ if (conn.isClosed()) {
+ throw new XQException ("Connection is closed");
+ }
+ closed = false;
+ connection = conn;
+ Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance();
+ try {
+ ReaderZorbaStream stream = new ReaderZorbaStream(reader);
+ query = zorba.compileQuery(stream, ((org.zorbaxquery.api.xqj.ZorbaXQStaticContext)sc).getZorbaStaticContext());
+ dynamicContext = query.getDynamicContext();
+ xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+ } catch (Exception e) {
+ throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+
+ }
+ }
+
+ public ZorbaXQPreparedExpression (XQConnection conn, InputStream input, XQStaticContext sc) throws XQException {
+ if (conn.isClosed()) {
+ throw new XQException ("Connection is closed");
+ }
+ closed = false;
+ connection = conn;
+ Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance();
+ try {
+ InputZorbaStream stream = new InputZorbaStream(input);
+ query = zorba.compileQuery(stream, ((org.zorbaxquery.api.xqj.ZorbaXQStaticContext)sc).getZorbaStaticContext());
+ dynamicContext = query.getDynamicContext();
+ xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+ } catch (Exception e) {
+ throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+
+ }
+ }
+
/** \brief Attempts to cancel the execution if both the XQuery engine and XQJ driver support aborting the execution of an ZorbaXQPreparedExpression.
*
* This method can be used by one thread to cancel an ZorbaXQPreparedExpression, that is being executed in another thread. If cancellation is not supported or the attempt to cancel the execution was not successful, the method returns without any error. If the cancellation is successful, an XQException is thrown, to indicate that it has been aborted, by executeQuery, executeCommand or any method accessing the ZorbaXQResultSequence returned by executeQuery. If applicable, any open ZorbaXQResultSequence and XQResultItem objects will also be implicitly closed in this case.
@@ -445,9 +515,8 @@
throw new XQException ("Variable not found in context.");
}
try {
- Iterator iter = xmlDataManager.parseXML(value);
Item item = new Item();
- iter.next(item);
+ item = xmlDataManager.parseXMLtoItem(value);
dynamicContext.setVariable(varName.getLocalPart(), item);
itemsBounded.add(varName.getLocalPart());
} catch (Exception e) {
=== modified file 'swig/xqj/managers/Api_test.java'
--- swig/xqj/managers/Api_test.java 2012-07-24 08:48:48 +0000
+++ swig/xqj/managers/Api_test.java 2012-08-03 20:31:44 +0000
@@ -16,10 +16,10 @@
package api_test;
-import java.io.BufferedReader;
-import java.io.FileReader;
+import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Properties;
import javax.xml.namespace.QName;
import javax.xml.xquery.*;
import org.zorbaxquery.api.*;
@@ -44,6 +44,7 @@
return true;
}
+
static boolean example_2 () throws XQException
{
StringBuilder strBuilder = new StringBuilder();
@@ -205,7 +206,6 @@
Zorba zorba = Zorba.getInstance ( store );
XmlDataManager xmlManager = new XmlDataManager(zorba.getXmlDataManager());
CollectionManager manager = new CollectionManager(xmlManager.getCollectionManager());
-
ItemFactory factory = zorba.getItemFactory();
Item name = factory.createQName("http://www.zorba-xquery.com/", "aaa");
manager.createCollection(name);
@@ -250,49 +250,144 @@
return true;
}
- public static void main ( String argv[] ) throws XQException
+ static boolean example_7() throws XQException
+ {
+ InMemoryStore store = InMemoryStore.getInstance();
+ Zorba zorba = Zorba.getInstance ( store );
+ ReaderZorbaStream stream = new ReaderZorbaStream(new StringReader("'Hello world!'"));
+ XQuery query = zorba.compileQuery(stream);
+ System.out.println(query.execute());
+ zorba.shutdown();
+ InMemoryStore.shutdown ( store );
+ return true;
+ }
+
+ static boolean example_8() throws XQException, UnsupportedEncodingException
+ {
+ InMemoryStore store = InMemoryStore.getInstance();
+ Zorba zorba = Zorba.getInstance ( store );
+ String test =
+ "'"+
+ // 500 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ // 500 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"+ // 100 chars
+
+ "1234567890123456789012"+ // 100 chars
+ "'";
+ InputZorbaStream stream = new InputZorbaStream(new ByteArrayInputStream(test.getBytes("UTF-8")));
+ XQuery query = zorba.compileQuery(stream);
+ System.out.println(query.execute());
+ zorba.shutdown();
+ InMemoryStore.shutdown ( store );
+ return true;
+ }
+
+ static boolean example_9() throws XQException, UnsupportedEncodingException
+ {
+ InMemoryStore store = InMemoryStore.getInstance();
+ Zorba zorba = Zorba.getInstance ( store );
+ String test = "<Hello><ab/><ax/>World</Hello>";
+ InputZorbaStream stream = new InputZorbaStream(new ByteArrayInputStream(test.getBytes("UTF-8")));
+ XQuery query = zorba.compileQuery(stream);
+ System.out.println(query.execute());
+ query.destroy();
+ zorba.shutdown();
+ InMemoryStore.shutdown ( store );
+
+ return true;
+ }
+
+ static boolean example_10() throws XQException, UnsupportedEncodingException
+ {
+ InMemoryStore store = InMemoryStore.getInstance();
+ Zorba zorba = Zorba.getInstance ( store );
+ String test = "<Hello><ab/><ax/>World</Hello>";
+ InputZorbaStream stream = new InputZorbaStream(new ByteArrayInputStream(test.getBytes("UTF-8")));
+ XQuery query = zorba.compileQuery(stream);
+
+ OutputZorbaStream OStream = new OutputZorbaStream(System.out);
+ query.execute(OStream);
+
+ query.destroy();
+ zorba.shutdown();
+ InMemoryStore.shutdown ( store );
+
+ return true;
+ }
+
+ public static void main ( String argv[] ) throws XQException, UnsupportedEncodingException
{
boolean res = false;
- System.out.println ("executing test 1" );
- res = example_1( );
+ System.out.println ("Executing test 1" );
+ res = example_1();
if ( !res )
- System.exit ( 1 );
+ System.exit (1);
- System.out.println ( "executing test 2" );
- res = example_2 ( );
- if (!res)
- System.exit ( 1 );
-
- System.out.println ( "executing test 3a" );
- res = example_3a ( );
- if (!res)
- System.exit ( 1 );
-
- System.out.println ( "executing test 3b" );
- res = example_3b ( );
- if (!res)
- System.exit ( 1 );
+ System.out.println ( "Executing test 2" );
+ res = example_2();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 3a" );
+ res = example_3a();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 3b" );
+ res = example_3b();
+ if (!res)
+ System.exit (1);
- System.out.println ( "executing test 4" );
- res = example_4 ( );
- if (!res)
- System.exit ( 1 );
-
- System.out.println ( "executing test 5" );
- res = example_5 ( );
- if (!res)
- System.exit ( 1 );
- System.out.println ( "executing test 6a" );
- res = example_6a ( );
- if (!res)
- System.exit ( 1 );
-
- System.out.println ( "executing test 6b" );
- res = example_6b ( );
- if (!res)
- System.exit ( 1 );
- System.out.println ( "done." );
+ System.out.println ( "Executing test 4" );
+ res = example_4();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 5" );
+ res = example_5();
+ if (!res)
+ System.exit (1);
+ System.out.println ( "Executing test 6a" );
+ res = example_6a();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 6b" );
+ res = example_6b();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 7" );
+ res = example_7();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 8" );
+ res = example_8();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 9" );
+ res = example_9();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Executing test 10" );
+ res = example_10();
+ if (!res)
+ System.exit (1);
+
+ System.out.println ( "Done." );
} // main
=== modified file 'swig/zorba_api.i'
--- swig/zorba_api.i 2012-07-24 08:48:48 +0000
+++ swig/zorba_api.i 2012-08-03 20:31:44 +0000
@@ -23,6 +23,9 @@
%include "std_string.i"
%include "std_pair.i"
%include "exception.i"
+%include "carrays.i"
+%array_class(int, intArray);
+%apply (const char *STRING, size_t LENGTH) { (const char *str, size_t len) };
#ifndef SWIGRUBY
%include "std_vector.i"
@@ -86,6 +89,8 @@
class Store;
class InMemoryStore;
+ #include "ZorbaStream.h"
+ #include "ZorbaBuffer.h"
#include "SerializationOptions.h"
#include "TypeIdentifier.h"
#include "Item.h"
@@ -114,7 +119,8 @@
/* %include "various.i" required for mapping to Java byte[]*/
-//%include "ZorbaStreamProxy.i"
+%include "ZorbaStream.i"
+%include "ZorbaBuffer.i"
%include "SerializationOptions.i"
%include "TypeIdentifier.i"
%include "Item.i"
Follow ups
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-09-07
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-09-06
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-09-03
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-09-01
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-31
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-31
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-31
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-31
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-30
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-30
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Zorba Build Bot, 2012-08-30
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
[Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-30
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Cezar Andrei, 2012-08-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Rodolfo Ochoa, 2012-08-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Cezar Andrei, 2012-08-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug938320 into lp:zorba
From: Chris Hillery, 2012-08-28