1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.caleigo.core;
20
21
22 import org.caleigo.core.exception.*;
23 import org.caleigo.toolkit.log.*;
24
25
26 /*** <Description for AbstractDataAction>
27 *
28 * @author Dennis Zikovic
29 * @version 1.00
30 *
31 *//*
32 *
33 * WHEN WHO WHY & WHAT
34 * -----------------------------------------------------------------------------
35 * 2002-09-12 Dennis Zikovic Creation
36 */
37 public abstract class AbstractTransactionEntityAction extends AbstractEntityAction implements ITransactionEntityAction
38 {
39
40
41
42
43
44
45 /*** Creates a new instance of AbstractDataAction.
46 */
47 public AbstractTransactionEntityAction(IEntityDescriptor entityDescriptor, String codeName, String displayName)
48 {
49 super(entityDescriptor, codeName, displayName);
50 }
51
52 /*** Creates a new instance of AbstractDataAction.
53 */
54 public AbstractTransactionEntityAction(IEntityDescriptor entityDescriptor, String codeName, String displayName, String displayHint)
55 {
56 super(entityDescriptor, codeName, displayName, displayHint);
57 }
58
59
60
61 /*** Prepare method for the action where the action is expected to add
62 * the data operations needed to perform the action.
63 */
64 public abstract void prepareTransaction(IDataBundle data, IDataTransaction transaction);
65
66
67 /*** This method is called by the action objects constructor once and only
68 * once. The method is expected to define the action data requriments
69 * (IDataBundleDescriptor) using the diferent add methods for descriptors
70 * defined in this class.
71 */
72 public abstract void defineDataDescriptor();
73
74
75
76 /*** Performs the actions logic using the provided IActionData object.
77 * This method is defined by the IAction interface.
78 */
79 public final void perform(IDataBundle data)
80 {
81 try
82 {
83 IDataSource dataSource = this.getDataSource();
84 if(dataSource==null)
85 throw new DataServiceNotFoundException("No default data source has been set for: "+this.getEntityDescriptor().getDataSourceDescriptor().getCodeName());
86
87 IDataTransaction transaction = dataSource.getDataService().newTransaction();
88 this.prepareTransaction(data, transaction);
89 transaction.commit();
90 this.cleanUpTransaction(data, transaction);
91 }
92 catch(DataServiceException e)
93 {
94 Log.printError(this, "Transaction failed in Action "+this.getEntityDescriptor()+"."+this.getCodeName(), e);
95
96 }
97 }
98
99
100
101 /*** Help method used to access the data source used by the perform method
102 * deined in the IEntityAction interface. Does by default return the default
103 * data source object registered in the the data source descripor that the
104 * action object belongs to.
105 */
106 public IDataSource getDataSource()
107 {
108 return this.getEntityDescriptor().getDataSourceDescriptor().getDefaultDataSource();
109 }
110
111 /*** Clean up method for the action where the action can clean up data
112 * operations, if necessary via an overriding method in an implementing
113 * class, which were performed by the action. E.g. resetting flags etc.
114 */
115 public void cleanUpTransaction(IDataBundle data, IDataTransaction transaction)
116 {
117 }
118 }