Package de.zalando.sprocwrapper.dsprovider

Examples of de.zalando.sprocwrapper.dsprovider.SameConnectionDatasource


        if (readOnly == false && writeTransaction != WriteTransaction.NONE) {
            for (final int shardId : shardIds) {
                final DataSource shardDs = dp.getDataSource(shardId);

                // we need to pin the calls to a single connection
                final SameConnectionDatasource sameConnDs = new SameConnectionDatasource(shardDs.getConnection());
                ret.put(shardId, sameConnDs);

                LOG.trace("startTransaction on shard [{}]", shardId);

                final Statement st = sameConnDs.getConnection().createStatement();
                st.execute("BEGIN");
                st.close();
            }
        }
View Full Code Here


    @Override
    public Object executeSProc(final DataSource ds, final String sql, final Object[] args, final int[] types,
            final InvocationContext invocationContext, final Class<?> returnType) {

        SameConnectionDatasource sameConnDs = null;

        try {

            sameConnDs = new SameConnectionDatasource(ds.getConnection());

            setTimeout(sameConnDs.getConnection());

            if (!lockAdvisoryLock(sameConnDs.getConnection())) {
                throw new RuntimeException("Could not acquire AdvisoryLock " + lock.name());
            }

            return executor.executeSProc(sameConnDs, sql, args, types, invocationContext, returnType);

        } catch (final SQLException e) {

            throw new RuntimeException("SQL Exception in execute sproc: " + sql, e);

        } finally {
            if (sameConnDs != null) {
                try {

                    if (timeoutInMilliSeconds > 0) {
                        try {
                            resetTimeout(sameConnDs.getConnection());
                        } catch (final SQLException ex) {
                            LOG.error("Exception in reseting statement timeout!", ex);
                        }
                    }

                    // unlock in all cases, locks not owned by this session cannot be unlocked
                    if (lock != AdvisoryLock.NO_LOCK) {
                        try {
                            unlockAdvisoryLock(sameConnDs.getConnection());
                        } catch (final SQLException ex) {
                            LOG.error("Exception in reseting advisory lock!", ex);
                        }
                    }
                } finally {
                    try {
                        sameConnDs.close();
                    } catch (final SQLException ex) {
                        LOG.error("Exception in closing underlying connection!", ex);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of de.zalando.sprocwrapper.dsprovider.SameConnectionDatasource

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.