From 8ef5c58ba55df2d721e5510955f981300f9ce195 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 24 Aug 2010 07:35:09 +0000
Subject: [PATCH] LMS-1712 bug fixed: running maintenance task twice

SVN: 17591
---
 .../generic/server/CommonServiceProvider.java | 19 +++++++++++--------
 .../MaintenanceTaskStarterRunnable.java       | 11 ++++++++++-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java
index 6250fd10c34..cda2d2251e0 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java
@@ -16,8 +16,7 @@
 
 package ch.systemsx.cisd.openbis.generic.server;
 
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.ApplicationContext;
 
 import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
@@ -30,27 +29,31 @@ import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
  */
 public class CommonServiceProvider
 {
-    public static final BeanFactory APPLICATION_CONTEXT =
-            new ClassPathXmlApplicationContext(new String[]
-                { "applicationContext.xml" }, true);
+    private static ApplicationContext applicationContext;
 
+    public static void setApplicationContext(ApplicationContext context)
+    {
+        applicationContext = context;
+    }
+    
     public static ICommonServer getCommonServer()
     {
-        return (ICommonServer) APPLICATION_CONTEXT.getBean("common-server");
+        return (ICommonServer) applicationContext.getBean("common-server");
     }
 
     public static IDAOFactory getDAOFactory()
     {
-        return (IDAOFactory) APPLICATION_CONTEXT.getBean("dao-factory");
+        return (IDAOFactory) applicationContext.getBean("dao-factory");
     }
 
     public static ICommonBusinessObjectFactory getBusinessObjectFactory()
     {
-        return (ICommonBusinessObjectFactory) APPLICATION_CONTEXT
+        return (ICommonBusinessObjectFactory) applicationContext
                 .getBean("common-business-object-factory");
     }
 
     private CommonServiceProvider()
     {
     }
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/MaintenanceTaskStarterRunnable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/MaintenanceTaskStarterRunnable.java
index 94d76007a65..0dfb7e92990 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/MaintenanceTaskStarterRunnable.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/MaintenanceTaskStarterRunnable.java
@@ -18,6 +18,10 @@ package ch.systemsx.cisd.openbis.generic.server;
 
 import javax.annotation.Resource;
 
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
 import ch.systemsx.cisd.common.maintenance.MaintenanceTaskParameters;
 import ch.systemsx.cisd.common.maintenance.MaintenanceTaskUtils;
 import ch.systemsx.cisd.common.spring.ExposablePropertyPlaceholderConfigurer;
@@ -27,11 +31,16 @@ import ch.systemsx.cisd.common.spring.ExposablePropertyPlaceholderConfigurer;
  * 
  * @author Piotr Buczek
  */
-public class MaintenanceTaskStarterRunnable implements Runnable
+public class MaintenanceTaskStarterRunnable implements Runnable, ApplicationContextAware
 {
 
     @Resource(name = "propertyConfigurer")
     private ExposablePropertyPlaceholderConfigurer configurer;
+    
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+    {
+        CommonServiceProvider.setApplicationContext(applicationContext);
+    }
 
     public void run()
     {
-- 
GitLab