Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java @ 172:60063c67f9e7 embedded
Merged with default
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Tue, 19 Sep 2017 13:49:34 +0200 (2017-09-19) |
parents | 8af0a7387b4e |
children | 5b13ccaba741 |
comparison
equal
deleted
inserted
replaced
171:0f95fee3cf29 | 172:60063c67f9e7 |
---|---|
32 */ | 32 */ |
33 public class MonetDataSource extends MonetWrapper implements DataSource { | 33 public class MonetDataSource extends MonetWrapper implements DataSource { |
34 | 34 |
35 private String user; | 35 private String user; |
36 private String password; // insecure, but how to do it better? | 36 private String password; // insecure, but how to do it better? |
37 private String description = "MonetDB database"; | 37 private String description = "MonetDB database"; |
38 private String url = "jdbc:monetdb://localhost/"; | 38 private String url = "jdbc:monetdb://localhost/"; |
39 private int loginTimeout; | 39 private int loginTimeout; |
40 private String directory; | 40 private String directory; |
41 private final MonetDriver driver = new MonetDriver(); | 41 private final MonetDriver driver = new MonetDriver(); |
42 | 42 |
43 // the following properties are also standard: | 43 // the following properties are also standard: |
44 // private String dataSourceName; | 44 // private String dataSourceName; |
45 // private String networkProtocol; | 45 // private String networkProtocol; |
46 // private String serverName; | 46 // private String serverName; |
47 // private String role; | 47 // private String role; |
48 | 48 |
49 public MonetDataSource() {} | 49 public MonetDataSource() {} |
50 | 50 |
51 /** | 51 /** |
52 * Attempts to establish a connection with the data source that this DataSource object represents. | 52 * Attempts to establish a connection with the data source that this DataSource object represents. |
53 * | 53 * |
54 * @return a MonetConnection | 54 * @return a MonetConnection |
70 @Override | 70 @Override |
71 public Connection getConnection(String username, String password) throws SQLException { | 71 public Connection getConnection(String username, String password) throws SQLException { |
72 Properties props = new Properties(); | 72 Properties props = new Properties(); |
73 props.put("user", username); | 73 props.put("user", username); |
74 props.put("password", password); | 74 props.put("password", password); |
75 if (loginTimeout > 0) { | 75 if (loginTimeout > 0) { |
76 props.put("so_timeout", Integer.toString(loginTimeout)); | 76 props.put("so_timeout", Integer.toString(loginTimeout)); |
77 } | 77 } |
78 if(directory != null) { | 78 if(directory != null) { |
79 props.put("embedded", "true"); | 79 props.put("embedded", "true"); |
80 props.put("directory", directory); | 80 props.put("directory", directory); |
81 } | 81 } |
82 return driver.connect(url, props); | 82 return driver.connect(url, props); |
83 } | 83 } |
84 | 84 |
85 /** | 85 /** |
86 * Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. | 86 * Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. |
182 */ | 182 */ |
183 public void setDescription(String description) { | 183 public void setDescription(String description) { |
184 this.description = description; | 184 this.description = description; |
185 } | 185 } |
186 | 186 |
187 /** | 187 /** |
188 * Gets the directory value | 188 * Gets the directory value |
189 * | 189 * |
190 * @return the directory value | 190 * @return the directory value |
191 */ | 191 */ |
192 public String getDirectory() { | 192 public String getDirectory() { |
193 return directory; | 193 return directory; |
194 } | 194 } |
195 | 195 |
196 /** | 196 /** |
197 * Sets the directory value, meaning it wil start an embedded connection | 197 * Sets the directory value, meaning it wil start an embedded connection |
198 * | 198 * |
199 * @param directory The directory location | 199 * @param directory The directory location |
200 */ | 200 */ |
201 public void setDirectory(String directory) { | 201 public void setDirectory(String directory) { |
202 this.directory = directory; | 202 this.directory = directory; |
203 } | 203 } |
204 | 204 |
205 /** | 205 /** |
206 * Gets the embedded connection directory. If not, then a MAPI connection will be created instead. | 206 * Gets the embedded connection directory. If not, then a MAPI connection will be created instead. |
207 * | 207 * |
208 * @return If the connection will be embedded. If not, then a MAPI connection will be created instead. | 208 * @return If the connection will be embedded. If not, then a MAPI connection will be created instead. |
209 */ | 209 */ |
210 public boolean isEmbedded() { | 210 public boolean isEmbedded() { |
211 return directory != null; | 211 return directory != null; |
212 } | 212 } |
213 | 213 |
214 /** | 214 /** |
215 * Return the parent Logger of all the Loggers used by this data | 215 * Return the parent Logger of all the Loggers used by this data |
216 * source. This should be the Logger farthest from the root Logger | 216 * source. This should be the Logger farthest from the root Logger |
217 * that is still an ancestor of all of the Loggers used by this data | 217 * that is still an ancestor of all of the Loggers used by this data |
218 * source. Configuring this Logger will affect all of the log | 218 * source. Configuring this Logger will affect all of the log |
219 * messages generated by the data source. In the worst case, this | 219 * messages generated by the data source. In the worst case, this |