SessionImpl.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase1739
Reviews2873
DPMO306
Sigma4.926

Metrics
NameNumberMinAvgMaxTotal
Class complexity132.0032.0032.0032.00
Code length181.003.3321.0060.00
File length1207.00207.00207.00207.00
Operation complexity181.001.776.0032.00
Work order132.2532.2532.2532.25

Violations
#LineColumnNameSeverityDescription
1231ER-0233Packages should begin with []
26691ER-0363Line is too long
379112ER-0363Line is too long
48686ER-0363Line is too long
588108ER-0363Line is too long
614494ER-0363Line is too long
714585ER-0363Line is too long
817499ER-0363Line is too long
9179108ER-0363Line is too long
10187100ER-0363Line is too long
11501ER-0492Unify logging strategy - define individual logger for class
127125ER-0823Avoid using method parameter names that conflict with class member names
13859ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
148888ER-1163Use StringBuffer for excessive String concatenation
158861ER-0303Avoid hardwired string literals
168889ER-0303Avoid hardwired string literals
17999ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
181039ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
191079ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
201119ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
2112032ER-0823Avoid using method parameter names that conflict with class member names
221309ER-1022String Arrays are deprecated and are ONLY allowed for final variables
231309ER-1042Use a Collection instead of arrays Object[]
2413233ER-0823Avoid using method parameter names that conflict with class member names
251369ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
261369ER-1073Instance variables and method names shouldn't have same name
271409ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
2814735ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
2914935ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
3015719ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
3117957ER-0303Avoid hardwired string literals
3218328ER-0823Avoid using method parameter names that conflict with class member names
3318761ER-0303Avoid hardwired string literals
341979ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc

JavaDoc
SessionImpl

1/*
2 * Hammurapi
3 * Automated Java code review system.
4 * Copyright (C) 2004 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.org
21 * e-Mail: support@hammurapi.biz
22 */

23package org.hammurapi;
24
25import java.io.IOException;
26import java.io.Reader;
27import java.sql.SQLException;
28import java.util.ArrayList;
29import java.util.Collection;
30import java.util.HashMap;
31import java.util.Iterator;
32import java.util.Map;
33import java.util.Properties;
34
35import javax.sql.DataSource;
36
37import org.hammurapi.results.ResultsFactory;
38
39import com.pavelvlasov.config.ConfigurationException;
40import com.pavelvlasov.persistence.Storage;
41import com.pavelvlasov.sql.ConnectionPerThreadDataSource;
42import com.pavelvlasov.sql.SQLProcessor;
43import com.pavelvlasov.sql.hypersonic.HypersonicTmpDataSource;
44import com.pavelvlasov.util.DispatchingVisitor;
45
46/**
47 * @author Pavel Vlasov
48 * @version $Revision: 1.6 $
49 */

50public class SessionImpl implements Session {
51
52 private DispatchingVisitor visitor;
53
54 private Map contexts=new HashMap();
55
56 private Collection inspectors;
57
58 private Storage storage;
59
60 private boolean inspectorsSet;
61
62 /**
63 * @return Returns the storage.
64 */

65 public Storage getStorage() {
66 return storage==null ? ResultsFactory.getInstance().getStorage() : storage;
67 }
68 /**
69 * @param storage The storage to set.
70 */

71 void setStorage(Storage storage) {
72 this.storage = storage;
73 }
74 /**
75 * @param inspectorSet The inspectors to set.
76 * @throws HammurapiException
77 * @throws ConfigurationException
78 */

79 public void setInspectors(InspectorSet inspectorSet) throws ConfigurationException, HammurapiException {
80 this.inspectorsSet=true;
81 this.inspectors = new ArrayList(inspectorSet.getInspectors());
82 inspectorSet.initInspectors();
83 }
84
85 public InspectorContext getContext(String inspectorName) {
86 InspectorContext ret = (InspectorContext) contexts.get(inspectorName);
87 if (ret==null) {
88 throw new HammurapiRuntimeException("Inspector '"+inspectorName+"' does not exist");
89 }
90 return ret;
91 }
92
93 void addContext(String inspectorName, InspectorContext context) {
94 contexts.put(inspectorName, context);
95 }
96
97 private Map attributes=new HashMap();
98
99 public void setAttribute(Object key, Object value) {
100 attributes.put(key, value);
101 }
102
103 public Object getAttribute(Object key) {
104 return attributes.get(key);
105 }
106
107 public Object removeAttribute(Object key) {
108 return attributes.remove(key);
109 }
110
111 public void disable(Inspector inspector) {
112 if (visitor!=null) {
113 visitor.remove(inspector);
114 }
115 }
116
117 /**
118 * @param visitor The visitor to set.
119 */

120 public void setVisitor(DispatchingVisitor visitor) {
121 this.visitor = visitor;
122 }
123
124 private SQLProcessor processor;
125
126 private ConnectionPerThreadDataSource datasource;
127
128 private boolean scheduleInitDb;
129
130 private String[] classPath;
131
132 void setClassPath(String[] classPath) {
133 this.classPath=classPath;
134 }
135
136 public void scheduleInitDb() {
137 this.scheduleInitDb = true;
138 }
139
140 public SQLProcessor getProcessor() {
141 try {
142 if (processor==null) {
143 try {
144 datasource=new HypersonicTmpDataSource((Reader) null);
145 processor=new SQLProcessor(datasource, null);
146 scheduleInitDb=true;
147 } catch (ClassNotFoundException e) {
148 throw new HammurapiRuntimeException(e);
149 } catch (IOException e) {
150 throw new HammurapiRuntimeException(e);
151 }
152 }
153 if (scheduleInitDb) {
154 scheduleInitDb=false;
155 initDb();
156 }
157 } catch (SQLException e) {
158 throw new HammurapiRuntimeException(e);
159 }
160
161 return processor;
162 }
163
164 /**
165 * @throws SQLException
166 */

167 private void initDb() throws SQLException {
168 if (inspectorsSet) {
169 if (inspectors!=null) {
170 Iterator it=inspectors.iterator();
171 while (it.hasNext()) {
172 Object next = it.next();
173 if (next instanceof Inspector) {
174 ((Inspector) next).initDb(processor, dbProperties);
175 }
176 }
177 }
178 } else {
179 throw new IllegalStateException("getProcessor() called before inspectors were set");
180 }
181 }
182
183 void setDatasource(DataSource datasource) {
184 if (processor==null) {
185 processor=new SQLProcessor(datasource,null);
186 } else {
187 throw new HammurapiRuntimeException("Illegal state: processor is not null");
188 }
189 }
190
191 void shutdown() throws SQLException {
192 if (datasource != null) {
193 datasource.shutdown();
194 }
195 }
196
197 public String[] getClassPath() {
198 return classPath;
199 }
200
201 private Properties dbProperties=new Properties();
202
203 void setDbProperty(String name, String value) {
204 dbProperties.setProperty(name, value);
205 }
206}
207
208

Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.