Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/backend/utils/DBCPConnectionProvider.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | ff27548d078c |
children | 0071702ba03f |
comparison
equal
deleted
inserted
replaced
8855:d7c005e12af0 | 8856:5e38e2924c07 |
---|---|
42 import org.hibernate.connection.ConnectionProvider; | 42 import org.hibernate.connection.ConnectionProvider; |
43 | 43 |
44 import org.hibernate.cfg.Environment; | 44 import org.hibernate.cfg.Environment; |
45 | 45 |
46 /** | 46 /** |
47 * <p>A connection provider that uses an Apache commons DBCP connection pool.</p> | 47 * A connection provider that uses an Apache commons DBCP connection pool. |
48 * | 48 * |
49 * <p>To use this connection provider set:<br> | 49 * To use this connection provider set hibernate.connection.provider_class |
50 * <code>hibernate.connection.provider_class org.hibernate.connection.DBCPConnectionProvider</code></p> | 50 * to org.hibernate.connection.DBCPConnectionProvider |
51 * | 51 * |
52 * <pre>Supported Hibernate properties: | 52 * <pre>Supported Hibernate properties: |
53 * hibernate.connection.driver_class | 53 * hibernate.connection.driver_class |
54 * hibernate.connection.url | 54 * hibernate.connection.url |
55 * hibernate.connection.username | 55 * hibernate.connection.username |
59 * hibernate.connection.pool_size | 59 * hibernate.connection.pool_size |
60 * hibernate.connection (JDBC driver properties)</pre> | 60 * hibernate.connection (JDBC driver properties)</pre> |
61 * <br> | 61 * <br> |
62 * All DBCP properties are also supported by using the hibernate.dbcp prefix. | 62 * All DBCP properties are also supported by using the hibernate.dbcp prefix. |
63 * A complete list can be found on the DBCP configuration page: | 63 * A complete list can be found on the DBCP configuration page: |
64 * <a href="http://jakarta.apache.org/commons/dbcp/configuration.html">http://jakarta.apache.org/commons/dbcp/configuration.html</a>. | 64 * http://jakarta.apache.org/commons/dbcp/configuration.html |
65 * <br> | 65 * <br> |
66 * <pre>Example: | |
67 * hibernate.connection.provider_class org.hibernate.connection.DBCPConnectionProvider | |
68 * hibernate.connection.driver_class org.hsqldb.jdbcDriver | |
69 * hibernate.connection.username sa | |
70 * hibernate.connection.password | |
71 * hibernate.connection.url jdbc:hsqldb:test | |
72 * hibernate.connection.pool_size 20 | |
73 * hibernate.dbcp.initialSize 10 | |
74 * hibernate.dbcp.maxWait 3000 | |
75 * hibernate.dbcp.validationQuery select 1 from dual</pre> | |
76 * | 66 * |
77 * <p>More information about configuring/using DBCP can be found on the | 67 * <p>More information about configuring/using DBCP can be found on the |
78 * <a href="http://jakarta.apache.org/commons/dbcp/">DBCP website</a>. | 68 * <a href="http://jakarta.apache.org/commons/dbcp/">DBCP website</a>. |
79 * There you will also find the DBCP wiki, mailing lists, issue tracking | 69 * There you will also find the DBCP wiki, mailing lists, issue tracking |
80 * and other support facilities</p> | 70 * and other support facilities</p> |
121 | 111 |
122 // Isolation level | 112 // Isolation level |
123 String isolationLevel = props.getProperty(Environment.ISOLATION); | 113 String isolationLevel = props.getProperty(Environment.ISOLATION); |
124 if (isolationLevel != null | 114 if (isolationLevel != null |
125 && (isolationLevel = isolationLevel.trim()).length() > 0) { | 115 && (isolationLevel = isolationLevel.trim()).length() > 0) { |
126 dbcpProperties.put("defaultTransactionIsolation", isolationLevel); | 116 dbcpProperties.put( |
117 "defaultTransactionIsolation", | |
118 isolationLevel); | |
127 } | 119 } |
128 | 120 |
129 // Turn off autocommit (unless autocommit property is set) | 121 // Turn off autocommit (unless autocommit property is set) |
130 String autocommit = props.getProperty(AUTOCOMMIT); | 122 String autocommit = props.getProperty(AUTOCOMMIT); |
131 if (autocommit != null | 123 if (autocommit != null |
132 && (autocommit = autocommit.trim()).length() > 0) { | 124 && (autocommit = autocommit.trim()).length() > 0) { |
133 dbcpProperties.put("defaultAutoCommit", autocommit); | 125 dbcpProperties.put("defaultAutoCommit", autocommit); |
134 } else { | 126 } else { |
135 dbcpProperties.put("defaultAutoCommit", String.valueOf(Boolean.FALSE)); | 127 dbcpProperties.put( |
128 "defaultAutoCommit", | |
129 String.valueOf(Boolean.FALSE)); | |
136 } | 130 } |
137 | 131 |
138 // Pool size | 132 // Pool size |
139 String poolSize = props.getProperty(Environment.POOL_SIZE); | 133 String poolSize = props.getProperty(Environment.POOL_SIZE); |
140 if (poolSize != null | 134 if (poolSize != null |
204 ds = (BasicDataSource)BasicDataSourceFactory | 198 ds = (BasicDataSource)BasicDataSourceFactory |
205 .createDataSource(dbcpProperties); | 199 .createDataSource(dbcpProperties); |
206 | 200 |
207 // This needs to be done manually as it is somehow ignored | 201 // This needs to be done manually as it is somehow ignored |
208 // by the BasicDataSourceFactory if you set it as a dbcpProperty | 202 // by the BasicDataSourceFactory if you set it as a dbcpProperty |
209 String connectionInitSqls = props.getProperty("connectionInitSqls"); | 203 String connectionInitSqls = props.getProperty( |
204 "connectionInitSqls"); | |
210 if (connectionInitSqls != null) { | 205 if (connectionInitSqls != null) { |
211 String[] statements = connectionInitSqls.split(";"); | 206 String[] statements = connectionInitSqls.split(";"); |
212 ds.setConnectionInitSqls(Arrays.asList(statements)); | 207 ds.setConnectionInitSqls(Arrays.asList(statements)); |
213 } | 208 } |
214 | 209 |