Package org.ofbiz.minerva.pool.jdbc.xa

Examples of org.ofbiz.minerva.pool.jdbc.xa.XAPoolDataSource


    public static final String module = MinervaConnectionFactory.class.getName();
    protected static Map<String, XAPoolDataSource> dsCache = FastMap.newInstance();

    public Connection getConnection(GenericHelperInfo helperInfo, Element jdbcElement) throws SQLException, GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperInfo.getHelperFullName());
        if (pds != null) {
            return TransactionFactory.getCursorConnection(helperInfo, pds.getConnection());
        }

        synchronized (MinervaConnectionFactory.class) {
            pds = dsCache.get(helperInfo.getHelperFullName());
            if (pds != null) {
                return pds.getConnection();
            } else {
                pds = new XAPoolDataSource();
                pds.setPoolName(helperInfo.getHelperFullName());
            }

            XADataSourceImpl ds = new XADataSourceImpl();

            if (ds == null) {
                throw new GenericEntityException("XADataSource was not created, big problem!");
            }
           
            String jdbcUri = UtilValidate.isNotEmpty(helperInfo.getOverrideJdbcUri()) ? helperInfo.getOverrideJdbcUri() : jdbcElement.getAttribute("jdbc-uri");
            String jdbcUsername = UtilValidate.isNotEmpty(helperInfo.getOverrideUsername()) ? helperInfo.getOverrideUsername() : jdbcElement.getAttribute("jdbc-username");
            String jdbcPassword = UtilValidate.isNotEmpty(helperInfo.getOverridePassword()) ? helperInfo.getOverridePassword() : jdbcElement.getAttribute("jdbc-password");

            ds.setDriver(jdbcElement.getAttribute("jdbc-driver"));
            ds.setURL(jdbcUri);

            String transIso = jdbcElement.getAttribute("isolation-level");
            if (UtilValidate.isNotEmpty(transIso)) {
                if ("Serializable".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                } else if ("RepeatableRead".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                } else if ("ReadUncommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
                } else if ("ReadCommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                } else if ("None".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_NONE);
                }
            }

            // set the datasource in the pool
            pds.setDataSource(ds);
            pds.setJDBCUser(jdbcUsername);
            pds.setJDBCPassword(jdbcPassword);

            // set the transaction manager in the pool
            pds.setTransactionManager(TransactionFactory.getTransactionManager());

            // configure the pool settings
            try {
                pds.setMaxSize(Integer.parseInt(jdbcElement.getAttribute("pool-maxsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-maxsize=" + jdbcElement.getAttribute("pool-maxsize") + "]; the values MUST be numbers, using default of 20.", module);
                pds.setMaxSize(20);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMaxSize(20);
            }
            try {
                pds.setMinSize(Integer.parseInt(jdbcElement.getAttribute("pool-minsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-minsize=" + jdbcElement.getAttribute("pool-minsize") + "]; the values MUST be numbers, using default of 5.", module);
                pds.setMinSize(2);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMinSize(2);
            }

            if (jdbcElement.hasAttribute("idle-maxsize")) {
                Debug.logWarning("idle-maxsize is not supported by MinervaConnectionFactory, ignoring value", module);
            }

            // cache the pool
            dsCache.put(helperInfo.getHelperFullName(), pds);

            return TransactionFactory.getCursorConnection(helperInfo, pds.getConnection());
        }
    }
View Full Code Here


        }
    }

    public void closeAll() {
        for (String helperName: dsCache.keySet()) {
            XAPoolDataSource pds = dsCache.remove(helperName);
            pds.close();
        }
    }
View Full Code Here

        }
    }

    // static methods for webtools
    public static <X> Set<X> getPooledData(String helperName) throws GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperName);
        if (pds == null) {
            Debug.logError("No pool found for helper name [" + helperName + "]", module);
            return new HashSet<X>();
        } else {
            return UtilGenerics.cast(pds.getPooledObjectRecords(0)); // 0 to return all (in use and waiting)
        }
    }
View Full Code Here

            return UtilGenerics.cast(pds.getPooledObjectRecords(0)); // 0 to return all (in use and waiting)
        }
    }

    public static String getPoolName(String helperName) throws GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperName);
        if (pds == null) {
            Debug.logError("No pool found for helper name [" + helperName + "]", module);
            return null;
        }
        return pds.getPoolDataString();
    }
