X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FWriteStateBase.java;h=db6dac1db5409e1e3b8b2968d8dc2f8a1b1c546b;hp=303e42cfc989e58da286c3f8d8dc5521258fc4b1;hb=1dd02a0d0e604a82e67f04559e213db76c9ebac5;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/WriteStateBase.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/WriteStateBase.java index 303e42cfc..db6dac1db 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/WriteStateBase.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/WriteStateBase.java @@ -1,83 +1,83 @@ -package fi.vtt.simantics.procore.internal; - -import java.util.concurrent.Semaphore; - -import org.simantics.db.common.utils.Logger; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.Procedure; -import org.simantics.db.request.WriteTraits; - -/** - * @author Tuukka Lehtonen - * - * @param result value type - */ -public class WriteStateBase { - - final protected WriteTraits request; - final protected Semaphore notify; - final protected Procedure procedure; - - protected T result; - protected Throwable exception; - - public WriteStateBase(WriteTraits request, Semaphore notify, Procedure procedure) { - assert(request != null); - - this.request = request; - this.notify = notify; - this.procedure = procedure; - } - - public WriteTraits getRequest() { - return request; - } - - @SuppressWarnings("unchecked") - public void setResult(Object result) { - this.result = (T) result; - } - - public void except(Throwable throwable) { - this.exception = throwable; - } - -// public void cancel(CancelTransactionException e) { -// this.exception = e; -// } -// -// public boolean isCanceled() { -// return exception instanceof CancelTransactionException; -// } - - public boolean isExcepted() { - return exception != null; - } - - public void finish() { - - if(procedure != null) { - - try { - // Callback is client code, we have to be prepared for it to throw unexpected exceptions. - // All we can do here is to log those, can't really pass them anywhere. - if (procedure != null) { - if(isExcepted()) { - if(exception instanceof DatabaseException) procedure.exception(exception); - else procedure.exception(new DatabaseException(exception)); - } - else procedure.execute(result); - } - } catch (Throwable t) { - Logger.defaultLogError("Write request callback caused an unexpected error, see exception.", t); - if (SessionImplSocket.DEBUG) - t.printStackTrace(); - } - - } - - if(notify != null) notify.release(); - - } - -} +package fi.vtt.simantics.procore.internal; + +import java.util.concurrent.Semaphore; + +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.WriteTraits; + +/** + * @author Tuukka Lehtonen + * + * @param result value type + */ +public class WriteStateBase { + + final protected WriteTraits request; + final protected Semaphore notify; + final protected Procedure procedure; + + protected T result; + protected Throwable exception; + + public WriteStateBase(WriteTraits request, Semaphore notify, Procedure procedure) { + assert(request != null); + + this.request = request; + this.notify = notify; + this.procedure = procedure; + } + + public WriteTraits getRequest() { + return request; + } + + @SuppressWarnings("unchecked") + public void setResult(Object result) { + this.result = (T) result; + } + + public void except(Throwable throwable) { + this.exception = throwable; + } + +// public void cancel(CancelTransactionException e) { +// this.exception = e; +// } +// +// public boolean isCanceled() { +// return exception instanceof CancelTransactionException; +// } + + public boolean isExcepted() { + return exception != null; + } + + public void finish() { + + if(procedure != null) { + + try { + // Callback is client code, we have to be prepared for it to throw unexpected exceptions. + // All we can do here is to log those, can't really pass them anywhere. + if (procedure != null) { + if(isExcepted()) { + if(exception instanceof DatabaseException) procedure.exception(exception); + else procedure.exception(new DatabaseException(exception)); + } + else procedure.execute(result); + } + } catch (Throwable t) { + Logger.defaultLogError("Write request callback caused an unexpected error, see exception.", t); + if (SessionImplSocket.DEBUG) + t.printStackTrace(); + } + + } + + if(notify != null) notify.release(); + + } + +}