You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2005/05/22 20:01:48 UTC
svn commit: r171352 [8/11] - in /incubator/jdo/trunk/runtime20: ./ src/
src/conf/ src/java/ src/java/org/ src/java/org/apache/
src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/
src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/model/
src/java/org/apache/jdo/impl/model/java/
src/java/org/apache/jdo/impl/model/java/runtime/
src/java/org/apache/jdo/impl/model/jdo/
src/java/org/apache/jdo/impl/model/jdo/xml/
src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/
src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/pm/
src/java/org/apache/jdo/query/ src/java/org/apache/jdo/sco/
src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentDirtyFlushed.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentDirtyFlushed.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentDirtyFlushed.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentDirtyFlushed.java Sun May 22 11:01:45 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentDirtyFlushed.java August 8, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.BitSet;
+
+import javax.jdo.Transaction;
+
+import org.apache.jdo.store.StoreManager;
+
+
+/**
+ * This class represents PersistentDirtyFlushedstate specific state
+ * transitions as requested by StateManagerImpl. This state differs from
+ * PersistentDirty in that it is the result of flush operation.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentDirtyFlushed extends PersistentDirty {
+
+ PersistentDirtyFlushed() {
+ isFlushed = true;
+
+ stateType = P_DIRTY_FLUSHED;
+ }
+
+ /**
+ * @see LifeCycleState#transitionDeletePersistent(StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionDeletePersistent(StateManagerImpl sm) {
+ sm.registerTransactional();
+ sm.preDelete();
+ return changeState(P_DELETED);
+ }
+
+ /**
+ * @see LifeCycleState#transitionWriteField(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionWriteField(StateManagerImpl sm,
+ Transaction tx) {
+ sm.registerTransactional();
+ return changeState(P_DIRTY);
+ }
+
+ /**
+ * It is a no-op.
+ * @see LifeCycleState#flush(BitSet loadedFields, BitSet dirtyFields,
+ * StoreManager srm, StateManagerImpl sm)
+ */
+ protected LifeCycleState flush(BitSet loadedFields, BitSet dirtyFields,
+ StoreManager srm, StateManagerImpl sm) {
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionCommit(boolean retainValues, StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionCommit(boolean retainValues, StateManagerImpl sm) {
+ int newstate;
+
+ if (retainValues) {
+ sm.replaceSCOFields();
+ newstate = P_NON_TX;
+ } else {
+ sm.clearFields();
+ newstate = HOLLOW;
+ }
+
+ sm.reset();
+ return changeState(newstate);
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNew.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNew.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNew.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNew.java Sun May 22 11:01:45 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNew.java March 10, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.BitSet;
+
+import org.apache.jdo.state.StateManagerInternal;
+import org.apache.jdo.store.StoreManager;
+
+
+/**
+ * This class represents PersistentNew state specific state transitions as requested
+ * by StateManagerImpl. This state is a result of a call to makePersistent on a
+ * transient instance.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNew extends LifeCycleState {
+
+ PersistentNew() {
+ // these flags are set only in the constructor
+ // and shouldn't be changed afterwards
+ // (cannot make them final since they are declared in superclass
+ // but their values are specific to subclasses)
+ isPersistent = true;
+ isTransactional = true;
+ isDirty = true;
+ isNew = true;
+ isDeleted = false;
+
+ isNavigable = false;
+ isRefreshable = false;
+ isBeforeImageUpdatable = false;
+ isFlushed = false;
+
+ isStored = false;
+
+ stateType = P_NEW;
+ }
+
+ /**
+ * @see LifeCycleState#transitionDeletePersistent(StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionDeletePersistent(StateManagerImpl sm) {
+ // Remove from non-flushed chache.
+ sm.getPersistenceManager().markAsFlushed(sm);
+ sm.preDelete();
+ return changeState(P_NEW_DELETED);
+ }
+
+ /**
+ * This implementation differs from a generic version from the LifeCycleState as
+ * the state transitions to transient.
+ * @see LifeCycleState#transitionRollback(boolean restoreValues, StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionRollback(boolean restoreValues, StateManagerImpl sm) {
+ if (restoreValues) {
+ sm.restoreFields();
+ } else {
+ sm.unsetSCOFields();
+ }
+ sm.disconnect();
+ return changeState(TRANSIENT);
+ }
+
+ /**
+ * @see LifeCycleState#flush(BitSet loadedFields, BitSet dirtyFields,
+ * StoreManager srm, StateManagerImpl sm)
+ */
+ protected LifeCycleState flush(BitSet loadedFields, BitSet dirtyFields,
+ StoreManager srm, StateManagerImpl sm) {
+
+ int result = srm.insert(loadedFields, dirtyFields, sm);
+
+ switch(result) {
+ case StateManagerInternal.FLUSHED_COMPLETE:
+ sm.markAsFlushed();
+ return changeState(P_NEW_FLUSHED);
+
+ case StateManagerInternal.FLUSHED_PARTIAL:
+ return changeState(P_NEW_FLUSHED_DIRTY);
+
+ case StateManagerInternal.FLUSHED_NONE:
+ default:
+ return this;
+
+ }
+ }
+}
+
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewDeleted.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewDeleted.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewDeleted.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewDeleted.java Sun May 22 11:01:45 2005
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNewDeleted.java March 10, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import javax.jdo.Transaction;
+import javax.jdo.JDOUserException;
+
+/**
+ * This class represents PersistentNewDeleted state specific state
+ * transitions as requested by StateManagerImpl. This state differs from
+ * PersistentNew state as it is result of a call to deletePersistent
+ * for the same instance.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNewDeleted extends LifeCycleState {
+
+ PersistentNewDeleted() {
+ // these flags are set only in the constructor
+ // and shouldn't be changed afterwards
+ // (cannot make them final since they are declared in superclass
+ // but their values are specific to subclasses)
+ isPersistent = true;
+ isTransactional = true;
+ isDirty = true;
+ isNew = true;
+ isDeleted = true;
+
+ isNavigable = false;
+ isRefreshable = false;
+ isBeforeImageUpdatable = false;
+ isFlushed = true;
+
+ isStored = false;
+
+ // The following flag allows merge
+ needMerge = false;
+
+ stateType = P_NEW_DELETED;
+ }
+
+ /**
+ * @see LifeCycleState#transitionReadField(StateManagerImpl sm, Transaction tx)
+ * @throws JDOUserException on read access.
+ */
+ protected LifeCycleState transitionReadField(StateManagerImpl sm,
+ Transaction tx) {
+ // Cannot read a deleted object
+ throw new JDOUserException(msg.msg(
+ "EXC_AccessDeletedField")); // NOI18N
+ }
+
+ /**
+ * @see LifeCycleState#transitionWriteField(StateManagerImpl sm, Transaction tx)
+ * @throws JDOUserException on write access.
+ */
+ protected LifeCycleState transitionWriteField(StateManagerImpl sm,
+ Transaction tx) {
+ // Cannot update a deleted object
+ throw new JDOUserException(msg.msg(
+ "EXC_AccessDeletedField")); // NOI18N
+ }
+
+ /**
+ * @see LifeCycleState#transitionCommit(boolean retainValues, StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionCommit(boolean retainValues, StateManagerImpl sm) {
+ sm.clearFields();
+ sm.disconnect();
+ return changeState(TRANSIENT);
+ }
+ /**
+ * Differs from the generic implementation in LifeCycleState that state transitions
+ * to Transient.
+ * @see LifeCycleState#transitionRollback(boolean restoreValues, StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionRollback(boolean restoreValues, StateManagerImpl sm) {
+ if (restoreValues) {
+ sm.restoreFields();
+ } else {
+ sm.unsetSCOFields();
+ }
+ sm.disconnect();
+ return changeState(TRANSIENT);
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushed.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushed.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushed.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushed.java Sun May 22 11:01:45 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNewFlushed.java March 10, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.BitSet;
+
+import javax.jdo.Transaction;
+
+import org.apache.jdo.store.StoreManager;
+
+/**
+ * This class represents PersistentNewFlushed state specific state
+ * transitions as requested by StateManagerImpl. This state differs from
+ * PersistentNew state as the correspondinfg instance has been flushed
+ * to a datastore.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNewFlushed extends PersistentNew {
+
+ protected PersistentNewFlushed() {
+ super();
+ isFlushed = true;
+
+ stateType = P_NEW_FLUSHED;
+ }
+
+ /**
+ * @see LifeCycleState#transitionDeletePersistent(StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionDeletePersistent(StateManagerImpl sm) {
+ sm.registerTransactional();
+ sm.preDelete();
+ return changeState(P_NEW_FLUSHED_DELETED);
+ }
+
+ /**
+ * @see LifeCycleState#transitionWriteField(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionWriteField(StateManagerImpl sm,
+ Transaction tx) {
+ sm.registerTransactional();
+ return changeState(P_NEW_FLUSHED_DIRTY);
+ }
+
+ /**
+ * This is a no-op.
+ * @see LifeCycleState#flush(BitSet loadedFields, BitSet dirtyFields,
+ * StoreManager srm, StateManagerImpl sm)
+ */
+ protected LifeCycleState flush(BitSet loadedFields, BitSet dirtyFields,
+ StoreManager srm, StateManagerImpl sm) {
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionCommit(boolean retainValues, StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionCommit(boolean retainValues, StateManagerImpl sm) {
+ int newstate;
+
+ if (retainValues) {
+ sm.replaceSCOFields();
+ newstate = P_NON_TX;
+ } else {
+ sm.clearFields();
+ newstate = HOLLOW;
+ }
+ sm.reset();
+ return changeState(newstate);
+ }
+}
+
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDeleted.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDeleted.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDeleted.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDeleted.java Sun May 22 11:01:45 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNewFlushedDeleted.java March 10, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.BitSet;
+
+import org.apache.jdo.state.StateManagerInternal;
+import org.apache.jdo.store.StoreManager;
+
+
+/**
+ * This class represents PersistentNewFlushedDeleted state specific state
+ * transitions as requested by StateManagerImpl. This state is the result
+ * calls: makePersistent-flush-deletePersistent on the same instance.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNewFlushedDeleted extends PersistentNewDeleted {
+
+ protected PersistentNewFlushedDeleted() {
+ super();
+
+ isFlushed = false;
+
+ stateType = P_NEW_FLUSHED_DELETED;
+ }
+
+
+ /**
+ * @see LifeCycleState#flush(BitSet loadedFields, BitSet dirtyFields,
+ * StoreManager srm, StateManagerImpl sm)
+ */
+ protected LifeCycleState flush(BitSet loadedFields, BitSet dirtyFields,
+ StoreManager srm, StateManagerImpl sm) {
+ if (srm.delete(loadedFields, dirtyFields, sm) ==
+ StateManagerInternal.FLUSHED_COMPLETE) {
+ sm.markAsFlushed();
+ return changeState(P_NEW_DELETED);
+ }
+ return this;
+ }
+}
+
+
+
+
+
+
+
+
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDirty.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDirty.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDirty.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNewFlushedDirty.java Sun May 22 11:01:45 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNewFlushedDirty.java August 3, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.BitSet;
+
+import org.apache.jdo.state.StateManagerInternal;
+import org.apache.jdo.store.StoreManager;
+
+
+/**
+ * This class represents PersistentNewFlushedDirty state specific state
+ * transitions as requested by StateManagerImpl. This state is the result
+ * calls: makePersistent-flush-write_field on the same instance.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNewFlushedDirty extends PersistentNew {
+
+ protected PersistentNewFlushedDirty() {
+ super();
+
+ isFlushed = false;
+
+ stateType = P_NEW_FLUSHED_DIRTY;
+ }
+
+ /**
+ * @see LifeCycleState#transitionDeletePersistent(StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionDeletePersistent(StateManagerImpl sm) {
+ sm.preDelete();
+ return changeState(P_NEW_FLUSHED_DELETED);
+ }
+
+ /**
+ * @see LifeCycleState#flush(BitSet loadedFields, BitSet dirtyFields,
+ * StoreManager srm, StateManagerImpl sm)
+ */
+ protected LifeCycleState flush(BitSet loadedFields, BitSet dirtyFields,
+ StoreManager srm, StateManagerImpl sm) {
+
+ if(srm.update(loadedFields, dirtyFields, sm) ==
+ StateManagerInternal.FLUSHED_COMPLETE) {
+ sm.markAsFlushed();
+ return changeState(P_NEW_FLUSHED);
+ }
+
+ return this;
+ }
+}
+
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNonTransactional.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNonTransactional.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNonTransactional.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/PersistentNonTransactional.java Sun May 22 11:01:45 2005
@@ -0,0 +1,282 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * PersistentNonTransactional.java March 10, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import javax.jdo.Transaction;
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.state.FieldManager;
+
+/**
+ * This class represents PersistentNonTransactional state specific state
+ * transitions as requested by StateManagerImpl. This state is the result
+ * of the following operations:
+ * - commit or rollback of a persistent instance when retainValues flag
+ * on the Transaction is set to true;
+ * - non-transactional access of a Hollow instance;
+ * - makeNontransactional call of a PersistentClean instance;
+ * - refresh of a PersistentDirty instance in an optimistic transaction
+ * or outside of an active transaction.
+ *
+ * @author Marina Vatkina
+ */
+class PersistentNonTransactional extends LifeCycleState {
+
+ PersistentNonTransactional() {
+ // these flags are set only in the constructor
+ // and shouldn't be changed afterwards
+ // (cannot make them final since they are declared in superclass
+ // but their values are specific to subclasses)
+ isPersistent = true;
+ isTransactional = false;
+ isDirty = false;
+ isNew = false;
+ isDeleted = false;
+
+ isNavigable = true;
+ isRefreshable = false;
+ isBeforeImageUpdatable = false;
+ isFlushed = true;
+
+ stateType = P_NON_TX;
+ }
+
+ /**
+ * @see LifeCycleState#transitionDeletePersistent(StateManagerImpl sm)
+ */
+ protected LifeCycleState transitionDeletePersistent(StateManagerImpl sm) {
+ sm.createBeforeImage();
+ sm.refresh();
+ sm.registerTransactional();
+ sm.preDelete();
+ return changeState(P_DELETED);
+ }
+
+ /**
+ * @see LifeCycleState#transitionMakeTransactional(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionMakeTransactional(StateManagerImpl sm,
+ Transaction tx) {
+ if (tx.isActive()) {
+ sm.registerTransactional();
+
+ if (tx.getOptimistic()) {
+ sm.createBeforeImage();
+ return changeState(P_CLEAN_TX);
+ } else { // pessimistic
+
+ sm.refresh();
+ // Need to remove from non-flushed cache
+ sm.markAsFlushed();
+
+ return changeState(P_CLEAN);
+ }
+ } else { // transaction not active
+ return this;
+ }
+ }
+
+ /**
+ * @see LifeCycleState#transitionMakeNontransactional(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionMakeNontransactional(StateManagerImpl sm,
+ Transaction tx) {
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionMakeTransient(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionMakeTransient(StateManagerImpl sm,
+ Transaction tx) {
+ sm.disconnect();
+ return changeState(TRANSIENT);
+ }
+
+ /**
+ * @see LifeCycleState#transitionEvict(StateManagerImpl sm, Transaction tx)
+ */
+ protected LifeCycleState transitionEvict(StateManagerImpl sm,
+ Transaction tx) {
+ sm.clearFields();
+ sm.reset();
+ return changeState(HOLLOW);
+ }
+
+ /**
+ * @see LifeCycleState#transitionRefresh(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionRefresh(StateManagerImpl sm,
+ Transaction tx) {
+ //Do NOT create BeforeImage here as the call is intended to
+ // synchronize state with the datastore.
+ sm.refresh();
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionReadField(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionReadField(StateManagerImpl sm,
+ Transaction tx) {
+
+ if (!tx.getNontransactionalRead()) {
+ assertTransaction(tx.isActive());
+ }
+
+ return transitionRead(sm, tx, false);
+ }
+
+ /**
+ * Transtions the state on read or retrieve.
+ * @see LifeCycleState#transitionReadField(StateManagerImpl sm,
+ * Transaction tx)
+ * @see LifeCycleState#transitionRetrieve(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ private LifeCycleState transitionRead(StateManagerImpl sm,
+ Transaction tx, boolean retrieve) {
+
+ if (tx.isActive() && !tx.getOptimistic()) {
+ // This is a datastore transaction.
+ if (retrieve) {
+ sm.loadUnloaded();
+ } else {
+ // If refresh, save current image for rollback.
+ sm.createBeforeImage();
+ sm.refresh();
+ }
+ sm.registerTransactional();
+
+ // Need to remove from non-flushed cache
+ sm.markAsFlushed();
+
+ return changeState(P_CLEAN);
+ } else if (retrieve) {
+ // Always load all the fields on retrieve.
+ sm.loadUnloaded();
+ }
+ return this;
+ }
+
+
+ /**
+ * @see LifeCycleState#transitionWriteField(StateManagerImpl sm,
+ * Transaction tx)
+ */
+ protected LifeCycleState transitionWriteField(StateManagerImpl sm,
+ Transaction tx) {
+
+ if (tx.isActive()) {
+ // This is the first change in the current transaction. Save image
+ // for rollback:
+ sm.createBeforeImage();
+ sm.registerTransactional();
+
+ return changeState(P_DIRTY);
+
+ } else if (!tx.getNontransactionalWrite()) {
+ // This actually throws an exception
+ assertTransaction(false);
+ }
+
+ return this;
+ }
+
+
+ /**
+ * @see LifeCycleState#transitionReload(StateManagerImpl sm, Transaction tx)
+ */
+ protected LifeCycleState transitionReload(StateManagerImpl sm,
+ Transaction tx) {
+
+ boolean transactional = (tx.isActive() && !tx.getOptimistic());
+
+ // This transition will refresh the fields.. Save current image
+ // for rollback:
+ if (transactional) {
+ sm.createBeforeImage();
+ }
+
+ sm.refresh();
+
+ if (transactional) {
+ sm.registerTransactional();
+ // Need to remove from non-flushed cache
+ sm.markAsFlushed();
+
+ return changeState(P_CLEAN);
+ }
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionRetrieve(StateManagerImpl sm, Transaction tx)
+ */
+ protected LifeCycleState transitionRetrieve(StateManagerImpl sm,
+ Transaction tx) {
+
+ return transitionRead(sm, tx, true);
+ }
+
+ /**
+ * @see LifeCycleState#transitionReplace(StateManagerImpl sm,
+ * Transaction tx, int[] fields, FieldManager fieldManager)
+ */
+ protected LifeCycleState transitionReplace(StateManagerImpl sm,
+ Transaction tx, int[] fields, FieldManager fieldManager) {
+
+ if (tx.isActive() && !tx.getOptimistic()) {
+ sm.replaceFields(fields, fieldManager);
+ sm.registerTransactional();
+
+ // Need to remove from non-flushed cache
+ sm.markAsFlushed();
+
+ return changeState(P_CLEAN);
+ } else {
+ sm.replaceUnloadedFields(fields, fieldManager);
+ }
+ return this;
+ }
+
+ /**
+ * @see LifeCycleState#transitionRollback(boolean restoreValues,
+ * StateManagerImpl sm)
+ * @throws JDOFatalInternalException if called as this state
+ * transition is not valid.
+ */
+ protected LifeCycleState transitionRollback(boolean restoreValues,
+ StateManagerImpl sm) {
+ throw new JDOFatalInternalException(msg.msg(
+ "EXC_InconsistentState", // NOI18N
+ "rollback", this.toString())); // NOI18N
+ }
+
+}
+
+
+
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/ReachabilityHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/ReachabilityHandler.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/ReachabilityHandler.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/ReachabilityHandler.java Sun May 22 11:01:45 2005
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * ReachabilityHandler.java
+ *
+ * Created on September 19, 2001, 9:29 AM
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.*;
+
+import javax.jdo.*;
+
+import javax.jdo.spi.PersistenceCapable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jdo.pm.PersistenceManagerInternal;
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * This is the helper class to process persistence-by-reachability requests
+ * from the StateManager.
+ *
+ * @author Marina Vatkina
+ * @version 1.0
+ */
+class ReachabilityHandler {
+
+ /** The singleton ReachabilityHandler instance. */
+ private static final ReachabilityHandler singleton = new ReachabilityHandler();
+
+ /**
+ * Map of possible processors.
+ */
+ private final HashMap processors = new HashMap();
+
+ /**
+ * I18N message handler
+ */
+ private final static I18NHelper msg =
+ I18NHelper.getInstance("org.apache.jdo.impl.state.Bundle"); // NOI18N
+
+ /**
+ * Logger instance
+ */
+ private static final Log logger = LogFactory.getFactory().getInstance(
+ "org.apache.jdo.impl.state"); // NOI18N
+
+ /** Constructs a new <code>ReachabilityHandler</code> without specific
+ * parameters.
+ */
+ private ReachabilityHandler() {
+ /**
+ * Processors instances.
+ */
+ MakePersistentProcessor _makePersistentProcessor =
+ new MakePersistentProcessor();
+ AutoPersistentProcessor _autoPersistentProcessor =
+ new AutoPersistentProcessor();
+
+ processors.put(Boolean.TRUE, _makePersistentProcessor);
+ processors.put(Boolean.FALSE, _autoPersistentProcessor);
+ }
+
+ /**
+ * Get the ReachabilityHandler singleton instance.
+ * @return an instance of ReachabilityHandler
+ */
+ public static ReachabilityHandler getInstance()
+ {
+ return singleton;
+ }
+
+ /**
+ * Process recursevely requests for persistence-by-reachability.
+ * @param o Object to process.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ * @param type true if the request comes during the commit operation.
+ */
+ void process (Object o,
+ PersistenceManagerInternal pm,
+ boolean type) {
+
+ Processor p = (Processor) processors.get(getBoolean(type));
+
+ if (debugging())
+ debug("process for " + o.getClass() + " with " + p.getClass().getName()); // NOI18N
+
+ p.process(o, pm);
+ }
+
+ /**
+ * Translates boolean value into Boolean.
+ * @param type as boolean.
+ * @return corresponding Boolean object.
+ */
+ private Boolean getBoolean(boolean type) {
+ return ((type)? Boolean.TRUE :Boolean.FALSE);
+ }
+
+ /**
+ * Tracing method
+ * @param msg String to display
+ */
+ private void debug(String msg) {
+ logger.debug("In ReachabilityHandler " + msg); // NOI18N
+ }
+
+ /**
+ * Verifies if debugging is enabled.
+ * @return true if debugging is enabled.
+ */
+ private boolean debugging() {
+ return logger.isDebugEnabled();
+ }
+
+
+
+ /** An abstract class that knows how process reachability requests.
+ */
+ abstract class Processor {
+ /**
+ * Processes reachability requests.
+ * @param o Object to process.
+ * @param pm the PersistenceManagerInternal instance associated with
+ * the caller.
+ */
+ abstract void process(Object o, PersistenceManagerInternal pm);
+ }
+
+ /** Processor for MakePersistent request.
+ */
+ class MakePersistentProcessor extends Processor {
+
+ /** Transition Object or elements of a Collection or values and
+ * keys of a Map to Persistent at commit (persistence-by-reachability)
+ * @param o Object to process.
+ * @param pm the PersistenceManagerInternal instance associated with
+ * the caller.
+ */
+ void process(Object o, PersistenceManagerInternal pm) {
+ try {
+ if (java.util.Collection.class.isInstance(o)) {
+ pm.makePersistentAll(((Collection)o).toArray());
+
+ } else if (java.util.Map.class.isInstance(o)) {
+ Map m = (Map)o;
+ try {
+ pm.makePersistentAll(m.keySet().toArray());
+ } catch (JDOException e) {
+ // Ignore all problems - some of the elements could be
+ // not PersistenceCapable
+ }
+ // Now process the values.
+ pm.makePersistentAll(m.values().toArray());
+
+ } else if (javax.jdo.spi.PersistenceCapable.class.isInstance(o)) {
+ pm.makePersistent(o);
+
+ } else {
+ Class c = o.getClass();
+ if (c.isArray() &&
+ PersistenceCapable.class.isAssignableFrom(
+ c.getComponentType())) {
+
+ pm.makePersistentAll((Object[])o);
+ } // else do nothing
+
+ }
+ } catch (JDOException e) {
+ // Ignore all problems - some of the elements could be
+ // not PersistenceCapable
+ }
+ }
+ }
+
+ /** Processor for MakeAutoPersistent request.
+ */
+ class AutoPersistentProcessor extends Processor {
+
+ /** Transition Object or elements of a Collection or values and
+ * keys of a Map to auto-persistent inside an active transaction
+ * (persistence-by-reachability)
+ * @param o Object to process.
+ * @param pm the PersistenceManagerInternal instance associated with
+ * the caller.
+ */
+ void process(Object o, PersistenceManagerInternal pm) {
+ StateManagerImpl sm = null;
+
+ if (javax.jdo.spi.PersistenceCapable.class.isInstance(o)) {
+ PersistenceCapable pc = (PersistenceCapable) o;
+ sm = (StateManagerImpl) pm.findStateManager(pc);
+ if (sm == null) {
+ sm = (StateManagerImpl)
+ StateManagerFactory.newInstance(pc, pm);
+ }
+ sm.makeAutoPersistent();
+
+ } else if (java.util.Collection.class.isInstance(o)) {
+ processArray(((Collection)o).toArray(), pm);
+
+ } else if (java.util.Map.class.isInstance(o)) {
+ Map m = (Map)o;
+ processArray(m.keySet().toArray(), pm);
+ processArray(m.values().toArray(), pm);
+
+ } else { // check for Arrays.
+ Class c = o.getClass();
+ if (c.isArray() && PersistenceCapable.class.isAssignableFrom(
+ c.getComponentType())) {
+ processArray((Object[])o, pm);
+ } // else do nothing
+
+ } // else do nothing
+ }
+
+ /** Processes Array of referenced objects for possible auto-persistence
+ * (persistence-by-reachability).
+ * @param o Array of referenced objects
+ * @param pm PersistenceManagerInternal instance associated with the
+ * request.
+ */
+ private void processArray(Object[] o,
+ PersistenceManagerInternal pm) {
+ if (o == null) {
+ return;
+ }
+ for (int i = 0; i < o.length; i++) {
+ if (o[i] != null) {
+ process(o[i], pm);
+ } // else nothing to do.
+ }
+ }
+
+ }
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SCOProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SCOProcessor.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SCOProcessor.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SCOProcessor.java Sun May 22 11:01:45 2005
@@ -0,0 +1,437 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * SCOProcessor.java
+ *
+ * Created on September 26, 2001, 9:29 AM
+ */
+
+package org.apache.jdo.impl.state;
+
+import java.util.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import javax.jdo.*;
+
+import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
+import org.apache.jdo.impl.sco.SqlTimestamp;
+import org.apache.jdo.model.jdo.JDOCollection;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.model.jdo.JDOMap;
+import org.apache.jdo.pm.PersistenceManagerInternal;
+import org.apache.jdo.sco.SCO;
+import org.apache.jdo.sco.SCOCollection;
+import org.apache.jdo.sco.SCODate;
+import org.apache.jdo.sco.SCOMap;
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * This is the helper class to process SCO-related requests
+ * from the StateManager.
+ *
+ * @author Marina Vatkina
+ * @version 1.0
+ */
+class SCOProcessor {
+
+ /** The singleton ReachabilityHandler instance. */
+ private static final SCOProcessor singleton = new SCOProcessor();
+
+ /**
+ * Map of possible processors.
+ */
+ private final HashMap processors = new HashMap();
+ private final HashMap scoprocessors = new HashMap();
+
+ /**
+ * I18N message handler
+ */
+ private final static I18NHelper msg =
+ I18NHelper.getInstance("org.apache.jdo.impl.state.Bundle"); // NOI18N
+
+ /** RuntimeJavaModelFactory. */
+ private static final RuntimeJavaModelFactory javaModelFactory =
+ (RuntimeJavaModelFactory) AccessController.doPrivileged(
+ new PrivilegedAction () {
+ public Object run () {
+ return RuntimeJavaModelFactory.getInstance();
+ }
+ }
+ );
+
+ /** Constructs a new <code>SCOProcessor</code> without specific
+ * parameters. Initializes processors maps.
+ */
+ private SCOProcessor() {
+ /**
+ * Processors for SCO-related requests.
+ */
+ CollectionProcessor _collectionProcessor = new CollectionProcessor();
+ MapProcessor _mapProcessor = new MapProcessor();
+ DateProcessor _dateProcessor = new DateProcessor();
+
+ // Non-SCO mappings.
+ processors.put(java.util.Date.class, _dateProcessor);
+ processors.put(java.sql.Date.class, _dateProcessor);
+ processors.put(java.sql.Time.class, _dateProcessor);
+ processors.put(java.sql.Timestamp.class, _dateProcessor);
+
+ processors.put(java.util.ArrayList.class, _collectionProcessor);
+ processors.put(java.util.Vector.class, _collectionProcessor);
+ processors.put(java.util.HashSet.class, _collectionProcessor);
+ processors.put(java.util.LinkedList.class, _collectionProcessor);
+ processors.put(java.util.TreeSet.class, _collectionProcessor);
+
+ processors.put(java.util.HashMap.class, _mapProcessor);
+ processors.put(java.util.Hashtable.class, _mapProcessor);
+ processors.put(java.util.TreeMap.class, _mapProcessor);
+
+ // SCO mappings.
+ scoprocessors.put(org.apache.jdo.impl.sco.Date.class, _dateProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.SqlDate.class, _dateProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.SqlTime.class, _dateProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.SqlTimestamp.class, _dateProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.ArrayList.class,
+ _collectionProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.Vector.class,
+ _collectionProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.HashSet.class,
+ _collectionProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.LinkedList.class,
+ _collectionProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.TreeSet.class,
+ _collectionProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.HashMap.class, _mapProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.Hashtable.class, _mapProcessor);
+ scoprocessors.put(org.apache.jdo.impl.sco.TreeMap.class, _mapProcessor);
+ }
+
+ /**
+ * Get the SCOProcessor singleton instance.
+ * @return an instance of SCOProcessor
+ */
+ public static SCOProcessor getInstance()
+ {
+ return singleton;
+ }
+
+ /**
+ * Process requests to trackUpdates for SCO changes.
+ * @param sm - StateManagerImpl instance that requested processing.
+ * @param field the field number associated with this SCO.
+ * @param sco Object to process.
+ */
+ void trackUpdates (StateManagerImpl sm, int field, SCO sco) {
+ Processor p = (Processor) scoprocessors.get(sco.getClass());
+ p.trackUpdates(sm, field, sco);
+ }
+
+ /**
+ * Process requests to create a tracked SCO instance for the corresponding
+ * JDK SCO.
+ * @param o Object to be replaced with tracked SCO instance.
+ * @param jdoField the JDOField associated with this number.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ */
+ SCO getSCOField(Object o, JDOField jdoField,
+ PersistenceManagerInternal pm) {
+ if (o != null) {
+ Processor p = (Processor) processors.get(o.getClass());
+ if (p != null) {
+ return p.getSCOField(o, jdoField, pm);
+ }
+ }
+ return null;
+ }
+
+ /** Assert element type of an SCO Collection or key and value types
+ * of an SCO Map.
+ * @param o Object to be tested.
+ * @param jdoField the corresponding JDOField element.
+ * @throws JDOUserException if assertion fails.
+ */
+ void assertSCOElementType(Object o, JDOField jdoField) {
+ if (o != null) {
+ Processor p = (Processor) scoprocessors.get(o.getClass());
+ if (p != null) {
+ p.assertSCOElementType(o, jdoField);
+ }
+ }
+ }
+
+ /** An abstract class that knows how process SCO-related requests.
+ */
+ abstract class Processor {
+ /** Makes newly added instances to an SCO Collection auto-persistent
+ * and fixes ownership on referenced SCO instances.
+ * @param sm - StateManagerImpl instance that requested processing.
+ * @param field the field number associated with this SCO.
+ * @param sco Object to process.
+ */
+ abstract void trackUpdates(StateManagerImpl sm, int field, SCO sco);
+
+ /**
+ * Replace field reference that contain java.util SCO instances
+ * with tracked SCOs. No recursion is performed on this operation.
+ * @param o Object to be replaced with tracked SCO instance.
+ * @param jdoField the JDOField associated with this number.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ */
+ abstract SCO getSCOField(Object o, JDOField jdoField,
+ PersistenceManagerInternal pm);
+
+ /** Assert element type of an SCO Collection or key and value types
+ * of an SCO Map.
+ * @param o Object to be tested.
+ * @param jdoField the corresponding JDOField element.
+ * @throws JDOUserException if assertion fails.
+ */
+ abstract void assertSCOElementType(Object o, JDOField jdoField);
+ }
+
+ /** Processor for trackUpdates request for SCODate.
+ */
+ class DateProcessor extends Processor {
+ /** Makes newly added instances to an SCO Collection auto-persistent
+ * and fixes ownership on referenced SCO instances. No-op for Date.
+ * @param sm - StateManagerImpl instance that requested processing.
+ * @param field the field number associated with this SCO.
+ * @param sco Object to process.
+ */
+ void trackUpdates(StateManagerImpl sm, int field, SCO sco) {}
+
+ /**
+ * Replace field reference that contain java.util SCO instances
+ * with tracked SCOs. No recursion is performed on this operation.
+ * @param o Object to be replaced with tracked SCO instance.
+ * @param jdoField the JDOField associated with this number.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ */
+ SCO getSCOField(Object o, JDOField jdoField,
+ PersistenceManagerInternal pm) {
+ SCODate sco = (SCODate)pm.newSCOInstanceInternal(o.getClass());
+ sco.setTimeInternal(((Date)o).getTime());
+ if (java.sql.Timestamp.class.isInstance(o)) {
+ int n = ((java.sql.Timestamp)o).getNanos();
+ ((SqlTimestamp)sco).setNanosInternal(n);
+ }
+ return sco;
+ }
+
+ /** Assert element type of an SCO Collection or key and value types
+ * of an SCO Map. No-op for SCODate.
+ * @param o Object to be tested.
+ * @param jdoField the corresponding JDOField element.
+ * @throws JDOUserException if assertion fails.
+ */
+ void assertSCOElementType(Object o, JDOField jdoField) {}
+ }
+
+ /** Processor for trackUpdates request for SCOCollection.
+ */
+ class CollectionProcessor extends Processor {
+
+ /** Makes newly added instances to an SCO Collection auto-persistent
+ * and fixes ownership on referenced SCO instances.
+ * @param sm - StateManagerImpl instance that requested processing.
+ * @param field the field number associated with this SCO.
+ * @param sco Object to process.
+ */
+ void trackUpdates(StateManagerImpl sm, int field, SCO sco) {
+ // We are interested in the added list for possible autoPersistence
+ // transitions. Both added and removed lists are verified if owners
+ // of referenced SCO instances should be fixed.
+ SCOCollection c = (SCOCollection)sco;
+ Collection added = c.getAdded();
+ Collection removed = c.getRemoved();
+
+ if (added != null) {
+ sm.makeAutoPersistent(added.toArray());
+ sm.resetOwner(added.toArray(), field, true);
+ }
+ if (removed != null) {
+ sm.resetOwner(removed.toArray(), field, false);
+ }
+ // Clear added and removed lists
+ c.reset();
+ }
+
+ /**
+ * Replace field reference that contain java.util SCO instances
+ * with tracked SCOs. No recursion is performed on this operation.
+ * @param o Object to be replaced with tracked SCO instance.
+ * @param jdoField the JDOField associated with this number.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ */
+ SCO getSCOField(Object o, JDOField jdoField,
+ PersistenceManagerInternal pm) {
+ Comparator cr = null;
+ Class el = null;
+ boolean allowNulls = true;
+
+ Collection c = (Collection)o;
+ Object rl = jdoField.getRelationship();
+ if (rl != null && rl instanceof JDOCollection) {
+ el = javaModelFactory.getJavaClass(((JDOCollection)rl).
+ getElementType());
+ }
+
+ // If it is a sorted set check for comparator:
+ if (java.util.SortedSet.class.isInstance(c)) {
+ cr = ((SortedSet)c).comparator();
+ }
+
+ // RESOLVE: allowNulls...
+ return (SCO) pm.newCollectionInstanceInternal(
+ c.getClass(), ((el == null)? Object.class : el), allowNulls,
+ new Integer(c.size()), null, c, cr);
+ }
+
+ /** Assert element type of an SCO Collection.
+ * @param o Object to be tested.
+ * @param jdoField the corresponding JDOField element.
+ * @throws JDOUserException if assertion fails.
+ */
+ void assertSCOElementType(Object o, JDOField jdoField) {
+ Class c = ((SCOCollection)o).getElementType();
+
+ Class el = null;
+ Object rl = jdoField.getRelationship();
+ if (rl != null && rl instanceof JDOCollection) {
+ el = javaModelFactory.getJavaClass(((JDOCollection)rl).
+ getElementType());
+ }
+
+ if (el != null && !(el.isAssignableFrom(c))) {
+ throw new JDOUserException(msg.msg(
+ "EXC_WrongElementType", // NOI18N
+ c.getName(), el.getName()));
+ }
+ }
+ }
+
+ /** Processor for trackUpdates request for SCOMap.
+ */
+ class MapProcessor extends Processor {
+
+ /** Makes newly added instances to an SCO Map auto-persistent
+ * and fixes ownership on referenced SCO instances.
+ * @param sm - StateManagerImpl instance that requested processing.
+ * @param field the field number associated with this SCO.
+ * @param sco Object to process.
+ */
+ void trackUpdates(StateManagerImpl sm, int field, SCO sco) {
+ // We are interested in the added lists for possible autoPersistence
+ // transitions. Both added and removed lists are verified if owners
+ // of referenced SCO instances should be fixed for keys and values.
+ SCOMap m = (SCOMap)sco;
+ Collection addedKeys = m.getAddedKeys();
+ Collection addedValues = m.getAddedValues();
+ Collection removedKeys = m.getRemovedKeys();
+ Collection removedValues = m.getRemovedValues();
+
+ if (addedKeys != null) {
+ sm.makeAutoPersistent(addedKeys.toArray());
+ sm.resetOwner(addedKeys.toArray(), field, true);
+ }
+ if (addedValues != null) {
+ sm.makeAutoPersistent(addedValues.toArray());
+ sm.resetOwner(addedValues.toArray(), field, true);
+ }
+ if (removedKeys != null) {
+ sm.resetOwner(removedKeys.toArray(), field, false);
+ }
+ if (removedValues != null) {
+ sm.resetOwner(removedValues.toArray(), field, false);
+ }
+ // Clear added and removed lists
+ m.reset();
+ }
+
+ /**
+ * Replace field reference that contain java.util SCO instances
+ * with tracked SCOs. No recursion is performed on this operation.
+ * @param o Object to be replaced with tracked SCO instance.
+ * @param jdoField the JDOField associated with this number.
+ * @param pm the PersistenceManagerInternal instance associated with the
+ * caller.
+ */
+ SCO getSCOField(Object o, JDOField jdoField,
+ PersistenceManagerInternal pm) {
+ Comparator cr = null;
+ boolean allowNulls = true;
+
+ Map m = (Map)o;
+
+ // If it is a sorted set check for comparator:
+ if (java.util.SortedMap.class.isInstance(m)) {
+ cr = ((SortedMap)m).comparator();
+ }
+
+ // Key/value types:
+ Class el = null;
+ Class k = null;
+ Object rl = jdoField.getRelationship();
+ if (rl != null && rl instanceof JDOMap) {
+ el = javaModelFactory.getJavaClass(((JDOMap)rl).getValueType());
+ k = javaModelFactory.getJavaClass(((JDOMap)rl).getKeyType());
+ }
+
+ // RESOLVE: allowNulls...
+ return (SCOMap) pm.newMapInstanceInternal(
+ m.getClass(), ((k == null)? Object.class :k),
+ ((el == null)? Object.class : el), allowNulls,
+ new Integer(m.size()), null, m, cr);
+ }
+
+ /** Assert key and value type of an SCO Map.
+ * @param o Object to be tested.
+ * @param jdoField the corresponding JDOField element.
+ * @throws JDOUserException if assertion fails.
+ */
+ void assertSCOElementType(Object o, JDOField jdoField) {
+ SCOMap m = (SCOMap)o;
+ Object rl = jdoField.getRelationship();
+ if (rl != null && rl instanceof JDOMap) {
+ JDOMap rm = (JDOMap) rl;
+
+ Class c = m.getValueType();
+ Class el = javaModelFactory.getJavaClass(rm.getValueType());
+
+ if (el != null && !(el.isAssignableFrom(c))) {
+ throw new JDOUserException(msg.msg(
+ "EXC_WrongValueType", // NOI18N
+ c.getName(), el.getName()));
+ }
+
+ c = m.getKeyType();
+ el = javaModelFactory.getJavaClass(rm.getKeyType());
+
+ if (el != null && !(el.isAssignableFrom(c))) {
+ throw new JDOUserException(msg.msg(
+ "EXC_WrongKeyType", // NOI18N
+ c.getName(), el.getName()));
+ }
+ }
+ }
+
+ }
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SimpleFieldManager.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SimpleFieldManager.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SimpleFieldManager.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/SimpleFieldManager.java Sun May 22 11:01:45 2005
@@ -0,0 +1,212 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.impl.state;
+
+import org.apache.jdo.state.FieldManager;
+
+
+/**
+ * This is the means by which a StateManager implementation's *
+ * setXXXField() method (where XXX is e.g. Int) can give the value *
+ * back to the object. This simple implementation does not do
+ * fieldNumber validation between store and fetch operations. I.e. it
+ * does not check, whether the field numbers in corresponding store
+ * and fetch calls are the same.
+ *
+ * @author Marina Vatkina
+ */
+public class SimpleFieldManager implements FieldManager {
+
+ private boolean booleanValue = false;
+
+ private char charValue = 0;
+
+ private byte byteValue = 0;
+
+ private short shortValue = 0;
+
+ private int intValue = 0;
+
+ private long longValue = 0;
+
+ private float floatValue = 0;
+
+ private double doubleValue = 0;
+
+ private String stringValue = null;
+
+ private Object objectValue = null;
+
+ /**
+ * Provides the means by which the value of a boolean field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Boolean that is the value of a particular field.
+ */
+ public void storeBooleanField(int fieldNum, boolean value) {
+ booleanValue = value;
+ }
+
+ public boolean fetchBooleanField(int fieldNum) {
+ return booleanValue;
+ }
+
+ /**
+ * Provides the means by which the value of a char field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Char that is the value of a particular field.
+ */
+ public void storeCharField(int fieldNum, char value){
+ charValue = value;
+ }
+
+ public char fetchCharField(int fieldNum) {
+ return charValue;
+ }
+
+ /**
+ * Provides the means by which the value of a byte field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Byte that is the value of a particular field.
+ */
+ public void storeByteField(int fieldNum, byte value){
+ byteValue = value;
+ }
+
+
+ public byte fetchByteField(int fieldNum) {
+ return byteValue;
+ }
+
+ /**
+ * Provides the means by which the value of a short field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Short that is the value of a particular field.
+ */
+ public void storeShortField(int fieldNum, short value){
+ shortValue = value;
+ }
+
+
+ public short fetchShortField(int fieldNum) {
+ return shortValue;
+ }
+
+ /**
+ * Provides the means by which the value of a int field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Int that is the value of a particular field.
+ */
+ public void storeIntField(int fieldNum, int value){
+ intValue = value;
+ }
+
+
+ public int fetchIntField(int fieldNum) {
+ return intValue;
+ }
+
+ /**
+ * Provides the means by which the value of a long field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Long that is the value of a particular field.
+ */
+ public void storeLongField(int fieldNum, long value){
+ longValue = value;
+ }
+
+
+ public long fetchLongField(int fieldNum) {
+ return longValue;
+ }
+
+ /**
+ * Provides the means by which the value of a field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value that is the value of a particular field.
+ */
+ public void storeFloatField(int fieldNum, float value){
+ floatValue = value;
+ }
+
+
+ public float fetchFloatField(int fieldNum) {
+ return floatValue;
+ }
+
+ /**
+ * Provides the means by which the value of a double field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Double that is the value of a particular field.
+ */
+ public void storeDoubleField(int fieldNum, double value){
+ doubleValue = value;
+ }
+
+
+ public double fetchDoubleField(int fieldNum) {
+ return doubleValue;
+ }
+
+ /**
+ * Provides the means by which the value of a String field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value String that is the value of a particular field.
+ */
+ public void storeStringField(int fieldNum, String value){
+ stringValue = value;
+ }
+
+
+ public String fetchStringField(int fieldNum) {
+ return stringValue;
+ }
+
+ /**
+ * Provides the means by which the value of an Object field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Object that is the value of a particular field.
+ */
+ public void storeObjectField(int fieldNum, Object value){
+ objectValue = value;
+ }
+
+
+ public Object fetchObjectField(int fieldNum) {
+ return objectValue;
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateFieldManager.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateFieldManager.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateFieldManager.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateFieldManager.java Sun May 22 11:01:45 2005
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.impl.state;
+
+import org.apache.jdo.state.FieldManager;
+
+/**
+ * This is the means by which a StateManager implementation's setXXXField()
+ * method (where XXX is e.g. Int) can give the value back to the object
+ *
+ * @author Marina Vatkina
+ */
+class StateFieldManager implements FieldManager {
+
+ private boolean booleanValue = false;
+
+ private char charValue = 0;
+
+ private byte byteValue = 0;
+
+ private short shortValue = 0;
+
+ private int intValue = 0;
+
+ private long longValue = 0;
+
+ private float floatValue = 0;
+
+ private double doubleValue = 0;
+
+ private String stringValue = null;
+
+ private Object objectValue = null;
+
+ /**
+ * Provides the means by which the value of a boolean field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Boolean that is the value of a particular field.
+ */
+ public void storeBooleanField(int fieldNum, boolean value) {
+ booleanValue = value;
+ }
+
+ public boolean fetchBooleanField(int fieldNum) {
+ return booleanValue;
+ }
+
+ /**
+ * Provides the means by which the value of a char field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Char that is the value of a particular field.
+ */
+ public void storeCharField(int fieldNum, char value){
+ charValue = value;
+ }
+
+ public char fetchCharField(int fieldNum) {
+ return charValue;
+ }
+
+ /**
+ * Provides the means by which the value of a byte field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Byte that is the value of a particular field.
+ */
+ public void storeByteField(int fieldNum, byte value){
+ byteValue = value;
+ }
+
+
+ public byte fetchByteField(int fieldNum) {
+ return byteValue;
+ }
+
+ /**
+ * Provides the means by which the value of a short field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Short that is the value of a particular field.
+ */
+ public void storeShortField(int fieldNum, short value){
+ shortValue = value;
+ }
+
+
+ public short fetchShortField(int fieldNum) {
+ return shortValue;
+ }
+
+ /**
+ * Provides the means by which the value of a int field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Int that is the value of a particular field.
+ */
+ public void storeIntField(int fieldNum, int value){
+ intValue = value;
+ }
+
+
+ public int fetchIntField(int fieldNum) {
+ return intValue;
+ }
+
+ /**
+ * Provides the means by which the value of a long field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Long that is the value of a particular field.
+ */
+ public void storeLongField(int fieldNum, long value){
+ longValue = value;
+ }
+
+
+ public long fetchLongField(int fieldNum) {
+ return longValue;
+ }
+
+ /**
+ * Provides the means by which the value of a field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value that is the value of a particular field.
+ */
+ public void storeFloatField(int fieldNum, float value){
+ floatValue = value;
+ }
+
+
+ public float fetchFloatField(int fieldNum) {
+ return floatValue;
+ }
+
+ /**
+ * Provides the means by which the value of a double field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Double that is the value of a particular field.
+ */
+ public void storeDoubleField(int fieldNum, double value){
+ doubleValue = value;
+ }
+
+
+ public double fetchDoubleField(int fieldNum) {
+ return doubleValue;
+ }
+
+ /**
+ * Provides the means by which the value of a String field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value String that is the value of a particular field.
+ */
+ public void storeStringField(int fieldNum, String value){
+ stringValue = value;
+ }
+
+
+ public String fetchStringField(int fieldNum) {
+ return stringValue;
+ }
+
+ /**
+ * Provides the means by which the value of an Object field can be given
+ * by a StateManager to an object that needs the value.
+ * @param fieldNum Field number of the field in the object whose value is
+ * given.
+ * @param value Object that is the value of a particular field.
+ */
+ public void storeObjectField(int fieldNum, Object value){
+ objectValue = value;
+ }
+
+
+ public Object fetchObjectField(int fieldNum) {
+ return objectValue;
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateManagerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateManagerFactory.java?rev=171352&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateManagerFactory.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/state/StateManagerFactory.java Sun May 22 11:01:45 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * StateManagerFactory.java
+ *
+ * Created on August 3, 2001
+ */
+
+package org.apache.jdo.impl.state;
+
+import javax.jdo.spi.PersistenceCapable;
+
+import org.apache.jdo.pm.PersistenceManagerInternal;
+import org.apache.jdo.state.StateManagerInternal;
+
+/**
+ * This class is responsible for creation of new instances of a StateManagerInternal.
+ * Called by CacheManagerImpl on call to makePersistent a Transient istance, or as a
+ * result of a StoreManager request to process query or navigation.
+ *
+ * @author mvatkina
+ * @version 1.0
+ */
+public class StateManagerFactory {
+
+ /**
+ * Returns a new instance of a StateManagerInternal
+ * @param pc instance of PersistenceCapable
+ * @param pm instance of PersistenceManagerInternal associated with this request
+ */
+ public static StateManagerInternal newInstance(PersistenceCapable pc,
+ PersistenceManagerInternal pm) {
+ StateManagerImpl sm = new StateManagerImpl(pc, pm);
+ return (StateManagerInternal)sm;
+ }
+
+
+ /**
+ * Returns a new instance of a StateManagerInternal. Called by the StoreManager
+ * to process query results.
+ * @param userOid User provided Object Id
+ * @param internalOid Object Id that can be used internally
+ * @param pm instance of PersistenceManagerInternal associated with this request
+ * @param clazz Class type for the PersistenceCapable to be created
+ */
+ public static StateManagerInternal newInstance(Object userOid, Object internalOid,
+ PersistenceManagerInternal pm, Class clazz) {
+ StateManagerImpl sm = new StateManagerImpl(userOid, internalOid, pm, clazz);
+ return (StateManagerInternal)sm;
+ }
+
+}