• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 24722773057

21 Apr 2026 12:38PM UTC coverage: 65.217% (-0.01%) from 65.229%
24722773057

push

github

web-flow
TRUNK-6481: Backport native support for MariaDB  (#5648)

2 of 14 new or added lines in 4 files covered. (14.29%)

8 existing lines in 5 files now uncovered.

23613 of 36207 relevant lines covered (65.22%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/web/src/main/java/org/openmrs/web/filter/initialization/DatabaseDetective.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.web.filter.initialization;
11

12
import java.sql.Connection;
13
import java.sql.DatabaseMetaData;
14
import java.sql.DriverManager;
15
import java.sql.ResultSet;
16
import java.util.Properties;
17

18
import org.openmrs.util.DatabaseUtil;
19

20
public class DatabaseDetective {
1✔
21
        
22
        private static final String CONNECTION_URL = "connection.url";
23
        
24
        private static final String CONNECTION_DRIVER_CLASS = "connection.driver_class";
25

26
        private static final String CONNECTION_USERNAME = "connection.username";
27
        
28
        private static final String CONNECTION_PASSWORD = "connection.password";
29
        
30
        /**
31
         * Check whether openmrs database is empty. Having just one non-liquibase table in the given
32
         * database qualifies this as a non-empty database.
33
         *
34
         * @param props the runtime properties
35
         * @return true if the openmrs database is empty or does not exist yet
36
         */
37
        public boolean isDatabaseEmpty(Properties props) {
38
                if (props == null) {
1✔
39
                        return true;
1✔
40
                }
41
                
42
                Connection connection = null;
1✔
43
                
44
                try {
45
                        DatabaseUtil.loadDatabaseDriver(props.getProperty(CONNECTION_URL), props.getProperty(CONNECTION_DRIVER_CLASS, null));
1✔
46
                        
47
                        connection = DriverManager.getConnection(props.getProperty(CONNECTION_URL), props
48
                                .getProperty(CONNECTION_USERNAME), props.getProperty(CONNECTION_PASSWORD));
1✔
49
                        
1✔
50
                        DatabaseMetaData dbMetaData = connection.getMetaData();
51
                        
1✔
52
                        String[] types = { "TABLE" };
53
                        
1✔
54
                        //get all tables
55
                        ResultSet tbls = dbMetaData.getTables(null, null, null, types);
56
                        
1✔
57
                        while (tbls.next()) {
58
                                String tableName = tbls.getString("TABLE_NAME");
1✔
59
                                //if any table exist besides "liquibasechangelog" or "liquibasechangeloglock", return false
1✔
60
                                if (!("liquibasechangelog".equals(tableName.toLowerCase()))
61
                                        && !("liquibasechangeloglock".equals(tableName.toLowerCase()))) {
1✔
62
                                        return false;
1✔
63
                                }
1✔
64
                        }
65
                        return true;
1✔
66
                }
1✔
67
                catch (Exception e) {
68
                        // consider the database to be empty
1✔
69
                        return true;
70
                }
1✔
71
                finally {
72
                        try {
73
                                if (connection != null) {
74
                                        connection.close();
1✔
75
                                }
1✔
76
                        }
77
                        catch (Exception e) {
UNCOV
78
                                // consider the database to be empty
×
79
                                return true;
UNCOV
80
                        }
×
81
                }
1✔
82
        }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc