Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 120 |  | Methods: | 11
| NCLOC: | 78 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
JdbcServerServiceImpl.java | 0% | 0% | 0% | 0% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     /*
6 |  |
      * Created on 2004/02/22
7 |  |
      */
8 |  |
     package org.asyrinx.brownie.jdbc.util;
9 |  |
10 |  |
     import java.io.IOException;
11 |  |
     import java.sql.Connection;
12 |  |
     import java.sql.Date;
13 |  |
     import java.sql.PreparedStatement;
14 |  |
     import java.sql.ResultSet;
15 |  |
     import java.sql.SQLException;
16 |  |
     import java.sql.Time;
17 |  |
     import java.sql.Timestamp;
18 |  |
19 |  |
     import org.asyrinx.brownie.core.io.sf.ClassResourceStreamFactory;
20 |  |
     import org.asyrinx.brownie.core.io.sf.StringLoader;
21 |  |
     import org.asyrinx.brownie.core.lang.StringUtils;
22 |  |
23 |  |
     /**
24 |  |
      * @author akima
25 |  |
      */
26 |  |
     public class JdbcServerServiceImpl implements JdbcServerService {
27 |  |
28 |  |
         /**
29 |  |
          *
30 |  |
          */
31 | 0 |
         public JdbcServerServiceImpl() {
32 | 0 |
             super();
33 |  |
         }
34 |  |
35 |  |
         /**
36 |  |
          *
37 |  |
          */
38 | 0 |
         public JdbcServerServiceImpl(Connection connection) {
39 | 0 |
             super();
40 | 0 |
             setConnection(connection);
41 |  |
         }
42 |  |
43 |  |
         private Connection connection = null;
44 |  |
45 |  |
         /**
46 |  |
          * @return
47 |  |
          */
48 | 0 |
         public Connection getConnection() {
49 | 0 |
             return connection;
50 |  |
         }
51 |  |
52 |  |
         /**
53 |  |
          * @param connection
54 |  |
          */
55 | 0 |
         public void setConnection(Connection connection) {
56 | 0 |
             this.connection = connection;
57 | 0 |
             if (this.connection == null)
58 | 0 |
                 jdbcDriver = null;
59 |  |
         }
60 |  |
61 |  |
         private JdbcDriverType jdbcDriver = null;
62 |  |
63 | 0 |
         private void initDriver() throws SQLException {
64 | 0 |
             if (this.getConnection() == null)
65 | 0 |
                 throw new SQLException("connection not found.");
66 | 0 |
             if (jdbcDriver == null)
67 | 0 |
                 jdbcDriver = JdbcDriverType.get(this.connection);
68 |  |
         }
69 |  |
70 | 0 |
         public Date getCurrentDate() throws SQLException {
71 | 0 |
             final ResultSet rs = executeNoParamSql("currentDate.sql");
72 | 0 |
             if (rs.next())
73 | 0 |
                 return rs.getDate(1);
74 |  |
             else
75 | 0 |
                 throw new SQLException("failed to retrieve current date.");
76 |  |
         }
77 |  |
78 | 0 |
         public Time getCurrentTime() throws SQLException {
79 | 0 |
             final ResultSet rs = executeNoParamSql("currentTime.sql");
80 | 0 |
             if (rs.next())
81 | 0 |
                 return rs.getTime(1);
82 |  |
             else
83 | 0 |
                 throw new SQLException("failed to retrieve current time.");
84 |  |
         }
85 |  |
86 | 0 |
         public Timestamp getCurrentTimestamp() throws SQLException {
87 | 0 |
             final ResultSet rs = executeNoParamSql("currentTimestamp.sql");
88 | 0 |
             if (rs.next())
89 | 0 |
                 return rs.getTimestamp(1);
90 |  |
             else
91 | 0 |
                 throw new SQLException("failed to retrieve current timestamp.");
92 |  |
         }
93 |  |
94 | 0 |
         protected final ResultSet executeNoParamSql(String filename) throws SQLException {
95 | 0 |
             initDriver();
96 | 0 |
             final String sql;
97 | 0 |
             try {
98 | 0 |
                 sql = getSql(filename);
99 |  |
             } catch (IOException e) {
100 | 0 |
                 throw new SQLException(e.getMessage());
101 |  |
             }
102 | 0 |
             final PreparedStatement st = getConnection().prepareStatement(sql);
103 | 0 |
             return st.executeQuery();
104 |  |
         }
105 |  |
106 |  |
         private static final String PATH_SQL = getPathSql();
107 |  |
108 | 0 |
         private static String getPathSql() {
109 | 0 |
             return StringUtils.replace(JdbcServerServiceImpl.class.getPackage().getName() + ".sql", ".", "/");
110 |  |
         }
111 |  |
112 |  |
         private StringLoader loader = null;
113 |  |
114 | 0 |
         public String getSql(String filename) throws IOException {
115 | 0 |
             if (loader == null)
116 | 0 |
                 loader = new StringLoader(new ClassResourceStreamFactory());
117 | 0 |
             return loader.load(PATH_SQL + "/" + jdbcDriver.getInnerName() + "/" + filename);
118 |  |
         }
119 |  |
120 |  |
     }