%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
net.sf.infrared.aspects.jdbc.SqlContextManager |
|
|
1 | /* |
|
2 | * Copyright 2005 Tavant Technologies and Contributors |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | * |
|
16 | * |
|
17 | * |
|
18 | * Original Author: binil.thomas (Tavant Technologies) |
|
19 | * Contributor(s): prashant.nair; |
|
20 | * |
|
21 | */ |
|
22 | package net.sf.infrared.aspects.jdbc; |
|
23 | ||
24 | import java.util.Map; |
|
25 | import java.util.WeakHashMap; |
|
26 | ||
27 | /** |
|
28 | * This class manages the SqlContext, SqlExecuteContext and SqlPrepareContext objects |
|
29 | * pertaining to a given SQL string. |
|
30 | * |
|
31 | * @author prashant.nair |
|
32 | * @author binil.thomas |
|
33 | */ |
|
34 | 0 | public class SqlContextManager { |
35 | // map of sql string -> SqlContext object |
|
36 | 0 | private Map sqlStringToSqlContextMap = new WeakHashMap(); |
37 | ||
38 | public SqlContext getSqlContext(String sql) { |
|
39 | 0 | SqlContext sqlCtx = (SqlContext) sqlStringToSqlContextMap.get(sql); |
40 | 0 | synchronized (sqlStringToSqlContextMap) { |
41 | 0 | if (sqlCtx == null) { |
42 | 0 | sqlCtx = new SqlContext(sql); |
43 | 0 | sqlStringToSqlContextMap.put(sql, sqlCtx); |
44 | } |
|
45 | 0 | } |
46 | 0 | return sqlCtx; |
47 | } |
|
48 | ||
49 | public SqlExecuteContext getExecuteContext(String sql) { |
|
50 | 0 | return getSqlContext(sql).getExecuteContext(); |
51 | } |
|
52 | ||
53 | public SqlPrepareContext getPrepareContext(String sql) { |
|
54 | 0 | return getSqlContext(sql).getPrepareContext(); |
55 | } |
|
56 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |