1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.jdbc;
31
32 import java.io.PrintWriter;
33 import java.sql.Connection;
34 import java.sql.Driver;
35 import java.sql.SQLException;
36 import java.util.Properties;
37 import java.util.logging.Logger;
38 import javax.sql.DataSource;
39 import lombok.EqualsAndHashCode;
40 import lombok.ToString;
41
42
43
44
45
46
47 @ToString
48 @EqualsAndHashCode(of = "name")
49 final class H2Source implements DataSource {
50
51
52
53
54 private static final Driver DRIVER = new org.h2.Driver();
55
56
57
58
59 private final transient String name;
60
61
62
63
64
65 H2Source(final String dbname) {
66 this.name = dbname;
67 }
68
69 @Override
70 public Connection getConnection() throws SQLException {
71 return H2Source.DRIVER.connect(
72 String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", this.name),
73 new Properties()
74 );
75 }
76
77 @Override
78 public Connection getConnection(final String username,
79 final String password) {
80 throw new UnsupportedOperationException("#getConnection()");
81 }
82
83 @Override
84 public PrintWriter getLogWriter() {
85 throw new UnsupportedOperationException("#getLogWriter()");
86 }
87
88 @Override
89 public void setLogWriter(final PrintWriter writer) {
90 throw new UnsupportedOperationException("#setLogWriter()");
91 }
92
93 @Override
94 public void setLoginTimeout(final int seconds) {
95 throw new UnsupportedOperationException("#setLoginTimeout()");
96 }
97
98 @Override
99 public int getLoginTimeout() {
100 throw new UnsupportedOperationException("#getLoginTimeout()");
101 }
102
103 @Override
104 public Logger getParentLogger() {
105 throw new UnsupportedOperationException("#getParentLogger()");
106 }
107
108 @Override
109 public <T> T unwrap(final Class<T> iface) {
110 throw new UnsupportedOperationException("#unwrap()");
111 }
112
113 @Override
114 public boolean isWrapperFor(final Class<?> iface) {
115 throw new UnsupportedOperationException("#isWrapperFor()");
116 }
117
118 }