Skip to content

Commit cd09411

Browse files
author
Open Lowcode SAS
committed
Close #132
1 parent d28461c commit cd09411

File tree

9 files changed

+172
-3
lines changed

9 files changed

+172
-3
lines changed

src/org/openlowcode/design/data/properties/basic/Trigger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void controlAfterParentDefinition() {
6666
MethodAdditionalProcessing triggeronupdate = new MethodAdditionalProcessing(false,
6767
uniqueidentified.getDataAccessMethod("UPDATE"));
6868
this.addMethodAdditionalProcessing(triggeronupdate);
69+
70+
MethodAdditionalProcessing triggerbeforeupdate = new MethodAdditionalProcessing(true,
71+
uniqueidentified.getDataAccessMethod("UPDATE"));
72+
this.addMethodAdditionalProcessing(triggerbeforeupdate);
73+
6974
MethodAdditionalProcessing triggerondelete = new MethodAdditionalProcessing(true,
7075
uniqueidentified.getDataAccessMethod("DELETE"));
7176
this.addMethodAdditionalProcessing(triggerondelete);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/********************************************************************************
2+
* Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/)
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0 .
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
********************************************************************************/
10+
11+
package org.openlowcode.design.data.properties.trigger;
12+
13+
import org.openlowcode.design.data.DataObjectDefinition;
14+
15+
/**
16+
* A trigger launch condition that will trigger before the persistence of data
17+
* on the database. It is an opportunity to peform checks and complex logic
18+
* before persistence
19+
*
20+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
21+
* SAS</a>
22+
*
23+
* @since 1.7
24+
*
25+
*/
26+
public class TriggerLaunchConditionBeforeUpdate
27+
extends
28+
TriggerLaunchCondition {
29+
30+
/**
31+
* create a trigger launch condition that will execute the trigger just before
32+
* the update of data in the database
33+
*
34+
* @param parent data object the trigger launch condition is on
35+
*/
36+
public TriggerLaunchConditionBeforeUpdate(DataObjectDefinition parent) {
37+
super(parent);
38+
39+
}
40+
41+
@Override
42+
public String generateDeclaration() {
43+
return "new TriggerConditionBeforeUpdate()";
44+
}
45+
46+
@Override
47+
public String[] generateImportConditions() {
48+
return new String[] { "import org.openlowcode.server.data.properties.trigger.TriggerConditionBeforeUpdate;" };
49+
}
50+
51+
}

src/org/openlowcode/server/data/properties/Trigger.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public void postprocUniqueidentifiedUpdate(E object) {
6969
}
7070
}
7171

72+
/**
73+
* pre-processing the object before object update
74+
*
75+
* @param object the object
76+
*
77+
* @since 1.7
78+
*/
79+
public void preprocUniqueidentifiedUpdate(E object) {
80+
if (triggerdefinition.getTriggerCondition().executeBeforeUpdate()) {
81+
processTriggerNow(object);
82+
}
83+
}
84+
7285
/**
7386
* post-processing after object delete
7487
*
@@ -154,6 +167,21 @@ public static <E extends DataObject<E> & UniqueidentifiedInterface<E>> void post
154167
for (int i = 0; i < triggerbatch.length; i++)
155168
triggerbatch[i].postprocUniqueidentifiedUpdate(objectbatch[i]);
156169
}
170+
171+
/**
172+
* massive pre-processing of update
173+
*
174+
* @param objectbatch object batch
175+
* @param triggerbatch trigger batch
176+
* @since 1.7
177+
*/
178+
public static <E extends DataObject<E> & UniqueidentifiedInterface<E>> void preprocUniqueidentifiedUpdate(
179+
E[] objectbatch, Trigger<E>[] triggerbatch) {
180+
logger.warning("----------- Not optimized for massive treatment --------------------");
181+
for (int i = 0; i < triggerbatch.length; i++)
182+
triggerbatch[i].preprocUniqueidentifiedUpdate(objectbatch[i]);
183+
}
184+
157185

