01: package org.andromda.cartridges.ejb.metafacades;
02:
03: import org.andromda.cartridges.ejb.EJBProfile;
04: import org.andromda.metafacades.uml.ParameterFacade;
05: import org.apache.commons.lang.StringUtils;
06:
07: import java.util.Collection;
08: import java.util.Iterator;
09:
10: /**
11: * <p/>
12: * Represents an EJB finder method. </p> Metaclass facade implementation.
13: */
14: public class EJBFinderMethodFacadeLogicImpl extends
15: EJBFinderMethodFacadeLogic {
16: // ---------------- constructor -------------------------------
17:
18: public EJBFinderMethodFacadeLogicImpl(java.lang.Object metaObject,
19: String context) {
20: super (metaObject, context);
21: }
22:
23: protected java.lang.String handleGetQuery() {
24:
25: // first see if there is a query stored as a constraint
26: String queryString = super .getQuery("query.EJB-QL");
27:
28: // otherwise see if there is a query stored as a tagged value
29: if (StringUtils.isEmpty(queryString)) {
30: Object value = this
31: .findTaggedValue(EJBProfile.TAGGEDVALUE_EJB_QUERY);
32: queryString = (String) value;
33: if (queryString != null) {
34: // remove any excess whitespace
35: queryString = queryString.replaceAll("[$\\s]+", " ");
36: }
37: }
38:
39: // if there wasn't any stored query, create one by default.
40: if (StringUtils.isEmpty(queryString)) {
41: String variableName = StringUtils.uncapitalize(this
42: .getOwner().getName());
43: queryString = "SELECT DISTINCT OBJECT(" + variableName
44: + ") FROM " + this .getOwner().getName() + " as "
45: + variableName;
46: if (this .getArguments().size() > 0) {
47: queryString = queryString + " WHERE";
48: Collection parameters = this .getArguments();
49: if (parameters != null && !parameters.isEmpty()) {
50: Iterator parameterIt = parameters.iterator();
51: for (int ctr = 1; parameterIt.hasNext(); ctr++) {
52: Object test = parameterIt.next();
53: ParameterFacade param = (ParameterFacade) test;
54: queryString = queryString + " " + variableName
55: + "." + param.getName() + " = ?" + ctr;
56: if (parameterIt.hasNext()) {
57: queryString = queryString + " AND";
58: }
59: }
60: }
61: }
62: }
63: return queryString;
64: }
65:
66: /**
67: * @see org.andromda.cartridges.ejb.metafacades.EJBFinderMethodFacade#getTransactionType()
68: */
69: protected java.lang.String handleGetTransactionType() {
70: return (String) this .findTaggedValue(
71: EJBProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE, true);
72: }
73:
74: }
|