View Full Code Here

    public static final String module = MinervaConnectionFactory.class.getName();
    protected static Map<String, XAPoolDataSource> dsCache = FastMap.newInstance();

    public Connection getConnection(String helperName, Element jotmJdbcElement) throws SQLException, GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperName);
        if (pds != null) {
            return TransactionFactory.getCursorConnection(helperName, pds.getConnection());
        }

        synchronized (MinervaConnectionFactory.class) {
            pds = dsCache.get(helperName);
            if (pds != null) {
                return pds.getConnection();
            } else {
                pds = new XAPoolDataSource();
                pds.setPoolName(helperName);
            }

            XADataSourceImpl ds = new XADataSourceImpl();

            if (ds == null)
                throw new GenericEntityException("XADataSource was not created, big problem!");

            ds.setDriver(jotmJdbcElement.getAttribute("jdbc-driver"));
            ds.setURL(jotmJdbcElement.getAttribute("jdbc-uri"));

            String transIso = jotmJdbcElement.getAttribute("isolation-level");
            if (transIso != null && transIso.length() > 0) {
                if ("Serializable".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                } else if ("RepeatableRead".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                } else if ("ReadUncommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
                } else if ("ReadCommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                } else if ("None".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_NONE);
                }
            }

            // set the datasource in the pool
            pds.setDataSource(ds);
            pds.setJDBCUser(jotmJdbcElement.getAttribute("jdbc-username"));
            pds.setJDBCPassword(jotmJdbcElement.getAttribute("jdbc-password"));

            // set the transaction manager in the pool
            pds.setTransactionManager(TransactionFactory.getTransactionManager());

            // configure the pool settings
            try {
                pds.setMaxSize(Integer.parseInt(jotmJdbcElement.getAttribute("pool-maxsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-maxsize=" + jotmJdbcElement.getAttribute("pool-maxsize") + "]; the values MUST be numbers, using default of 20.", module);
                pds.setMaxSize(20);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMaxSize(20);
            }
            try {
                pds.setMinSize(Integer.parseInt(jotmJdbcElement.getAttribute("pool-minsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-minsize=" + jotmJdbcElement.getAttribute("pool-minsize") + "]; the values MUST be numbers, using default of 5.", module);
                pds.setMinSize(2);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMinSize(2);
            }

            // cache the pool
            dsCache.put(helperName, pds);

            return TransactionFactory.getCursorConnection(helperName, pds.getConnection());
        }
    }
View Full Code Here

        }
    }

    public void closeAll() {
        for (String helperName: dsCache.keySet()) {
            XAPoolDataSource pds = dsCache.remove(helperName);
            pds.close();
        }
    }
View Full Code Here

        }
    }

    // static methods for webtools
    public static Set getPooledData(String helperName) throws GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperName);
        if (pds == null) {
            Debug.logError("No pool found for helper name [" + helperName + "]", module);
            return new HashSet();
        } else {
            return pds.getPooledObjectRecords(0); // 0 to return all (in use and waiting)
        }
    }
View Full Code Here

            return pds.getPooledObjectRecords(0); // 0 to return all (in use and waiting)
        }
    }

    public static String getPoolName(String helperName) throws GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperName);
        if (pds == null) {
            Debug.logError("No pool found for helper name [" + helperName + "]", module);
            return null;
        }
        return pds.getPoolDataString();
    }
View Full Code Here

    public static final String module = MinervaConnectionFactory.class.getName();
    protected static Map<String, XAPoolDataSource> dsCache = FastMap.newInstance();

    public Connection getConnection(GenericHelperInfo helperInfo, Element jdbcElement) throws SQLException, GenericEntityException {
        XAPoolDataSource pds = dsCache.get(helperInfo.getHelperFullName());
        if (pds != null) {
            return TransactionFactory.getCursorConnection(helperInfo, pds.getConnection());
        }

        synchronized (MinervaConnectionFactory.class) {
            pds = dsCache.get(helperInfo.getHelperFullName());
            if (pds != null) {
                return pds.getConnection();
            } else {
                pds = new XAPoolDataSource();
                pds.setPoolName(helperInfo.getHelperFullName());
            }

            XADataSourceImpl ds = new XADataSourceImpl();

            if (ds == null) {
                throw new GenericEntityException("XADataSource was not created, big problem!");
            }
           
            String jdbcUri = UtilValidate.isNotEmpty(helperInfo.getOverrideJdbcUri()) ? helperInfo.getOverrideJdbcUri() : jdbcElement.getAttribute("jdbc-uri");
            String jdbcUsername = UtilValidate.isNotEmpty(helperInfo.getOverrideUsername()) ? helperInfo.getOverrideUsername() : jdbcElement.getAttribute("jdbc-username");
            String jdbcPassword = UtilValidate.isNotEmpty(helperInfo.getOverridePassword()) ? helperInfo.getOverridePassword() : jdbcElement.getAttribute("jdbc-password");

            ds.setDriver(jdbcElement.getAttribute("jdbc-driver"));
            ds.setURL(jdbcUri);

            String transIso = jdbcElement.getAttribute("isolation-level");
            if (UtilValidate.isNotEmpty(transIso)) {
                if ("Serializable".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                } else if ("RepeatableRead".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                } else if ("ReadUncommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
                } else if ("ReadCommitted".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                } else if ("None".equals(transIso)) {
                    pds.setTransactionIsolation(Connection.TRANSACTION_NONE);
                }
            }

            // set the datasource in the pool
            pds.setDataSource(ds);
            pds.setJDBCUser(jdbcUsername);
            pds.setJDBCPassword(jdbcPassword);

            // set the transaction manager in the pool
            pds.setTransactionManager(TransactionFactory.getTransactionManager());

            // configure the pool settings
            try {
                pds.setMaxSize(Integer.parseInt(jdbcElement.getAttribute("pool-maxsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-maxsize=" + jdbcElement.getAttribute("pool-maxsize") + "]; the values MUST be numbers, using default of 20.", module);
                pds.setMaxSize(20);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMaxSize(20);
            }
            try {
                pds.setMinSize(Integer.parseInt(jdbcElement.getAttribute("pool-minsize")));
            } catch (NumberFormatException nfe) {
                Debug.logError("Problems with pool settings [pool-minsize=" + jdbcElement.getAttribute("pool-minsize") + "]; the values MUST be numbers, using default of 5.", module);
                pds.setMinSize(2);
            } catch (Exception e) {
                Debug.logError(e, "Problems with pool settings", module);
                pds.setMinSize(2);
            }

            // cache the pool
            dsCache.put(helperInfo.getHelperFullName(), pds);

            return TransactionFactory.getCursorConnection(helperInfo, pds.getConnection());
        }
    }
View Full Code Here

        }
    }

    public void closeAll() {
        for (String helperName: dsCache.keySet()) {
            XAPoolDataSource pds = dsCache.remove(helperName);
            pds.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.ofbiz.minerva.pool.jdbc.xa.XAPoolDataSource

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.