158186
/**
159187
* massive post-processing of insert
@@ -175,6 +203,7 @@ public static <E extends DataObject<E> & UniqueidentifiedInterface<E>> void post
175203
* @param object the object on which to execute the trigger
176204
*/
177205
private void processTriggerImmediately(E object) {
206+
logger.severe(" --> Process Trigger Immediately");
178207
CustomTriggerExecution<E> trigger = triggerdefinition.getTriggerExecution().generate();
179208
trigger.compute(object);
180209
}
@@ -194,6 +223,17 @@ private void processTrigger(E object) {
194223
.addTriggerToList(new TriggerToExecute<E>(triggerdefinition.getTriggerExecution().generate(), object));
195224
}
196225

226+
/**
227+
* Executes immediately the trigger
228+
*
229+
* @param object the object on which to execute the trigger
230+
* @since 1.7
231+
*/
232+
private void processTriggerNow(E object) {
233+
triggerdefinition.getTriggerExecution().generate().execute(object);
234+
235+
}
236+
197237
/**
198238
* sets dependent property unique identified
199239
*

src/org/openlowcode/server/data/properties/trigger/TriggerCondition.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ public abstract class TriggerCondition<E extends DataObject<E> & Uniqueidentifie
4545
*/
4646
public abstract boolean executeOnStateChange(ChoiceValue<?> newstate);
4747

48+
/**
49+
* @return true if the trigger should be executed before object update
50+
* @since 1.7
51+
*/
52+
public abstract boolean executeBeforeUpdate();
53+
4854
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/********************************************************************************
2+
* Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/)
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0 .
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
********************************************************************************/
10+
11+
package org.openlowcode.server.data.properties.trigger;
12+
13+
import org.openlowcode.server.data.ChoiceValue;
14+
import org.openlowcode.server.data.DataObject;
15+
import org.openlowcode.server.data.properties.UniqueidentifiedInterface;
16+
17+
/**
18+
* This trigger will execute before persistence during an update.
19+
*
20+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
21+
* SAS</a>
22+
* @since 1.7
23+
*
24+
*/
25+
public class TriggerConditionBeforeUpdate<E extends DataObject<E> & UniqueidentifiedInterface<E>>
26+
extends
27+
TriggerCondition<E> {
28+
@Override
29+
public boolean executeOnInsert() {
30+
return false;
31+
}
32+
33+
@Override
34+
public boolean executeOnUpdate() {
35+
return false;
36+
}
37+
38+
@Override
39+
public boolean executeOnStateChange(ChoiceValue<?> newstate) {
40+
41+
return false;
42+
}
43+
44+
@Override
45+
public boolean executeBeforeDelete() {
46+
47+
return false;
48+
}
49+
@Override
50+
public boolean executeBeforeUpdate() {
51+
return true;
52+
}
53+
}

src/org/openlowcode/server/data/properties/trigger/TriggerConditionCreate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public boolean executeOnStateChange(ChoiceValue<?> newstate) {
4444
public boolean executeBeforeDelete() {
4545
return false;
4646
}
47+
48+
@Override
49+
public boolean executeBeforeUpdate() {
50+
return false;
51+
}
4752

4853
}

src/org/openlowcode/server/data/properties/trigger/TriggerConditionCreateUpdate.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ public boolean executeBeforeDelete() {
4646

4747
return false;
4848
}
49-
49+
@Override
50+
public boolean executeBeforeUpdate() {
51+
return false;
52+
}
5053
}

src/org/openlowcode/server/data/properties/trigger/TriggerConditionDelete.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@ public boolean executeOnStateChange(ChoiceValue<?> newstate) {
4545

4646
return false;
4747
}
48-
48+
@Override
49+
public boolean executeBeforeUpdate() {
50+
return false;
51+
}
4952
}

src/org/openlowcode/server/data/properties/trigger/TriggerConditionStateChange.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ public boolean executeBeforeDelete() {
6565

6666
return false;
6767
}
68-
68+
@Override
69+
public boolean executeBeforeUpdate() {
70+
return false;
71+
}
6972
}

0 commit comments

Comments
 (0)