|
24 | 24 | import java.sql.Connection; |
25 | 25 | import java.sql.PreparedStatement; |
26 | 26 | import java.sql.SQLException; |
| 27 | +import java.sql.Statement; |
27 | 28 | import java.sql.Timestamp; |
28 | 29 |
|
29 | 30 | import org.springframework.core.env.Environment; |
@@ -63,7 +64,7 @@ public class JDBCCollector extends AbstractDbCollector { |
63 | 64 | private Environment environment; |
64 | 65 |
|
65 | 66 | @PostConstruct |
66 | | - public void init() { |
| 67 | + public void init() throws IOException { |
67 | 68 | String baseURL = environment.getProperty("proxy.usage-stats-url"); |
68 | 69 | String username = environment.getProperty("proxy.usage-stats-username", "monetdb"); |
69 | 70 | String password = environment.getProperty("proxy.usage-stats-password", "monetdb"); |
@@ -96,7 +97,29 @@ public void init() { |
96 | 97 | if (maximumPoolSize != null) { |
97 | 98 | ds.setMaximumPoolSize(maximumPoolSize); |
98 | 99 | } |
99 | | - |
| 100 | + |
| 101 | + // create table if not already exists |
| 102 | + try (Connection con = ds.getConnection()) { |
| 103 | + Statement statement = con.createStatement(); |
| 104 | + if (con.getMetaData().getDatabaseProductName().equals("Microsoft SQL Server")) { |
| 105 | + statement.execute( |
| 106 | + "IF OBJECT_ID('event', 'U') IS NULL" + |
| 107 | + " create table event(" + |
| 108 | + " event_time datetime," + |
| 109 | + " username varchar(128)," + |
| 110 | + " type varchar(128)," + |
| 111 | + " data text)"); |
| 112 | + } else { |
| 113 | + statement.execute( |
| 114 | + "create table if not exists event(" + |
| 115 | + " event_time timestamp," + |
| 116 | + " username varchar(128)," + |
| 117 | + " type varchar(128)," + |
| 118 | + " data text)"); |
| 119 | + } |
| 120 | + } catch (SQLException e) { |
| 121 | + throw new IOException("Exception while logging stats", e); |
| 122 | + } |
100 | 123 | } |
101 | 124 |
|
102 | 125 | @Override |
|
0 commit comments