Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
09bf59de
Commit
09bf59de
authored
Dec 22, 2017
by
GregDThomas
Committed by
Guus der Kinderen
Dec 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OF-1419 revisited: ensure that the embedded database works too.
parent
6c52d409
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
21 deletions
+23
-21
EmbeddedConnectionProvider.java
...org/jivesoftware/database/EmbeddedConnectionProvider.java
+23
-21
No files found.
src/java/org/jivesoftware/database/EmbeddedConnectionProvider.java
View file @
09bf59de
...
@@ -16,6 +16,14 @@
...
@@ -16,6 +16,14 @@
package
org
.
jivesoftware
.
database
;
package
org
.
jivesoftware
.
database
;
import
org.apache.commons.dbcp2.ConnectionFactory
;
import
org.apache.commons.dbcp2.DriverManagerConnectionFactory
;
import
org.apache.commons.dbcp2.PoolableConnection
;
import
org.apache.commons.dbcp2.PoolableConnectionFactory
;
import
org.apache.commons.dbcp2.PoolingDataSource
;
import
org.apache.commons.pool2.impl.GenericObjectPool
;
import
org.apache.commons.pool2.impl.GenericObjectPoolConfig
;
import
org.jivesoftware.util.JiveConstants
;
import
org.jivesoftware.util.JiveGlobals
;
import
org.jivesoftware.util.JiveGlobals
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -25,8 +33,6 @@ import java.io.IOException;
...
@@ -25,8 +33,6 @@ import java.io.IOException;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.DriverManager
;
import
java.util.Properties
;
/**
/**
* A connection provider for the embedded hsqlDB database. The database file is stored at
* A connection provider for the embedded hsqlDB database. The database file is stored at
...
@@ -40,10 +46,8 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
...
@@ -40,10 +46,8 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
EmbeddedConnectionProvider
.
class
);
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
EmbeddedConnectionProvider
.
class
);
private
Properties
settings
;
private
String
serverURL
;
private
String
serverURL
;
private
String
driver
=
"org.hsqldb.jdbcDriver"
;
private
PoolingDataSource
<
PoolableConnection
>
dataSource
;
private
String
proxoolURL
;
public
EmbeddedConnectionProvider
()
{
public
EmbeddedConnectionProvider
()
{
}
}
...
@@ -55,13 +59,10 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
...
@@ -55,13 +59,10 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
@Override
@Override
public
Connection
getConnection
()
throws
SQLException
{
public
Connection
getConnection
()
throws
SQLException
{
try
{
if
(
dataSource
==
null
)
{
Class
.
forName
(
"org.logicalcobwebs.proxool.ProxoolDriver"
);
throw
new
SQLException
(
"Check HSQLDB properties; data source was not be initialised"
);
return
DriverManager
.
getConnection
(
proxoolURL
,
settings
);
}
catch
(
ClassNotFoundException
e
)
{
throw
new
SQLException
(
"EmbeddedConnectionProvider: Unable to find driver: "
+
e
);
}
}
return
dataSource
.
getConnection
();
}
}
@Override
@Override
...
@@ -78,13 +79,16 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
...
@@ -78,13 +79,16 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
catch
(
IOException
ioe
)
{
catch
(
IOException
ioe
)
{
Log
.
error
(
"EmbeddedConnectionProvider: Error starting connection pool: "
,
ioe
);
Log
.
error
(
"EmbeddedConnectionProvider: Error starting connection pool: "
,
ioe
);
}
}
proxoolURL
=
"proxool.openfire:"
+
driver
+
":"
+
serverURL
;
final
ConnectionFactory
connectionFactory
=
new
DriverManagerConnectionFactory
(
serverURL
,
"sa"
,
""
);
settings
=
new
Properties
();
final
PoolableConnectionFactory
poolableConnectionFactory
=
new
PoolableConnectionFactory
(
connectionFactory
,
null
);
settings
.
setProperty
(
"proxool.maximum-connection-count"
,
"25"
);
poolableConnectionFactory
.
setMaxConnLifetimeMillis
((
long
)
(
0.5
*
JiveConstants
.
DAY
));
settings
.
setProperty
(
"proxool.minimum-connection-count"
,
"3"
);
settings
.
setProperty
(
"proxool.maximum-connection-lifetime"
,
Integer
.
toString
((
int
)(
86400000
*
0.5
)));
final
GenericObjectPoolConfig
poolConfig
=
new
GenericObjectPoolConfig
();
settings
.
setProperty
(
"user"
,
"sa"
);
poolConfig
.
setMinIdle
(
3
);
settings
.
setProperty
(
"password"
,
""
);
poolConfig
.
setMaxTotal
(
25
);
final
GenericObjectPool
<
PoolableConnection
>
connectionPool
=
new
GenericObjectPool
<>(
poolableConnectionFactory
,
poolConfig
);
poolableConnectionFactory
.
setPool
(
connectionPool
);
dataSource
=
new
PoolingDataSource
<>(
connectionPool
);
}
}
@Override
@Override
...
@@ -111,13 +115,11 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
...
@@ -111,13 +115,11 @@ public class EmbeddedConnectionProvider implements ConnectionProvider {
finally
{
finally
{
DbConnectionManager
.
closeConnection
(
pstmt
,
con
);
DbConnectionManager
.
closeConnection
(
pstmt
,
con
);
}
}
// Blank out the settings
settings
=
null
;
}
}
@Override
@Override
public
void
finalize
()
throws
Throwable
{
public
void
finalize
()
throws
Throwable
{
super
.
finalize
();
destroy
();
destroy
();
super
.
finalize
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment