View Javadoc
1   package org.andromda.cartridges.hibernate.metafacades;
2   
3   import org.andromda.metafacades.uml.ClassifierFacade;
4   
5   /**
6    * MetafacadeLogic implementation for
7    * org.andromda.cartridges.hibernate.metafacades.HibernateFinderMethodArgument.
8    *
9    * @see org.andromda.cartridges.hibernate.metafacades.HibernateFinderMethodArgument
10   */
11  public class HibernateFinderMethodArgumentLogicImpl
12      extends HibernateFinderMethodArgumentLogic
13  {
14      private static final long serialVersionUID = 34L;
15      // ---------------- constructor -------------------------------
16      /**
17       * @param metaObject
18       * @param context
19       */
20      public HibernateFinderMethodArgumentLogicImpl(
21          Object metaObject,
22          String context)
23      {
24          super(metaObject, context);
25      }
26  
27      /**
28       * Defines if specific setters methods will be created for primitive types
29       * and dates
30       */
31      private static final String USE_SPECIALIZED_SETTERS = "hibernateQueryUseSpecializedSetters";
32  
33      /**
34       * @see org.andromda.cartridges.hibernate.metafacades.HibernateFinderMethodArgument#getQueryArgumentNameSetter()
35       */
36      @Override
37      protected String handleGetQueryArgumentNameSetter()
38      {
39          StringBuilder setterName = new StringBuilder();
40          boolean specializedSetters =
41              Boolean.valueOf(String.valueOf(this.getConfiguredProperty(USE_SPECIALIZED_SETTERS))).booleanValue();
42          ClassifierFacade classifier = this.getType();
43          if (classifier != null)
44          {
45              if (specializedSetters)
46              {
47                  if (classifier.isPrimitive())
48                  {
49                      setterName.append("set").append(classifier.getWrapperName().replaceAll("(.)*\\.", ""));
50                  }
51                  else if (classifier.isDateType() || classifier.isStringType())
52                  {
53                      setterName.append("set").append(classifier.getName());
54                  }
55                  else
56                  {
57                      setterName.append("setParameter");
58                  }
59              }
60              else
61              {
62                  setterName.append("setParameter");
63              }
64              if (classifier.isCollectionType())
65              {
66                  setterName.append("List");
67              }
68          }
69          return setterName.toString();
70      }
71  }