001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.server.j2ee.repository;
046:
047: import org.apache.commons.logging.Log;
048: import org.apache.commons.logging.LogFactory;
049: import org.obe.OBERuntimeException;
050: import org.obe.client.api.repository.RepositoryException;
051: import org.obe.server.j2ee.ejb.AbstractEntityEJB;
052: import org.obe.server.util.ObjectUtil;
053: import org.obe.spi.service.ServerConfig;
054: import org.wfmc.audit.WMAAuditEntry;
055: import org.wfmc.audit.WMAEventCode;
056: import org.wfmc.wapi.WMFilter;
057: import org.wfmc.wapi.WMProcessInstanceState;
058:
059: import javax.ejb.CreateException;
060: import java.io.IOException;
061: import java.sql.SQLException;
062: import java.util.Date;
063:
064: /**
065: * Used to perform non-transactional audit logging.
066: *
067: * @author Adrian Price
068: * @ejb:bean type="CMP"
069: * cmp-version="2.x"
070: * name="AuditEntry"
071: * display-name="OBE Audit Entry"
072: * local-jndi-name="org/obe/ejb/AuditEntryLocal"
073: * primkey-field="auditId"
074: * reentrant="False"
075: * schema="AUDITENTRY"
076: * transaction-type="Container"
077: * view-type="local"
078: * @ejb:home local-class="org.obe.server.j2ee.audit.AuditEntryLocalHome"
079: * local-extends="javax.ejb.EJBLocalHome"
080: * @ejb:interface local-class="org.obe.server.j2ee.audit.AuditEntryLocal"
081: * local-extends="javax.ejb.EJBLocalObject"
082: * @ejb:persistence table-name="OBEAUDITENTRY"
083: * @ejb:pk class="java.lang.Long"
084: * unchecked="true"
085: * @ejb:permission unchecked="true"
086: * @ejb:transaction type="Supports"
087: * @weblogic:transaction-isolation ${transaction.isolation}
088: * @ejb:resource-ref res-name="jdbc/TxDataSource"
089: * res-type="javax.sql.DataSource"
090: * res-auth="Container"
091: * @jboss:resource-manager res-man-class="javax.sql.DataSource"
092: * res-man-name="jdbc/TxDataSource"
093: * res-man-jndi-name="java:/${xdoclet.DataSource}"
094: * @weblogic:resource-description res-ref-name="jdbc/TxDataSource"
095: * jndi-name="${xdoclet.DataSource}"
096: * @weblogic:data-source-name java:comp/env/jdbc/TxDataSource
097: * @jboss:create-table false
098: * @weblogic:pool max-beans-in-free-pool="10"
099: * initial-beans-in-free-pool="0"
100: * @weblogic:cache max-beans-in-cache="10"
101: * idle-timeout-seconds="0"
102: * concurrency-strategy="Database"
103: * @weblogic:persistence delay-updates-until-end-of-tx="True"
104: * @jboss:tuned-updates tune="false"
105: * @jboss:container-configuration name="${xdoclet.jboss.container-configuration}"
106: * @jboss:cache-invalidation value="True"
107: * @jboss:cache-invalidation-config invalidation-group-name="AuditEntry"
108: */
109: public abstract class AuditEntryEJB extends AbstractEntityEJB {
110: private static final long serialVersionUID = 6451902064891238641L;
111: private static final Log _logger = LogFactory
112: .getLog(AuditEntryEJB.class);
113:
114: public AuditEntryEJB() {
115: }
116:
117: // TODO: ejbc can't recognize the corresponding home.create() method!
118: // * @ejb:transaction type="RequiresNew"
119:
120: /**
121: * @ejb:create-method
122: */
123: public Long ejbCreate(WMAAuditEntry entry) throws CreateException {
124: if (_logger.isDebugEnabled() && ServerConfig.isVerbose()) {
125: _logger.debug("ejbCreate(" + entry + ')');
126: }
127: setAuditId(new Long(AuditEntryDAO.getInstance().getNewId()));
128: setProcessDefinitionId(entry.getProcessDefinitionId());
129: setActivityDefinitionId(entry.getActivityDefinitionId());
130: setInitialProcessInstanceId(entry.getInitialProcessInstanceId());
131: setCurrentProcessInstanceId(entry.getCurrentProcessInstanceId());
132: setActivityInstanceId(entry.getActivityInstanceId());
133: setWorkItemId(entry.getWorkItemId());
134: setProcessState(entry.getProcessState());
135: setEventCode(entry.getEventCode());
136: setDomainId(entry.getDomainId());
137: setNodeId(entry.getNodeId());
138: setUserId(entry.getUserId());
139: setRoleId(entry.getRoleId());
140: setTimestamp(entry.getTimestamp());
141: setAuditEntry(entry);
142:
143: return null;
144: }
145:
146: public void ejbPostCreate(WMAAuditEntry entry)
147: throws CreateException {
148: if (_logger.isDebugEnabled() && ServerConfig.isVerbose()) {
149: _logger.debug("ejbPostCreate() pk=" + getAuditId());
150: }
151: }
152:
153: /**
154: * Finds the audit entries matching a user-supplied criterion.
155: *
156: * @param filter Filter criterion.
157: * @return The matching audit records.
158: * @throws RepositoryException If the filter type is unsupported.
159: * @ejb:home-method
160: */
161: public WMAAuditEntry[] ejbHomeXfindByFilter(WMFilter filter)
162: throws RepositoryException {
163:
164: try {
165: return AuditEntryDAO.getInstance().findByFilter(filter);
166: } catch (SQLException e) {
167: throw new OBERuntimeException(e);
168: }
169: }
170:
171: /**
172: * Finds the audit entries matching a user-supplied criterion.
173: *
174: * @param filter Filter criterion.
175: * @return The matching audit records.
176: * @throws RepositoryException If the filter type is unsupported.
177: * @ejb:home-method
178: */
179: public int ejbHomeDeleteByFilter(WMFilter filter)
180: throws RepositoryException {
181:
182: try {
183: return AuditEntryDAO.getInstance().deleteByFilter(filter);
184: } catch (SQLException e) {
185: throw new OBERuntimeException(e);
186: }
187: }
188:
189: /**
190: * @ejb:persistence column-name="AUDITENTRYID"
191: */
192: public abstract Long getAuditId();
193:
194: /**
195: * @ejb:persistence column-name="AUDITENTRYID"
196: */
197: public abstract void setAuditId(Long id);
198:
199: /**
200: * @ejb:persistence column-name="PROCESSDEFINITIONID"
201: */
202: public abstract String getProcessDefinitionId();
203:
204: /**
205: * @ejb:persistence column-name="PROCESSDEFINITIONID"
206: */
207: public abstract void setProcessDefinitionId(String procDefId);
208:
209: /**
210: * @ejb:persistence column-name="ACTIVITYDEFINITIONID"
211: */
212: public abstract String getActivityDefinitionId();
213:
214: /**
215: * @ejb:persistence column-name="ACTIVITYDEFINITIONID"
216: */
217: public abstract void setActivityDefinitionId(String actDefId);
218:
219: /**
220: * @ejb:persistence column-name="INITIALPROCESSINSTANCEID"
221: */
222: public abstract String getInitialProcessInstanceId();
223:
224: /**
225: * @ejb:persistence column-name="INITIALPROCESSINSTANCEID"
226: */
227: public abstract void setInitialProcessInstanceId(
228: String initProcInstId);
229:
230: /**
231: * @ejb:persistence column-name="CURRENTPROCESSINSTANCEID"
232: */
233: public abstract String getCurrentProcessInstanceId();
234:
235: /**
236: * @ejb:persistence column-name="CURRENTPROCESSINSTANCEID"
237: */
238: public abstract void setCurrentProcessInstanceId(
239: String curProcInstId);
240:
241: /**
242: * @ejb:persistence column-name="ACTIVITYINSTANCEID"
243: */
244: public abstract String getActivityInstanceId();
245:
246: /**
247: * @ejb:persistence column-name="ACTIVITYINSTANCEID"
248: */
249: public abstract void setActivityInstanceId(String actInstId);
250:
251: /**
252: * @ejb:persistence column-name="WORKITEMID"
253: */
254: public abstract String getWorkItemId();
255:
256: /**
257: * @ejb:persistence column-name="WORKITEMID"
258: */
259: public abstract void setWorkItemId(String workItemId);
260:
261: /**
262: * @ejb:persistence column-name="PROCESSSTATE"
263: */
264: public abstract Integer getProcessStateCmp();
265:
266: /**
267: * @ejb:persistence column-name="PROCESSSTATE"
268: */
269: public abstract void setProcessStateCmp(Integer procInstState);
270:
271: /**
272: * @ejb:persistence column-name="EVENT"
273: */
274: public abstract int getEventCodeCmp();
275:
276: /**
277: * @ejb:persistence column-name="EVENT"
278: */
279: public abstract void setEventCodeCmp(int eventCode);
280:
281: /**
282: * @ejb:persistence column-name="DOMAINID"
283: */
284: public abstract String getDomainId();
285:
286: /**
287: * @ejb:persistence column-name="DOMAINID"
288: */
289: public abstract void setDomainId(String domainId);
290:
291: /**
292: * @ejb:persistence column-name="NODEID"
293: */
294: public abstract String getNodeId();
295:
296: /**
297: * @ejb:persistence column-name="NODEID"
298: */
299: public abstract void setNodeId(String nodeId);
300:
301: /**
302: * @ejb:persistence column-name="USERID"
303: */
304: public abstract String getUserId();
305:
306: /**
307: * @ejb:persistence column-name="USERID"
308: */
309: public abstract void setUserId(String userId);
310:
311: /**
312: * @ejb:persistence column-name="ROLEID"
313: */
314: public abstract String getRoleId();
315:
316: /**
317: * @ejb:persistence column-name="ROLEID"
318: */
319: public abstract void setRoleId(String roleId);
320:
321: /**
322: * @ejb:persistence column-name="AUDITDATE"
323: */
324: public abstract Date getTimestamp();
325:
326: /**
327: * @ejb:persistence column-name="AUDITDATE"
328: */
329: public abstract void setTimestamp(Date timestamp);
330:
331: /**
332: * @ejb:persistence column-name="AUDITENTRY"
333: */
334: public abstract byte[] getAuditEntryCmp();
335:
336: /**
337: * @ejb:persistence column-name="AUDITENTRY"
338: */
339: public abstract void setAuditEntryCmp(byte[] serializedData);
340:
341: private void setAuditEntry(WMAAuditEntry entry) {
342: try {
343: setAuditEntryCmp(ObjectUtil.serializeToByteArray(entry));
344: } catch (IOException e) {
345: throw new OBERuntimeException(e);
346: }
347: }
348:
349: public String getProcessState() {
350: Integer processState = getProcessStateCmp();
351: return processState == null ? null : WMProcessInstanceState
352: .valueOf(processState.intValue()).toString();
353: }
354:
355: public void setProcessState(String processState) {
356: setProcessStateCmp(processState == null ? null : new Integer(
357: WMProcessInstanceState.valueOf(processState).value()));
358: }
359:
360: public WMAEventCode getEventCode() {
361: return WMAEventCode.valueOf(getEventCodeCmp());
362: }
363:
364: public void setEventCode(WMAEventCode eventCode) {
365: setEventCodeCmp((eventCode == null ? WMAEventCode.UNKNOWN
366: : eventCode).value());
367: }
368:
369: protected Log getLogger() {
370: return _logger;
371: }
372: }
|