1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.openjpa.kernel;
20
21 /**
22 * Lifecycle state.
23 * Represents an instance that was made persistent within the
24 * current transaction.
25 *
26 * @author Abe White
27 */
28 class PNewState
29 extends PCState {
30
31 void initialize(StateManagerImpl context) {
32 context.setLoaded(true);
33 context.setDirty(true);
34 context.saveFields(false);
35 }
36
37 void beforeFlush(StateManagerImpl context, boolean logical,
38 OpCallbacks call) {
39 context.preFlush(logical, call);
40 }
41
42 PCState commit(StateManagerImpl context) {
43 return HOLLOW;
44 }
45
46 PCState commitRetain(StateManagerImpl context) {
47 return PNONTRANS;
48 }
49
50 PCState rollback(StateManagerImpl context) {
51 return TRANSIENT;
52 }
53
54 PCState rollbackRestore(StateManagerImpl context) {
55 context.restoreFields();
56 return TRANSIENT;
57 }
58
59 PCState delete(StateManagerImpl context) {
60 context.preDelete();
61 if (context.isFlushed())
62 return PNEWFLUSHEDDELETED;
63 return PNEWDELETED;
64 }
65
66 PCState nontransactional(StateManagerImpl context) {
67 return error("new", context);
68 }
69
70 PCState release(StateManagerImpl context) {
71 return error("new", context);
72 }
73
74 boolean isVersionCheckRequired(StateManagerImpl context) {
75 return context.isFlushedDirty();
76 }
77
78 boolean isTransactional() {
79 return true;
80 }
81
82 boolean isPersistent() {
83 return true;
84 }
85
86 boolean isNew() {
87 return true;
88 }
89
90 boolean isDirty() {
91 return true;
92 }
93 }