All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.store.connection.AbstractManagedConnection Maven / Gradle / Ivy

Go to download

DataNucleus Core provides the primary components of a heterogenous Java persistence solution. It supports persistence API's being layered on top of the core functionality.

There is a newer version: 6.0.7
Show newest version
/**********************************************************************
Copyright (c) 2009 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
   ...
**********************************************************************/
package org.datanucleus.store.connection;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.xa.XAResource;

import org.datanucleus.util.StringUtils;

/**
 * Abstract implementation of a managed connection.
 * There are three primary modes for a connection.
 * 
    *
  • Transactional - the commit of connection is controlled external to this class, and when we release * the connection it is handed back into a pooled state, available for reuse.
  • *
  • Non-transactional (1) - the commit of the connection happens at close and when we release the * connection it closes the connection (after committing it).
  • *
  • Non-transactional (2) - the commit of the connection happens at release, and when we release * the connection it is handed back into a pooled state, available for reuse.
  • *
*/ public abstract class AbstractManagedConnection implements ManagedConnection { /** The underlying (datastore-specific) connection. */ protected Object conn; /** Whether we should close() when release() of the connection is called. */ protected boolean closeOnRelease = true; /** Whether we should commit() the connection on release(). */ protected boolean commitOnRelease = true; /** Whether the connection is locked for use. */ protected boolean locked = false; /** Listeners for the connection. */ protected List listeners = new ArrayList(); /** Count on the number of outstanding uses of this connection. Incremented on get. Decremented on release(). */ protected int useCount = 0; protected void incrementUseCount() { useCount = useCount + 1; } /** * Release this connection back to us so we can pool it if required. In the case of a transactional * connection it is allocated and released and always pooled (not committed) during the transaction. * With non-transactional connections, they can be pooled (where selected), or not (default). */ public void release() { if (closeOnRelease) { useCount = useCount -1; if (useCount == 0) { // Close if this is the last use of the connection close(); } } } public void transactionFlushed() { if (!listeners.isEmpty()) { ManagedConnectionResourceListener[] mcrls = listeners.toArray(new ManagedConnectionResourceListener[listeners.size()]); for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy