Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
2058fafa
Commit
2058fafa
authored
10 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-1388: User database.url-host-part for testing connectivity to database server.
SVN: 33261
parent
dffa7ae5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java
+23
-23
23 additions, 23 deletions
.../cisd/openbis/installer/izpack/DBConnectionValidator.java
with
23 additions
and
23 deletions
installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java
+
23
−
23
View file @
2058fafa
...
...
@@ -23,7 +23,7 @@ import java.sql.SQLException;
import
com.izforge.izpack.api.data.AutomatedInstallData
;
/**
* Tests if there is a valid PostgreSQL installation
on the local machine
that is setup to accept
* Tests if there is a valid PostgreSQL installation that is setup to accept
* connections from local users without requiring a password.
*
* @author Kaloyan Enimanev
...
...
@@ -35,8 +35,6 @@ public class DBConnectionValidator extends AbstractDataValidator
private
static
final
String
JDBC_DRIVER_NAME
=
"org.postgresql.Driver"
;
private
static
final
String
CONNECTION_STRING
=
"jdbc:postgresql://localhost/template1"
;
private
static
final
String
NO_PASSWORD
=
""
;
@Override
...
...
@@ -70,52 +68,54 @@ public class DBConnectionValidator extends AbstractDataValidator
{
return
Status
.
OK
;
}
String
host
=
getHost
();
String
owner
=
getOwner
();
String
ownerPassword
=
getOwnerPassword
();
if
(
testConnectionOK
(
owner
,
ownerPassword
,
"database.owner"
)
==
false
)
if
(
testConnectionOK
(
host
,
owner
,
ownerPassword
,
"database.owner"
)
==
false
)
{
return
Status
.
ERROR
;
}
return
Status
.
OK
;
}
private
String
getHost
()
{
return
getProperty
(
"database.url-host-part"
,
"localhost"
);
}
private
String
getOwner
()
{
String
user
=
System
.
getProperty
(
"user.name"
).
toLowerCase
();
if
(
GlobalInstallationContext
.
isFirstTimeInstallation
)
{
return
user
;
}
String
owner
=
Utils
.
tryToGetServicePropertyOfAS
(
GlobalInstallationContext
.
installDir
,
"database.owner"
);
if
(
owner
!=
null
&&
owner
.
length
()
>
0
)
{
return
owner
;
}
return
user
;
return
getProperty
(
"database.owner"
,
user
);
}
private
String
getOwnerPassword
()
{
return
getProperty
(
"database.owner-password"
,
NO_PASSWORD
);
}
private
String
getProperty
(
String
key
,
String
defaultValue
)
{
if
(
GlobalInstallationContext
.
isFirstTimeInstallation
)
{
return
NO_PASSWORD
;
return
defaultValue
;
}
String
property
=
Utils
.
tryToGetServicePropertyOfAS
(
GlobalInstallationContext
.
installDir
,
key
);
if
(
property
!=
null
&&
property
.
length
()
>
0
)
{
return
property
;
}
String
password
=
Utils
.
tryToGetServicePropertyOfAS
(
GlobalInstallationContext
.
installDir
,
"database.owner-password"
);
return
password
==
null
?
""
:
password
;
return
defaultValue
;
}
private
boolean
testConnectionOK
(
String
username
,
String
password
,
String
messagePostfix
)
private
boolean
testConnectionOK
(
String
host
,
String
username
,
String
password
,
String
messagePostfix
)
{
boolean
connected
=
false
;
try
{
Class
.
forName
(
JDBC_DRIVER_NAME
);
Connection
connection
=
DriverManager
.
getConnection
(
CONNECTION_STRING
,
username
,
password
);
DriverManager
.
getConnection
(
"jdbc:postgresql://"
+
host
+
"/template1"
,
username
,
password
);
if
(
connection
!=
null
)
{
connected
=
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment