Mercurial > dive4elements > framework
changeset 128:bfa65a812c7a
Made the backend singleton.
artifacts/trunk@1352 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 01 Mar 2011 18:52:48 +0000 |
parents | 0245a87df368 |
children | 10d726907419 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/App.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java |
diffstat | 3 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Mar 01 18:45:34 2011 +0000 +++ b/ChangeLog Tue Mar 01 18:52:48 2011 +0000 @@ -1,3 +1,11 @@ +2011-03-01 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + Made it a singleton. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/App.java: + Use the singleton Backend. + 2011-03-01 Ingo Weinzierl <ingo@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/App.java Tue Mar 01 18:45:34 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/App.java Tue Mar 01 18:52:48 2011 +0000 @@ -62,7 +62,7 @@ bootstrap.boot(); - Backend backend = new Backend(); + Backend backend = Backend.getInstance(); ArtifactDatabaseImpl db = new ArtifactDatabaseImpl( bootstrap, backend);
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Tue Mar 01 18:45:34 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Tue Mar 01 18:52:48 2011 +0000 @@ -80,6 +80,9 @@ public static final String SQL_REPLACE = SQL.get("artifacts.replace"); + /** The singleton.*/ + protected static Backend instance; + /** * The database cleaner. Reference is stored here because * the cleaner is woken up if the backend finds an outdated @@ -207,6 +210,20 @@ this.cleaner = cleaner; } + + /** + * Returns the singleton of this Backend. + * + * @return the backend. + */ + public static synchronized Backend getInstance() { + if (instance == null) { + instance = new Backend(); + } + + return instance; + } + /** * Sets the factory lookup mechanism to decouple ArtifactDatabase * and Backend.