13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package org .culturegraph .mf .morph .maps ;
17
-
18
- import java .io .Closeable ;
19
- import java .io .IOException ;
20
- import java .sql .Connection ;
21
- import java .sql .PreparedStatement ;
22
- import java .sql .ResultSet ;
23
- import java .sql .SQLException ;
16
+ package org .culturegraph .mf .morph .maps ;
17
+
18
+ import java .io .Closeable ;
19
+ import java .io .IOException ;
20
+ import java .sql .Connection ;
21
+ import java .sql .PreparedStatement ;
22
+ import java .sql .ResultSet ;
23
+ import java .sql .SQLException ;
24
24
import java .sql .Statement ;
25
- import javax .naming .InitialContext ;
26
- import javax .naming .NamingException ;
27
- import javax .sql .DataSource ;
28
-
29
- import org .culturegraph .mf .exceptions .MorphException ;
25
+ import javax .naming .InitialContext ;
26
+ import javax .naming .NamingException ;
27
+ import javax .sql .DataSource ;
28
+
29
+ import org .culturegraph .mf .exceptions .MorphException ;
30
30
import org .slf4j .Logger ;
31
31
import org .slf4j .LoggerFactory ;
32
-
33
-
34
- /**
35
- * @author Daniel
36
- *
37
- */
38
- public final class JndiSqlMap extends AbstractReadOnlyMap <String , String > implements Closeable {
39
-
40
- private static final Logger LOG = LoggerFactory .getLogger (JndiSqlMap .class );
41
- private DataSource datasource ;
42
- private String query ;
32
+
33
+
34
+ /**
35
+ * @author Daniel
36
+ *
37
+ */
38
+ public final class JndiSqlMap extends AbstractReadOnlyMap <String , String > implements Closeable {
39
+
40
+ private static final Logger LOG = LoggerFactory .getLogger (JndiSqlMap .class );
41
+ private DataSource datasource ;
42
+ private String query ;
43
43
private Connection connection ;
44
-
45
-
46
- @ Override
47
- public void close () throws IOException {
48
- try {
49
- if (connection != null ) {
50
- connection .close ();
51
- }
52
- } catch (SQLException e ) {
53
- throw new MorphException (e );
54
- }
55
- }
56
-
57
- protected DataSource getDatasource () {
58
- return datasource ;
59
- }
60
-
61
- public void setDatasource (final String name ) {
62
- try {
63
- this .datasource = (DataSource ) new InitialContext ().lookup (name );
64
- } catch (NamingException e ) {
65
- throw new MorphException (e );
66
- }
67
- }
68
-
69
- public void setQuery (final String query ) {
70
- this .query = query ;
71
- }
72
-
73
- @ Override
74
- public String get (final Object key ) {
75
- String resultString = null ;
44
+
45
+
46
+ @ Override
47
+ public void close () throws IOException {
48
+ try {
49
+ if (connection != null ) {
50
+ connection .close ();
51
+ }
52
+ } catch (SQLException e ) {
53
+ throw new MorphException (e );
54
+ }
55
+ }
56
+
57
+ protected DataSource getDatasource () {
58
+ return datasource ;
59
+ }
60
+
61
+ public void setDatasource (final String name ) {
62
+ try {
63
+ this .datasource = (DataSource ) new InitialContext ().lookup (name );
64
+ } catch (NamingException e ) {
65
+ throw new MorphException (e );
66
+ }
67
+ }
68
+
69
+ public void setQuery (final String query ) {
70
+ this .query = query ;
71
+ }
72
+
73
+ @ Override
74
+ public String get (final Object key ) {
75
+ String resultString = null ;
76
76
final ResultSet resultSet ;
77
77
PreparedStatement stmt = null ;
78
- Connection con = null ;
78
+ Connection con = null ;
79
79
try {
80
80
con = datasource .getConnection ();
81
- stmt = con .prepareStatement (query );
82
- stmt .setString (1 , key .toString ());
83
- resultSet = stmt .executeQuery ();
84
- if (resultSet .first ()) {
85
- resultString = resultSet .getString (1 );
86
- }
87
- resultSet .close ();
88
- } catch (SQLException e ) {
89
- throw new MorphException (e );
81
+ stmt = con .prepareStatement (query );
82
+ stmt .setString (1 , key .toString ());
83
+ resultSet = stmt .executeQuery ();
84
+ if (resultSet .first ()) {
85
+ resultString = resultSet .getString (1 );
86
+ }
87
+ resultSet .close ();
88
+ } catch (SQLException e ) {
89
+ throw new MorphException (e );
90
90
} finally {
91
91
if (stmt != null ){
92
92
try {
@@ -102,8 +102,8 @@ public String get(final Object key) {
102
102
LOG .error ("Can't close Connection." , e );
103
103
}
104
104
}
105
- }
106
- return resultString ;
107
- }
108
-
109
- }
105
+ }
106
+ return resultString ;
107
+ }
108
+
109
+ }
0 commit comments