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.DriverManager;
35 import java.sql.SQLException;
36 import java.util.logging.Logger;
37 import javax.sql.DataSource;
38 import lombok.EqualsAndHashCode;
39 import lombok.ToString;
40
41
42
43
44
45
46 @ToString
47 @EqualsAndHashCode(of = "url")
48 public final class UrlSource implements DataSource {
49
50
51
52
53 private final transient String url;
54
55
56
57
58
59 public UrlSource(final String jdbc) {
60 this.url = jdbc;
61 }
62
63 @Override
64 public Connection getConnection() {
65 try {
66 return DriverManager.getConnection(this.url);
67 } catch (final SQLException ex) {
68 throw new IllegalArgumentException(ex);
69 }
70 }
71
72 @Override
73 public Connection getConnection(final String username,
74 final String password) {
75 return this.getConnection();
76 }
77
78 @Override
79 public PrintWriter getLogWriter() {
80 throw new UnsupportedOperationException("#getLogWriter()");
81 }
82
83 @Override
84 public void setLogWriter(final PrintWriter writer) {
85 throw new UnsupportedOperationException("#setLogWriter()");
86 }
87
88 @Override
89 public void setLoginTimeout(final int seconds) {
90 throw new UnsupportedOperationException("#setLoginTimeout()");
91 }
92
93 @Override
94 public int getLoginTimeout() {
95 throw new UnsupportedOperationException("#getLoginTimeout()");
96 }
97
98 @Override
99 public Logger getParentLogger() {
100 throw new UnsupportedOperationException("#getParentLogger()");
101 }
102
103 @Override
104 public <T> T unwrap(final Class<T> iface) {
105 throw new UnsupportedOperationException("#unwrap()");
106 }
107
108 @Override
109 public boolean isWrapperFor(final Class<?> iface) {
110 throw new UnsupportedOperationException("#isWrapperFor()");
111 }
112
113 }