diff --git a/3005.pdf b/3005.pdf new file mode 100644 index 0000000..a9997ba Binary files /dev/null and b/3005.pdf differ diff --git a/3006.pdf b/3006.pdf new file mode 100644 index 0000000..3d7ad70 Binary files /dev/null and b/3006.pdf differ diff --git a/3007.pdf b/3007.pdf new file mode 100644 index 0000000..405b7ac Binary files /dev/null and b/3007.pdf differ diff --git a/3014.pdf b/3014.pdf new file mode 100644 index 0000000..61599d6 Binary files /dev/null and b/3014.pdf differ diff --git a/6668/Chapter01/0553211757.xml b/6668/Chapter01/0553211757.xml new file mode 100644 index 0000000..5956946 --- /dev/null +++ b/6668/Chapter01/0553211757.xml @@ -0,0 +1,8 @@ + + Crime and Punishment + + Bantam Classics + 9.3 + 576 + + diff --git a/6668/Chapter01/author-923117.xml b/6668/Chapter01/author-923117.xml new file mode 100644 index 0000000..eb52727 --- /dev/null +++ b/6668/Chapter01/author-923117.xml @@ -0,0 +1,6 @@ + + Fyodor Dostoevsky + November 11 1821 + February 9 1881 + + diff --git a/6668/Chapter02/2-1.pl b/6668/Chapter02/2-1.pl new file mode 100644 index 0000000..1c25fa0 --- /dev/null +++ b/6668/Chapter02/2-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl -w +use strict; +use XML::LibXML; +use DB_File; +$DB_BTREE->{'flags'} = R_DUP ; +my $datadir = "./xml-src/"; +my $indexdir = "./index/"; +my $parser = new XML::LibXML; +my %btree; +tie %btree, 'DB_File', "$indexdir/words.index", O_RDWR|O_CREAT, 0666, $DB_BTREE, + or die "Cannot open $indexdir/words.index: $!\n"; + +opendir my $dir, $datadir; +while (my $file = readdir($dir)) { + next if ($file =~ /^\./); + my $dom = $parser->parse_file("$datadir/$file"); + foreach my $node ($dom->findnodes("/Synset/Word")) { + my ($textnode) = $node->findnodes("text()"); + my $lcname = lc($textnode->getData); + if ($textnode) { $btree{$lcname} = $file; } + } +} + diff --git a/6668/Chapter07/7-1.xml b/6668/Chapter07/7-1.xml new file mode 100644 index 0000000..8196227 --- /dev/null +++ b/6668/Chapter07/7-1.xml @@ -0,0 +1,23 @@ + + + Brown + Jim + Austin + Big + + 24 + + 612-555-0091 + + + Attn: Jim Brown + Pleax Systems, Inc. + 18520 25th Ave + + Minneapolis + MN + male + boats + carpentry + + diff --git a/6668/Chapter07/7-10.xq b/6668/Chapter07/7-10.xq new file mode 100644 index 0000000..418419f --- /dev/null +++ b/6668/Chapter07/7-10.xq @@ -0,0 +1,6 @@ +declare namespace my = "http://brians.org/temperature"; +declare function my:celsius-to-fahrenheit ($celsius as xs:decimal) as xs:decimal { + ($celsius + 32) * (9 div 5) +}; +my:celsius-to-fahrenheit(15) + diff --git a/6668/Chapter07/7-11.xqm b/6668/Chapter07/7-11.xqm new file mode 100644 index 0000000..51fb9e7 --- /dev/null +++ b/6668/Chapter07/7-11.xqm @@ -0,0 +1,5 @@ +module namespace temp = "http://brians.org/temperature"; +declare function temp:celsius-to-fahrenheit ($celsius as xs:decimal) { + ($celsius + 32) * (9 div 5) +}; + diff --git a/6668/Chapter07/7-12.xq b/6668/Chapter07/7-12.xq new file mode 100644 index 0000000..8a382f5 --- /dev/null +++ b/6668/Chapter07/7-12.xq @@ -0,0 +1,3 @@ +import module namespace temp = "http://brians.org/temperature" at "temperature.xqm"; +temp:celsius-to-fahrenheit(10) + diff --git a/6668/Chapter07/7-13.xq b/6668/Chapter07/7-13.xq new file mode 100644 index 0000000..24af6e6 --- /dev/null +++ b/6668/Chapter07/7-13.xq @@ -0,0 +1,4 @@ +for $person in collection("people.dbxml")/person +where starts-with($person/phone, "612") +return $person + diff --git a/6668/Chapter07/7-14.xq b/6668/Chapter07/7-14.xq new file mode 100644 index 0000000..60ecc38 --- /dev/null +++ b/6668/Chapter07/7-14.xq @@ -0,0 +1,5 @@ +for $person in collection("people.dbxml")/person +for $phone in $person/phone +where starts-with($phone, "612") +return $person + diff --git a/6668/Chapter07/7-15.xq b/6668/Chapter07/7-15.xq new file mode 100644 index 0000000..651ead7 --- /dev/null +++ b/6668/Chapter07/7-15.xq @@ -0,0 +1,4 @@ +for $person in collection("people.dbxml")/person +where some $phone in $person/phone satisfies (starts-with($phone, "612")) +return $person + diff --git a/6668/Chapter07/7-16.xq b/6668/Chapter07/7-16.xq new file mode 100644 index 0000000..57c7929 --- /dev/null +++ b/6668/Chapter07/7-16.xq @@ -0,0 +1,4 @@ +for $person in collection("people.dbxml")/person +where some $phone in $person/phone satisfies (matches($phone, "^612")) +return $person + diff --git a/6668/Chapter07/7-17.xq b/6668/Chapter07/7-17.xq new file mode 100644 index 0000000..1f5d004 --- /dev/null +++ b/6668/Chapter07/7-17.xq @@ -0,0 +1,4 @@ +let $areacode := "612" +let $match := concat("^", $areacode, "[-\\.]\\d{3}[-\\.]\\d{4}$") +return matches("612.423.1124", $match) + diff --git a/6668/Chapter07/7-18.xq b/6668/Chapter07/7-18.xq new file mode 100644 index 0000000..2289536 --- /dev/null +++ b/6668/Chapter07/7-18.xq @@ -0,0 +1,4 @@ +for $document in collection("people.dbxml")/* +where $document[dbxml:metadata("dbxml:name") = "person1"] +return $document + diff --git a/6668/Chapter07/7-19.xq b/6668/Chapter07/7-19.xq new file mode 100644 index 0000000..6073f5f --- /dev/null +++ b/6668/Chapter07/7-19.xq @@ -0,0 +1,5 @@ +for $x in collection("people.dbxml")/person/name/first +for $y in collection("synsets.dbxml")/Synset/Word +where contains($y, $x) +return (string($x), "=>", string($y)) + diff --git a/6668/Chapter07/7-2.xml b/6668/Chapter07/7-2.xml new file mode 100644 index 0000000..f96d235 --- /dev/null +++ b/6668/Chapter07/7-2.xml @@ -0,0 +1,13 @@ + + 14861 + 02772480 + 06 + n + baseball + + 14746 + 14866 + + a ball used in playing baseball + + diff --git a/6668/Chapter07/7-20.xml b/6668/Chapter07/7-20.xml new file mode 100644 index 0000000..4da24f2 --- /dev/null +++ b/6668/Chapter07/7-20.xml @@ -0,0 +1,14 @@ + + 41886 + 07647890 + 13 + n + banana + + 41581 + 65855 + 65852 + + elongated crescent-shaped yellow fruit with soft sweet flesh + + diff --git a/6668/Chapter07/7-21.xq b/6668/Chapter07/7-21.xq new file mode 100644 index 0000000..614da68 --- /dev/null +++ b/6668/Chapter07/7-21.xq @@ -0,0 +1,13 @@ +declare namespace my = "http://brians.org/synsets"; +declare function my:hypernyms ($synset) { + let $hyp := $synset/Pointers/Hypernym[1]/string() + return + if (empty($hyp)) + then ($synset/Word)[1]/string() + else + let $next := my:hypernyms(collection("synsets.dbxml")/Synset[Id = $hyp]) + return concat($next, " => ", $synset/Word[1]) + }; + +my:hypernyms((collection("synsets.dbxml")/Synset[Word="banana"])[1]) + diff --git a/6668/Chapter07/7-22.xq b/6668/Chapter07/7-22.xq new file mode 100644 index 0000000..831cdfb --- /dev/null +++ b/6668/Chapter07/7-22.xq @@ -0,0 +1,11 @@ +declare namespace my = "http://brians.org/temperature"; +declare function my:binary ($dec as xs:decimal) { + if ($dec eq 0 or $dec eq 1) + then $dec + else + let $m := xs:integer($dec div 2) + let $j := $dec mod 2 + let $D := my:binary($m) + return concat(string($D), string($j)) +}; + diff --git a/6668/Chapter07/7-23.xq b/6668/Chapter07/7-23.xq new file mode 100644 index 0000000..a2023b1 --- /dev/null +++ b/6668/Chapter07/7-23.xq @@ -0,0 +1,16 @@ +declare namespace my = "http://brians.org/synsets"; +declare function my:steps ($synset) as element() { + let $hyp := $synset/Pointers/Hypernym[1]/string() + return + if (empty($hyp)) + then element step { attribute name {($synset/Word)[1]} } + else + let $next := my:steps(collection("synsets.dbxml")/Synset[Id = $hyp]) + return element step { + attribute name { $synset/Word[1] }, + $next + } +}; + +my:steps((collection("synsets.dbxml")/Synset[Word="banana"])[1]) + diff --git a/6668/Chapter07/7-24.xq b/6668/Chapter07/7-24.xq new file mode 100644 index 0000000..be39b20 --- /dev/null +++ b/6668/Chapter07/7-24.xq @@ -0,0 +1,24 @@ +declare namespace my = "http://brians.org/synsets"; +declare function my:hypernyms ($synset) { + let $hyp := $synset/Pointers/Hypernym[1]/string() + return + if (empty($hyp)) + then $synset/Id/string() + else + let $next := my:hypernyms(collection("synsets.dbxml")/Synset[Id = $hyp]) + return ($synset/Id/string(), $next) + }; + declare function my:tree ($idlist) { + if (empty($idlist)) + then () + else + element step { + attribute id {$idlist[1]}, + attribute name {collection("synsets.dbxml")/Synset[Id = $idlist[1]]/Word[1]}, + my:tree(remove($idlist, 1)) + } +}; + +let $list := my:hypernyms((collection("synsets.dbxml")/Synset[Word="flan"])[1]) +return my:tree(reverse($list)) + diff --git a/6668/Chapter07/7-27.xq b/6668/Chapter07/7-27.xq new file mode 100644 index 0000000..d587164 --- /dev/null +++ b/6668/Chapter07/7-27.xq @@ -0,0 +1,11 @@ +declare namespace my = "http://brians.org/synsets"; +declare variable $rand as xs:decimal external; +declare function my:random-synset () { + let $count := 250000 (: the number of records for our set :) + let $synset := (collection("steps.dbxml")//*[@id="9"]//*)[($count * $rand) cast as + xs:integer] + return ($synset/@id/string(), $synset/@name/string()) +}; + +my:random-synset() + diff --git a/6668/Chapter07/7-28.xq b/6668/Chapter07/7-28.xq new file mode 100644 index 0000000..5cfcadc --- /dev/null +++ b/6668/Chapter07/7-28.xq @@ -0,0 +1,10 @@ +declare namespace my = "http://brians.org/synsets"; +declare function my:guess($answerId as xs:decimal, $guessId as xs:decimal) { + if (collection("steps.dbxml")//*[@id = $guessId]//*[@id = $answerId]) + then true() + else false() +}; + +my:guess(56056, 19), (: policeman, person :) +my:guess(56056, 53188) (: policeman, cook :) + diff --git a/6668/Chapter07/7-29.xq b/6668/Chapter07/7-29.xq new file mode 100644 index 0000000..a7e54fc --- /dev/null +++ b/6668/Chapter07/7-29.xq @@ -0,0 +1,4 @@ +for $step in collection("steps.dbxml")//*[@id = "24"]//* +where matches($step/@name, "an$") +return $step/@name/string() + diff --git a/6668/Chapter07/7-31.xml b/6668/Chapter07/7-31.xml new file mode 100644 index 0000000..7bf2e4c --- /dev/null +++ b/6668/Chapter07/7-31.xml @@ -0,0 +1,14 @@ + + + Four Seasons Cairo at Nile Plaza + 1089 Corniche El Nile
Cairo, Egypt

+

Score: 86.09

+

30-story hotel near Garden City on the east bank of the river.

+ © 2006 Travel + Leisure

]]>
+ + relativeToGround + 31.229338,30.03595,0 + +
+
+ diff --git a/6668/Chapter07/7-33.xq b/6668/Chapter07/7-33.xq new file mode 100644 index 0000000..dd1fcfb --- /dev/null +++ b/6668/Chapter07/7-33.xq @@ -0,0 +1,13 @@ +declare namespace my = "http://brians.org/range"; +declare function my:in-range ($myLon as xs:decimal, $myLat as xs:decimal, $range + as xs:decimal) { + for $place in collection("coord.dbxml")/place + where ($place/latitude > ($myLat - $range) and $place/latitude < ($myLat + + $range)) + and ($place/longitude > ($myLon - $range) and $place/longitude < ($myLon + + $range)) + return $place/name/text() +}; + +my:in-range (-111.651862515931, 40.00652821419428, 2) + diff --git a/6668/Chapter07/7-34.xq b/6668/Chapter07/7-34.xq new file mode 100644 index 0000000..71b0020 --- /dev/null +++ b/6668/Chapter07/7-34.xq @@ -0,0 +1,12 @@ +declare namespace my = "http://brians.org/range"; +declare function my:in-range ($myLon as xs:decimal, $myLat as xs:decimal, $range as xs:decimal) { + for $place in collection("coord.dbxml")/place + where ($place/latitude > ($myLat - $range) and $place/latitude < ($myLat + $range)) + and ($place/longitude > ($myLon - $range) and $place/longitude < ($myLon + $range)) + return $place/name/text() +}; + +let $placesCloseToHome := my:in-range (-111.651862515931, 40.00652821419428, 12) +let $placesCloseToJim := my:in-range (-93.49764084020113, 45.01312134030998, 12) +return $placesCloseToHome union $placesCloseToJim + diff --git a/6668/Chapter07/7-35.xq b/6668/Chapter07/7-35.xq new file mode 100644 index 0000000..a627b1f --- /dev/null +++ b/6668/Chapter07/7-35.xq @@ -0,0 +1,5 @@ +for $person in collection("people.dbxml")/person +for $phone in $person/phone/*/string() +where $phone = "612-555-9901" +return $person + diff --git a/6668/Chapter07/7-36.xq b/6668/Chapter07/7-36.xq new file mode 100644 index 0000000..6476ce8 --- /dev/null +++ b/6668/Chapter07/7-36.xq @@ -0,0 +1,6 @@ +for $person in collection("people.dbxml")/person +for $office in $person/phone/office +for $home in $person/phone/home +where $office = "612-555-9901" or $home = "612-555-9901" +return $person + diff --git a/6668/Chapter07/7-37.xq b/6668/Chapter07/7-37.xq new file mode 100644 index 0000000..1fb1ab4 --- /dev/null +++ b/6668/Chapter07/7-37.xq @@ -0,0 +1,5 @@ +declare variable $phone xs:string external; +for $person in collection("people.dbxml")/person +where $person/phone eq $phone +return concat($person/name/first, "'s ", $person/phone[string() = $phone]/@loc, " phone is: ", $phone) + diff --git a/6668/Chapter07/7-5.xq b/6668/Chapter07/7-5.xq new file mode 100644 index 0000000..6532b49 --- /dev/null +++ b/6668/Chapter07/7-5.xq @@ -0,0 +1,21 @@ +declare namespace people = "urn:something"; +declare variable $name as xs:string external; +declare function people:age-ok($age) { +if (21 < $age and $age < 100) +then true() +else false() +}; +(: Here is a comment. :) + +{ + for $person in collection("people.dbxml")/person + where people:age-ok($person/age/number()) and $person/name/*/string() = $name + order by $person/name/last + return + + {$person/name/*} + {$person/age/string()} + +} + + diff --git a/6668/Chapter07/7-6.xq b/6668/Chapter07/7-6.xq new file mode 100644 index 0000000..1e8b2ee --- /dev/null +++ b/6668/Chapter07/7-6.xq @@ -0,0 +1,3 @@ +collection("synsets.dbxml")/Synset[Pointers/Hypernym = + collection("synsets.dbxml")/Synset[Word="baseball"]/Id/string()]/Id + diff --git a/6668/Chapter07/7-7.xq b/6668/Chapter07/7-7.xq new file mode 100644 index 0000000..7ce0fa1 --- /dev/null +++ b/6668/Chapter07/7-7.xq @@ -0,0 +1,5 @@ +for $baseball in collection("synsets.dbxml")/Synset[Word="baseball"]/Id, + $synset in collection("synsets.dbxml")/Synset +where $synset/Pointers/Hypernym = $baseball/Id +return $synset/Id + diff --git a/6668/Chapter07/7-8.xq b/6668/Chapter07/7-8.xq new file mode 100644 index 0000000..ca1c534 --- /dev/null +++ b/6668/Chapter07/7-8.xq @@ -0,0 +1,5 @@ +let $baseballs := collection("synsets.dbxml")/Synset[Word="baseball"]/Id +for $synset in collection("synsets.dbxml")/Synset +where $synset/Pointers/Hypernym = $baseballs +return $synset/Id + diff --git a/6668/Chapter07/7-9.xq b/6668/Chapter07/7-9.xq new file mode 100644 index 0000000..47039a9 --- /dev/null +++ b/6668/Chapter07/7-9.xq @@ -0,0 +1,5 @@ +for $person in collection("people.dbxml")//person[name/first = "Jim"] +for $known in collection("people.dbxml")//person[name/last = "Brown"] +where $person is $known +return $person + diff --git a/6668/Chapter07/README.txt b/6668/Chapter07/README.txt new file mode 100644 index 0000000..12cf6ee --- /dev/null +++ b/6668/Chapter07/README.txt @@ -0,0 +1,13 @@ +Most of these XQuery files cannot be run outside of BDB XML's shell or an +application using the API, since the database collection is unavailable. + +One exception is listing 7-10. To run it using the XQuery eval tool +(or xqilla): + + % dbxml-2.2.13/xquery-1.2.0/build_unix/eval 7-10.xq + +The module example: + + % dbxml-2.2.13/xquery-1.2.0/build_unix/eval 7-12.xq + + diff --git a/6668/Chapter07/temperature.xqm b/6668/Chapter07/temperature.xqm new file mode 100644 index 0000000..51fb9e7 --- /dev/null +++ b/6668/Chapter07/temperature.xqm @@ -0,0 +1,5 @@ +module namespace temp = "http://brians.org/temperature"; +declare function temp:celsius-to-fahrenheit ($celsius as xs:decimal) { + ($celsius + 32) * (9 div 5) +}; + diff --git a/6668/Chapter08/8-1.cpp b/6668/Chapter08/8-1.cpp new file mode 100644 index 0000000..06a0448 --- /dev/null +++ b/6668/Chapter08/8-1.cpp @@ -0,0 +1,18 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + // Create an XmlManager + XmlManager myManager; + try { + // Open a container + XmlContainer myContainer = + myManager.openContainer("container.dbxml"); + } catch (XmlException &xe) { + printf ("%s\n", xe.what()); + } catch (std::exception &e) { + // Other error handling goes here + } +} + diff --git a/6668/Chapter08/8-10.cpp b/6668/Chapter08/8-10.cpp new file mode 100644 index 0000000..7bd693c --- /dev/null +++ b/6668/Chapter08/8-10.cpp @@ -0,0 +1,22 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + std::string docFilename = "file176.xml"; // the filename + + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + + // The update context is needed to add the document. + XmlUpdateContext theContext = myManager.createUpdateContext(); + + // Create the file input stream + XmlInputStream *myStream = myManager.createLocalFileInputStream(docFilename); + + // Put the document in the container + myContainer.putDocument(docFilename, myStream, theContext, 0); + + return(0); +} + diff --git a/6668/Chapter08/8-11.cpp b/6668/Chapter08/8-11.cpp new file mode 100644 index 0000000..8079eb4 --- /dev/null +++ b/6668/Chapter08/8-11.cpp @@ -0,0 +1,13 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + myContext.setDefaultCollection("myCollection"); + std::string myQuery = "collection()/Synset[Word='wisdom']"; + XmlQueryExpression qe = myManager.prepare(myQuery, myContext); + XmlResults results = qe.execute(myContext); +} + diff --git a/6668/Chapter08/8-12.cpp b/6668/Chapter08/8-12.cpp new file mode 100644 index 0000000..088e649 --- /dev/null +++ b/6668/Chapter08/8-12.cpp @@ -0,0 +1,17 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("synsets.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + myContext.setNamespace("people", "http://brians.org/people"); + myContext.setVariableValue("name", "Bob"); + std::string myQuery = "collection('myCollection')/people:person[name=$name]"; + XmlQueryExpression qe = myManager.prepare(myQuery, myContext); + XmlResults results = qe.execute(myContext); + // Change the variable, and requery without recompiling query. + myContext.setVariableValue("name", "Julie"); + results = qe.execute(myContext); +} + diff --git a/6668/Chapter08/8-13.cpp b/6668/Chapter08/8-13.cpp new file mode 100644 index 0000000..ace0094 --- /dev/null +++ b/6668/Chapter08/8-13.cpp @@ -0,0 +1,11 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + std::string myQuery = "collection()/person[name='Bob']"; + XmlResults results = myManager.query(myQuery, myContext); +} + diff --git a/6668/Chapter08/8-15.cpp b/6668/Chapter08/8-15.cpp new file mode 100644 index 0000000..8dad46b --- /dev/null +++ b/6668/Chapter08/8-15.cpp @@ -0,0 +1,20 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + std::string myQuery = "collection()/person[name='Bob']"; + XmlResults results = myManager.query(myQuery, myContext); + printf("%i results from query.\n", results.size()); + XmlValue value; + while (results.next(value)) { + XmlDocument myDoc = value.asDocument(); + std::string docContent = value.asString(); + std::string docName = myDoc.getName(); + std::cout << "Document " << docName << ":" << std::endl; + std::cout << docContent << std::endl; + } +} + diff --git a/6668/Chapter08/8-16.cpp b/6668/Chapter08/8-16.cpp new file mode 100644 index 0000000..4f4c467 --- /dev/null +++ b/6668/Chapter08/8-16.cpp @@ -0,0 +1,25 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + XmlResults results = myManager.query("collection('myContainer.dbxml')/person[name='Bob']", myContext); + printf("%i results from query.\n", results.size()); + XmlQueryExpression phoneQuery = + myManager.prepare("/person/phone/string()", myContext); + XmlValue value; + while (results.next(value)) { + XmlQueryContext phoneContext = myManager.createQueryContext(); + XmlResults phoneResults = phoneQuery.execute(value, phoneContext); + XmlDocument myDoc = value.asDocument(); + std::string docName = myDoc.getName(); + std::cout << "Document " << docName << ":" << std::endl; + XmlValue phoneValue; + while (phoneResults.next(phoneValue)) { + std::cout << " Phone: " << phoneValue.asString() << std::endl; + } + } +} + diff --git a/6668/Chapter08/8-17.cpp b/6668/Chapter08/8-17.cpp new file mode 100644 index 0000000..cf448b5 --- /dev/null +++ b/6668/Chapter08/8-17.cpp @@ -0,0 +1,14 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlUpdateContext myContext = myManager.createUpdateContext(); + std::string docContent = "Bob"; + myContainer.putDocument("", docContent, // The document's content as string + myContext, // The update context + DBXML_GEN_NAME); // Autogenerate document name +} + diff --git a/6668/Chapter08/8-18.cpp b/6668/Chapter08/8-18.cpp new file mode 100644 index 0000000..a3a2243 --- /dev/null +++ b/6668/Chapter08/8-18.cpp @@ -0,0 +1,16 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlResults results = myManager.query("collection('container.bdbxml')/person[name='Bob']", myContext); + printf("Deleting %i documents matching query.\n", results.size()); + XmlDocument docToDelete; + while (results.next(docToDelete)) { + myContainer.deleteDocument(docToDelete, myUpdateContext); + } +} + diff --git a/6668/Chapter08/8-19.cpp b/6668/Chapter08/8-19.cpp new file mode 100644 index 0000000..4861267 --- /dev/null +++ b/6668/Chapter08/8-19.cpp @@ -0,0 +1,13 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlDocument myDoc = myContainer.getDocument("114.xml"); + myDoc.setContent("Charles"); + myContainer.updateDocument(myDoc, myUpdateContext); +} + diff --git a/6668/Chapter08/8-20.cpp b/6668/Chapter08/8-20.cpp new file mode 100644 index 0000000..87a19cf --- /dev/null +++ b/6668/Chapter08/8-20.cpp @@ -0,0 +1,10 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + myContainer.addIndex("", "person", "node-element-equality-string", myUpdateContext); +} + diff --git a/6668/Chapter08/8-21.cpp b/6668/Chapter08/8-21.cpp new file mode 100644 index 0000000..79d5391 --- /dev/null +++ b/6668/Chapter08/8-21.cpp @@ -0,0 +1,16 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + myContainer.addIndex("", "person", + (XmlIndexSpecification::Type) + (XmlIndexSpecification::PATH_NODE | + XmlIndexSpecification::NODE_ELEMENT | + XmlIndexSpecification::KEY_EQUALITY), + XmlValue::STRING, + myUpdateContext); +} + diff --git a/6668/Chapter08/8-22.cpp b/6668/Chapter08/8-22.cpp new file mode 100644 index 0000000..defbf72 --- /dev/null +++ b/6668/Chapter08/8-22.cpp @@ -0,0 +1,13 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlIndexSpecification myIndexSpec = myContainer.getIndexSpecification(); + myIndexSpec.deleteIndex("", "person", "node-element-equality-string"); + myIndexSpec.addIndex("", "name", "node-element-equality-string"); + myContainer.setIndexSpecification(myIndexSpec, myUpdateContext); +} + diff --git a/6668/Chapter08/8-23.2.cpp b/6668/Chapter08/8-23.2.cpp new file mode 100644 index 0000000..16d8bc6 --- /dev/null +++ b/6668/Chapter08/8-23.2.cpp @@ -0,0 +1,20 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myQueryContext = myManager.createQueryContext(); + XmlIndexLookup myLookup = myManager.createIndexLookup(myContainer, "", "age", + "node-element-equality-decimal", + XmlValue(XmlValue::DECIMAL, "16"), + XmlIndexLookup::GTE); + myLookup.setHighBound(XmlValue(XmlValue::DECIMAL, "35"), XmlIndexLookup::LT); + XmlResults myResults = myLookup.execute(myQueryContext, DBXML_REVERSE_ORDER); + XmlDocument myDoc; + while (myResults.next(myDoc)) { + std::string dummyString; + std::cout << myDoc.getName() << ": " << myDoc.getContent(dummyString) << std::endl; + } +} + diff --git a/6668/Chapter08/8-23.cpp b/6668/Chapter08/8-23.cpp new file mode 100644 index 0000000..ef4283e --- /dev/null +++ b/6668/Chapter08/8-23.cpp @@ -0,0 +1,18 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) { + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlQueryContext myQueryContext = myManager.createQueryContext(); + + XmlIndexLookup myLookup = myManager.createIndexLookup(myContainer, "", "name", + "node-element-equality-string"); + XmlResults myResults = myLookup.execute(myQueryContext); + XmlDocument myDoc; + while (myResults.next(myDoc)) { + std::string dummyString; + std::cout << myDoc.getName() << ": " << myDoc.getContent(dummyString) << std::endl; + } +} + diff --git a/6668/Chapter08/8-24.cpp b/6668/Chapter08/8-24.cpp new file mode 100644 index 0000000..b46f4d6 --- /dev/null +++ b/6668/Chapter08/8-24.cpp @@ -0,0 +1,18 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + + std::string URI = "http://dbxmlExamples/metadata"; + std::string metadataName = "createdOn"; + XmlValue metadataValue(XmlValue::DATE_TIME, "2006-02-05T05:23:14"); + + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlDocument myDoc = myContainer.getDocument("dbxml_11"); + myDoc.setMetaData(URI, metadataName, metadataValue); + myContainer.updateDocument(myDoc, myUpdateContext); +} + diff --git a/6668/Chapter08/8-25.cpp b/6668/Chapter08/8-25.cpp new file mode 100644 index 0000000..45f5576 --- /dev/null +++ b/6668/Chapter08/8-25.cpp @@ -0,0 +1,13 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlDocument myDoc = myContainer.getDocument("dbxml_11"); + XmlValue metadataValue; + myDoc.getMetaData("http://dbxmlExamples/metadata", "createdOn", metadataValue); + std::cout << "Document 114.xml, created on " << metadataValue.asString() << std::endl; +} + diff --git a/6668/Chapter08/8-26.cpp b/6668/Chapter08/8-26.cpp new file mode 100644 index 0000000..b885b19 --- /dev/null +++ b/6668/Chapter08/8-26.cpp @@ -0,0 +1,17 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlQueryContext myQueryContext = myManager.createQueryContext(); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlModify myModify = myManager.createModify(); + XmlQueryExpression myQuery = myManager.prepare("/person/name", myQueryContext); + myModify.addAppendStep(myQuery, XmlModify::Attribute, "type", "given"); + XmlDocument myDoc = myContainer.getDocument("dbxml_11"); + XmlValue docValue(myDoc); + myModify.execute(docValue, myQueryContext, myUpdateContext); +} + diff --git a/6668/Chapter08/8-27.cpp b/6668/Chapter08/8-27.cpp new file mode 100644 index 0000000..571047d --- /dev/null +++ b/6668/Chapter08/8-27.cpp @@ -0,0 +1,16 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + XmlQueryContext myQueryContext = myManager.createQueryContext(); + XmlUpdateContext myUpdateContext = myManager.createUpdateContext(); + XmlModify myModify = myManager.createModify(); + XmlQueryExpression myQuery = myManager.prepare("/person/name", myQueryContext); + myModify.addAppendStep(myQuery, XmlModify::Attribute, "type", "given"); + XmlResults myResults = myManager.query("collection('container.bdbxml')/person/name", myQueryContext); + myModify.execute(myResults, myQueryContext, myUpdateContext); +} + diff --git a/6668/Chapter08/8-28.cpp b/6668/Chapter08/8-28.cpp new file mode 100644 index 0000000..7efc3ea --- /dev/null +++ b/6668/Chapter08/8-28.cpp @@ -0,0 +1,16 @@ +#include "DbXml.hpp" +using namespace DbXml; +int main(void) +{ + u_int32_t env_flags = DB_CREATE | // Create environment if it doesn't exist + DB_INIT_LOCK | // Initialize locking + DB_INIT_LOG | // Initialize logging + DB_INIT_MPOOL| // Initialize the cache + DB_INIT_TXN; // Initialize transactions + DbEnv myEnv(0); + myEnv.open("/path/to/environment", env_flags, 0); + XmlManager myManager = new XmlManager(myEnv, DBXML_ADOPT_DBENV); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml", + DB_CREATE | DBXML_TRANSACTIONAL); +} + diff --git a/6668/Chapter08/8-29.cpp b/6668/Chapter08/8-29.cpp new file mode 100644 index 0000000..e33162d --- /dev/null +++ b/6668/Chapter08/8-29.cpp @@ -0,0 +1,35 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + u_int32_t env_flags = DB_CREATE | // Create environment if it doesn't exist + DB_INIT_LOCK | // Initialize locking + DB_INIT_LOG | // Initialize logging + DB_INIT_MPOOL | // Initialize the cache + DB_INIT_TXN; // Initialize transactions + XmlManager *myManager = NULL; + XmlTransaction myTxn; + try { + DbEnv *myEnv = new DbEnv(0); + myEnv->open("/myEnv", env_flags, 0); + myManager = new XmlManager(myEnv, DBXML_ADOPT_DBENV); + myTxn = myManager->createTransaction(); + XmlContainer myContainer = myManager->openContainer("myContainer.dbxml", DB_CREATE | DBXML_TRANSACTIONAL); + + XmlUpdateContext myUpdateContext = myManager->createUpdateContext(); + XmlInputStream *theStream = myManager->createLocalFileInputStream("myfile12.xml"); + myContainer.putDocument(myTxn, // the transaction object + "myfile12", // the document's name + theStream, // the document + myUpdateContext, // The update context + 0); // Put flags. + myTxn.commit(); + } catch(XmlException &error) { + std::cerr << "Error in transaction: " + << error.what() << "\n" + << "Aborting." << std::endl; + myTxn.abort(); + } +} + diff --git a/6668/Chapter08/8-3.cpp b/6668/Chapter08/8-3.cpp new file mode 100644 index 0000000..f279bd3 --- /dev/null +++ b/6668/Chapter08/8-3.cpp @@ -0,0 +1,18 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + // Create an XmlManager + XmlManager myManager; + // Set the errors stream to standard out + myManager.getDbEnv()->set_error_stream(&std::cerr); + try { + XmlContainer myContainer = myManager.openContainer("container.dbxml"); + DbXml::setLogLevel(DbXml::LEVEL_ALL, true); + DbXml::setLogCategory(DbXml::CATEGORY_ALL, true); + } catch (XmlException &xe) { + // Error handling goes here + } +} + diff --git a/6668/Chapter08/8-30.cpp b/6668/Chapter08/8-30.cpp new file mode 100644 index 0000000..0926e2d --- /dev/null +++ b/6668/Chapter08/8-30.cpp @@ -0,0 +1,11 @@ +XmlDocument doc = container.getDocument("doc12"); +XmlEventReader &reader = doc.getContentAsEventReader(); +while (reader.hasNext()) { + XmlEventType type = reader.next(); + if (type == StartElement) { + cout << "Event is StartElement for node: " << + reader.getLocalName(); + } + reader.close(); // release resources +} + diff --git a/6668/Chapter08/8-4.cpp b/6668/Chapter08/8-4.cpp new file mode 100644 index 0000000..17b711d --- /dev/null +++ b/6668/Chapter08/8-4.cpp @@ -0,0 +1,26 @@ +#include "DbXml.hpp" + +using namespace DbXml; +u_int32_t env_flags = DB_CREATE | // Create if environment doesn't exist + DB_INIT_LOCK | // Initialize the locking subsystem + DB_INIT_LOG | // Initialize the logging subsystem + DB_INIT_MPOOL | // Initialize the cache + DB_INIT_TXN; // Initialize transactions for this environment +std::string envPath("/myEnv"); + +int main(void) +{ + DbEnv *myEnv = new DbEnv(0); + try { + myEnv->open(envPath.c_str(), env_flags, 0); + } catch(DbException &e) { + std::cerr << "Error opening database environment: " + << envPath << std::endl; + std::cerr << e.what() << std::endl; + } catch(std::exception &e) { + std::cerr << "Error opening database environment: " + << envPath << std::endl; + std::cerr << e.what() << std::endl; + } +} + diff --git a/6668/Chapter08/8-5.cpp b/6668/Chapter08/8-5.cpp new file mode 100644 index 0000000..f894e43 --- /dev/null +++ b/6668/Chapter08/8-5.cpp @@ -0,0 +1,44 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + u_int32_t env_flags = DB_CREATE | // Create environment if it doesn't exist + DB_INIT_LOCK | // Initialize locking + DB_INIT_LOG | // Initialize logging + DB_INIT_MPOOL | // Initialize the cache + DB_INIT_TXN; // Initialize transactions + + std::string envPath("/myEnv"); + DbEnv *myEnv = new DbEnv(0); + XmlManager *myManager = NULL; + + try { + myEnv->open(envPath.c_str(), env_flags, 0); + myManager = new XmlManager(myEnv, DBXML_ADOPT_DBENV); + } catch(DbException &e) { + std::cerr << "Error opening database environment: " + << envPath << std::endl; + std::cerr << e.what() << std::endl; + } catch (XmlException &xe) { + std::cerr << "Error opening database environment: " + << envPath + << " or opening XmlManager." << std::endl; + std::cerr << xe.what() << std::endl; + } + + try { + if (myManager != NULL) { + delete myManager; + } + } catch(DbException &e) { + std::cerr << "Error closing database environment: " + << envPath << std::endl; + std::cerr << e.what() << std::endl; + } catch(XmlException &xe) { + std::cerr << "Error closing database environment: " + << envPath << std::endl; + std::cerr << xe.what() << std::endl; + } +} + diff --git a/6668/Chapter08/8-7.cpp b/6668/Chapter08/8-7.cpp new file mode 100644 index 0000000..c72e4f1 --- /dev/null +++ b/6668/Chapter08/8-7.cpp @@ -0,0 +1,13 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.createContainer( + "/path/to/myContainer.bdbxml", + DBXML_ALLOW_VALIDATION, + XmlContainer::NodeContainer, 766 ); + return(0); +} + diff --git a/6668/Chapter08/8-8.cpp b/6668/Chapter08/8-8.cpp new file mode 100644 index 0000000..015c53c --- /dev/null +++ b/6668/Chapter08/8-8.cpp @@ -0,0 +1,11 @@ +#include "DbXml.hpp" + +using namespace DbXml; +int main(void) +{ + XmlManager myManager; + XmlContainer myContainer = myManager.openContainer("/path/to/myContainer.bdbxml"); + return(0); + // Container will be closed at the end of main() +} + diff --git a/6668/Chapter08/README.txt b/6668/Chapter08/README.txt new file mode 100644 index 0000000..3438bfe --- /dev/null +++ b/6668/Chapter08/README.txt @@ -0,0 +1,10 @@ +To build C++ programs, refer to the BDB XML reference guide. + +On Unix, compile thus (your paths may differ): + + % g++ -I/usr/local/dbxml/install/include/ -I/usr/local/dbxml/install/include/dbxml/ -c test.cpp + +Then link: + + % g++ -I/usr/local/dbxml/install/include/ -I/usr/local/dbxml/install/include/dbxml/ -c test.cpp + diff --git a/6668/Chapter09/9-1.py b/6668/Chapter09/9-1.py new file mode 100644 index 0000000..89e70ec --- /dev/null +++ b/6668/Chapter09/9-1.py @@ -0,0 +1,8 @@ +from bsddb3.db import * +from dbxml import * + +myenv = DBEnv() +myenv.open("myenv/", DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0) +mgr = XmlManager(myenv, 0) + + diff --git a/6668/Chapter09/9-10.py b/6668/Chapter09/9-10.py new file mode 100644 index 0000000..1dda93c --- /dev/null +++ b/6668/Chapter09/9-10.py @@ -0,0 +1,19 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() +myquery = r"collection('test.dbxml')/person[name='Fred']" + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +qcontext.setEvaluationType(XmlQueryContext.Lazy) + +results = mymgr.query(myquery, qcontext) +for value in results: + document = value.asDocument() + name = document.getName() + content = value.asString() + print name, ": ", content + +del mycontainer + diff --git a/6668/Chapter09/9-11.py b/6668/Chapter09/9-11.py new file mode 100644 index 0000000..0e48c62 --- /dev/null +++ b/6668/Chapter09/9-11.py @@ -0,0 +1,19 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +qcontext.setEvaluationType(XmlQueryContext.Lazy) + +results = mymgr.query("collection('test.dbxml')/person[name='Fred']", qcontext) +phonequery = mymgr.prepare("/person/phone", qcontext); + +for value in results: + phoneresults = phonequery.execute(value, qcontext) + for phones in phoneresults: + print " phone: ", phoneresults.asString(), "\n" + +del mycontainer + diff --git a/6668/Chapter09/9-12.py b/6668/Chapter09/9-12.py new file mode 100644 index 0000000..bbddd02 --- /dev/null +++ b/6668/Chapter09/9-12.py @@ -0,0 +1,13 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +ucontext = mymgr.createUpdateContext() + +content = r"Bob" +mycontainer.putDocument("1", content, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-13.py b/6668/Chapter09/9-13.py new file mode 100644 index 0000000..1c78a37 --- /dev/null +++ b/6668/Chapter09/9-13.py @@ -0,0 +1,17 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +ucontext = mymgr.createUpdateContext() + +results = mymgr.query("collection('test.dbxml')/person[name='Bob']", qcontext) +for result in results: + document = result.asDocument() + print "Deleting document: ", document.getName(), "\n" + mycontainer.deleteDocument(document, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-14.py b/6668/Chapter09/9-14.py new file mode 100644 index 0000000..7e39823 --- /dev/null +++ b/6668/Chapter09/9-14.py @@ -0,0 +1,15 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +ucontext = mymgr.createUpdateContext() + +document = mycontainer.getDocument("1") +document.setContent("Bob") +mycontainer.updateDocument(document, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-15.py b/6668/Chapter09/9-15.py new file mode 100644 index 0000000..db5555e --- /dev/null +++ b/6668/Chapter09/9-15.py @@ -0,0 +1,12 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +ucontext = mymgr.createUpdateContext() + +mycontainer.addIndex("", "person", "node-element-equality-string", ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-16.py b/6668/Chapter09/9-16.py new file mode 100644 index 0000000..4fde00c --- /dev/null +++ b/6668/Chapter09/9-16.py @@ -0,0 +1,15 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +ucontext = mymgr.createUpdateContext() + +indexspec = mycontainer.getIndexSpecification() +indexspec.deleteIndex("", "person", "node-element-equality-string") +indexspec.addIndex("", "person", "node-attribute-equality-string") +mycontainer.setIndexSpecification(indexspec, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-17.py b/6668/Chapter09/9-17.py new file mode 100644 index 0000000..1d5aa45 --- /dev/null +++ b/6668/Chapter09/9-17.py @@ -0,0 +1,17 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() + +indexlookup = mymgr.createIndexLookup(mycontainer, "", "name", "node-element-equality-string") +results = indexlookup.execute(qcontext) + +for result in results: + document = result.asDocument() + print document.getName(), ": ", document.getContent() + +del mycontainer + diff --git a/6668/Chapter09/9-18.py b/6668/Chapter09/9-18.py new file mode 100644 index 0000000..b81b34c --- /dev/null +++ b/6668/Chapter09/9-18.py @@ -0,0 +1,18 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +ucontext = mymgr.createUpdateContext() + +uri = "http://brians.org/metadata" +metaname = "createdOn" +metavalue = XmlValue(XmlValue.DATE_TIME, "2006-02-05T05:23:14") + +document = mycontainer.getDocument("114.xml") +document.setMetaData(uri, metaname, metavalue) +mycontainer.updateDocument(document, ucontext, DBXML_LAZY_DOCS) + +del mycontainer + diff --git a/6668/Chapter09/9-19.py b/6668/Chapter09/9-19.py new file mode 100644 index 0000000..0842f33 --- /dev/null +++ b/6668/Chapter09/9-19.py @@ -0,0 +1,19 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") + +uri = "http://brians.org/metadata" +metaname = "createdOn" + +document = mycontainer.getDocument("1") +metavalue = XmlValue() +metavalue2 = XmlValue() +metavalue2 = document.getMetaData(uri, metaname, metavalue) +print "114.xml, created on ", metavalue.asString(), "\n" +print "114.xml, created on ", metavalue2.asString(), "\n" + +del mycontainer + diff --git a/6668/Chapter09/9-2.py b/6668/Chapter09/9-2.py new file mode 100644 index 0000000..d66fa4d --- /dev/null +++ b/6668/Chapter09/9-2.py @@ -0,0 +1,8 @@ +from bsddb3.db import * +from dbxml import * + +mgr = XmlManager() +container = mgr.createContainer("test.dbxml") + + + diff --git a/6668/Chapter09/9-20.py b/6668/Chapter09/9-20.py new file mode 100644 index 0000000..71a2883 --- /dev/null +++ b/6668/Chapter09/9-20.py @@ -0,0 +1,19 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +ucontext = mymgr.createUpdateContext() + +mymodify = mymgr.createModify() +queryexp = mymgr.prepare("/person/name", qcontext) +mymodify.addAppendStep(queryexp, XmlModify.Attribute, "type", "given") + +document = mycontainer.getDocument("1") +docvalue = XmlValue(document) +mymodify.execute(docvalue, qcontext, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-21.py b/6668/Chapter09/9-21.py new file mode 100644 index 0000000..6834a3f --- /dev/null +++ b/6668/Chapter09/9-21.py @@ -0,0 +1,18 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +ucontext = mymgr.createUpdateContext() + +mymodify = mymgr.createModify() +queryexp = mymgr.prepare("/person/name", qcontext) +mymodify.addAppendStep(queryexp, XmlModify.Attribute, "type", "given") + +results = mymgr.query("collection('test.dbxml')/person[name='Bill']", qcontext) +mymodify.execute(results, qcontext, ucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-22.py b/6668/Chapter09/9-22.py new file mode 100644 index 0000000..792ef2b --- /dev/null +++ b/6668/Chapter09/9-22.py @@ -0,0 +1,13 @@ +from bsddb3.db import * +from dbxml import * + +environment = DBEnv() +environment.open("myEnv", + DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0) +mymgr = XmlManager(environment, 0) +uc = mymgr.createUpdateContext() +container = mymgr.createContainer("test.dbxml", DBXML_TRANSACTIONAL) +txn = mymgr.createTransaction() +container.putDocument(txn, "doc12", "Bill", uc) +txn.commit() + diff --git a/6668/Chapter09/9-3.py b/6668/Chapter09/9-3.py new file mode 100644 index 0000000..fe4ac65 --- /dev/null +++ b/6668/Chapter09/9-3.py @@ -0,0 +1,11 @@ +from bsddb3.db import * +from dbxml import * + +myenv = DBEnv() +myenv.open("myenv", DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0) +mymgr = XmlManager(myenv, 0) + +mycontainer = mymgr.createContainer("test.dbxml", DBXML_TRANSACTIONAL|DBXML_ALLOW_VALIDATION, XmlContainer.NodeContainer ) + +del mycontainer + diff --git a/6668/Chapter09/9-4.py b/6668/Chapter09/9-4.py new file mode 100644 index 0000000..1f444ec --- /dev/null +++ b/6668/Chapter09/9-4.py @@ -0,0 +1,8 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mymgr.renameContainer("test.dbxml", "newtest.dbxml") +mymgr.removeContainer("newtest.dbxml") + diff --git a/6668/Chapter09/9-5.py b/6668/Chapter09/9-5.py new file mode 100644 index 0000000..57760a4 --- /dev/null +++ b/6668/Chapter09/9-5.py @@ -0,0 +1,14 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() + +mycontainer = mymgr.openContainer("test.dbxml") +xmlucontext = mymgr.createUpdateContext() + +xmlinput = mymgr.createLocalFileInputStream("file14.xml") + +mycontainer.putDocument("file14", xmlinput, xmlucontext) + +del mycontainer + diff --git a/6668/Chapter09/9-6.py b/6668/Chapter09/9-6.py new file mode 100644 index 0000000..6225b4b --- /dev/null +++ b/6668/Chapter09/9-6.py @@ -0,0 +1,15 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() +myquery = r"collection()/person[name='Bob']" + +mycontainer = mymgr.openContainer("test.dbxml") +xmlqcontext = mymgr.createQueryContext() + +xmlqcontext.setDefaultCollection("test.dbxml") +queryexp = mymgr.prepare(myquery, xmlqcontext) +results = queryexp.execute(xmlqcontext) + +del mycontainer + diff --git a/6668/Chapter09/9-7.py b/6668/Chapter09/9-7.py new file mode 100644 index 0000000..422da0e --- /dev/null +++ b/6668/Chapter09/9-7.py @@ -0,0 +1,19 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() +myquery = r"collection('test.dbxml')/people:person[name=$name]" + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() + +qcontext.setNamespace("people", "http://brians.org/people") +qcontext.setVariableValue("name", XmlValue("Bob")) + +queryexp = mymgr.prepare(myquery, qcontext) +results = queryexp.execute(qcontext) +qcontext.setVariableValue("name", XmlValue("Bob")) +results = queryexp.execute(qcontext) + +del mycontainer + diff --git a/6668/Chapter09/9-8.py b/6668/Chapter09/9-8.py new file mode 100644 index 0000000..b56914e --- /dev/null +++ b/6668/Chapter09/9-8.py @@ -0,0 +1,13 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() +myquery = r"collection('test.dbxml')/person[name='Jim']" + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() + +results = mymgr.query(myquery, qcontext) + +del mycontainer + diff --git a/6668/Chapter09/9-9.py b/6668/Chapter09/9-9.py new file mode 100644 index 0000000..472e600 --- /dev/null +++ b/6668/Chapter09/9-9.py @@ -0,0 +1,14 @@ +from bsddb3.db import * +from dbxml import * + +mymgr = XmlManager() +myquery = r"collection('test.dbxml')/person[name='Jim']" + +mycontainer = mymgr.openContainer("test.dbxml") +qcontext = mymgr.createQueryContext() +qcontext.setEvaluationType(XmlQueryContext.Lazy) + +results = mymgr.query(myquery, qcontext) + +del mycontainer + diff --git a/6668/Chapter09/README.txt b/6668/Chapter09/README.txt new file mode 100644 index 0000000..3079a0e --- /dev/null +++ b/6668/Chapter09/README.txt @@ -0,0 +1,3 @@ +The Python examples need the Python bindings to be installed, as described in +the installation chapter and the BDB XML reference. + diff --git a/6668/Chapter09/file14.xml b/6668/Chapter09/file14.xml new file mode 100644 index 0000000..5882514 --- /dev/null +++ b/6668/Chapter09/file14.xml @@ -0,0 +1,12 @@ + + + 114 + 00047668 + 04 + n + incursion + + 113 + + the act of entering some territory or domain (often in large numbers); "the incursion of television into the American living room" + diff --git a/6668/Chapter10/10-1.java b/6668/Chapter10/10-1.java new file mode 100644 index 0000000..03d0bed --- /dev/null +++ b/6668/Chapter10/10-1.java @@ -0,0 +1,23 @@ +import com.sleepycat.dbxml.XmlContainer; +import com.sleepycat.dbxml.XmlException; +import com.sleepycat.dbxml.XmlManager; + +class myDbXml { +public static void main(String args[]) throws Throwable +{ + // Create an XmlManager + XmlManager myManager = null; + try { + // Open a container + XmlContainer myContainer = + myManager.openContainer("container.dbxml"); + } catch (XmlException e) { + System.out.print(e.what()); + // Error handling goes here + } catch (Exception e) { + // Error handling goes here + } +} + +} + diff --git a/6668/Chapter10/10-10.java b/6668/Chapter10/10-10.java new file mode 100644 index 0000000..7ffa5d5 --- /dev/null +++ b/6668/Chapter10/10-10.java @@ -0,0 +1,19 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main() throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + + XmlQueryContext myContext = myManager.createQueryContext(); + String myQuery = "collection('myContainer.dbxml')/person[name='Jim']"; + + XmlResults myResults = myManager.query(myQuery, myContext); + + myResults.delete(); + myContext.delete(); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-11.java b/6668/Chapter10/10-11.java new file mode 100644 index 0000000..6931e96 --- /dev/null +++ b/6668/Chapter10/10-11.java @@ -0,0 +1,17 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main() throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + + XmlQueryContext myContext = myManager.createQueryContext(); + myContext.setEvaluationType(XmlQueryContext.Lazy); + String myQuery = "collection('myContainer.dbxml')/person[name='Jim']"; + XmlResults myResults = myManager.query(myQuery, myContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-12.java b/6668/Chapter10/10-12.java new file mode 100644 index 0000000..05c62c9 --- /dev/null +++ b/6668/Chapter10/10-12.java @@ -0,0 +1,30 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + + XmlQueryContext myContext = myManager.createQueryContext(); + String myQuery = "collection('myContainer.dbxml')/person[name='Jim']"; + + XmlResults myResults = myManager.query(myQuery, myContext); + XmlValue myValue = myResults.next(); + while (myValue != null) { + XmlDocument myDocument = myValue.asDocument(); + String name = myDocument.getName(); + String content = myValue.asString(); + //System.out.print("Document " + name + ":\n"); + System.out.print(content); + myValue = myResults.next(); + } + + myValue.delete(); + myResults.delete(); + myQuery.delete(); + myContext.delete(); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-13.java b/6668/Chapter10/10-13.java new file mode 100644 index 0000000..f548959 --- /dev/null +++ b/6668/Chapter10/10-13.java @@ -0,0 +1,34 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + + XmlQueryExpression mySubquery = myManager.prepare("/person/phone", myContext); + XmlResults myResults = myManager.query("collection('myContainer.dbxml')/person[name='Jim']", myContext); + XmlValue myValue = myResults.next(); + while (myValue != null) { + XmlResults subResults = mySubquery.execute(myValue, myContext); + XmlValue subValue = subResults.next(); + while (subValue != null) { + XmlDocument myDocument = subValue.asDocument(); + String name = myDocument.getName(); + String content = subValue.asString(); + System.out.print("Document " + name + ":\n"); + System.out.print(content); + subValue = subResults.next(); + } + myValue = myResults.next(); + } + + myValue.delete(); + myResults.delete(); + myQuery.delete(); + myContext.delete(); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-14.java b/6668/Chapter10/10-14.java new file mode 100644 index 0000000..1175308 --- /dev/null +++ b/6668/Chapter10/10-14.java @@ -0,0 +1,18 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + XmlQueryContext qContext = myManager.createQueryContext(); + + String content = "Bob"; + myContainer.putDocument("", content, theContext, docConfig); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-15.java b/6668/Chapter10/10-15.java new file mode 100644 index 0000000..d8e7133 --- /dev/null +++ b/6668/Chapter10/10-15.java @@ -0,0 +1,25 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext qContext = myManager.createQueryContext(); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + String myQuery = "collection('myContainer.dbxml')/person[name='Steve']"; + + XmlResults myResults = myManager.query(myQuery, qContext); + XmlValue myValue = myResults.next(); + while (myValue != null) { + XmlDocument myDocument = myValue.asDocument(); + String name = myDocument.getName(); + System.out.print("Deleting " + name + "\n"); + myContainer.deleteDocument(myDocument, uContext); + myValue = myResults.next(); + } + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-16.java b/6668/Chapter10/10-16.java new file mode 100644 index 0000000..34205b2 --- /dev/null +++ b/6668/Chapter10/10-16.java @@ -0,0 +1,18 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlDocument myDocument = myContainer.getDocument("12.xml"); + myDocument.setContent("Bob"); + myContainer.updateDocument(myDocument, uContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-17.java b/6668/Chapter10/10-17.java new file mode 100644 index 0000000..254900b --- /dev/null +++ b/6668/Chapter10/10-17.java @@ -0,0 +1,16 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + myContainer.addIndex("", "person", "node-element-equality-string", uContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-18.java b/6668/Chapter10/10-18.java new file mode 100644 index 0000000..8647c1b --- /dev/null +++ b/6668/Chapter10/10-18.java @@ -0,0 +1,19 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlIndexSpecification myIndexSpec = myContainer.getIndexSpecification(); + myIndexSpec.deleteIndex("", "person", "node-element-equality-string"); + myIndexSpec.addIndex("", "person", "node-attribute-equality-string"); + myContainer.setIndexSpecification(myIndexSpec, uContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-19.java b/6668/Chapter10/10-19.java new file mode 100644 index 0000000..4a5a58f --- /dev/null +++ b/6668/Chapter10/10-19.java @@ -0,0 +1,22 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext qContext = myManager.createQueryContext(); + XmlIndexLookup myLookup = myManager.createIndexLookup(myContainer, "", "name", "node-element-equality-stirng"); + + XmlResults myResults = myLookup.execute(qContext); + XmlValue myValue = myResults.next(); + while (myValue != null) { + XmlDocument myDocument = myValue.asDocument(); + String name = myDocument.getName(); + System.out.print("Index touches " + name + "\n"); + myValue = myResults.next(); + } + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-2.java b/6668/Chapter10/10-2.java new file mode 100644 index 0000000..773e73b --- /dev/null +++ b/6668/Chapter10/10-2.java @@ -0,0 +1,24 @@ +import com.sleepycat.dbxml.XmlContainer; +import com.sleepycat.dbxml.XmlManager; +import com.sleepycat.dbxml.XmlManagerConfig; +import com.sleepycat.db.Environment; +import com.sleepycat.db.EnvironmentConfig; +import java.io.File; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + File myDir = new File("myEnv/"); + + // Open environment + EnvironmentConfig myEnvConf = new EnvironmentConfig(); + myEnvConf.setErrorStream(System.err); + Environment myEnv = new Environment(myDir, myEnvConf); + + // Create an XmlManager + XmlManagerConfig myManagerConf = new XmlManagerConfig(); + XmlManager myManager = new XmlManager(myEnv, myManagerConf); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-20.java b/6668/Chapter10/10-20.java new file mode 100644 index 0000000..90f674e --- /dev/null +++ b/6668/Chapter10/10-20.java @@ -0,0 +1,20 @@ +import com.sleepycat.dbxml.*; +import java.io.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlDocument myDocument = myContainer.getDocument("114.xml"); + myDocument.setMetaData("http://brians.org/metadata", "createdOn", + new XmlValue(XmlValue.DATE_TIME, "2006-02-05T05:23:14")); + + myContainer.updateDocument(myDocument, uContext); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-21.java b/6668/Chapter10/10-21.java new file mode 100644 index 0000000..567a618 --- /dev/null +++ b/6668/Chapter10/10-21.java @@ -0,0 +1,22 @@ +import com.sleepycat.dbxml.*; +import java.io.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlDocument myDocument = myContainer.getDocument("114.xml"); + + XmlValue metaValue = new XmlValue(); + + myDocument.getMetaData("http://brians.org/metadata", "createdOn", metaValue); + System.out.print("114.xml created on " + metaValue.asString() + "\n"); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-22.java b/6668/Chapter10/10-22.java new file mode 100644 index 0000000..84e7921 --- /dev/null +++ b/6668/Chapter10/10-22.java @@ -0,0 +1,22 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext qContext = myManager.createQueryContext(); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlModify myModify = myManager.createModify(); + XmlQueryExpression myQuery = myManager.prepare("/person/name", qContext); + myModify.addAppendStep(myQuery, XmlModify.Attribute, "type", "given"); + XmlDocument myDocument = myContainer.getDocument("114.xml"); + XmlValue docValue = new XmlValue(myDocument); + myModify.execute(docValue, qContext, uContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-23.java b/6668/Chapter10/10-23.java new file mode 100644 index 0000000..49a17fe --- /dev/null +++ b/6668/Chapter10/10-23.java @@ -0,0 +1,21 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext qContext = myManager.createQueryContext(); + XmlUpdateContext uContext = myManager.createUpdateContext(); + + XmlModify myModify = myManager.createModify(); + XmlQueryExpression myQuery = myManager.prepare("/person/name", qContext); + myModify.addAppendStep(myQuery, XmlModify.Attribute, "type", "given"); + XmlResults myResults = myManager.query("collection('myContainer.dbxml')/person[name='Bill']", qContext); + myModify.execute(myResults, qContext, uContext); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-3.java b/6668/Chapter10/10-3.java new file mode 100644 index 0000000..29327df --- /dev/null +++ b/6668/Chapter10/10-3.java @@ -0,0 +1,22 @@ +import com.sleepycat.dbxml.*; +import com.sleepycat.db.*; +import java.io.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + File myDir = new File("myEnv/"); + + // Open environment + EnvironmentConfig myEnvConf = new EnvironmentConfig(); + myEnvConf.setErrorStream(System.err); + Environment myEnv = new Environment(myDir, myEnvConf); + + // Create an XmlManager + XmlManagerConfig myManagerConf = new XmlManagerConfig(); + XmlManager myManager = new XmlManager(myEnv, myManagerConf); + myManager.setLogLevel(XmlManager.LEVEL_ALL, true); + myManager.setLogCategory(XmlManager.CATEGORY_ALL, true); + } +} + diff --git a/6668/Chapter10/10-4.java b/6668/Chapter10/10-4.java new file mode 100644 index 0000000..3c19767 --- /dev/null +++ b/6668/Chapter10/10-4.java @@ -0,0 +1,29 @@ +import com.sleepycat.dbxml.*; +import com.sleepycat.db.*; +import java.io.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + File myDir = new File("myEnv/"); + + // Open environment + EnvironmentConfig myEnvConf = new EnvironmentConfig(); + + myEnvConf.setErrorStream(System.err); + myEnvConf.setAllowCreate(true); // create if it doesn't exist + myEnvConf.setInitializeCache(true); // turn on shared memory + myEnvConf.setTransactional(true); // transactions on + myEnvConf.setInitializeLocking(true); // locking on + myEnvConf.setInitializeLogging(true); // logging on + + Environment myEnv = new Environment(myDir, myEnvConf); + + // Create an XmlManager + XmlManagerConfig myManagerConf = new XmlManagerConfig(); + XmlManager myManager = new XmlManager(myEnv, myManagerConf); + myManager.setLogLevel(XmlManager.LEVEL_ALL, true); + myManager.setLogCategory(XmlManager.CATEGORY_ALL, true); + } +} + diff --git a/6668/Chapter10/10-5.java b/6668/Chapter10/10-5.java new file mode 100644 index 0000000..1972da6 --- /dev/null +++ b/6668/Chapter10/10-5.java @@ -0,0 +1,21 @@ +import com.sleepycat.dbxml.*; +import com.sleepycat.db.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + // Create an XmlManager + XmlManagerConfig myManagerConf = new XmlManagerConfig(); + XmlManager myManager = new XmlManager(myManagerConf); + + XmlContainerConfig myContainerConf = new XmlContainerConfig(); + myContainerConf.setAllowValidation(true); + myContainerConf.setNodeContainer(true); + + XmlContainer myContainer = myManager.createContainer( "myContainer.bdbxml", myContainerConf ); + + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-6.java b/6668/Chapter10/10-6.java new file mode 100644 index 0000000..d3407de --- /dev/null +++ b/6668/Chapter10/10-6.java @@ -0,0 +1,14 @@ +import com.sleepycat.dbxml.*; +import com.sleepycat.db.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + // Create an XmlManager + XmlManager myManager = new XmlManager(); + myManager.renameContainer("test.dbxml", "newtest.dbxml"); + myManager.removeContainer("newtest.dbxml"); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-7.java b/6668/Chapter10/10-7.java new file mode 100644 index 0000000..90bb40b --- /dev/null +++ b/6668/Chapter10/10-7.java @@ -0,0 +1,22 @@ +import com.sleepycat.dbxml.*; +import java.io.*; + +class myDbXml { + public static void main(String args[]) throws Throwable + { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("container.bdbxml"); + + // The update context is needed to add the document. + XmlUpdateContext theContext = myManager.createUpdateContext(); + + // Create the file input stream + XmlInputStream myStream = myManager.createLocalFileInputStream("./file176.xml"); + + // Put the document in the container + myContainer.putDocument("176", myStream, theContext); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-8.java b/6668/Chapter10/10-8.java new file mode 100644 index 0000000..c9c0fc0 --- /dev/null +++ b/6668/Chapter10/10-8.java @@ -0,0 +1,20 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + XmlQueryContext myContext = myManager.createQueryContext(); + myContext.setDefaultCollection("myCollection"); + String myQuery = "collection('myContainer.dbxml')/Synset[Word='wisdom']"; + XmlQueryExpression qe = myManager.prepare(myQuery, myContext); + XmlResults results = qe.execute(myContext); + + results.delete(); + qe.delete(); + myContext.delete(); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/10-9.java b/6668/Chapter10/10-9.java new file mode 100644 index 0000000..bd10975 --- /dev/null +++ b/6668/Chapter10/10-9.java @@ -0,0 +1,25 @@ +import com.sleepycat.dbxml.*; + +class myDbXml { + public static void main(String args[]) throws Throwable { + XmlManager myManager = new XmlManager(); + XmlContainer myContainer = myManager.openContainer("myContainer.dbxml"); + + XmlQueryContext myContext = myManager.createQueryContext(); + myContext.setNamespace("people", "http://brians.org/people"); + myContext.setVariableValue("name", new XmlValue("Bob")); + String myQuery = "collection('myContainer.dbxml')/people:person[name=$name]"; + + XmlQueryExpression qe = myManager.prepare(myQuery, myContext); + + myContext.setVariableValue("name", new XmlValue("Bob")); + XmlResults results = qe.execute(myContext); + + results.delete() + qe.delete(); + myContext.delete(); + myContainer.delete(); + myManager.delete(); + } +} + diff --git a/6668/Chapter10/README.txt b/6668/Chapter10/README.txt new file mode 100644 index 0000000..b03e010 --- /dev/null +++ b/6668/Chapter10/README.txt @@ -0,0 +1,8 @@ +See the book or the BDB XML reference for instructions on compiling Java +examples. Remember that you need the BDB XML .jar files in your classpath, +as well as the BDB XML library files in your dynamic linker environment +(LD_LIBRARY_PATH, or similar on different platforms). + +The Java examples do not use exception handling, but you should in your own +applications. + diff --git a/6668/Chapter11/11-1.pl b/6668/Chapter11/11-1.pl new file mode 100644 index 0000000..0fb5c58 --- /dev/null +++ b/6668/Chapter11/11-1.pl @@ -0,0 +1,8 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $env = new DbEnv; +$env->open("myenv/", Db::DB_CREATE|Db::DB_INIT_LOCK|Db::DB_INIT_LOG|Db::DB_INIT_MPOOL|Db::DB_INIT_TXN, 0); + +my $mgr = new XmlManager($env, 0); + diff --git a/6668/Chapter11/11-10.pl b/6668/Chapter11/11-10.pl new file mode 100644 index 0000000..8817bc3 --- /dev/null +++ b/6668/Chapter11/11-10.pl @@ -0,0 +1,18 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection('test.dbxml')//Word"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +my $results = $mgr->query($query, $qcontext); + +my $value = new XmlValue(); +while ($results->next($value)) { + my $document = $value->asDocument(); + my $name = $document->getName(); + my $content = $value->asString(); + print name . ": " . $content . "\n"; +} + diff --git a/6668/Chapter11/11-11.pl b/6668/Chapter11/11-11.pl new file mode 100644 index 0000000..dd6859c --- /dev/null +++ b/6668/Chapter11/11-11.pl @@ -0,0 +1,23 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection('test.dbxml')/person[name='Fred']"; +my $subquery = "/person/phone"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +my $phoneqcontext = $mgr->createQueryContext(); + +my $results = $mgr->query($query, $qcontext); +my $phonequery = $mgr->prepare($subquery, $phoneqcontext); + +my $value = new XmlValue(); +my $phonevalue = new XmlValue(); +while ($results->next($value)) { + my $phoneresults = $phonequery->execute($value, $phoneqcontext); + while ($phoneresults->next($phonevalue)) { + print $phonevalue->asString() . "\n"; + } +} + diff --git a/6668/Chapter11/11-12.pl b/6668/Chapter11/11-12.pl new file mode 100644 index 0000000..b249b84 --- /dev/null +++ b/6668/Chapter11/11-12.pl @@ -0,0 +1,10 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); + +my $content = "Bob"; +$container->putDocument("", $content, $ucontext, DbXml::DBXML_GEN_NAME); + diff --git a/6668/Chapter11/11-13.pl b/6668/Chapter11/11-13.pl new file mode 100644 index 0000000..c9053f5 --- /dev/null +++ b/6668/Chapter11/11-13.pl @@ -0,0 +1,20 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); +my $qcontext = $mgr->createQueryContext(); + +my $content = "Bob"; +$container->putDocument("", $content, $ucontext, DbXml::DBXML_GEN_NAME); + +my $results = $mgr->query("collection('test.dbxml')/person[name='Bob']", $qcontext); +my $value = new XmlValue(); +my $phonevalue = new XmlValue(); +while ($results->next($value)) { + my $document = $value->asDocument(); + print "Deleting document: " . $document->getName() . "\n"; + $container->deleteDocument($document, $ucontext); +} + diff --git a/6668/Chapter11/11-14.pl b/6668/Chapter11/11-14.pl new file mode 100644 index 0000000..9febe49 --- /dev/null +++ b/6668/Chapter11/11-14.pl @@ -0,0 +1,13 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); + +my $newcontent = "Bob"; + +my $document = $container->getDocument("file14"); +$document->setContent("Bob2"); +$container->updateDocument($document, $ucontext); + diff --git a/6668/Chapter11/11-15.pl b/6668/Chapter11/11-15.pl new file mode 100644 index 0000000..8ad8084 --- /dev/null +++ b/6668/Chapter11/11-15.pl @@ -0,0 +1,9 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); + +$container->addIndex("", "person", "node-element-equality-string", $ucontext); + diff --git a/6668/Chapter11/11-16.pl b/6668/Chapter11/11-16.pl new file mode 100644 index 0000000..36707bd --- /dev/null +++ b/6668/Chapter11/11-16.pl @@ -0,0 +1,13 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); + +my $indexspec = $container->getIndexSpecification(); +$indexspec->deleteIndex("", "person", "node-element-equality-string"); +$indexspec->addIndex("", "person", "node-attribute-equality-string"); +$container->setIndexSpecification($indexspec, $ucontext); + + diff --git a/6668/Chapter11/11-17.pl b/6668/Chapter11/11-17.pl new file mode 100644 index 0000000..ac89450 --- /dev/null +++ b/6668/Chapter11/11-17.pl @@ -0,0 +1,16 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); + +my $indexlookup = $mgr->createIndexLookup($container, "", "person", "node-element-equality-string"); +my $results = $indexlookup->execute($qcontext); + +my $value = new XmlValue(); +while ($results->next($value)) { + my $document = $value->asDocument(); + print $document->getName() . ": " . $document->getContent(); +} + diff --git a/6668/Chapter11/11-18.pl b/6668/Chapter11/11-18.pl new file mode 100644 index 0000000..bc8d077 --- /dev/null +++ b/6668/Chapter11/11-18.pl @@ -0,0 +1,13 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); +my $uri = "http://brians.org/metadata/"; +my $metaname = "createdOn"; +my $metavalue = new XmlValue(XmlValue::DATE_TIME, "2006-02-05T05:23:14"); +my $document = $container->getDocument("file14.xml"); +$document->setMetaData($uri, $metaname, $metavalue); +$container->updateDocument($document, $ucontext); + diff --git a/6668/Chapter11/11-19.pl b/6668/Chapter11/11-19.pl new file mode 100644 index 0000000..fdcfbc5 --- /dev/null +++ b/6668/Chapter11/11-19.pl @@ -0,0 +1,16 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); + +my $uri = "http://brians.org/metadata/"; +my $metaname = "createdOn"; +my $metavalue = new XmlValue(); + +my $document = $container->getDocument("file14"); +$document->getMetaData($uri, $metaname, $metavalue); +print "file14, created on " . $metavalue->asString() . "\n"; + + diff --git a/6668/Chapter11/11-2.pl b/6668/Chapter11/11-2.pl new file mode 100644 index 0000000..88f1909 --- /dev/null +++ b/6668/Chapter11/11-2.pl @@ -0,0 +1,6 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +$mgr->createContainer("test.dbxml"); + diff --git a/6668/Chapter11/11-20.pl b/6668/Chapter11/11-20.pl new file mode 100644 index 0000000..d7993be --- /dev/null +++ b/6668/Chapter11/11-20.pl @@ -0,0 +1,18 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +my $ucontext = $mgr->createUpdateContext(); + +my $modify = $mgr->createModify(); +my $queryexp = $mgr->prepare("/person/name", $qcontext); + +$modify->addAppendStep($queryexp, XmlModify::Attribute, "type", "given"); + +my $document = $container->getDocument("file14"); +my $doc_value = new XmlValue($document); + +$modify->execute($doc_value, $qcontext, $ucontext); + diff --git a/6668/Chapter11/11-21.pl b/6668/Chapter11/11-21.pl new file mode 100644 index 0000000..23bd086 --- /dev/null +++ b/6668/Chapter11/11-21.pl @@ -0,0 +1,16 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +my $ucontext = $mgr->createUpdateContext(); + +my $modify = $mgr->createModify(); +my $queryexp = $mgr->prepare("/person/name", $qcontext); + +$modify->addAppendStep($queryexp, XmlModify::Attribute, "type", "given"); + +my $results = $mgr->query("collection('test.dbxml')/person[name='Bill']", $qcontext); +$modify->execute($results, $qcontext, $ucontext); + diff --git a/6668/Chapter11/11-3.pl b/6668/Chapter11/11-3.pl new file mode 100644 index 0000000..4fcacc5 --- /dev/null +++ b/6668/Chapter11/11-3.pl @@ -0,0 +1,9 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $env = new DbEnv; +$env->open("myenv/", Db::DB_CREATE|Db::DB_INIT_LOCK|Db::DB_INIT_LOG|Db::DB_INIT_MPOOL|Db::DB_INIT_TXN, 0); + +my $mgr = new XmlManager($env, 0); +my $container = $mgr->createContainer("test.dbxml", DbXml::DBXML_TRANSACTIONAL|DbXml::DBXML_ALLOW_VALIDATION, XmlContainer::NodeContainer); + diff --git a/6668/Chapter11/11-4.pl b/6668/Chapter11/11-4.pl new file mode 100644 index 0000000..134949f --- /dev/null +++ b/6668/Chapter11/11-4.pl @@ -0,0 +1,8 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +$mgr->renameContainer("test.dbxml", "old-test.dbxml"); +$mgr->removeContainer("backup-test.dbxml"); + + diff --git a/6668/Chapter11/11-5.pl b/6668/Chapter11/11-5.pl new file mode 100644 index 0000000..8aaa705 --- /dev/null +++ b/6668/Chapter11/11-5.pl @@ -0,0 +1,9 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $container = $mgr->openContainer("test.dbxml"); +my $ucontext = $mgr->createUpdateContext(); +my $xmlinput = $mgr->createLocalFileInputStream("file14.xml"); +$container->putDocument("file14", $xmlinput, $ucontext); + diff --git a/6668/Chapter11/11-6.pl b/6668/Chapter11/11-6.pl new file mode 100644 index 0000000..30fed5b --- /dev/null +++ b/6668/Chapter11/11-6.pl @@ -0,0 +1,13 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection()/person[name='Bob']"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +$qcontext->setDefaultCollection("test.dbxml"); + +my $query_exp = $mgr->prepare($query, $qcontext); +my $results = $query_exp->execute($qcontext); + diff --git a/6668/Chapter11/11-7.pl b/6668/Chapter11/11-7.pl new file mode 100644 index 0000000..a576d07 --- /dev/null +++ b/6668/Chapter11/11-7.pl @@ -0,0 +1,14 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection('test.dbxml')/people:person[name='\$name']"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +$qcontext->setNamespace("people", "http://brians.org/people/"); +$qcontext->setVariableValue("name", new XmlValue("Bob")); + +my $query_exp = $mgr->prepare($query, $qcontext); +my $results = $query_exp->execute($qcontext); + diff --git a/6668/Chapter11/11-8.pl b/6668/Chapter11/11-8.pl new file mode 100644 index 0000000..7ea6851 --- /dev/null +++ b/6668/Chapter11/11-8.pl @@ -0,0 +1,11 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection('test.dbxml')/person[name='Jim']"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); + +my $results = $mgr->query($query, $qcontext); + diff --git a/6668/Chapter11/11-9.pl b/6668/Chapter11/11-9.pl new file mode 100644 index 0000000..5727c5a --- /dev/null +++ b/6668/Chapter11/11-9.pl @@ -0,0 +1,12 @@ +use Sleepycat::DbXml 'simple'; +use strict; + +my $mgr = new XmlManager(); +my $query = "collection('test.dbxml')/person[name='Jim']"; + +my $container = $mgr->openContainer("test.dbxml"); +my $qcontext = $mgr->createQueryContext(); +$qcontext->setEvaluationType(XmlQueryContext::Lazy); + +my $results = $mgr->query($query, $qcontext); + diff --git a/6668/Chapter11/README.txt b/6668/Chapter11/README.txt new file mode 100644 index 0000000..b6a908b --- /dev/null +++ b/6668/Chapter11/README.txt @@ -0,0 +1,7 @@ +The Perl examples as a rule do not use exception handling for brevity, but +you should in your own code. + +Remember that the 'simple' parameter is necessary as part of +'use Sleepycat::DbXml' in order to make transactions optional. Not doing so +(and not using transactions properly) can result in segfaults. + diff --git a/6668/Chapter11/file14.xml b/6668/Chapter11/file14.xml new file mode 100644 index 0000000..5882514 --- /dev/null +++ b/6668/Chapter11/file14.xml @@ -0,0 +1,12 @@ + + + 114 + 00047668 + 04 + n + incursion + + 113 + + the act of entering some territory or domain (often in large numbers); "the incursion of television into the American living room" + diff --git a/6668/Chapter12/12-1.php b/6668/Chapter12/12-1.php new file mode 100644 index 0000000..1b51c39 --- /dev/null +++ b/6668/Chapter12/12-1.php @@ -0,0 +1,5 @@ +open("myenv/", DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0); +$mgr = new XmlManager($env, 0); + diff --git a/6668/Chapter12/12-10.php b/6668/Chapter12/12-10.php new file mode 100644 index 0000000..bc070c4 --- /dev/null +++ b/6668/Chapter12/12-10.php @@ -0,0 +1,14 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$results = $mgr->query($query, $qcontext); +while ($results->hasNext()) { + $value = $results->next(); + $document = $value->asDocument(); + $name = $document->getName(); + $content = $value->asString(); + print $name . ": " . $content . "\n"; +} + diff --git a/6668/Chapter12/12-11.php b/6668/Chapter12/12-11.php new file mode 100644 index 0000000..9dce30c --- /dev/null +++ b/6668/Chapter12/12-11.php @@ -0,0 +1,18 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$phoneqcontext = $mgr->createQueryContext(); +$results = $mgr->query($query, $qcontext); +$phonequery = $mgr->prepare($subquery, $phoneqcontext); +while ($results->hasNext()) { + $value = $results->next(); + $phoneresults = $phonequery->execute($value, $phoneqcontext); + while ($phoneresults->hasNext()) { + $phonevalue = $phoneresults->next(); + print $phonevalue->asString() . "\n"; + } +} + diff --git a/6668/Chapter12/12-12.php b/6668/Chapter12/12-12.php new file mode 100644 index 0000000..459f515 --- /dev/null +++ b/6668/Chapter12/12-12.php @@ -0,0 +1,7 @@ +openContainer("test.dbxml"); +$ucontext = $mgr->createUpdateContext(); +$content = "Bob"; +$container->putDocument("", $content, $ucontext, DBXML_GEN_NAME); + diff --git a/6668/Chapter12/12-13.php b/6668/Chapter12/12-13.php new file mode 100644 index 0000000..17bf715 --- /dev/null +++ b/6668/Chapter12/12-13.php @@ -0,0 +1,15 @@ +openContainer("test.dbxml"); +$ucontext = $mgr->createUpdateContext(); +$qcontext = $mgr->createQueryContext(); +$content = "Bob"; +$container->putDocument("", $content, $ucontext, DBXML_GEN_NAME); +$results = $mgr->query("collection('test.dbxml')/person[name='Bob']", $qcontext); +while ($results->hasNext()) { + $value = $results->next(); + $document = $value->asDocument(); + print "Deleting document: " . $document->getName() . "\n"; + $container->deleteDocument($document, $ucontext); +} + diff --git a/6668/Chapter12/12-14.php b/6668/Chapter12/12-14.php new file mode 100644 index 0000000..592a051 --- /dev/null +++ b/6668/Chapter12/12-14.php @@ -0,0 +1,9 @@ +openContainer("test.dbxml"); +$ucontext = $mgr->createUpdateContext(); +$newcontent = "Bob"; +$document = $container->getDocument("file12.xml"); +$document->setContent("Bob2"); +$container->updateDocument($document, $ucontext); + diff --git a/6668/Chapter12/12-15.php b/6668/Chapter12/12-15.php new file mode 100644 index 0000000..23ead02 --- /dev/null +++ b/6668/Chapter12/12-15.php @@ -0,0 +1,5 @@ +openContainer("test.dbxml"); +$container->addIndex("", "person", "node-element-equality-string"); + diff --git a/6668/Chapter12/12-16.php b/6668/Chapter12/12-16.php new file mode 100644 index 0000000..dd4d90e --- /dev/null +++ b/6668/Chapter12/12-16.php @@ -0,0 +1,9 @@ +openContainer("test.dbxml"); +$ucontext = $mgr->createUpdateContext(); +$indexspec = $container->getIndexSpecification(); +$indexspec->deleteIndex("", "person", "node-element-equality-string"); +$indexspec->addIndex("", "person", "node-attribute-equality-string"); +$container->setIndexSpecification($indexspec, $ucontext); + diff --git a/6668/Chapter12/12-17.php b/6668/Chapter12/12-17.php new file mode 100644 index 0000000..053e620 --- /dev/null +++ b/6668/Chapter12/12-17.php @@ -0,0 +1,13 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$indexlookup = $mgr->createIndexLookup($container, "", "person", +"node-element-equality-string"); +$results = $indexlookup->execute($qcontext); +while ($results->hasNext()) { + $value = $results->next(); + my $document = $value->asDocument(); + print $document->getName() . ": " . $document->getContent(); +} + diff --git a/6668/Chapter12/12-18.php b/6668/Chapter12/12-18.php new file mode 100644 index 0000000..f782844 --- /dev/null +++ b/6668/Chapter12/12-18.php @@ -0,0 +1,10 @@ +openContainer("test.dbxml"); +$uri = "http://brians.org/metadata/"; +$metaname = "createdOn"; +$metavalue = new XmlValue(XmlValue_DATE_TIME, "2006-02-05T05:23:14"); +$document = $container->getDocument("file14.xml"); +$document->setMetaData($uri, $metaname, $metavalue); +$container->updateDocument($document); + diff --git a/6668/Chapter12/12-19.php b/6668/Chapter12/12-19.php new file mode 100644 index 0000000..ef58d15 --- /dev/null +++ b/6668/Chapter12/12-19.php @@ -0,0 +1,11 @@ +openContainer("test.dbxml"); +$ucontext = $mgr->createUpdateContext(); +$uri = "http://brians.org/metadata/"; +$metaname = "createdOn"; +$metavalue = new XmlValue(); +$document = $container->getDocument("file14.xml"); +$metavalue = $document->getMetaData($uri, $metaname); +print "file14.xml, created on " . $metavalue->asString() . "\n"; + diff --git a/6668/Chapter12/12-2.php b/6668/Chapter12/12-2.php new file mode 100644 index 0000000..205c98c --- /dev/null +++ b/6668/Chapter12/12-2.php @@ -0,0 +1,4 @@ +createContainer("test.dbxml"); + diff --git a/6668/Chapter12/12-20.php b/6668/Chapter12/12-20.php new file mode 100644 index 0000000..b580fa5 --- /dev/null +++ b/6668/Chapter12/12-20.php @@ -0,0 +1,12 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$ucontext = $mgr->createUpdateContext(); +$modify = $mgr->createModify(); +$queryexp = $mgr->prepare("/person/name", $qcontext); +$modify->addAppendStep($queryexp, XmlModify_Attribute, "type", "given"); +$document = $container->getDocument("file14"); +$doc_value = new XmlValue($document); +$modify->execute($doc_value, $qcontext, $ucontext); + diff --git a/6668/Chapter12/12-21.php b/6668/Chapter12/12-21.php new file mode 100644 index 0000000..850fb2b --- /dev/null +++ b/6668/Chapter12/12-21.php @@ -0,0 +1,11 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$ucontext = $mgr->createUpdateContext(); +$modify = $mgr->createModify(); +$queryexp = $mgr->prepare("/person/name", $qcontext); +$modify->addAppendStep($queryexp, XmlModify_Attribute, "type", "given"); +$results = $mgr->query("collection('test.dbxml')/person[name='Bill']", $qcontext); +$modify->execute($results, $qcontext, $ucontext); + diff --git a/6668/Chapter12/12-3.php b/6668/Chapter12/12-3.php new file mode 100644 index 0000000..6839de4 --- /dev/null +++ b/6668/Chapter12/12-3.php @@ -0,0 +1,8 @@ +open("myenv/",DB_CREATE| DB_INIT_LOCK| DB_INIT_LOG|DB_INIT_MPOOL| DB_INIT_TXN, 0); + +$mgr = new XmlManager($env, 0); +$container = $mgr->createContainer("test.dbxml", DBXML_TRANSACTIONAL| DBXML_ALLOW_VALIDATION, XmlContainer::NodeContainer); + + diff --git a/6668/Chapter12/12-4.php b/6668/Chapter12/12-4.php new file mode 100644 index 0000000..16b4633 --- /dev/null +++ b/6668/Chapter12/12-4.php @@ -0,0 +1,5 @@ +renameContainer("test.dbxml", "old-test.dbxml"); +$mgr->removeContainer("backup-test.dbxml"); + diff --git a/6668/Chapter12/12-5.php b/6668/Chapter12/12-5.php new file mode 100644 index 0000000..47a31fb --- /dev/null +++ b/6668/Chapter12/12-5.php @@ -0,0 +1,6 @@ +openContainer("test.dbxml"); +$xmlinput = $mgr->createLocalFileInputStream("file14.xml"); +$container->putDocument("file14", $xmlinput); + diff --git a/6668/Chapter12/12-6.php b/6668/Chapter12/12-6.php new file mode 100644 index 0000000..82b95bf --- /dev/null +++ b/6668/Chapter12/12-6.php @@ -0,0 +1,9 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$qcontext->setDefaultCollection("test.dbxml"); +$query_exp = $mgr->prepare($query, $qcontext); +$results = $query_exp->execute($qcontext); + diff --git a/6668/Chapter12/12-7.php b/6668/Chapter12/12-7.php new file mode 100644 index 0000000..63ef6c2 --- /dev/null +++ b/6668/Chapter12/12-7.php @@ -0,0 +1,10 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$qcontext->setNamespace("people", "http://brians.org/people/"); +$qcontext->setVariableValue("name", new XmlValue("Bob")); +$query_exp = $mgr->prepare($query, $qcontext); +$results = $query_exp->execute($qcontext); + diff --git a/6668/Chapter12/12-8.php b/6668/Chapter12/12-8.php new file mode 100644 index 0000000..74b78c2 --- /dev/null +++ b/6668/Chapter12/12-8.php @@ -0,0 +1,6 @@ +openContainer("test.dbxml"); +$results = $mgr->query($query, $qcontext); + diff --git a/6668/Chapter12/12-9.php b/6668/Chapter12/12-9.php new file mode 100644 index 0000000..015ce07 --- /dev/null +++ b/6668/Chapter12/12-9.php @@ -0,0 +1,8 @@ +openContainer("test.dbxml"); +$qcontext = $mgr->createQueryContext(); +$qcontext->setEvaluationType(XmlQueryContext_Lazy); +$results = $mgr->query($query, $qcontext); + diff --git a/6668/Extra/bdbxml-refcard.pdf b/6668/Extra/bdbxml-refcard.pdf new file mode 100644 index 0000000..61599d6 Binary files /dev/null and b/6668/Extra/bdbxml-refcard.pdf differ diff --git a/6668/README.txt b/6668/README.txt new file mode 100644 index 0000000..f57a97e --- /dev/null +++ b/6668/README.txt @@ -0,0 +1,33 @@ +This is the source code from the book: + + The Definitive Guide to Berkeley DB XML + Danny Brian + ISBN: 1-59059-666-8 + August 21st, 2006 + http://apress.com/book/bookDisplay.html?bID=10128 + +USING THE CODE + +This code requires Berkeley DB XML 2.2.13 to be installed, along with the +language API for the particular chapter. See invidual README.txt files in +the respective chapter directories for more info. + +EXTRAS + +Note that the Extra/ directory contains a quick reference card (PDF) for +Berkeley DB XML. + +The author's site, including FAQ and other information, is at: + + http://conceptuary.com/bdbxml/ + +The author may be contacted at: + + dan@brians.org + +Note that since publication, the main source of Berkeley DB XML support and +information has changed to the Oracle forum: + + http://forums.oracle.com/forums/forum.jspa?forumID=274 + + diff --git a/9781590596661.jpg b/9781590596661.jpg new file mode 100644 index 0000000..7bda84f Binary files /dev/null and b/9781590596661.jpg differ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..fab275e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2006 Daniel Brian + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..778fe19 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*The Definitive Guide to Berkeley DB XML*](http://www.apress.com/9781590596661) by Daniel Brian (Apress, 2006). + +![Cover image](9781590596661.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file