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 Takae Kanai <KY...@nifty.com> on 2003/11/25 06:29:24 UTC
MySQL and org.apache.slide.store.impl.rdbms.JDBCStore
Hi,
I am trying org.apache.slide.store.impl.rdbms.JDBCStore of Slide2.0.1.
I am testing by using my test CODE(JDBCsotreTest.java). I am testing by
the following Environments.
At that time, the following ERROR are output. This ERROR is generated
by the third addObject(). In 1 and 2nd addObject(), it does not become
an ERROR.
I do not understand the Reason to which this ERROR occurs.
Why does it become an ERROR by the third addObject()?
Please help me.
thank you.
<><><><><>My test environment<><><><><>
Platform : Windows 2000 professional
JDK version : jdk 1.3.1_09
MySQL version : 4.0.15
JDBC driver : mysql-connector-java-3.0.9-stable-bin.jar
Jakrta-Slide version : 2.0.1
(I got Slide 2.0.1 source code from CVS by tag "SLIDE_2_0_1".)
Adapter : MySqlRDBMSAdapter.java
I used MySqlRDBMSAdapter.java.
MySqlRDBMSAdapter.java was contributed to the Slide user mailing.
The EMail below. Thank you, Grant.
From: Grant Gongaware
Subject: Re: Transactions in Slide?
Date: Tue, 17 Jun 2003 14:44:54 -0700
<><><><><>ERROR<><><><><>
org.apache.slide.common.ServiceAccessException: Service org.apache.slide.store.impl.rdbms.JDBCStore@7b6889 access error : General error, message from server: "Cannot delete or update a parent row: a foreign key constraint fails"
at org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter.removeRevisionDescriptors(StandardRDBMSAdapter.java:965)
at org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter.storeRevisionDescriptors(StandardRDBMSAdapter.java:923)
at org.apache.slide.store.impl.rdbms.JDBCStore.storeRevisionDescriptors(JDBCStore.java:678)
at org.apache.slide.store.AbstractStore.storeRevisionDescriptors(AbstractStore.java:991)
at org.apache.slide.store.StandardStore.storeRevisionDescriptors(StandardStore.java:522)
at org.apache.slide.content.ContentImpl.create(ContentImpl.java:648)
at JDBCsotreTest.addObject(JDBCsotreTest.java:120)
at JDBCsotreTest.testAddContent(JDBCsotreTest.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
<><><><><>My test code(JDBCsotreTest.java)<><><><><>
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Vector;
import junit.framework.TestCase;
import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.authenticate.SecurityToken;
import org.apache.slide.common.Domain;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.SlideToken;
import org.apache.slide.common.SlideTokenImpl;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.lock.Lock;
import org.apache.slide.security.Security;
import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.Structure;
public class JDBCsotreTest extends TestCase {
private NamespaceAccessToken token;
private Structure structure;
private Security security;
private Lock lock;
private Content content;
private SlideToken slideToken;
public static void main(String[] args) {
}
public JDBCsotreTest(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
// Initialization
String namespace = "jdbc_store";
this.token =
Domain.accessNamespace( new SecurityToken(new String()),
namespace);
this.structure = token.getStructureHelper();
this.security = token.getSecurityHelper();
this.lock = token.getLockHelper();
this.content = token.getContentHelper();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testAddContent() throws Exception {
CredentialsToken credentials = new CredentialsToken("root");
slideToken = new SlideTokenImpl(credentials);
// first addObject
String str1 = "test";
InputStream in1 =
(InputStream)(new ByteArrayInputStream(str1.getBytes()));
addObject(slideToken, in1, "/object1", true);
in1.close();
// second addObject
String str2 = "test test";
InputStream in2 =
(InputStream)(new ByteArrayInputStream(str2.getBytes()));
addObject(slideToken, in2, "/object1", true);
in2.close();
// third addObject
String str3 = "test test";
InputStream in3 =
(InputStream)(new ByteArrayInputStream(str3.getBytes()));
//
// <><><><>The ERROR is output here. <><><><>
//
addObject(slideToken, in3, "/object1", true);
in3.close();
}
private void addObject(SlideToken slideToken, InputStream in,
String uri, boolean isVersioned)
throws Exception {
try {
// transaction begin
token.begin();
// Structure create
boolean exists = false;
try {
structure.create(slideToken,
new slideroles.basic.UserRoleImpl(), uri);
content.create(slideToken, uri, isVersioned);
} catch (ObjectAlreadyExistsException e) {
exists = true;
}
// Revision create
NodeRevisionDescriptors revisionDescriptors =
content.retrieve(slideToken, uri);
NodeRevisionDescriptor currentRevisionDescriptor =
new NodeRevisionDescriptor(
new NodeRevisionNumber("1.0"), "main",
new Vector(), new Hashtable());
// Contenet create
NodeRevisionContent currentRevisionContent = null;
if( in!=null ){
currentRevisionContent = new NodeRevisionContent();
currentRevisionContent.setContent(in);
}
// Store
if( exists && !revisionDescriptors.isVersioned() ){
try {
content.store(slideToken, uri,
currentRevisionDescriptor, currentRevisionContent);
} catch (Exception ex){}
} else {
content.create(slideToken, uri,
currentRevisionDescriptor, currentRevisionContent);
}
// transaction commit
token.commit();
} catch (Exception e) {
token.rollback();
throw e;
}
}
}
<><><><><>Database creation scripts<><><><><>
drop database rfDB;
create database rfDB;
use rfDB;
CREATE TABLE SLIDE_URI (
URI_ID bigint IDENTITY UNIQUE NOT NULL,
URI_STRING varchar(800) NOT NULL,
UNIQUE NONCLUSTERED (URI_ID)
)
CREATE TABLE SLIDE_QNAME (
QNAME_ID bigint IDENTITY UNIQUE NOT NULL,
NAMESPACE_URI VARCHAR(800) NOT NULL,
LOCAL_NAME VARCHAR(800) NOT NULL,
UNIQUE NON_CLUSTERED (QNAME_ID)
)
GO
CREATE TABLE SLIDE_OBJECT (
URI_ID bigint PRIMARY KEY,
CLASS_NAME varchar(255) NOT NULL,
CONSTRAINT FK_OBJECT_URI_ID
FOREIGN KEY (URI_ID)
REFERENCES SLIDE_URI (URI_ID)
)
GO
CREATE TABLE SLIDE_CHILD (
URI_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
CHILD_URI_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
UNIQUE CLUSTERED (URI_ID, CHILD_URI_ID)
)
GO
CREATE TABLE SLIDE_LINK (
URI_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
TARGET_URI_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
UNIQUE CLUSTERED (URI_ID, TARGET_URI_ID)
)
GO
CREATE TABLE SLIDE_LOCK (
LOCK_ID bigint PRIMARY KEY,
OBJECT_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
SUBJECT_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
TYPE_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
EXPIRATION_DATE numeric(14, 0) NOT NULL,
INHERITABLE bit NOT NULL,
EXCLUSIVE bit NOT NULL,
CONSTRAINT FK_LOCKS_LOCK_ID
FOREIGN KEY (LOCK_ID)
REFERENCES SLIDE_URI (URI_ID)
)
GO
CREATE TABLE SLIDE_BRANCH (
BRANCH_ID bigint IDENTITY UNIQUE NOT NULL,
BRANCH_NAME varchar(255) NOT NULL,
UNIQUE NONCLUSTERED (BRANCH_ID)
)
GO
CREATE TABLE SLIDE_LABEL (
LABEL_ID bigint IDENTITY UNIQUE NOT NULL,
LABEL_NAME varchar(255) NOT NULL,
UNIQUE NONCLUSTERED (LABEL_ID)
)
GO
CREATE TABLE SLIDE_REVISION_HISTORY (
URI_ID bigint PRIMARY KEY,
VERSIONED bit NOT NULL,
CONSTRAINT FK_VERSION_URI_ID
FOREIGN KEY (URI_ID)
REFERENCES SLIDE_URI (URI_ID)
)
GO
CREATE TABLE SLIDE_REVISION (
REVISION_ID bigint IDENTITY UNIQUE NOT NULL,
URI_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_REVISION_HISTORY (URI_ID),
BRANCH_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_BRANCH (BRANCH_ID),
REVISION_NUMBER VARCHAR(20) NOT NULL,
UNIQUE NONCLUSTERED (URI_ID, BRANCH_ID, REVISION_NUMBER)
)
GO
CREATE TABLE SLIDE_REVISION_PREDECESSOR (
REVISION_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_REVISION (REVISION_ID),
PREDECESSOR_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_REVISION (REVISION_ID),
UNIQUE CLUSTERED (REVISION_ID, PREDECESSOR_ID)
)
GO
CREATE TABLE SLIDE_REVISION_LABEL (
REVISION_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_REVISION (REVISION_ID),
LABEL_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_LABEL (LABEL_ID),
UNIQUE CLUSTERED (REVISION_ID, LABEL_ID)
)
GO
CREATE TABLE SLIDE_REVISION_CONTENT (
REVISION_ID bigint PRIMARY KEY,
CONTENT image NOT NULL,
CONSTRAINT FK_VC_VERSION_ID
FOREIGN KEY (REVISION_ID)
REFERENCES SLIDE_REVISION (REVISION_ID),
)
GO
CREATE TABLE SLIDE_REVISION_PROPERTY (
REVISION_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_REVISION (REVISION_ID),
QNAME_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_QNAME (QNAME_ID),
PROPERTY_VALUE varchar(255) NOT NULL,
PROTECTED bit NOT NULL,
UNIQUE CLUSTERED (REVISION_ID, QNAME_ID)
)
GO
CREATE TABLE SLIDE_REVISION_PERMISSION (
OBJECT_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
SUBJECT_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
ACTION_ID bigint NOT NULL FOREIGN KEY
REFERENCES SLIDE_URI (URI_ID),
REVISION_NUMBER VARCHAR(20),
INHERITABLE bit NOT NULL,
NEGATIVE bit NOT NULL,
UNIQUE CLUSTERED (OBJECT_ID, SUBJECT_ID, ACTION_ID)
)
GO
<><><><><>Domain.xml<><><><><>
<?xml version="1.0" ?>
<slide default="slide">
<namespace name="jdbc_store">
<definition>
<store name="jdbc">
<nodestore classname="org.apache.slide.store.impl.rdbms.JDBCStore">
<parameter name="driver">com.mysql.jdbc.Driver</parameter>
<parameter name="url">jdbc:mysql://localhost:3306/JDBC_DB?useUnicode=true&characterEncoding=UTF-8</parameter>
<parameter name="user">root</parameter>
<parameter name="password"></parameter>
<parameter name="adapter">itensil.bpn.io.rdbms.MySqlRDBMSAdapter</parameter>
</nodestore>
<securitystore>
<reference store="nodestore" />
</securitystore>
<lockstore>
<reference store="nodestore" />
</lockstore>
<revisiondescriptorsstore>
<reference store="nodestore" />
</revisiondescriptorsstore>
<revisiondescriptorstore>
<reference store="nodestore" />
</revisiondescriptorstore>
<contentstore>
<reference store="nodestore" />
</contentstore>
</store>
<scope match="/" store="jdbc" />
<logger classname="org.apache.slide.util.logger.SimpleLogger"
logger-level="6" />
</definition>
<configuration>
<!-- Actions mapping -->
<read-object>/actions/read</read-object>
<create-object>/actions/write</create-object>
<remove-object>/actions/write</remove-object>
<grant-permission>/actions/manage</grant-permission>
<revoke-permission>/actions/manage</revoke-permission>
<read-permissions>/actions/manage</read-permissions>
<lock-object>/actions/write</lock-object>
<kill-lock>/actions/manage</kill-lock>
<read-locks>/actions/read</read-locks>
<read-revision-metadata>/actions/read</read-revision-metadata>
<create-revision-metadata>/actions/write</create-revision-metadata>
<modify-revision-metadata>/actions/write</modify-revision-metadata>
<remove-revision-metadata>/actions/write</remove-revision-metadata>
<read-revision-content>/actions/read</read-revision-content>
<create-revision-content>/actions/write</create-revision-content>
<modify-revision-content>/actions/write</modify-revision-content>
<remove-revision-content>/actions/write</remove-revision-content>
<bind-member>/actions/write</bind-member>
<unbind-member>/actions/write</unbind-member>
<!-- Paths configuration -->
<userspath>/users</userspath>
<guestpath>guest</guestpath>
<groupspath>/groups</groupspath>
<filespath>/files</filespath>
<actionspath>/actions</actionspath>
<parameter name="dav">true</parameter>
<parameter name="standalone">true</parameter>
<!-- Roles definition -->
<role name="root">slideroles.basic.RootRole</role>
<role name="user">slideroles.basic.UserRole</role>
<role name="guest">slideroles.basic.GuestRole</role>
<!-- Users management -->
<auto-create-users>true</auto-create-users>
<!-- Default properties mapping -->
<default-property name="password" value="" role="user"/>
</configuration>
<data>
<objectnode classname="org.apache.slide.structure.SubjectNode" uri="/">
<!-- <permission action="/actions" subject="root"/> -->
<permission action="/actions" subject="/users/root"/>
<permission action="/actions/read" subject="/users" inheritable="false"/>
<permission action="/actions/read" subject="nobody" inheritable="false"/>
<!-- /users represents the unauthenticated user -->
<objectnode classname="org.apache.slide.structure.SubjectNode" uri="/users">
<permission action="/actions" subject="~"/>
<permission action="/actions" subject="/users/guest" inheritable="true"
negative="true"/>
<permission action="/actions/read" subject="/users" inheritable="false"/>
<!-- /users/root represents the administrator -->
<objectnode classname="slideroles.basic.RootRoleImpl" uri="/users/root">
<!-- Uncomment and change the password to allow login as root to
edit the namespace -->
<revision>
<property name="password"
namespace="DAV">root</property>
</revision>
</objectnode>
<!-- /users/guest represents an authenticated or unauthenticated
guest user -->
<objectnode classname="slideroles.basic.GuestRoleImpl" uri="/users/guest" />
</objectnode>
<objectnode classname="org.apache.slide.structure.ActionNode" uri="/actions">
<objectnode classname="org.apache.slide.structure.ActionNode"
uri="/actions/read"/>
<objectnode classname="org.apache.slide.structure.ActionNode"
uri="/actions/write"/>
<objectnode classname="org.apache.slide.structure.ActionNode"
uri="/actions/manage"/>
</objectnode>
</objectnode>
</data>
</namespace>
<parameter name="historypath">/history</parameter>
<parameter name="workspacepath">/workspace</parameter>
<parameter name="workingresourcepath">/workingresource</parameter>
<parameter name="auto-version">checkout-checkin</parameter>
<parameter name="auto-version-control">false</parameter>
<parameter name="versioncontrol-exclude"></parameter>
<parameter name="checkout-fork">forbidden</parameter>
<parameter name="checkin-fork">forbidden</parameter>
</slide>
--
Takae Kanai <KY...@nifty.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org
Re: MySQL and org.apache.slide.store.impl.rdbms.JDBCStore
Posted by Takae Kanai <KY...@nifty.com>.
Hi,
I found cause of the ERROR.
The following SQL is sent by the third addObject().
===================
:
SELECT REVISION_ID FROM SLIDE_REVISION WHERE URI_ID = 12
DELETE FROM SLIDE_REVISION_PREDECESSOR WHERE REVISION_ID = 10
DELETE FROM SLIDE_REVISION_LATEST WHERE REVISION_ID = 10
DELETE FROM SLIDE_REVISION_HISTORY WHERE URI_ID = 12
===================
The ERROR was output in the last DELETE.
Correct SQL is as follows.
===================
:
SELECT REVISION_ID FROM SLIDE_REVISION WHERE URI_ID = 12
DELETE FROM SLIDE_REVISION_PREDECESSOR WHERE REVISION_ID = 11
DELETE FROM SLIDE_REVISION_LATEST WHERE REVISION_ID = 11
DELETE FROM SLIDE_REVISION_HISTORY WHERE URI_ID = 12
===================
I think that StandardRDBMSAdapter.java imperfect to use revision
by MySQL.
So, I tried modified StandardRDBMSAdapter.java as follows.
===================
$ diff -u StandardRDBMSAdapter.java.org StandardRDBMSAdapter.java
--- StandardRDBMSAdapter.java.org Wed Aug 28 02:10:02 2002
+++ StandardRDBMSAdapter.java Wed Nov 26 08:57:10 2003
@@ -938,7 +938,7 @@
long uriId = getUriId(conn, uri.toString());
sql.setLength(0);
- sql.append("SELECT REVISION_ID FROM SLIDE_REVISION ")
+ sql.append("SELECT REVISION_ID FROM SLIDE_REVISION_LATEST ")
.append("WHERE URI_ID = ").append(uriId);
rs = stmt.executeQuery(sql.toString());
stmt2 = conn.createStatement();
===================
My trouble was solved by this modification.
However, I am not confident that this modification is correct.
Is this modification correct?
Thank you.
On Tue, 25 Nov 2003 14:29:24 +0900
Takae Kanai <KY...@nifty.com> wrote:
> Hi,
>
> I am trying org.apache.slide.store.impl.rdbms.JDBCStore of Slide2.0.1.
> I am testing by using my test CODE(JDBCsotreTest.java). I am testing by
> the following Environments.
>
> At that time, the following ERROR are output. This ERROR is generated
> by the third addObject(). In 1 and 2nd addObject(), it does not become
> an ERROR.
>
> I do not understand the Reason to which this ERROR occurs.
> Why does it become an ERROR by the third addObject()?
> Please help me.
>
> thank you.
--
Takae Kanai <KY...@nifty.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org