Example usage for org.apache.commons.transaction.memory.jca MapXAResource MapXAResource

List of usage examples for org.apache.commons.transaction.memory.jca MapXAResource MapXAResource

Introduction

In this page you can find the example usage for org.apache.commons.transaction.memory.jca MapXAResource MapXAResource.

Prototype

public MapXAResource(TransactionalMapWrapper map) 

Source Link

Usage

From source file:org.apache.slide.store.mem.AbstractTransientStore.java

public void initialize(NamespaceAccessToken token) throws ServiceInitializationFailedException {
    super.initialize(token);

    TxLogger txLogger = new TxLogger(getLogger(), LogChannel());

    String param = (String) this.parameters.get(MAP_IMPL_PARAMETER);
    if (param == null) {
        param = MAP_IMPL_PARAMETER_DEFAULT;
    }//ww  w.  java2  s.  c om
    try {
        info("Initializing {0} using {1}.", getClass().getName(), param);
        Map toBeWrapped = new HashMap();
        Class mapClass = Class.forName(param);

        try {
            Class[] ctorFormalArgs = { Map.class, LoggerFacade.class };
            Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
            Object[] ctorArgs = { toBeWrapped, txLogger };
            this.store = (TransactionalMapWrapper) ctor.newInstance(ctorArgs);
        } catch (NoSuchMethodException e) {
            // try next
            try {
                Class[] ctorFormalArgs = { Map.class };
                Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
                Object[] ctorArgs = { toBeWrapped };
                this.store = (TransactionalMapWrapper) ctor.newInstance(ctorArgs);
            } catch (NoSuchMethodException ee) {
                error("Initialization error: ", ee);
                throw new ServiceInitializationFailedException(this, ee);
            }
        }
    } catch (ClassNotFoundException e) {
        error("Initialization error: ", e);
        throw new ServiceInitializationFailedException(this, e);
    } catch (InstantiationException e) {
        error("Initialization error: ", e);
        throw new ServiceInitializationFailedException(this, e);
    } catch (IllegalAccessException e) {
        error("Initialization error: ", e);
        throw new ServiceInitializationFailedException(this, e);
    } catch (InvocationTargetException e) {
        error("Initialization error: ", e);
        throw new ServiceInitializationFailedException(this, e);
    } catch (ClassCastException e) {
        error("Initialization error: ", e);
        throw new ServiceInitializationFailedException(this, "class in parameter '" + MAP_IMPL_PARAMETER
                + "' must " + "be derived from TransactionalMapWrapper");
    }

    this.xaResource = new MapXAResource(this.store);
    // FIXME can't set logging because methods are not public, and
    // ctor doesn't take a loggerFacade
}