Package net.sf.hajdbc.invocation

Examples of net.sf.hajdbc.invocation.InvocationStrategy


  @Override
  public InvocationStrategy getInvocationStrategy(final InvocationStrategy strategy, final Phase phase, final Object transactionId)
  {
    final DurabilityListener listener = this.cluster.getStateManager();

    return new InvocationStrategy()
    {
      @Override
      public <ZZ, DD extends Database<ZZ>, T, R, EE extends Exception> SortedMap<DD, R> invoke(ProxyFactory<ZZ, DD, T, EE> proxy, Invoker<ZZ, DD, T, R, EE> invoker) throws EE
      {
        InvocationEvent event = new InvocationEventImpl(transactionId, phase, proxy.getExceptionFactory().getType());
View Full Code Here


  {
    if (this.transactionId != null) return strategy;
   
    if (connection.getAutoCommit())
    {
      return new InvocationStrategy()
      {
        @Override
        public <ZZ, DD extends Database<ZZ>, T, R, E extends Exception> SortedMap<DD, R> invoke(ProxyFactory<ZZ, DD, T, E> proxy, Invoker<ZZ, DD, T, R, E> invoker) throws E
        {
          LocalTransactionContext.this.lock();
         
          try
          {
            InvocationStrategy durabilityStrategy = LocalTransactionContext.this.durability.getInvocationStrategy(strategy, Durability.Phase.COMMIT, LocalTransactionContext.this.transactionId);
           
            return durabilityStrategy.invoke(proxy, invoker);
          }
          finally
          {
            LocalTransactionContext.this.unlock();
          }
        }
      };
    }
   
    return new InvocationStrategy()
    {
      @Override
      public <ZZ, DD extends Database<ZZ>, T, R, E extends Exception> SortedMap<DD, R> invoke(ProxyFactory<ZZ, DD, T, E> proxy, Invoker<ZZ, DD, T, R, E> invoker) throws E
      {
        LocalTransactionContext.this.lock();
View Full Code Here

  @Override
  public InvocationStrategy end(final InvocationStrategy strategy, final Durability.Phase phase)
  {
    if (this.transactionId == null) return strategy;

    return new InvocationStrategy()
    {
      @Override
      public <ZZ, DD extends Database<ZZ>, T, R, E extends Exception> SortedMap<DD, R> invoke(ProxyFactory<ZZ, DD, T, E> proxy, Invoker<ZZ, DD, T, R, E> invoker) throws E
      {
        InvocationStrategy durabilityStrategy = LocalTransactionContext.this.durability.getInvocationStrategy(strategy, phase, LocalTransactionContext.this.transactionId);
       
        try
        {
          return durabilityStrategy.invoke(proxy, invoker);
        }
        finally
        {
          LocalTransactionContext.this.unlock();
        }
View Full Code Here

    boolean start = method.equals(startMethod);
    boolean end = endTransactionMethodSet.contains(method);
   
    if (start || end || method.equals(prepareMethod) || intraTransactionMethodSet.contains(method))
    {
      final InvocationStrategy strategy = end ? InvocationStrategies.END_TRANSACTION_INVOKE_ON_ALL : InvocationStrategies.TRANSACTION_INVOKE_ON_ALL;
     
      Xid xid = (Xid) parameters[0];
     
      DatabaseCluster<XADataSource, XADataSourceDatabase> cluster = this.getProxyFactory().getDatabaseCluster();
     
      if (start)
      {
        final Lock lock = cluster.getLockManager().readLock(null);
       
        // Lock may already exist if we're resuming a suspended transaction
        if (lockMap.putIfAbsent(xid, lock) == null)
        {
          return new InvocationStrategy()
          {
            @Override
            public <Z, D extends Database<Z>, T, R, E extends Exception> SortedMap<D, R> invoke(ProxyFactory<Z, D, T, E> proxy, Invoker<Z, D, T, R, E> invoker) throws E
            {
              lock.lock();
             
              try
              {
                return strategy.invoke(proxy, invoker);
              }
              catch (Exception e)
              {
                lock.unlock();

                throw proxy.getExceptionFactory().createException(e);
              }
            }
          };
        }
      }
     
      Durability.Phase phase = phaseRegistry.get(method);
     
      if (phase != null)
      {
        final InvocationStrategy durabilityStrategy = cluster.getDurability().getInvocationStrategy(strategy, phase, xid);
       
        if (endTransactionMethodSet.contains(method))
        {
          final Lock lock = lockMap.remove(xid);

          return new InvocationStrategy()
          {
            @Override
            public <Z, D extends Database<Z>, T, R, E extends Exception> SortedMap<D, R> invoke(ProxyFactory<Z, D, T, E> proxy, Invoker<Z, D, T, R, E> invoker) throws E
            {
              try
              {
                return durabilityStrategy.invoke(proxy, invoker);
              }
              finally
              {
                if (lock != null)
                {
View Full Code Here

    return this.invokeOnProxy(this.proxyClass.cast(proxy), method, args);
  }

  private <R> R invokeOnProxy(T proxy, Method method, Object... parameters) throws E
  {
    InvocationStrategy strategy = this.getInvocationStrategy(proxy, method, parameters);

    Invoker<Z, D, T, R, E> invoker = this.getInvoker(proxy, method, parameters);

    this.logger.log(Level.TRACE, "Invoking {0} using {1}", method, strategy);
    SortedMap<D, R> results = strategy.invoke(this.proxyFactory, invoker);

    this.postInvoke(invoker, proxy, method, parameters);
   
    @SuppressWarnings("unchecked")
    ProxyFactoryFactory<Z, D, T, E, R, ? extends Exception> factory = (ProxyFactoryFactory<Z, D, T, E, R, ? extends Exception>) this.getProxyFactoryFactory(proxy, method, parameters);
View Full Code Here

        boolean repeatableReadSelect = (statement.getConnection().getTransactionIsolation() >= Connection.TRANSACTION_REPEATABLE_READ);
       
        return repeatableReadSelect ? InvocationStrategies.INVOKE_ON_PRIMARY : InvocationStrategies.INVOKE_ON_NEXT;
      }
     
      InvocationStrategy strategy = InvocationStrategies.TRANSACTION_INVOKE_ON_ALL;
      if (!locks.isEmpty())
      {
        strategy = new LockingInvocationStrategy(strategy, locks);
      }
     
View Full Code Here

        boolean repeatableReadSelect = (statement.getConnection().getTransactionIsolation() >= Connection.TRANSACTION_REPEATABLE_READ);
       
        return repeatableReadSelect ? InvocationStrategies.INVOKE_ON_PRIMARY : InvocationStrategies.INVOKE_ON_NEXT;
      }
     
      InvocationStrategy strategy = InvocationStrategies.TRANSACTION_INVOKE_ON_ALL;
      if (!locks.isEmpty())
      {
        strategy = new LockingInvocationStrategy(strategy, locks);
      }
     
View Full Code Here

    return this.invokeOnProxy(this.proxyClass.cast(proxy), method, args);
  }

  private <R> R invokeOnProxy(T proxy, Method method, Object... parameters) throws E
  {
    InvocationStrategy strategy = this.getInvocationStrategy(proxy, method, parameters);

    Invoker<Z, D, T, R, E> invoker = this.getInvoker(proxy, method, parameters);

    this.logger.log(Level.TRACE, "Invoking {0} using {1}", method, strategy);
    SortedMap<D, R> results = strategy.invoke(this.proxyFactory, invoker);

    this.postInvoke(invoker, proxy, method, parameters);
   
    @SuppressWarnings("unchecked")
    ProxyFactoryFactory<Z, D, T, E, R, ? extends Exception> factory = (ProxyFactoryFactory<Z, D, T, E, R, ? extends Exception>) this.getProxyFactoryFactory(proxy, method, parameters);
View Full Code Here

TOP

Related Classes of net.sf.hajdbc.invocation.InvocationStrategy

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.