Permalink
Browse files

Merge branch 'master' into pascal_semi

  • Loading branch information...
2 parents b22bba6 + 1ae7e59 commit 4aca3f5dbfdae33e0883ef3d9506560d46c0346c @gavinking gavinking committed Jan 25, 2011
Showing with 61 additions and 0 deletions.
  1. +38 −0 corpus/annotations/transactions/Transactional.ceylon
  2. +23 −0 corpus/ui/component/Component.ceylon
@@ -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
+ }
+ }
+ }
+ }
+
+}
@@ -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);
+ }
+ }
+
+}

0 comments on commit 4aca3f5

Please sign in to comment.