| Line | Hits | Note | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * $Id: DefaultConnectionManager.java 1011 2008-06-16 17:57:36Z amandel $ | ||
| 3 | * | ||
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * Redistributions in binary form must reproduce the above | ||
| 13 | * copyright notice, this list of conditions and the following | ||
| 14 | * disclaimer in the documentation and/or other materials | ||
| 15 | * provided with the distribution. | ||
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of | ||
| 17 | * its contributors may be used to endorse or promote products | ||
| 18 | * derived from this software without specific prior written | ||
| 19 | * permission. | ||
| 20 | * | ||
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND | ||
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS | ||
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | */ | ||
| 33 | package org.jcoderz.commons.connector; | ||
| 34 | |||
| 35 | import java.util.HashSet; | ||
| 36 | import java.util.Iterator; | ||
| 37 | import java.util.Set; | ||
| 38 | import java.util.logging.Logger; | ||
| 39 | |||
| 40 | import javax.resource.ResourceException; | ||
| 41 | import javax.resource.spi.ConnectionManager; | ||
| 42 | import javax.resource.spi.ConnectionRequestInfo; | ||
| 43 | import javax.resource.spi.ManagedConnection; | ||
| 44 | import javax.resource.spi.ManagedConnectionFactory; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * The default Connection Manager. This Manager is intended to be used in a | ||
| 48 | * <b>two tier scenario</b> (Non-managed Environment, see Connection | ||
| 49 | * Architecture 1.0 Chapter 5.9). | ||
| 50 | * | ||
| 51 | */ | ||
| 52 | 100 | (1) | public class DefaultConnectionManager |
| 53 | implements ConnectionManager | ||
| 54 | { | ||
| 55 | /** The full qualified name of this class. */ | ||
| 56 | 75 | private static final transient String CLASSNAME | |
| 57 | = DefaultConnectionManager.class.getName(); | ||
| 58 | |||
| 59 | /** The logger to use. */ | ||
| 60 | 100 | private static final transient Logger logger = Logger.getLogger(CLASSNAME); | |
| 61 | |||
| 62 | /** | ||
| 63 | * The Default <code>serialVersionUID</code> | ||
| 64 | */ | ||
| 65 | private static final long serialVersionUID = 1L; | ||
| 66 | |||
| 67 | 100 | private final Set mMc = new HashSet(); | |
| 68 | |||
| 69 | /** | ||
| 70 | * Creates a new physical connection to the underlying EIS instance. | ||
| 71 | * | ||
| 72 | * @see javax.resource.spi.ConnectionManager#allocateConnection(javax.resource.spi.ManagedConnectionFactory, javax.resource.spi.ConnectionRequestInfo) | ||
| 73 | */ | ||
| 74 | (2)(3) | public Object allocateConnection (ManagedConnectionFactory mcf, | |
| 75 | (4) | ConnectionRequestInfo cri) | |
| 76 | (5) | throws ResourceException | |
| 77 | { | ||
| 78 | 100 | logger.entering(CLASSNAME, "allocateConnection", | |
| 79 | new Object [] {mcf, cri}); | ||
| 80 | |||
| 81 | 100 | ManagedConnection mc = mcf.matchManagedConnections(mMc, null, cri); | |
| 82 | |||
| 83 | 100 | if (mc == null) | |
| 84 | { | ||
| 85 | 100 | mc = mcf.createManagedConnection(null, cri); | |
| 86 | 100 | synchronized (mMc) | |
| 87 | { | ||
| 88 | 100 | mMc.add(mc); | |
| 89 | 50 | } | |
| 90 | } | ||
| 91 | |||
| 92 | 100 | final Object result = mc.getConnection(null, cri); | |
| 93 | |||
| 94 | 100 | logger.exiting(CLASSNAME, "allocateConnection", result); | |
| 95 | |||
| 96 | 100 | return result; | |
| 97 | } | ||
| 98 | |||
| 99 | /** | ||
| 100 | * Cleans up all managed connections. | ||
| 101 | */ | ||
| 102 | public void cleanUp () | ||
| 103 | { | ||
| 104 | 100 | synchronized (mMc) | |
| 105 | { | ||
| 106 | 100 | final Iterator itr = mMc.iterator(); | |
| 107 | 100 | while (itr.hasNext()) | |
| 108 | { | ||
| 109 | try | ||
| 110 | { | ||
| 111 | 100 | ((ManagedConnection) itr.next()).cleanup(); | |
| 112 | } | ||
| 113 | 0 | catch (ResourceException re) | |
| 114 | { | ||
| 115 | // nothing to do | ||
| 116 | 50 | } | |
| 117 | } | ||
| 118 | 50 | } | |
| 119 | 100 | } | |
| 120 | |||
| 121 | /** | ||
| 122 | * Destroys all managed connections. | ||
| 123 | */ | ||
| 124 | public void destroy () | ||
| 125 | { | ||
| 126 | 100 | synchronized (mMc) | |
| 127 | { | ||
| 128 | 100 | final Iterator itr = mMc.iterator(); | |
| 129 | 100 | while (itr.hasNext()) | |
| 130 | { | ||
| 131 | try | ||
| 132 | { | ||
| 133 | 100 | ((ManagedConnection) itr.next()).destroy(); | |
| 134 | } | ||
| 135 | 0 | catch (ResourceException re) | |
| 136 | { | ||
| 137 | // nothing to do | ||
| 138 | 50 | } | |
| 139 | } | ||
| 140 | 50 | } | |
| 141 | 100 | mMc.clear(); | |
| 142 | 100 | } | |
| 143 | } |
|
|
(6) | Class org.jcoderz.commons.connector.DefaultConnectionManager defines non-transient non-serializable instance field mMc | |||
|
|
(7) | The field org.jcoderz.commons.connector.DefaultConnectionManager.CLASSNAME is transient but isn't set by deserialization | |||
|
|
(1) | 52 | : | 0 | Type Javadoc comment is missing an @author tag. |
|
|
(2) | 74 | : | 0 | Expected an @return tag. |
|
|
(3) | 74 | : | 63 | Expected @param tag for 'mcf'. |
|
|
(4) | 75 | : | 32 | Expected @param tag for 'cri'. |
|
|
(5) | 76 | : | 17 | Expected @throws tag for 'ResourceException'. |