You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Davide Savazzi <da...@corefandango.net> on 2004/05/12 16:59:16 UTC

Oracle Store

I've made an Oracle 9 adapter, I've tested it with Konqueror on Linux, 
Explorer on Windows and it seems to work... There's no support for 
compression yet. In storeContent() I use a method of the Oracle JDBC driver, 
someone knows if it could be implemented without it?

Is there a test suite for Stores???

-- 
Davide Savazzi


Re: compression support [Was: Re: Oracle Store]

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
Davide Savazzi wrote:

> On Monday 17 May 2004 09:36, Oliver Zeigermann wrote:
> 
> 
>>Hmmm, I am not quite sure if this is a good solution. Compression was
>>introduced to achive a speedup. I guess writing to a temporary file
>>first rather slows down everything, am I wrong? 
> 
> 
> It's obviously slower but the real bottleneck is always the db, I'll make some 
> benchmark ;)
> What do you think about using NIO to keep all in memory but outside the vm?

Well, we onced decided to rely on Java 1.3 only, I guess, but we may 
change this for the 2.1 if people agree...

> 
>>Maybe the solution would
>>be to disable compression when you want up-/download large files?
> 
> 
> Or write to a tmp file only if ByteArrayOutputStream becomes too big?
> 

Sounds good. But I am wondering why using the compression mode anyhow if 
it is slower? Could you please verify with your benchmark.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


compression support [Was: Re: Oracle Store]

Posted by Davide Savazzi <da...@corefandango.net>.
On Monday 17 May 2004 09:36, Oliver Zeigermann wrote:

> Hmmm, I am not quite sure if this is a good solution. Compression was
> introduced to achive a speedup. I guess writing to a temporary file
> first rather slows down everything, am I wrong? 

It's obviously slower but the real bottleneck is always the db, I'll make some 
benchmark ;)
What do you think about using NIO to keep all in memory but outside the vm?

> Maybe the solution would
> be to disable compression when you want up-/download large files?

Or write to a tmp file only if ByteArrayOutputStream becomes too big?

-- 
Davide Savazzi



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
Davide Savazzi wrote:

> On Thursday 13 May 2004 09:48, Oliver Zeigermann wrote:
> 
> 
>>As some sort of motivation for sequences. They are really *mandatory*
>>when you use versioning and have more than one Client creating new
>>resources concurrently. Without sequences you will get many conflicts as
>>the 2.0 workaround does not have any effect with Oracle.
> 
> 
> Ok, I will look at it... (2.0 workaround?)

Some code that prevents deadlocks with the file stores. Merely a hack...

> I have added support for content compression, 2 problems:
> - the field "bcompress" in StandardRDBMSAdapter is private, can it be changed 
> to protected?

Done

> - another OutOfMemoryError: StoreContentZip creates a ByteArrayOutputStream 
> that stores all the zipped content in memory.
> 
> I've modified StandardRDBMSAdapter to write compressed data in temp file.

Hmmm, I am not quite sure if this is a good solution. Compression was 
introduced to achive a speedup. I guess writing to a temporary file 
first rather slows down everything, am I wrong? Maybe the solution would 
be to disable compression when you want up-/download large files?

> I've tested these changes with Oracle and MySql. Oracle works fine, MySql 
> still suffers of OOM exceptions, but I think the problem is the JDBC driver. 
> On mysql.com they say "With newly added large-packet protocol support, the 
> driver can send rows and BLOBs up to 2 gigabytes in size." But in the README 
> of the driver:
> ---
> This version of the driver also supports large packet sizes
> (up to the limits of your server) when you're using MySQL-4.0
> or newer. Your JVM will need to be able to allocate enough
> memory to store the entire large packet, as well as an overhead
> of 16 megabytes or so.
> ---
> 
> With MySql and compression enabled I have also random IOExceptions (even 
> without my changes, in 2.0):
> 
> 14 May 2004 12:24:18 - org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter 
> - ERROR - java.io.EOFException: Unexpected end of ZLIB input stream
> java.io.EOFException: Unexpected end of ZLIB input stream

Maybe it is because of the BLOB size limitation to 64K we have discussed 
before. I think data above 64K simply get truncated. A suggested 
solution was to use LONGBLOB (or so).

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Davide Savazzi <da...@corefandango.net>.
On Thursday 13 May 2004 09:48, Oliver Zeigermann wrote:

> As some sort of motivation for sequences. They are really *mandatory*
> when you use versioning and have more than one Client creating new
> resources concurrently. Without sequences you will get many conflicts as
> the 2.0 workaround does not have any effect with Oracle.

Ok, I will look at it... (2.0 workaround?)

I have added support for content compression, 2 problems:
- the field "bcompress" in StandardRDBMSAdapter is private, can it be changed 
to protected?
- another OutOfMemoryError: StoreContentZip creates a ByteArrayOutputStream 
that stores all the zipped content in memory.

I've modified StandardRDBMSAdapter to write compressed data in temp file.

I've tested these changes with Oracle and MySql. Oracle works fine, MySql 
still suffers of OOM exceptions, but I think the problem is the JDBC driver. 
On mysql.com they say "With newly added large-packet protocol support, the 
driver can send rows and BLOBs up to 2 gigabytes in size." But in the README 
of the driver:
---
This version of the driver also supports large packet sizes
(up to the limits of your server) when you're using MySQL-4.0
or newer. Your JVM will need to be able to allocate enough
memory to store the entire large packet, as well as an overhead
of 16 megabytes or so.
---

With MySql and compression enabled I have also random IOExceptions (even 
without my changes, in 2.0):

14 May 2004 12:24:18 - org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter 
- ERROR - java.io.EOFException: Unexpected end of ZLIB input stream
java.io.EOFException: Unexpected end of ZLIB input stream

--
Davide Savazzi


Re: Oracle Store

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
As some sort of motivation for sequences. They are really *mandatory* 
when you use versioning and have more than one Client creating new 
resources concurrently. Without sequences you will get many conflicts as 
the 2.0 workaround does not have any effect with Oracle.

Oliver

Oliver Zeigermann wrote:

> I have added a sequence feature in preparation for the 2.1 release. I 
> should be very straight forward to implement it in Oracle. Are you 
> interested to contribute it as well. If so have a look at the SQLServer 
> implementation as a reference at
> 
> http://cvs.apache.org/viewcvs.cgi/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java?rev=1.4&view=markup 
> 
> 
> or from the CVS HEAD branch. As Oracle sequences are much more flexible 
> than this sort of workaround in the SQLServer you might also consider 
> getting larger chunks using something like "INCREMENT BY 100" and manage 
> this chunk in the Java code for less DB-requests and better performance. 
> I have done so in the file system implementation at
> 
> http://cvs.apache.org/viewcvs.cgi/jakarta-slide/src/stores/org/apache/slide/store/txfile/FileSequenceStore.java?rev=1.2&view=markup 
> 
> 
> which should be very obvious.
> 
> Cheers,
> 
> Oliver
> 
> Davide Savazzi wrote:
> 
>> On Thursday 13 May 2004 09:19, Oliver Zeigermann wrote:
>>
>>
>>> as a contribution to Slide I have added the ASF copyright to the code
>>> and checked it in. I guess this was your intention, right?
>>
>>
>>
>> Sure!
>> I've downloaded the sources from cvs, ASAP I will run the testsuite 
>> and add compression support...
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
I have added a sequence feature in preparation for the 2.1 release. I 
should be very straight forward to implement it in Oracle. Are you 
interested to contribute it as well. If so have a look at the SQLServer 
implementation as a reference at

http://cvs.apache.org/viewcvs.cgi/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java?rev=1.4&view=markup

or from the CVS HEAD branch. As Oracle sequences are much more flexible 
than this sort of workaround in the SQLServer you might also consider 
getting larger chunks using something like "INCREMENT BY 100" and manage 
this chunk in the Java code for less DB-requests and better performance. 
I have done so in the file system implementation at

http://cvs.apache.org/viewcvs.cgi/jakarta-slide/src/stores/org/apache/slide/store/txfile/FileSequenceStore.java?rev=1.2&view=markup

which should be very obvious.

Cheers,

Oliver

Davide Savazzi wrote:

