From: P.L.Coetzee <P.L...@op...> - 2007-07-02 08:33:10
|
Dear all, As Christian suggested, I've modified the MysqlFindIterator I posted = previously to use the same ADODB mechanism as RAP prefers. Instead of = taking connection parameters and model URI on the constructor, it now = takes the DBModel which you wish to execute the find() over and extracts = its data from that. Thanks for suggesting the change Christian - it = should hopefully be more widely usable now :) As ever, comments gratefully received! Cheers, Peter ______________________________________________________ ADOFindIterator.class.php: <?php /* * Find Iterator operating over an ADODB Connection, to work in ~linear = time * Particular application in iterating over large datasets, performs = faster * + in a more scalable manner than the existing FindIterator class. * * Author: Peter Coetzee * */ class ADOFindIter { private $curr; private $res; private $dbConn; private $dummy; // Pre: $dbmodel is a connected RAP DB Model. // Post: Prepare Iterator for operation. If $ordered =3D=3D = true, // select rows ordered by subject then predicate, for ease // of processing. public function ADOFindIter( $dbModel, $ordered=3Dfalse, $sub=3Dnull, $pred=3Dnull, = $obj=3Dnull ) { $this->dbConn =3D $dbModel->getDbConn(); $modelID =3D $dbModel->getModelID(); $sql =3D "SELECT subject, predicate, object, = subject_is, " . "object_is, l_language, l_datatype FROM = statements " . "WHERE modelID =3D $modelID"; if ( $sub !=3D null ) $sql .=3D " AND subject =3D '$sub'"; if ( $pred !=3D null ) $sql .=3D " AND predicate =3D '$pred'"; if ( $obj !=3D null ) $sql .=3D " AND object =3D '$obj'"; if ( $ordered ) $sql .=3D " ORDER BY subject, predicate"; $this->res =3D &$this->dbConn->Execute( $sql ) or die( "ADODB error: " . = $dbConn->ErrorMsg() ); $this->dummy =3D ModelFactory::getDefaultModel(); $this->curr =3D $this->res->fields; } // Post: Return the next statement in the Iterator public function next() { if ( $this->curr =3D=3D null && !$this->hasNext() ) return null; if ( $this->curr[4] =3D=3D 'l' ) { $object =3D new Literal( $this->curr[2] ); if ( $this->curr[5] !=3D '' && $this->curr[5] = !=3D null ) $object->setLanguage( $this->curr[5] ); if ( $this->curr[6] !=3D '' && $this->curr[6] = !=3D null ) $object->setDatatype( $this->curr[6] ); } else if ( $this->curr[4] =3D=3D 'b' ) { $object =3D new BlankNode( $this->dummy ); } else { $object =3D new Resource( $this->curr[2] ); } $predicate =3D new Resource( $this->curr[1] ); if ( $this->curr[3] =3D=3D 'r' ) $subject =3D new Resource( $this->curr[0] ); else $subject =3D new BlankNode( $this->dummy ); $this->curr =3D null; return new Statement( $subject, $predicate, $object ); } // Post: True iff there is another Statement in the Iterator public function hasNext() { return $this->curr =3D=3D null ? ( !$this->res->EOF && $this->res->MoveNext() && $this->curr =3D $this->res->fields ) : = true; } // Post: Answer the number of Statements in the Iterator public function size() { return $this->res->RecordCount(); } // Post: Free up resources used by this Iterator. Behaviour of = any // subsequent calls is undefined. public function free() { $this->res->Close(); } } ?> -----Original Message----- From: rdf...@li... on behalf of = P.L.Coetzee Sent: Mon 02/07/2007 08:13 To: Christian Weiske; rdf...@li... Subject: Re: [Rdfapi-php-interest] FindIterator over a Database =20 Christian, I should imagine so - it started off as a simple exercise "make it work = for me", so I've not looked all that much into the innards of RAP etc. I = shall do so this morning, and post back once I've got something worth = looking at (or catastrophic failure, whichever comes first ;) Cheers, Peter P.S. - As an occasional-Jena-user, your benchmarks were particularly = intriguing! Thanks for sharing :) -----Original Message----- From: rdf...@li... on behalf of = Christian Weiske Sent: Sat 30/06/2007 07:43 To: rdf...@li... Subject: Re: [Rdfapi-php-interest] FindIterator over a Database =20 Peter, > This has led me to write the attached MysqlFindIterator class, which =20 > bypasses the RAP API, and instead queries the database directly. It =20 > scales in approximately linear time, so is useful for these large =20 > resultsets. At the moment I've only written it to handle MySQL =20 > databases, but it should be easily modifiable for whatever DB Driver =20 > you wish to use. Do you think it is possible to use RAP's preferred connection to = databases, ADODB? --=20 Mit freundlichen Gr=FC=DFen/Regards, Christian Weiske -------------------------------------------------------------------------= This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Rdfapi-php-interest mailing list Rdf...@li... https://lists.sourceforge.net/lists/listinfo/rdfapi-php-interest -------------------------------------------------------------------------= This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Rdfapi-php-interest mailing list Rdf...@li... https://lists.sourceforge.net/lists/listinfo/rdfapi-php-interest |