001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.event;
020:
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.EventObject;
024:
025: import org.apache.openjpa.kernel.Broker;
026:
027: /**
028: * A transactional event. The event source is the {@link Broker} whose
029: * transaction state changed.
030: *
031: * @since 0.3.0
032: * @author Abe White
033: */
034: public class TransactionEvent extends EventObject {
035:
036: /**
037: * Event type signifying that a transaction has just begun.
038: */
039: public static final int AFTER_BEGIN = 0;
040:
041: /**
042: * Event type signifying that changes are about to be flushed to the
043: * datastore. This does not necessarily mean that a commit is taking place.
044: */
045: public static final int BEFORE_FLUSH = 1;
046:
047: /**
048: * Event type signifying that changes have been flushed to the datastore.
049: * This event is only fired if flushing is successful.
050: */
051: public static final int AFTER_FLUSH = 2;
052:
053: /**
054: * Event type signifying that the transaction is about to be committed.
055: * This will be fired before the {@link #BEFORE_FLUSH} event for the
056: * transaction, so that you can differentiate between flushes for commits
057: * and other flushes.
058: */
059: public static final int BEFORE_COMMIT = 3;
060:
061: /**
062: * Event type signifying that the transaction has committed.
063: */
064: public static final int AFTER_COMMIT = 4;
065:
066: /**
067: * Event type signifying that the transaction was rolled back.
068: */
069: public static final int AFTER_ROLLBACK = 5;
070:
071: /**
072: * Event type signifying that all state transitions have been made.
073: */
074: public static final int AFTER_STATE_TRANSITIONS = 6;
075:
076: /**
077: * Event type signifying that the commit has completey ended and the
078: * transaction is no longer active.
079: */
080: public static final int AFTER_COMMIT_COMPLETE = 7;
081:
082: /**
083: * Event type signifying that the rollback has completey ended and the
084: * transaction is no longer active.
085: */
086: public static final int AFTER_ROLLBACK_COMPLETE = 8;
087:
088: private final int _type;
089: private transient final Collection _objs;
090: private transient final Collection _addClss;
091: private transient final Collection _updateClss;
092: private transient final Collection _deleteClss;
093:
094: /**
095: * Constructor.
096: *
097: * @param broker the event source
098: * @param type the event type
099: * @param objs transactional objects
100: * @param addClss classes of added instances
101: * @param updateClss classes of updated instances
102: * @param deleteClss classes of deleted instances
103: */
104: public TransactionEvent(Broker broker, int type, Collection objs,
105: Collection addClss, Collection updateClss,
106: Collection deleteClss) {
107: super (broker);
108: _type = type;
109: _objs = (objs == null) ? Collections.EMPTY_LIST : objs;
110: _addClss = (addClss == null) ? Collections.EMPTY_SET : addClss;
111: _updateClss = (updateClss == null) ? Collections.EMPTY_SET
112: : updateClss;
113: _deleteClss = (deleteClss == null) ? Collections.EMPTY_SET
114: : deleteClss;
115: }
116:
117: /**
118: * Return the type of event.
119: */
120: public int getType() {
121: return _type;
122: }
123:
124: /**
125: * Return the unmodifiable set of persistence capable objects
126: * participating in the transaction. This set will contain all dirty
127: * objects, but may not contain clean objects.
128: */
129: public Collection getTransactionalObjects() {
130: return _objs;
131: }
132:
133: /**
134: * Return the unmodifiable the set of classes of
135: * persistence capable objects that were created in the transaction.
136: */
137: public Collection getPersistedTypes() {
138: return _addClss;
139: }
140:
141: /**
142: * Return the unmodifiable the set of classes of
143: * persistence capable objects that were modified in the transaction.
144: */
145: public Collection getUpdatedTypes() {
146: return _updateClss;
147: }
148:
149: /**
150: * Return the unmodifiable the set of classes of
151: * persistence capable objects that were deleted in the transaction.
152: */
153: public Collection getDeletedTypes() {
154: return _deleteClss;
155: }
156: }
|