1 16 package scriptella.core; 17 18 import scriptella.configuration.ScriptingElement; 19 import scriptella.spi.Connection; 20 21 22 28 public class ConnectionInterceptor extends ElementInterceptor { 29 private ConnectionInterceptor(ExecutableElement next, String conId) { 30 super(next, new ConnectionDecorator(conId)); 31 } 32 33 public void execute(final DynamicContext ctx) { 34 final DynamicContextDecorator ctxDecorator = getCtxDecorator(); 35 ctxDecorator.setContext(ctx); 36 executeNext(ctxDecorator); 37 } 38 39 public static ExecutableElement prepare( 40 final ExecutableElement next, final ScriptingElement se) { 41 final String cid = se.getConnectionId(); 42 if (cid == null) { 43 return next; 44 } else { 45 for (ScriptingElement s = se; (s = s.getParent()) != null;) { 46 if (s.getConnectionId() != null) { 47 if (cid.equals(s.getConnectionId())) { 48 return next; 49 } 50 break; 51 } 52 } 53 return new ConnectionInterceptor(next, cid); 54 } 55 } 56 57 private static class ConnectionDecorator extends DynamicContextDecorator { 58 private String connectionId; 59 60 public ConnectionDecorator(String connectionId) { 61 this.connectionId = connectionId; 62 } 63 64 @Override 65 public Connection getConnection() { 66 return getGlobalContext().getSession().getConnection(connectionId) 67 .getConnection(); 68 } 69 } 70 } 71 | Popular Tags |