package org.nybatis.core.db.session.executor.util;

import org.nybatis.core.db.session.executor.SqlExecutor;
import org.nybatis.core.db.session.executor.batch.AbstractBatchExecutor;
import org.nybatis.core.db.session.type.orm.OrmListExecutorImpl;
import org.nybatis.core.db.session.type.orm.OrmSessionImpl;
import org.nybatis.core.db.session.type.sql.BatchExecutorImpl;
import org.nybatis.core.db.session.type.sql.ListExecutorImpl;
import org.nybatis.core.db.session.type.sql.SessionExecutorImpl;

import java.util.HashSet;
import java.util.Set;

/**
 * Sql caller finder
 *
 * @author nayasis
 * @since 2016-10-21
 */
public class SqlCallerFinder {

    Set<String> excludeClass = new HashSet<>();

    public SqlCallerFinder() {
        excludeClass.add( Thread.class.getName() );
        excludeClass.add( SqlCallerFinder.class.getName() );
        excludeClass.add( DbUtils.class.getName() );
        excludeClass.add( SqlExecutor.class.getName() );
        excludeClass.add( SessionExecutorImpl.class.getName() );
        excludeClass.add( AbstractBatchExecutor.class.getName() );
        excludeClass.add( BatchExecutorImpl.class.getName() );
        excludeClass.add( ListExecutorImpl.class.getName() );
        excludeClass.add( OrmListExecutorImpl.class.getName() );
        excludeClass.add( OrmSessionImpl.class.getName() );
    }

    /**
     * get caller information
     * <pre>
     *  for example :
     *    - org.nybatis.core.db.session.SqlSessionSqliteTest.case10_initDummyDataByStatementBatch (SqlSessionSqliteTest.java:122)
     * </pre>
     * @return sql caller information
     */
    public String get() {
        for( StackTraceElement e : Thread.currentThread().getStackTrace() ) {
            String className = e.getClassName();
            if( excludeClass.contains( className ) ) continue;
            return String.format( "%s.%s (%s:%s)", e.getClassName(), e.getMethodName(), e.getFileName(), e.getLineNumber() );
        }
        return "";
    }

}

@@ -167,32 +167,98 @@
 tBatchExecutor;%0A
+import org.nybatis.core.db.session.type.orm.OrmBatchExecutorImpl;%0A
 import org.nybat
@@ -298,32 +298,32 @@
 stExecutorImpl;%0A
-
 import org.nybat
@@ -805,25 +805,16 @@
  exclude
-Class.add
 ( Thread
@@ -815,34 +815,39 @@
 Thread.class
-.getName()
+               
  );%0A        
@@ -849,33 +849,24 @@
      exclude
-Class.add
 ( SqlCallerF
@@ -872,34 +872,30 @@
 Finder.class
-.getName()
+      
  );%0A        
@@ -901,25 +901,16 @@
  exclude
-Class.add
 ( DbUtil
@@ -912,34 +912,38 @@
 bUtils.class
-.getName()
+              
  );%0A        
@@ -949,25 +949,16 @@
  exclude
-Class.add
 ( SqlExe
@@ -964,34 +964,34 @@
 ecutor.class
-.getName()
+          
  );%0A        
@@ -997,25 +997,16 @@
  exclude
-Class.add
 ( Sessio
@@ -1020,34 +1020,26 @@
 orImpl.class
-.getName()
+  
  );%0A        
@@ -1045,25 +1045,16 @@
  exclude
-Class.add
 ( Abstra
@@ -1070,34 +1070,24 @@
 ecutor.class
-.getName()
  );%0A        
@@ -1093,25 +1093,16 @@
  exclude
-Class.add
 ( BatchE
@@ -1114,34 +1114,28 @@
 orImpl.class
-.getName()
+    
  );%0A        
@@ -1141,27 +1141,69 @@
  exclude
-Class.add( 
+( ListExecutorImpl.class      );%0A        exclude( Orm
 ListExec
@@ -1212,34 +1212,26 @@
 orImpl.class
-.getName()
+  
  );%0A        
@@ -1241,57 +1241,137 @@
 lude
-Class.add( OrmListExecutorImpl.class.getName() );
+( OrmSessionImpl.class        );%0A        exclude( OrmBatchExecutorImpl.class  );%0A    %7D%0A%0A    private void exclude( Class klass ) %7B
 %0A   
@@ -1393,32 +1393,17 @@
 ss.add( 
-OrmSessionImpl.c
+k
 lass.get

add OrmBatchExecutorImpl in SqlCallerFinder.