Search in sources :

Example 1 with IModelService

use of ch.elexis.core.services.IModelService in project elexis-server by elexis.

the class ElexisDBConnection method getDatabaseInformationString.

public static String getDatabaseInformationString() {
    IModelService modelService = CoreModelServiceHolder.get();
    if (modelService == null) {
        return "No database connection set.";
    }
    Optional<IConfig> dbVersion = modelService.load("dbversion", IConfig.class);
    if (!dbVersion.isPresent()) {
        return "Could not find dbversion entry in config table.";
    }
    Optional<IConfig> _elVersion = modelService.load("ElexisVersion", IConfig.class);
    String elVersion = (_elVersion.isPresent()) ? _elVersion.get().getValue() : "unknown";
    Optional<IConfig> _created = modelService.load("created", IConfig.class);
    String created = (_created.isPresent()) ? _created.get().getValue() : "unknown";
    String dbMetaData = "";
    Optional<DataSource> dataSource = OsgiServiceUtil.getService(DataSource.class, "(id=default)");
    if (dataSource.isPresent()) {
        try {
            DatabaseMetaData dbmd = dataSource.get().getConnection().getMetaData();
            dbMetaData += dbmd.getDatabaseProductName();
            dbMetaData += " " + dbmd.getDatabaseProductVersion();
            dbMetaData += " @ " + dbmd.getURL();
        } catch (SQLException e) {
        }
    }
    String statusInfo = "Elexis " + elVersion + " DBv " + dbVersion.get().getValue() + ", created " + created + " [" + dbMetaData + "] ";
    return statusInfo;
}
Also used : IConfig(ch.elexis.core.model.IConfig) IModelService(ch.elexis.core.services.IModelService) SQLException(java.sql.SQLException) DatabaseMetaData(java.sql.DatabaseMetaData) DataSource(javax.sql.DataSource)

Aggregations

IConfig (ch.elexis.core.model.IConfig)1 IModelService (ch.elexis.core.services.IModelService)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1