1
|
package vldc.aswi.configuration;
|
2
|
|
3
|
import javax.sql.DataSource;
|
4
|
|
5
|
import com.sun.istack.NotNull;
|
6
|
import oracle.jdbc.pool.OracleDataSource;
|
7
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
8
|
import org.springframework.context.annotation.Bean;
|
9
|
import org.springframework.context.annotation.Configuration;
|
10
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
|
14
|
/**
|
15
|
* Connection configuration for database.
|
16
|
*/
|
17
|
@Configuration
|
18
|
@EnableTransactionManagement
|
19
|
@ConfigurationProperties(prefix = "oracle")
|
20
|
public class DbConfig {
|
21
|
|
22
|
/** Username of logging user. */
|
23
|
@NotNull
|
24
|
private String username;
|
25
|
|
26
|
/** Password of logging user. */
|
27
|
@NotNull
|
28
|
private String password;
|
29
|
|
30
|
/** TNS url for connection into database. */
|
31
|
@NotNull
|
32
|
private String url;
|
33
|
|
34
|
/**
|
35
|
* Set new username.
|
36
|
* @param username - User's name.
|
37
|
*/
|
38
|
public void setUsername(String username) {
|
39
|
this.username = username;
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Set new password.
|
44
|
* @param password - User's password.
|
45
|
*/
|
46
|
public void setPassword(String password) {
|
47
|
this.password = password;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Set new url.
|
52
|
* @param url - TNS url for connection into database.
|
53
|
*/
|
54
|
public void setUrl(String url) {
|
55
|
this.url = url;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Create new datasource.
|
60
|
* @return new Datasource of currently logged database.
|
61
|
* @throws SQLException
|
62
|
*/
|
63
|
@Bean
|
64
|
DataSource dataSource() throws SQLException {
|
65
|
OracleDataSource dataSource = new OracleDataSource();
|
66
|
dataSource.setUser(username);
|
67
|
dataSource.setPassword(password);
|
68
|
dataSource.setURL(url);
|
69
|
dataSource.setImplicitCachingEnabled(true);
|
70
|
dataSource.setFastConnectionFailoverEnabled(true);
|
71
|
return dataSource;
|
72
|
}
|
73
|
|
74
|
}
|