Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into pascal_semi
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
shared annotation { | ||
ofElements = methods; | ||
occurs = onceEachElement; | ||
} | ||
Transactional transactional(Boolean requiresNew = false) { | ||
return Transactional(requiresNew) | ||
} | ||
|
||
shared class Transactional(Boolean requiresNew) | ||
satisfies MethodAnnotation { | ||
|
||
shared Boolean requiresNew = requiresNew; | ||
|
||
doc "This method is called whenever Ceylon loads a class with a method | ||
annotated |transactional|. It registers a transaction management | ||
interceptor for the method." | ||
shared actual void onDefineMethod<X,T,P...>(OpenMethod<X,T,P...> method) { | ||
method.intercept() | ||
onInvoke(X instance, T proceed(P... args), P... args) { | ||
if (currentTransaction.inProcess || !requiresNew) { | ||
return proceed(args) | ||
} | ||
else { | ||
currentTransaction.begin(); | ||
try { | ||
T result = proceed(args); | ||
currentTransaction.commit(); | ||
return result | ||
} | ||
catch (Exception e) { | ||
currentTransaction.rollback(); | ||
throw e | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
shared abstract class Component() { | ||
|
||
OpenList<Observer> observers = none; | ||
|
||
shared Observer[] currentObservers { | ||
return observers | ||
} | ||
|
||
shared void addObserver(Observer o)() { | ||
observers.append(o); | ||
void remove() { | ||
observers.remove(o); | ||
} | ||
return remove | ||
} | ||
|
||
shared void fire(Event event) { | ||
for (Observer o in observers) { | ||
o.observe(event); | ||
} | ||
} | ||
|
||
} |