]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java
DB and Layer0 modifications for related issues
[simantics/platform.git] / bundles / org.simantics.db.services / src / org / simantics / db / services / adaption / reflection / ReflectionAdapter2.java
index 187fc52199a390f37b68b3a48a940d20faa4d359..42eb3d8bee0cf2cfd7fed0b8e47555665341931f 100644 (file)
@@ -18,12 +18,16 @@ import java.util.Arrays;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.adaption.Adapter;
-import org.simantics.db.common.request.AsyncReadRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionAdapter2.class);
+
        Constructor<? extends T> constructor;
        IDynamicAdapter2[] parameters;
        
@@ -40,22 +44,20 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
 
        if(parameters.length == 0) {
            
-//            System.out.println("ReflectionAdapter2 " + ReflectionAdapter2.this);
-
            try {
                 procedure.execute(g, constructor.newInstance());
             } catch (IllegalArgumentException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InstantiationException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (IllegalAccessException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InvocationTargetException e) {
                 procedure.exception(g, e.getCause());
-                e.getCause().printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e.getCause());
             }
             
        } else if( parameters.length == 1 && parameters[0] instanceof ThisResource2) {
@@ -64,49 +66,50 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
                 procedure.execute(g, constructor.newInstance(r));
             } catch (IllegalArgumentException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InstantiationException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (IllegalAccessException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InvocationTargetException e) {
                 procedure.exception(g, e.getCause());
-                e.getCause().printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e.getCause());
             }
                
        } else {
        
-            g.asyncRequest(new AsyncReadRequest() {
-    
+            g.asyncRequest(new AsyncRead<T>() {
+                
                 @Override
-                public void run(AsyncReadGraph graph) {
-                       
+                public void perform(AsyncReadGraph graph, AsyncProcedure<T> p) {
+                    
                     Object[] args = new Object[parameters.length];
                     try {
-                       for(int i=0;i<parameters.length;++i)
-                               args[i] = parameters[i].adapt(graph, r);
-                       procedure.execute(graph, constructor.newInstance(args));
-                               } catch (IllegalArgumentException e) {
-                                   procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (InstantiationException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (IllegalAccessException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (InvocationTargetException e) {
-                        procedure.exception(g, e.getCause());
-                                       e.getCause().printStackTrace();
-                               } catch (DatabaseException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (Throwable t) {
-                                   procedure.exception(g, t);
-                                   t.printStackTrace();
-                               }
+                        for(int i=0;i<parameters.length;++i)
+                            args[i] = parameters[i].adapt(graph, r);
+                        p.execute(graph, constructor.newInstance(args));
+                    } catch (IllegalArgumentException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (InstantiationException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (IllegalAccessException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (InvocationTargetException e) {
+                        p.exception(g, e.getCause());
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (DatabaseException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (Throwable t) {
+                        p.exception(g, t);
+                        LOGGER.error("Unexpected exception during adapter creation", t);
+                    }
+                    
                 }
                 
                 @Override
@@ -114,7 +117,7 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
                        return "ReflectionAdapter$1" + constructor + "$" + Arrays.toString(parameters);
                 }
                 
-            });
+            }, procedure);
         
        }