Package com.jfinal.plugin.activerecord

Examples of com.jfinal.plugin.activerecord.Config


    for (String actionKey : actionKeys)
      actionKeySet.add(actionKey.trim());
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (actionKeySet.contains(ai.getActionKey())) {
      DbPro.use(config.getName()).tx(new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here


    for (String actionMethod : actionMethods)
      actionMethodSet.add(actionMethod.trim());
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (actionMethodSet.contains(ai.getMethodName())) {
      DbPro.use(config.getName()).tx(new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here

    TxConfig txConfig = ai.getMethod().getAnnotation(TxConfig.class);
    if (txConfig == null)
      txConfig = ai.getController().getClass().getAnnotation(TxConfig.class);
   
    if (txConfig != null) {
      Config config = DbKit.getConfig(txConfig.value());
      if (config == null)
        throw new RuntimeException("Config not found with TxConfig");
      return config;
    }
    return null;
View Full Code Here

  protected int getTransactionLevel(Config config) {
    return config.getTransactionLevel();
  }
 
  public void intercept(ActionInvocation ai) {
    Config config = getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    Connection conn = config.getThreadLocalConnection();
    if (conn != null) {  // Nested transaction support
      try {
        if (conn.getTransactionIsolation() < getTransactionLevel(config))
          conn.setTransactionIsolation(getTransactionLevel(config));
        ai.invoke();
        return ;
      } catch (SQLException e) {
        throw new ActiveRecordException(e);
      }
    }
   
    Boolean autoCommit = null;
    try {
      conn = config.getConnection();
      autoCommit = conn.getAutoCommit();
      config.setThreadLocalConnection(conn);
      conn.setTransactionIsolation(getTransactionLevel(config))// conn.setTransactionIsolation(transactionLevel);
      conn.setAutoCommit(false);
      ai.invoke();
      conn.commit();
    } catch (NestedTransactionHelpException e) {
      if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
    } catch (Throwable t) {
      if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
      throw new ActiveRecordException(t);
    }
    finally {
      try {
        if (conn != null) {
          if (autoCommit != null)
            conn.setAutoCommit(autoCommit);
          conn.close();
        }
      } catch (Throwable t) {
        t.printStackTrace()// can not throw exception here, otherwise the more important exception in previous catch block can not be thrown
      }
      finally {
        config.removeThreadLocalConnection()// prevent memory leak
      }
    }
  }
View Full Code Here

   
    pattern = caseSensitive ? Pattern.compile(regex) : Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (pattern.matcher(ai.getActionKey()).matches()) {
      DbPro.use(config.getName()).tx(new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here

    for (String actionKey : actionKeys)
      actionKeySet.add(actionKey.trim());
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (actionKeySet.contains(ai.getActionKey())) {
      Db.tx(config.getName(), new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here

    for (String actionMethod : actionMethods)
      actionMethodSet.add(actionMethod.trim());
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (actionMethodSet.contains(ai.getMethodName())) {
      Db.tx(config.getName(), new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here

    TxConfig txConfig = ai.getMethod().getAnnotation(TxConfig.class);
    if (txConfig == null)
      txConfig = ai.getController().getClass().getAnnotation(TxConfig.class);
   
    if (txConfig != null) {
      Config config = DbKit.getConfig(txConfig.value());
      if (config == null)
        throw new RuntimeException("Config not found with TxConfig");
      return config;
    }
    return null;
View Full Code Here

  protected int getTransactionLevel(Config config) {
    return config.getTransactionLevel();
  }
 
  public void intercept(ActionInvocation ai) {
    Config config = getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    Connection conn = config.getThreadLocalConnection();
    if (conn != null) {  // Nested transaction support
      try {
        if (conn.getTransactionIsolation() < getTransactionLevel(config))
          conn.setTransactionIsolation(getTransactionLevel(config));
        ai.invoke();
        return ;
      } catch (SQLException e) {
        throw new ActiveRecordException(e);
      }
    }
   
    Boolean autoCommit = null;
    try {
      conn = config.getConnection();
      autoCommit = conn.getAutoCommit();
      config.setThreadLocalConnection(conn);
      conn.setTransactionIsolation(getTransactionLevel(config))// conn.setTransactionIsolation(transactionLevel);
      conn.setAutoCommit(false);
      ai.invoke();
      conn.commit();
    } catch (NestedTransactionHelpException e) {
      if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
    } catch (Exception e) {
      if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
      throw new ActiveRecordException(e);
    }
    finally {
      try {
        if (conn != null) {
          if (autoCommit != null)
            conn.setAutoCommit(autoCommit);
          conn.close();
        }
      } catch (Exception e) {
        e.printStackTrace()// can not throw exception here, otherwise the more important exception in previous catch block can not be thrown
      }
      finally {
        config.removeThreadLocalConnection()// prevent memory leak
      }
    }
  }
View Full Code Here

   
    pattern = caseSensitive ? Pattern.compile(regex) : Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  }
 
  public void intercept(final ActionInvocation ai) {
    Config config = Tx.getConfigWithTxConfig(ai);
    if (config == null)
      config = DbKit.getConfig();
   
    if (pattern.matcher(ai.getActionKey()).matches()) {
      Db.tx(config.getName(), new IAtom(){
        public boolean run() throws SQLException {
          ai.invoke();
          return true;
        }});
    }
View Full Code Here

TOP

Related Classes of com.jfinal.plugin.activerecord.Config

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.