Author: clr
Date: Wed Aug 13 15:13:17 2008
New Revision: 685700
URL: http://svn.apache.org/viewvc?rev=685700&view=rev
Log:
JDO-597 Add ReadOnly property to PMF
Added:
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java (with props)
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java (with props)
Modified:
db/jdo/trunk/api2/src/java/javax/jdo/Constants.java
db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd
db/jdo/trunk/tck2/src/conf/pmf.conf
Modified: db/jdo/trunk/api2/src/java/javax/jdo/Constants.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/Constants.java?rev=685700&r1=685699&r2=685700&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/Constants.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/Constants.java Wed Aug 13 15:13:17 2008
@@ -121,6 +121,14 @@
static String PMF_ATTRIBUTE_OPTIMISTIC
= "optimistic";
/**
+ * The name of the persistence manager factory element's "readonly"
+ * attribute.
+ *
+ * @since 2.2
+ */
+ static String PMF_ATTRIBUTE_READONLY
+ = "readonly";
+ /**
* The name of the persistence manager factory element's "retain-values"
* attribute.
*
@@ -547,6 +555,14 @@
static String PROPERTY_OPTIMISTIC
= "javax.jdo.option.Optimistic";
/**
+ * "javax.jdo.option.ReadOnly"
+ *
+ * @see PersistenceManagerFactory#getReadOnly()
+ * @since 2.2
+ */
+ static String PROPERTY_READONLY
+ = "javax.jdo.option.ReadOnly";
+ /**
* "javax.jdo.option.RetainValues"
*
* @see PersistenceManagerFactory#getRetainValues()
Modified: db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd?rev=685700&r1=685699&r2=685700&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd (original)
+++ db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd Wed Aug 13 15:13:17 2008
@@ -115,6 +115,8 @@
+
+
Modified: db/jdo/trunk/tck2/src/conf/pmf.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/pmf.conf?rev=685700&r1=685699&r2=685700&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/pmf.conf (original)
+++ db/jdo/trunk/tck2/src/conf/pmf.conf Wed Aug 13 15:13:17 2008
@@ -26,6 +26,7 @@
org.apache.jdo.tck.api.persistencemanagerfactory.Close \
org.apache.jdo.tck.api.persistencemanagerfactory.CloseFailsIfTransactionActive \
org.apache.jdo.tck.api.persistencemanagerfactory.CloseWithoutPermissionThrowsSecurityException \
+org.apache.jdo.tck.api.persistencemanagerfactory.FlushThrowsIfReadOnly \
org.apache.jdo.tck.api.persistencemanagerfactory.GetPMFByFile \
org.apache.jdo.tck.api.persistencemanagerfactory.GetPMFByFileAndClassLoader \
org.apache.jdo.tck.api.persistencemanagerfactory.GetPMFByResource \
@@ -46,6 +47,7 @@
org.apache.jdo.tck.api.persistencemanagerfactory.SetNonTransactionalRead \
org.apache.jdo.tck.api.persistencemanagerfactory.SetNonTransactionalWrite \
org.apache.jdo.tck.api.persistencemanagerfactory.SetOptimistic \
+org.apache.jdo.tck.api.persistencemanagerfactory.SetReadOnly \
org.apache.jdo.tck.api.persistencemanagerfactory.SetRetainValues \
org.apache.jdo.tck.api.persistencemanagerfactory.SupportedOptions \
org.apache.jdo.tck.api.persistencemanagerfactory.config.Jdoconfig \
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java?rev=685700&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java Wed Aug 13 15:13:17 2008
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.api.persistencemanagerfactory;
+
+import java.util.Date;
+
+import java.util.Properties;
+import javax.jdo.Constants;
+import javax.jdo.JDOHelper;
+import javax.jdo.JDOReadOnlyException;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.Address;
+import org.apache.jdo.tck.pc.company.Company;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title:ReadOnly property of PersistenceManagerFactory
+ *
+ *Keywords: persistencemanagerfactory
+ *
+ *Assertion IDs: A11.1-28
+ *
+ *Assertion Description:
+ * if an attempt is made to write (via flush) then JDOReadOnlyException
+ * is thrown.
+ */
+
+
+public class FlushThrowsIfReadOnly extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A11.1-28 FlushThrowsIfReadOnly failed: ";
+
+ /** Second PMF that is read-only */
+ PersistenceManagerFactory pmf2;
+
+ /** The company oid */
+ Object oid;
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(FlushThrowsIfReadOnly.class);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(Company.class);
+ Properties properties = loadProperties(PMFProperties);
+ properties.put(Constants.PROPERTY_READONLY, "true");
+ pmf2 = JDOHelper.getPersistenceManagerFactory(properties);
+ // insert an instance to find
+ getPM();
+ pm.currentTransaction().begin();
+ Company comp = new Company(1L, "Sun Microsystems", new Date(),
+ new Address(0,"","","","",""));
+ pm.makePersistent(comp);
+ oid = pm.getObjectId(comp);
+ pm.currentTransaction().commit();
+ pm.close();
+ }
+
+ /** */
+ public void testMakePersistent() {
+ //Try to makePersistent and flush the transaction
+ pm = pmf2.getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ Company comp = new Company(2L, "Sun Microsystems2", new Date(),
+ new Address(0,"","","","",""));
+ try {
+ pm.makePersistent(comp);
+ pm.flush();
+ } catch (JDOReadOnlyException jDOReadOnlyException) {
+ // good catch
+ }
+ tx.rollback();
+ pm.close();
+ pm = null;
+ closePMF(pmf2);
+ }
+
+ /** */
+ public void testUpdate() {
+ //Try to update and flush the transaction
+ pm = getPM();
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ Company comp = (Company)pm.getObjectById(oid);
+ try {
+ comp.setName("new name");
+ pm.flush();
+ } catch (JDOReadOnlyException jDOReadOnlyException) {
+ // good catch
+ }
+ tx.rollback();
+ pm.close();
+ pm = null;
+ closePMF(pmf2);
+ }
+
+ /** */
+ public void testDeletePersistent() {
+ //Try to deletePersistent and flush the transaction
+ pm = getPM();
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ Company comp = (Company)pm.getObjectById(oid);
+ try {
+ pm.deletePersistent(comp);
+ pm.flush();
+ } catch (JDOReadOnlyException jDOReadOnlyException) {
+ // good catch
+ }
+ tx.rollback();
+ pm.close();
+ pm = null;
+ closePMF(pmf2);
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/FlushThrowsIfReadOnly.java
------------------------------------------------------------------------------
svn:eol-style = LF
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java?rev=685700&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java Wed Aug 13 15:13:17 2008
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.api.persistencemanagerfactory;
+
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title:Set ReadOnly property of persistencemanagerfactory
+ *
+ *Keywords: persistencemanagerfactory
+ *
+ *Assertion IDs: A11.1-29, A11.1-30
+ *
+ *Assertion Description:
+ * PersistenceManagerFactory.setReadOnly(boolean) sets the value of the
+ * ReadOnly property
+ * PersistenceManagerFactory.getReadOnly() returns the value of the
+ * ReadOnly property
+ */
+
+public class SetReadOnly extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A11.1-29, A11.1-30 (SetRetainValues) failed: ";
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(SetReadOnly.class);
+ }
+
+ /** */
+ protected void localSetUp() {
+ closePMF();
+ pmf = getUnconfiguredPMF();
+ }
+
+ /**
+ * Set ReadOnly to true or false and use getReadOnly to verify.
+ */
+ public void test() {
+ try {
+ setReadOnly(false);
+ setReadOnly(true);
+ } finally {
+ closePMF();
+ }
+ }
+
+ /** */
+ private void setReadOnly(boolean newValue) {
+ pmf.setReadOnly(newValue);
+ boolean current = pmf.getReadOnly();
+ if (current != newValue) {
+ fail(ASSERTION_FAILED, "ReadOnly set to " + newValue +
+ ", value returned by PMF is " + current);
+ }
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetReadOnly.java
------------------------------------------------------------------------------
svn:eol-style = LF