Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
isochrone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Institut für Informatik
dbis
dbis-isochrone
isochrone
Commits
08372956
Commit
08372956
authored
11 years ago
by
Nikolaus Krismer
Browse files
Options
Downloads
Patches
Plain Diff
refactored constructors
parent
81ffa6ca
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
src/main/java/it/unibz/inf/isochrone/util/Config.java
+82
-61
82 additions, 61 deletions
src/main/java/it/unibz/inf/isochrone/util/Config.java
with
82 additions
and
61 deletions
src/main/java/it/unibz/inf/isochrone/util/Config.java
+
82
−
61
View file @
08372956
...
@@ -28,57 +28,43 @@ import java.util.Properties;
...
@@ -28,57 +28,43 @@ import java.util.Properties;
* @author <a href="mailto:markus.innerebner@inf.unibz.it">Markus Innerebner</a>.
* @author <a href="mailto:markus.innerebner@inf.unibz.it">Markus Innerebner</a>.
* @version 2.2
* @version 2.2
*/
*/
//TODO: Shouldn't Config be a singleton class
public
class
Config
{
public
class
Config
{
protected
Properties
internalProperties
;
protected
Properties
internalProperties
;
protected
final
ConnectionFactory
factory
;
protected
final
ConnectionFactory
factory
;
protected
short
densityLimit
=
Short
.
MIN_VALUE
;
protected
short
densityLimit
=
Short
.
MIN_VALUE
;
// Constructors
public
Config
()
{
public
Config
()
{
this
(
null
);
this
(
"config.xml"
);
}
}
public
Config
(
final
Dataset
dataset
)
{
public
Config
(
final
String
fileName
)
{
internalProperties
=
new
Properties
();
appendPropertiesFromFile
(
fileName
);
final
String
fileName
=
"config.xml"
;
final
InputStream
in
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
fileName
);
appendPropertyFile
(
in
);
if
(
dataset
!=
null
)
{
final
String
fileName2
=
"config_"
+
dataset
.
toString
().
toLowerCase
()
+
".xml"
;
final
InputStream
in2
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
fileName2
);
appendPropertyFile
(
in2
);
}
factory
=
initConnectionFactory
();
factory
=
initConnectionFactory
();
}
}
p
rotected
Properties
getInternalProperties
(
)
{
p
ublic
Config
(
final
Dataset
dataset
)
{
return
internalProperties
;
appendPropertiesFromFile
(
"config.xml"
)
;
}
appendPropertiesFromFile
(
"config_"
+
dataset
.
toString
().
toLowerCase
()
+
".xml"
);
protected
ConnectionFactory
initConnectionFactory
()
{
factory
=
initConnectionFactory
();
final
String
serverName
=
getDBServerName
();
}
final
String
dbName
=
getDBName
();
final
int
dbPort
=
getDBPort
();
final
String
dbUser
=
getDBUser
();
final
String
dbPassword
=
getDBPassword
();
final
boolean
isPooling
=
getDBPooling
();
ConnectionFactory
f
=
null
;
public
Config
(
final
Config
config
)
{
try
{
if
(
config
==
null
)
{
f
=
new
ConnectionFactory
(
isPooling
);
throw
new
NullPointerException
(
"Invalid config in clone constructor given!"
);
f
.
register
(
serverName
,
dbName
,
dbPort
,
dbUser
,
dbPassword
);
}
catch
(
final
SQLException
e
)
{
throw
new
RuntimeException
(
"Unable to connect to the database: "
+
e
);
}
catch
(
final
ClassNotFoundException
e
)
{
throw
new
RuntimeException
(
"Class not found: "
+
e
);
}
}
return
f
;
internalProperties
=
new
Properties
();
appendProperties
(
config
.
internalProperties
);
factory
=
config
.
factory
;
}
}
// Public methods
public
Connection
getConnection
()
{
public
Connection
getConnection
()
{
try
{
try
{
return
factory
.
getConnection
();
return
factory
.
getConnection
();
...
@@ -127,34 +113,6 @@ public class Config {
...
@@ -127,34 +113,6 @@ public class Config {
return
Integer
.
parseInt
(
getProperty
(
"org.postgresql.port"
));
return
Integer
.
parseInt
(
getProperty
(
"org.postgresql.port"
));
}
}
/**
* <p>
* Method appendPropertyFile
* </p>
* appends the properties of that stream. An existing property is overwritten
*
* @param inputStream
*/
protected
void
appendPropertyFile
(
final
InputStream
inputStream
)
{
try
{
internalProperties
.
loadFromXML
(
inputStream
);
internalProperties
.
putAll
(
System
.
getProperties
());
final
String
density
=
getProperty
(
"limit.density"
);
if
(
densityLimit
==
Short
.
MIN_VALUE
&&
density
!=
null
)
{
densityLimit
=
Short
.
parseShort
(
density
);
}
}
catch
(
final
InvalidPropertiesFormatException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
final
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
void
appendProperties
(
final
Properties
properties
)
{
internalProperties
.
putAll
(
properties
);
}
public
String
getEdgeTable
()
{
public
String
getEdgeTable
()
{
return
getProperty
(
"tbl.links"
);
return
getProperty
(
"tbl.links"
);
}
}
...
@@ -183,4 +141,67 @@ public class Config {
...
@@ -183,4 +141,67 @@ public class Config {
return
Integer
.
parseInt
(
getProperty
(
"sql.spatial.srid"
));
return
Integer
.
parseInt
(
getProperty
(
"sql.spatial.srid"
));
}
}
// Protected methods
/**
* This appends properties from the given file to the configuration.
* Old values will be kept, but overwritten by new values (if the same property has been specified)
*/
protected
void
appendPropertiesFromFile
(
final
String
fileName
)
{
internalProperties
=
new
Properties
();
final
InputStream
in
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
fileName
);
appendPropertiesFromStream
(
in
);
}
/**
* This appends properties from the given stream to the configuration.
* Old values will be kept, but overwritten by new values (if the same property has been specified)
*/
protected
void
appendPropertiesFromStream
(
final
InputStream
inputStream
)
{
try
{
internalProperties
.
loadFromXML
(
inputStream
);
internalProperties
.
putAll
(
System
.
getProperties
());
final
String
density
=
getProperty
(
"limit.density"
);
if
(
densityLimit
==
Short
.
MIN_VALUE
&&
density
!=
null
)
{
densityLimit
=
Short
.
parseShort
(
density
);
}
}
catch
(
final
InvalidPropertiesFormatException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
final
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* This merges properties to the configuration.
* Old values will be kept, but overwritten by new values (if the same property has been specified)
*/
protected
void
appendProperties
(
final
Properties
properties
)
{
internalProperties
.
putAll
(
properties
);
}
// Private methods
private
ConnectionFactory
initConnectionFactory
()
{
final
String
serverName
=
getDBServerName
();
final
String
dbName
=
getDBName
();
final
int
dbPort
=
getDBPort
();
final
String
dbUser
=
getDBUser
();
final
String
dbPassword
=
getDBPassword
();
final
boolean
isPooling
=
getDBPooling
();
ConnectionFactory
f
=
null
;
try
{
f
=
new
ConnectionFactory
(
isPooling
);
f
.
register
(
serverName
,
dbName
,
dbPort
,
dbUser
,
dbPassword
);
}
catch
(
final
SQLException
e
)
{
throw
new
RuntimeException
(
"Unable to connect to the database: "
+
e
);
}
catch
(
final
ClassNotFoundException
e
)
{
throw
new
RuntimeException
(
"Class not found: "
+
e
);
}
return
f
;
}
}
}
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