1 | |
package org.apache.ojb.broker.accesslayer; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor; |
19 | |
import org.apache.ojb.broker.util.logging.Logger; |
20 | |
import org.apache.ojb.broker.util.logging.LoggerFactory; |
21 | |
|
22 | |
import java.sql.Connection; |
23 | |
import java.sql.SQLException; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class ConnectionFactoryNotPooledImpl extends ConnectionFactoryAbstractImpl |
32 | |
{ |
33 | |
private Logger log = LoggerFactory.getLogger(ConnectionFactoryNotPooledImpl.class); |
34 | |
|
35 | |
public Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd) throws LookupException |
36 | |
{ |
37 | |
if (log.isDebugEnabled()) |
38 | |
{ |
39 | |
log.debug("checkOutJdbcConnection: this implementation always return a new Connection"); |
40 | |
} |
41 | |
final Connection conn = newConnectionFromDriverManager(jcd); |
42 | |
validateConnection(conn, jcd); |
43 | |
|
44 | |
return conn; |
45 | |
} |
46 | |
|
47 | |
protected void validateConnection(Connection conn, JdbcConnectionDescriptor jcd) |
48 | |
throws LookupException |
49 | |
{ |
50 | |
if (conn == null) |
51 | |
{ |
52 | |
log.error(getJcdDescription(jcd) + " failed, DriverManager returned null"); |
53 | |
throw new LookupException("No Connection returned from DriverManager"); |
54 | |
} |
55 | |
try |
56 | |
{ |
57 | |
if (conn.isClosed()) |
58 | |
{ |
59 | |
log.error(getJcdDescription(jcd) + " is invalid (closed)"); |
60 | |
throw new LookupException("Could not create valid connection, connection was " + |
61 | |
conn); |
62 | |
} |
63 | |
} |
64 | |
catch (SQLException e) |
65 | |
{ |
66 | |
log.error(getJcdDescription(jcd) + " failed validation with exception"); |
67 | |
throw new LookupException("Connection validation failed", e); |
68 | |
} |
69 | |
} |
70 | |
|
71 | |
public void releaseJdbcConnection(JdbcConnectionDescriptor jcd, Connection con) |
72 | |
throws LookupException |
73 | |
{ |
74 | |
try |
75 | |
{ |
76 | |
con.close(); |
77 | |
} |
78 | |
catch (SQLException e) |
79 | |
{ |
80 | |
log.warn("Connection.close() failed, message was " + e.getMessage()); |
81 | |
} |
82 | |
} |
83 | |
|
84 | |
} |