01: /*
02: * Copyright (c) 2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: */
17:
18: package org.jpublish.module.cayenne;
19:
20: import com.anthonyeden.lib.config.Configuration;
21: import org.apache.cayenne.access.DataContext;
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.jpublish.JPublishContext;
25:
26: import java.util.Collection;
27: import java.util.Iterator;
28:
29: /**
30: * Action executed after a request was fulfilled and the page rendered. There will be
31: * no page context at the time of executing this Action.
32: *
33: * @author <a href="mailto:florin.patrascu@gmail.com">Florin T.PATRASCU</a>
34: * @since $Revision$ (created: Sep 23, 2007 2:45:20 PM)
35: */
36: public class CayenneSupportAfterAction extends CayenneSupportAction {
37: protected static final Log log = LogFactory
38: .getLog(CayenneSupportAfterAction.class);
39:
40: public CayenneSupportAfterAction(JPCayenneModule jpCayenneModule) {
41: super (jpCayenneModule);
42: }
43:
44: /**
45: * Execute the action using the given context.
46: *
47: * @param context The current context
48: * @param configuration The configuration
49: * @throws Exception Any error
50: */
51: public void execute(JPublishContext context,
52: Configuration configuration) throws Exception {
53: DataContext dc = (DataContext) context.getRequest()
54: .getAttribute(JPCayenneModule.JPCAYENNE_DATA_CONTEXT);
55:
56: if (dc != null) {
57: if (jpCayenneModule.isDebugEnabled() && dc.hasChanges()) {
58: log.info("[DEBUG] Uncommitted data objects:");
59:
60: Collection uncommitted = dc.uncommittedObjects();
61: for (Iterator i = uncommitted.iterator(); i.hasNext();) {
62: log.info("[DEBUG] " + i.next());
63: }
64: }
65:
66: if (jpCayenneModule.isAutoRollback()) {
67: dc.rollbackChanges();
68: }
69:
70: DataContext.bindThreadDataContext(null);
71: }
72: }
73: }
|