> On Thursday 13 May 2004 09:19, Oliver Zeigermann wrote:
> 
> 
>>as a contribution to Slide I have added the ASF copyright to the code
>>and checked it in. I guess this was your intention, right?
> 
> 
> Sure!
> I've downloaded the sources from cvs, ASAP I will run the testsuite and add 
> compression support...
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Davide Savazzi <da...@corefandango.net>.
On Thursday 13 May 2004 09:19, Oliver Zeigermann wrote:

> as a contribution to Slide I have added the ASF copyright to the code
> and checked it in. I guess this was your intention, right?

Sure!
I've downloaded the sources from cvs, ASAP I will run the testsuite and add 
compression support...

-- 
Davide Savazzi



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
Davide,

as a contribution to Slide I have added the ASF copyright to the code 
and checked it in. I guess this was your intention, right?

Thanks again and cheers,

Oliver

Davide Savazzi wrote:

> I've made an Oracle 9 adapter, I've tested it with Konqueror on Linux, 
> Explorer on Windows and it seems to work... There's no support for 
> compression yet. In storeContent() I use a method of the Oracle JDBC driver, 
> someone knows if it could be implemented without it?
> 
> Is there a test suite for Stores???
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ALTER SESSION SET SQL_TRACE = TRUE;
> 
> DROP TRIGGER "URI-URI_ID-TRG";
> DROP TRIGGER "BRANCH-BRANCH_ID-TRG";
> DROP TRIGGER "LABEL-LABEL_ID-TRG";
> DROP TRIGGER "VERSION_HISTORY-VERSION_ID-TRG";
> 
> DROP SEQUENCE "URI-URI_ID-SEQ";
> DROP SEQUENCE "BRANCH-BRANCH_ID-SEQ";
> DROP SEQUENCE "LABEL-LABEL_ID-SEQ";
> DROP SEQUENCE "VERSION_HISTORY-VERSION_ID-SEQ";
> 
> DROP TABLE "URI" CASCADE CONSTRAINTS;
> DROP TABLE "OBJECT" CASCADE CONSTRAINTS;
> DROP TABLE "BINDING" CASCADE CONSTRAINTS;
> DROP TABLE "PARENT_BINDING" CASCADE CONSTRAINTS;
> DROP TABLE "LINKS" CASCADE CONSTRAINTS;
> DROP TABLE "LOCKS" CASCADE CONSTRAINTS;
> DROP TABLE "BRANCH" CASCADE CONSTRAINTS;
> DROP TABLE "LABEL" CASCADE CONSTRAINTS;
> DROP TABLE "VERSION" CASCADE CONSTRAINTS;
> DROP TABLE "VERSION_HISTORY" CASCADE CONSTRAINTS;
> DROP TABLE "VERSION_PREDS" CASCADE CONSTRAINTS;
> DROP TABLE "VERSION_LABELS" CASCADE CONSTRAINTS;
> DROP TABLE "VERSION_CONTENT" CASCADE CONSTRAINTS;
> DROP TABLE "PROPERTIES" CASCADE CONSTRAINTS;
> DROP TABLE "PERMISSIONS" CASCADE CONSTRAINTS;
> 
> 
> // path max length: 2500
> 
> CREATE TABLE "URI" (
> 	"URI_ID" NUMBER(10) NOT NULL,
>     	"URI_STRING" VARCHAR2(2500) NOT NULL,
> 	PRIMARY KEY("URI_ID"),
>     	UNIQUE("URI_STRING")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "OBJECT" (
> 	"URI_ID" NUMBER(10),
>     	"CLASS_NAME" VARCHAR2(255) NOT NULL,
> 	PRIMARY KEY("URI_ID"),
>     	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> // node name max length: 512
> 
> CREATE TABLE "BINDING" (
> 	"URI_ID" NUMBER(10) NOT NULL,
> 	"NAME" VARCHAR2(512) NOT NULL,
> 	"CHILD_UURI_ID" NUMBER(10) NOT NULL,
> 	PRIMARY KEY("URI_ID", "NAME", "CHILD_UURI_ID"),
> 	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("CHILD_UURI_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "PARENT_BINDING" (
> 	"URI_ID" NUMBER(10) NOT NULL,
> 	"NAME" VARCHAR2(512) NOT NULL,
>     	"PARENT_UURI_ID" NUMBER(10) NOT NULL,
> 	PRIMARY KEY("URI_ID", "NAME", "PARENT_UURI_ID"),
> 	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("PARENT_UURI_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "LINKS" (
> 	"URI_ID" NUMBER(10) NOT NULL,
> 	"LINK_TO_ID" NUMBER(10) NOT NULL,
> 	PRIMARY KEY("URI_ID", "LINK_TO_ID"),
> 	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("LINK_TO_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "LOCKS" (
> 	"LOCK_ID" NUMBER(10) NOT NULL, 
>     	"OBJECT_ID" NUMBER(10) NOT NULL, 
> 	"SUBJECT_ID" NUMBER(10) NOT NULL, 
> 	"TYPE_ID" NUMBER(10) NOT NULL, 
> 	"EXPIRATION_DATE" NUMBER(14) NOT NULL,
> 	"IS_INHERITABLE" NUMBER(1) NOT NULL, 
>     	"IS_EXCLUSIVE" NUMBER(1) NOT NULL, 
> 	"OWNER" VARCHAR2(512), 
> 	PRIMARY KEY("LOCK_ID"), 
> 	FOREIGN KEY("LOCK_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("OBJECT_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("SUBJECT_ID") REFERENCES "URI"("URI_ID"),
> 	FOREIGN KEY("TYPE_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "BRANCH" (
> 	"BRANCH_ID" NUMBER(10) NOT NULL, 
>     	"BRANCH_STRING" VARCHAR2(512) NOT NULL, 
> 	PRIMARY KEY("BRANCH_ID"), 
> 	UNIQUE("BRANCH_STRING")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "LABEL" (
> 	"LABEL_ID" NUMBER(10) NOT NULL, 
>     	"LABEL_STRING" VARCHAR2(512) NOT NULL, 
> 	PRIMARY KEY("LABEL_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "VERSION" (
> 	"URI_ID" NUMBER(10) NOT NULL, 
>     	"IS_VERSIONED" NUMBER(1) NOT NULL, 
> 	PRIMARY KEY("URI_ID"), 
>     	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "VERSION_HISTORY" (
> 	"VERSION_ID" NUMBER(10) NOT NULL, 
> 	"URI_ID" NUMBER(10) NOT NULL, 
> 	"BRANCH_ID" NUMBER(10) NOT NULL, 
> 	"REVISION_NO" VARCHAR2(20) NOT NULL, 
>     	PRIMARY KEY("VERSION_ID"), 
> 	UNIQUE("URI_ID", "BRANCH_ID", "REVISION_NO"), 
> 	FOREIGN KEY("URI_ID") REFERENCES "URI"("URI_ID"), 
> 	FOREIGN KEY("BRANCH_ID") REFERENCES "BRANCH"("BRANCH_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "VERSION_PREDS" (
> 	"VERSION_ID" NUMBER(10) NOT NULL, 
> 	"PREDECESSOR_ID" NUMBER(10) NOT NULL, 
> 	FOREIGN KEY("VERSION_ID") REFERENCES "VERSION_HISTORY"("VERSION_ID"), 
> 	FOREIGN KEY("PREDECESSOR_ID") REFERENCES "VERSION_HISTORY"("VERSION_ID"), 
>     	UNIQUE("VERSION_ID", "PREDECESSOR_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "VERSION_LABELS" (
> 	"VERSION_ID" NUMBER(10) NOT NULL, 
> 	"LABEL_ID" NUMBER(10) NOT NULL, 
> 	UNIQUE("VERSION_ID", "LABEL_ID"), 
> 	FOREIGN KEY("VERSION_ID") REFERENCES "VERSION_HISTORY"("VERSION_ID"), 
> 	FOREIGN KEY("LABEL_ID") REFERENCES "LABEL"("LABEL_ID")
> ) CACHE NOLOGGING;
> 
> CREATE TABLE "VERSION_CONTENT" (
> 	"VERSION_ID" NUMBER(10) NOT NULL, 
> 	"CONTENT" BLOB, 
> 	PRIMARY KEY("VERSION_ID"), 
> 	FOREIGN KEY("VERSION_ID") REFERENCES "VERSION_HISTORY"("VERSION_ID")
> ) CACHE NOLOGGING
> LOB ("CONTENT") STORE AS (NOCACHE NOLOGGING STORAGE(MAXEXTENTS UNLIMITED));
> 
> CREATE TABLE "PROPERTIES" (
> 	"VERSION_ID" NUMBER(10) NOT NULL, 
> 	"PROPERTY_NAMESPACE" VARCHAR2(50) NOT NULL, 
> 	"PROPERTY_NAME" VARCHAR2(50) NOT NULL, 
> 	"PROPERTY_VALUE" VARCHAR2(255), 
> 	"PROPERTY_TYPE" VARCHAR2(50),
> 	"IS_PROTECTED" NUMBER(1) NOT NULL, 
> 	UNIQUE("VERSION_ID", "PROPERTY_NAMESPACE", "PROPERTY_NAME"), 
> 	FOREIGN KEY("VERSION_ID") REFERENCES "VERSION_HISTORY"("VERSION_ID")
> ) CACHE NOLOGGING;
> 	
> CREATE TABLE "PERMISSIONS" (
> 	"OBJECT_ID" NUMBER(10) NOT NULL, 
> 	"SUBJECT_ID" NUMBER(10) NOT NULL, 
> 	"ACTION_ID" NUMBER(10) NOT NULL, 
> 	"VERSION_NO" VARCHAR2(20), 
> 	"IS_INHERITABLE" NUMBER(1) NOT NULL, 
> 	"IS_NEGATIVE" NUMBER(1) NOT NULL, 
> 	"SUCCESSION" NUMBER(10) NOT NULL, 
> 	FOREIGN KEY("OBJECT_ID") REFERENCES "URI"("URI_ID"), 
> 	FOREIGN KEY("SUBJECT_ID") REFERENCES "URI"("URI_ID"), 
> 	FOREIGN KEY("ACTION_ID") REFERENCES "URI"("URI_ID"), 
> 	UNIQUE("OBJECT_ID", "SUBJECT_ID", "ACTION_ID"), 
> 	UNIQUE("OBJECT_ID", "SUCCESSION")
> ) CACHE NOLOGGING;
> 
> CREATE SEQUENCE "URI-URI_ID-SEQ" START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
> CREATE SEQUENCE "BRANCH-BRANCH_ID-SEQ" START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
> CREATE SEQUENCE "LABEL-LABEL_ID-SEQ" START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
> CREATE SEQUENCE "VERSION_HISTORY-VERSION_ID-SEQ" START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
> 
> CREATE TRIGGER "URI-URI_ID-TRG" BEFORE INSERT ON "URI" FOR EACH ROW 
> BEGIN 
> SELECT "URI-URI_ID-SEQ".nextval INTO :new.URI_ID from dual; 
> END;
> /
> 
> CREATE TRIGGER "BRANCH-BRANCH_ID-TRG" BEFORE INSERT ON "BRANCH" FOR EACH ROW 
> BEGIN 
> SELECT "BRANCH-BRANCH_ID-SEQ".nextval INTO :new.BRANCH_ID from dual; 
> END;
> /
> 
> CREATE TRIGGER "LABEL-LABEL_ID-TRG" BEFORE INSERT ON "LABEL" FOR EACH ROW 
> BEGIN 
> SELECT "LABEL-LABEL_ID-SEQ".nextval INTO :new.LABEL_ID from dual; 
> END;
> /
> 
> CREATE TRIGGER "VERSION_HISTORY-VERSION_ID-TRG" BEFORE INSERT ON "VERSION_HISTORY" FOR EACH ROW 
> BEGIN 
> SELECT "VERSION_HISTORY-VERSION_ID-SEQ".nextval INTO :new.VERSION_ID from dual; 
> END;
> /
> 
> 
> ------------------------------------------------------------------------
> 
> package org.apache.slide.store.impl.rdbms;
> 
> import org.apache.slide.common.*;
> import org.apache.slide.content.*;
> import org.apache.slide.lock.LockTokenNotFoundException;
> import org.apache.slide.lock.NodeLock;
> import org.apache.slide.security.NodePermission;
> import org.apache.slide.structure.LinkNode;
> import org.apache.slide.structure.ObjectAlreadyExistsException;
> import org.apache.slide.structure.ObjectNode;
> import org.apache.slide.structure.ObjectNotFoundException;
> import org.apache.slide.util.logger.Logger;
> 
> import java.io.*;
> //import java.util.zip.GZIPOutputStream;
> //import java.util.zip.GZIPInputStream;
> import java.sql.*;
> import java.util.*;
> 
> 
> /**
>  * @todo compression support
>  *
>  * @author Davide Savazzi
>  */
> public class OracleRDBMSAdapter extends StandardRDBMSAdapter {
>     
>     // Constructor
>     
>     public OracleRDBMSAdapter(Service service, Logger logger) {
>         super(service, logger);
>     }
>     
> 
>     // Public Methods
>     
>     public void removeObject(Connection connection, Uri uri, ObjectNode object)
>         throws ServiceAccessException, ObjectNotFoundException 
>     {
>         PreparedStatement statement = null;
>         try {
>             clearBinding(connection, uri);
> 
>             // delete links
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from LINKS l where l.URI_ID in (" + 
>                         "select u.URI_ID from URI u where u.URI_STRING = ?)");
>                 statement.setString(1, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             // delete version history
>             // FIXME: Is this true??? Should the version history be removed if the object is removed???
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from VERSION_HISTORY vh where vh.URI_ID in (" + 
>                         "select u.URI_ID from URI u where u.URI_STRING = ?)");
>                 statement.setString(1, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             // delete version
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from VERSION v where v.URI_ID in (" + 
>                         "select u.URI_ID from URI u where u.URI_STRING = ?)");
>                 statement.setString(1, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             // delete the object itself
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from OBJECT o where o.URI_ID in (" +
>                         "select u.URI_ID from URI u where u.URI_STRING = ?)");
>                 statement.setString(1, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             // finally delete the uri
>             try {
>                 statement = connection.prepareStatement("delete from URI where URI_STRING = ?");
>                 statement.setString(1, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
> 
>         }
>     }
>     
>     public void removeRevisionContent(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor)
>         throws ServiceAccessException {
>         try {
>             PreparedStatement statement = null;
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from VERSION_CONTENT vc where vc.VERSION_ID in (" + 
>                         "select vh.VERSION_ID from VERSION_HISTORY vh, URI u where vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?)");
>                         // "delete VERSION_CONTENT from VERSION_CONTENT vc, VERSION_HISTORY vh, URI u where vc.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?");
>                 statement.setString(1, revisionDescriptor.getRevisionNumber().toString());
>                 statement.setString(2, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         }
>     }
>     
>     public void removeRevisionDescriptors(Connection connection, Uri uri) throws ServiceAccessException {
>         PreparedStatement statement = null;
>         try {
>             statement =
>                 connection.prepareStatement(
>                 "delete from VERSION_PREDS vp where vp.VERSION_ID in (" + 
>                 "select vh.VERSION_ID from VERSION_HISTORY vh, URI u where vh.URI_ID = u.URI_ID and u.URI_STRING = ?)");
>                 // "delete VERSION_PREDS from VERSION_PREDS vp, VERSION_HISTORY vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and u.URI_STRING = ?");
>             statement.setString(1, uri.toString());
>             statement.executeUpdate();
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         } finally {
>             close(statement);
>         }
>     }
> 
>     public void removeRevisionDescriptor(Connection connection, Uri uri, NodeRevisionNumber revisionNumber)
>         throws ServiceAccessException 
>     {
>         PreparedStatement statement = null;
>         try {
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from VERSION_LABELS vl where vl.VERSION_ID in (" + 
>                         "select vh.VERSION_ID from VERSION_HISTORY vh, URI u where vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?)");
>                         // "delete VERSION_LABELS from VERSION_LABELS vl, VERSION_HISTORY vh, URI u where vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
>                 statement.setString(1, revisionNumber.toString());
>                 statement.setString(2, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from PROPERTIES p where p.VERSION_ID in (" + 
>                         "select vh.VERSION_ID from VERSION_HISTORY vh, URI u where vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?)");
>                         // "delete PROPERTIES from PROPERTIES p, VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
>                 statement.setString(1, revisionNumber.toString());
>                 statement.setString(2, uri.toString());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         }
>     }
>     
>     public void removeLock(Connection connection, Uri uri, NodeLock lock)
>         throws ServiceAccessException, LockTokenNotFoundException {
>         PreparedStatement statement = null;
>         try {
>             // FIXME: What about inheritage?
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from LOCKS where LOCKS.LOCK_ID in (select u.URI_ID from URI u where u.URI_STRING=?)");
>                         // "delete LOCKS from LOCKS, URI u where LOCK_ID = u.URI_ID and u.URI_STRING=?");
>                 statement.setString(1, lock.getLockId());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>             try {
>                 statement =
>                     connection.prepareStatement(
>                         "delete from URI where URI.URI_ID in (select LOCK_ID from LOCKS) and URI_STRING=?");
>                         // "delete URI from URI, LOCKS l where URI_ID = l.LOCK_ID and URI_STRING=?");
>                 statement.setString(1, lock.getLockId());
>                 statement.executeUpdate();
>             } finally {
>                 close(statement);
>             }
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         }
>     }
>     
>     public void revokePermission(Connection connection, Uri uri, NodePermission permission)
>         throws ServiceAccessException {
>         PreparedStatement statement = null;
>         try {
>             NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
>             statement =
>                 connection.prepareStatement(
>                     "delete from PERMISSIONS where PERMISSIONS.OBJECT_ID in (select ou.URI_ID from URI ou, URI su, URI au where ou.URI_STRING = ? and SUBJECT_ID = su.URI_ID and su.URI_STRING = ? and ACTION_ID = au.URI_ID and au.URI_STRING = ? and VERSION_NO"
>                         + getRevisionNumberAsWhereQueryFragement(revisionNumber) + ")");
> //                    "delete PERMISSIONS from PERMISSIONS, URI ou, URI su, URI au where OBJECT_ID = ou.URI_ID and ou.URI_STRING = ? and SUBJECT_ID = su.URI_ID and su.URI_STRING = ? and ACTION_ID = au.URI_ID and au.URI_STRING = ? and VERSION_NO"
> //                        + getRevisionNumberAsWhereQueryFragement(revisionNumber));
>             statement.setString(1, permission.getObjectUri());
>             statement.setString(2, permission.getSubjectUri());
>             statement.setString(3, permission.getActionUri());
>             statement.executeUpdate();
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         } finally {
>             close(statement);
>         }
>     }
> 
>     public void revokePermissions(Connection connection, Uri uri) throws ServiceAccessException {
>         PreparedStatement statement = null;
>         try {
>             statement =
>                 connection.prepareStatement(
>                     "delete from PERMISSIONS where PERMISSIONS.OBJECT_ID in (select u.URI_ID from URI u where u.URI_STRING = ?)");
>                     // "delete PERMISSIONS from PERMISSIONS, URI u where OBJECT_ID = u.URI_ID and u.URI_STRING = ?");
>             statement.setString(1, uri.toString());
>             statement.executeUpdate();
>         } catch (SQLException e) {
>             throw createException(e, uri.toString());
>         } finally {
>             close(statement);
>         }
>     }
>     
>     
>     // Private Methods
>     
>     protected void storeContent(
>         Connection connection,
>         Uri uri,
>         NodeRevisionDescriptor revisionDescriptor,
>         NodeRevisionContent revisionContent)
>         throws IOException, SQLException 
>     {
>         getLogger().log("storeContent: " + uri, Logger.DEBUG);
>         
>         assureVersionInfo(connection, uri, revisionDescriptor);
>         long versionContentId = getVersionContentId(connection, uri, revisionDescriptor);
>         insertEmptyContent(connection, versionContentId);
>         
>         PreparedStatement statement = connection.prepareStatement(
>             "SELECT vc.CONTENT FROM VERSION_CONTENT vc WHERE vc.VERSION_ID = ? FOR UPDATE");
>         try {
>             statement.setLong(1, versionContentId);
>             ResultSet res = statement.executeQuery();
>             try {
>                 res.next();
>                 Blob blob = res.getBlob(1);
>                 InputStream in = revisionContent.streamContent();
> //                OutputStream out = new GZIPOutputStream(
> //                    ((oracle.sql.BLOB) blob).getBinaryOutputStream());
>                 OutputStream out = ((oracle.sql.BLOB) blob).getBinaryOutputStream();
>                 
>                 try {
>                     copy(in, out, ((oracle.sql.BLOB) blob).getBufferSize());
>                 } finally {
>                     close(out);
>                 }
>             } finally {
>                 close(res);
>             }
>         }  finally {
>             close(statement);
>         }
>     }
>     
>     protected void clearBinding(Connection connection, Uri uri)
>         throws ServiceAccessException, ObjectNotFoundException, SQLException 
>     {
>         PreparedStatement statement = null;
> 
>         try {
>             statement =
>                 connection.prepareStatement(
>                     "delete from BINDING where BINDING.URI_ID in (select URI_ID from URI where URI.URI_STRING = ?)");
>                     // "delete BINDING from BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
>             statement.setString(1, uri.toString());
>             statement.executeUpdate();
>         } finally {
>             close(statement);
>         }
> 
>         try {
>             statement =
>                 connection.prepareStatement(
>                     "delete from PARENT_BINDING where PARENT_BINDING.URI_ID in (select URI_ID from URI where URI.URI_STRING = ?)");
>                     // "delete PARENT_BINDING from PARENT_BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
>             statement.setString(1, uri.toString());
>             statement.executeUpdate();
>         } finally {
>             close(statement);
>         }
>     }
>     
>     protected ServiceAccessException createException(SQLException sqle, String uri) {
>         if (getLogger().isEnabled(Logger.DEBUG)) {
>             sqle.printStackTrace();
>         }
>         return new ServiceAccessException(service, sqle);
>     }
>     
>     private long getVersionContentId(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor) 
>         throws SQLException 
>     {
>         PreparedStatement statement = connection.prepareStatement(
>             "select vh.VERSION_ID from VERSION_HISTORY vh, URI u " + 
>             "where vh.URI_ID = u.URI_ID and u.URI_STRING = ? and vh.REVISION_NO"
>             + getRevisionNumberAsWhereQueryFragement(revisionDescriptor.getRevisionNumber()));
>         try {
>             statement.setString(1, uri.toString());
>             ResultSet res = statement.executeQuery();
>             try {
>                 res.next();
>                 return res.getLong(1);
>             } finally {
>                 close(res);
>             }
>         } finally {
>             close(statement);
>         }
>     }
>     
>     private void insertEmptyContent(Connection connection, long versionContentId) 
>         throws SQLException 
>     {
>         PreparedStatement statement = connection.prepareStatement(
>             "insert into VERSION_CONTENT (VERSION_ID, CONTENT) values (?, EMPTY_BLOB())");
>         try {
>             statement.setLong(1, versionContentId);
>             statement.executeUpdate();
>         } finally {
>             close(statement);
>         }
>     }
>     
>     private void close(ResultSet resultSet) {
>         try {
>             if (resultSet != null) {
>                 resultSet.close();
>             }
>         } catch (SQLException e) {
>             getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
>         }
>     }
>     
>     private void close(InputStream in) {
>         try {
>             if (in != null) {
>                 in.close();
>             }
>         } catch (IOException e) {
>             getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
>         }
>     }
>     
>     private void close(OutputStream out) {
>         try {
>             if (out != null) {
>                 out.close();
>             }
>         } catch (IOException e) {
>             getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
>         }
>     }
>     
>     private static void copy(InputStream in, OutputStream out, int bufferSize) 
>         throws IOException 
>     {
>         int read = 0;
>         byte buffer[] = new byte[bufferSize];
>         while ((read = in.read(buffer, 0, bufferSize)) != -1) {
>             out.write(buffer, 0, read);
>         }
>     }
>     
> }
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Oracle Store

Posted by Oliver Zeigermann <oz...@c1-fse.de>.
Hi Davide!

Thanks a lot, this is a very valuable contribution :) Especially, as a 
number of people have announced their port without actually delivering 
anything ;)

I will have a look at it ASAP (=tommorow) and will check it in into the 
HEAD branch that will eventually spawn the 2.1 release.

As for the test suite. Simply run the ordinary test suite, it should 
work without an error.

Thanks a lot,

Oliver

Davide Savazzi wrote:

> I've made an Oracle 9 adapter, I've tested it with Konqueror on Linux, 
> Explorer on Windows and it seems to work... There's no support for 
> compression yet. In storeContent() I use a method of the Oracle JDBC driver, 
> someone knows if it could be implemented without it?
> 
> Is there a test suite for Stores???
[snip]

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org