Merge lp:~zorba-coders/zorba/core_archive_module into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Chris Hillery
Approved revision: 10885
Merged at revision: 10903
Proposed branch: lp:~zorba-coders/zorba/core_archive_module
Merge into: lp:zorba
Diff against target: 200 lines (+86/-63)
4 files modified
ChangeLog (+1/-0)
include/zorba/item.h (+9/-0)
modules/org/expath/ns/file.xq.src/file_function.cpp (+65/-63)
src/api/item.cpp (+11/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/core_archive_module
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Matthias Brantner Approve
Review via email: mp+112661@code.launchpad.net

Commit message

- added API function Item:isSeekable
- fixed a problem in the file module where all exceptions being throw in the body were caught and rethrown as file exception

Description of the change

- added API function Item:isSeekable
- fixed a problem in the file module where all exceptions being throw in the body were caught and rethrown as file exception. This could have lead to confusing error messages if an exception was reported while evaluating the input sequence to file:write.

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job core_archive_module-2012-06-28T22-43-57.486Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Chris Hillery (ceejatec) wrote :

Matthias - we worked on something recently (I can't remember exactly what) which also involved a function to mark whether a stream was seekable or not. In particular, I asked for the comment to define clearly what "seekable" meant - does it mean arbitrarily seekable, or just restartable, or forward-seekable only, or what.

Do you remember where that code was? At any rate, I would make the same request here - "seekable" is not IMHO sufficiently explicit. Other than that it looks good.

10885. By Matthias Brantner

better comment

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

> Matthias - we worked on something recently (I can't remember exactly what)
> which also involved a function to mark whether a stream was seekable or not.
> In particular, I asked for the comment to define clearly what "seekable" meant
> - does it mean arbitrarily seekable, or just restartable, or forward-seekable
> only, or what.
>
> Do you remember where that code was? At any rate, I would make the same
> request here - "seekable" is not IMHO sufficiently explicit. Other than that
> it looks good.
That was in include/zorba/uri_resolver.h. I have committed a fix by improving the documentation the same way we did for the URI Resolvers.

Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job core_archive_module-2012-06-29T07-13-03.31Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-06-28 19:06:27 +0000
3+++ ChangeLog 2012-06-29 03:09:19 +0000
4@@ -4,6 +4,7 @@
5 version 2.x
6
7 New Features:
8+ * Item::isSeekable API extension for streamable content (xs:string and xs:base64Binary).
9 * Implemented the latest W3C specification for the group by clause
10 * New XQuery 3.0 functions
11 - fn:parse-xml-fragment#1
12
13=== modified file 'include/zorba/item.h'
14--- include/zorba/item.h 2012-06-28 04:14:03 +0000
15+++ include/zorba/item.h 2012-06-29 03:09:19 +0000
16@@ -422,6 +422,15 @@
17 isStreamable() const;
18
19 /**
20+ * Checks whether the item's streamable content is arbitrarily
21+ * (forward anb backward) seekable.
22+ *
23+ * @return true only if it is.
24+ */
25+ bool
26+ isSeekable() const;
27+
28+ /**
29 * Gets an istream for the item's content.
30 *
31 * @return the stream.
32
33=== modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp'
34--- modules/org/expath/ns/file.xq.src/file_function.cpp 2012-06-28 04:14:03 +0000
35+++ modules/org/expath/ns/file.xq.src/file_function.cpp 2012-06-29 03:09:19 +0000
36@@ -241,77 +241,79 @@
37 File_t lFile = File::createFile(lFileStr.c_str());
38
39 // precondition
40- if (lFile->isDirectory()) {
41- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
42+ if (lFile->isDirectory())
43+ {
44+ raiseFileError("FOFL0004",
45+ "The given path points to a directory", lFile->getFilePath());
46 }
47
48 bool lBinary = isBinary();
49+ // open the output stream in the desired write mode
50+ std::ofstream lOutStream;
51
52 // actual write
53- try {
54-
55- // open the output stream in the desired write mode
56- std::ofstream lOutStream;
57+ try
58+ {
59 lFile->openOutputStream(lOutStream, lBinary, isAppend());
60-
61- // if this is a binary write
62- if (lBinary) {
63- Item lBinaryItem;
64- Iterator_t lContentSeq = aArgs[1]->getIterator();
65- lContentSeq->open();
66- while (lContentSeq->next(lBinaryItem))
67- {
68- if (lBinaryItem.isStreamable() && !lBinaryItem.isEncoded())
69- {
70- lOutStream << lBinaryItem.getStream().rdbuf();
71- }
72- else
73- {
74- Zorba_SerializerOptions lOptions;
75- lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY;
76- Serializer_t lSerializer = Serializer::createSerializer(lOptions);
77- SingletonItemSequence lSeq(lBinaryItem);
78- lSerializer->serialize(&lSeq, lOutStream);
79- }
80-
81- }
82- }
83- // if we only write text
84- else {
85- Item lStringItem;
86- Iterator_t lContentSeq = aArgs[1]->getIterator();
87- lContentSeq->open();
88- // for each item (string or base64Binary) in the content sequence
89- while (lContentSeq->next(lStringItem)) {
90- // if the item is streamable make use of the stream
91- if (lStringItem.isStreamable()) {
92- std::istream& lInStream = lStringItem.getStream();
93- char lBuf[1024];
94- while (!lInStream.eof()) {
95- lInStream.read(lBuf, 1024);
96- lOutStream.write(lBuf, lInStream.gcount());
97- }
98- }
99- // else write the string value
100- else {
101- zorba::String lString = lStringItem.getStringValue();
102- lOutStream.write(lString.data(), lString.size());
103- }
104- }
105- lContentSeq->close();
106- }
107-
108- // close the file stream
109- lOutStream.close();
110-
111- } catch (ZorbaException& ze) {
112+ }
113+ catch (ZorbaException& ze)
114+ {
115 std::stringstream lSs;
116- lSs << "An unknown error occured: " << ze.what() << "Can not read file";
117+ lSs << "Can not open file for writing: " << ze.what();
118 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
119- } catch (...) {
120- //assert(false); if this happens errors are not proprly thrown
121- raiseFileError("FOFL9999", "Can not read file", lFile->getFilePath());
122- }
123+ }
124+
125+ // if this is a binary write
126+ if (lBinary)
127+ {
128+ Item lBinaryItem;
129+ Iterator_t lContentSeq = aArgs[1]->getIterator();
130+ lContentSeq->open();
131+ while (lContentSeq->next(lBinaryItem))
132+ {
133+ if (lBinaryItem.isStreamable() && !lBinaryItem.isEncoded())
134+ {
135+ lOutStream << lBinaryItem.getStream().rdbuf();
136+ }
137+ else
138+ {
139+ Zorba_SerializerOptions lOptions;
140+ lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY;
141+ Serializer_t lSerializer = Serializer::createSerializer(lOptions);
142+ SingletonItemSequence lSeq(lBinaryItem);
143+ lSerializer->serialize(&lSeq, lOutStream);
144+ }
145+
146+ }
147+ }
148+ // if we only write text
149+ else
150+ {
151+ Item lStringItem;
152+ Iterator_t lContentSeq = aArgs[1]->getIterator();
153+ lContentSeq->open();
154+ // for each item (string or base64Binary) in the content sequence
155+ while (lContentSeq->next(lStringItem)) {
156+ // if the item is streamable make use of the stream
157+ if (lStringItem.isStreamable()) {
158+ std::istream& lInStream = lStringItem.getStream();
159+ char lBuf[1024];
160+ while (!lInStream.eof()) {
161+ lInStream.read(lBuf, 1024);
162+ lOutStream.write(lBuf, lInStream.gcount());
163+ }
164+ }
165+ // else write the string value
166+ else {
167+ zorba::String lString = lStringItem.getStringValue();
168+ lOutStream.write(lString.data(), lString.size());
169+ }
170+ }
171+ lContentSeq->close();
172+ }
173+
174+ // close the file stream
175+ lOutStream.close();
176
177 return ItemSequence_t(new EmptySequence());
178 }
179
180=== modified file 'src/api/item.cpp'
181--- src/api/item.cpp 2012-06-28 04:14:03 +0000
182+++ src/api/item.cpp 2012-06-29 03:09:19 +0000
183@@ -546,6 +546,17 @@
184 return false;
185 }
186
187+bool
188+Item::isSeekable() const
189+{
190+ ITEM_TRY
191+ SYNC_CODE(AutoLock lock(GENV_STORE.getGlobalLock(), Lock::READ);)
192+
193+ return m_item->isSeekable();
194+ ITEM_CATCH
195+ return false;
196+}
197+
198 std::istream&
199 Item::getStream()
200 {

Subscribers

People subscribed via source and target branches