package eu.etaxonomy.cdm.vaadin.util;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import javax.servlet.ServletContext;
import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.server.VaadinServlet;
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.api.service.ICommonService;
import eu.etaxonomy.cdm.api.service.IDescriptionService;
import eu.etaxonomy.cdm.api.service.INameService;
+import eu.etaxonomy.cdm.api.service.IPreferenceService;
import eu.etaxonomy.cdm.api.service.IReferenceService;
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.api.service.IVocabularyService;
+/**
+ * This helper relates to the problem that in the Vaadin framework it is
+ * not possible to autowire beans from the underlying application context
+ * as Vaadin prevents this possibility. To overcome this problem, this singleton
+ * helper class has
+ * been written to retrieve the beans given the bean name.
+ *
+ * @author c.mathew
+ *
+ * TODO This class may no longer needed in a couple of cases since vaadin-spring
+ * is being used and spring beans can be injected now.
+ *
+ */
public class CdmSpringContextHelper {
private final ApplicationContext context;
private final JDBCConnectionPool connPool;
private static CdmSpringContextHelper contextHelper;
+ private static DatabaseMetaData databaseMetaData;
+
private CdmSpringContextHelper(ServletContext servletContext) throws SQLException {
context = WebApplicationContextUtils.
getRequiredWebApplicationContext(servletContext);
return connPool;
}
+
// public static JDBCConnectionPool createConnectionPool() {
// return new J2EEConnectionPool(getCurrent().getDataSource());
// }
return getCurrent().getDataSource().getConnection();
}
- public static ICdmApplicationConfiguration getApplicationConfiguration() {
- return (ICdmApplicationConfiguration) getCurrent().getBean("cdmApplicationDefaultConfiguration");
+ public static DatabaseMetaData getDatabaseMetaData() throws SQLException {
+ if(databaseMetaData == null) {
+ Connection conn = getConnection();
+ databaseMetaData = conn.getMetaData();
+ conn.close();
+ }
+ return databaseMetaData;
+ }
+
+ public static ICdmRepository getApplicationConfiguration() {
+ return (ICdmRepository) getCurrent().getBean("cdmRepository");
}
public static ITaxonService getTaxonService() {
return (ITaxonService)getCurrent().getBean(ITaxonService.class);
return (IDescriptionService)getCurrent().getBean(IDescriptionService.class);
}
+ public static IPreferenceService getPreferenceService() {
+ return (IPreferenceService)getCurrent().getBean(IPreferenceService.class);
+ }
}