src/java/de/uapcore/lightpit/entities/ModuleDao.java

changeset 27
1f2a96efa69f
parent 26
65d5a0ca49ae
     1.1 --- a/src/java/de/uapcore/lightpit/entities/ModuleDao.java	Sun Apr 08 15:34:11 2018 +0200
     1.2 +++ b/src/java/de/uapcore/lightpit/entities/ModuleDao.java	Sun Apr 08 16:41:02 2018 +0200
     1.3 @@ -34,7 +34,6 @@
     1.4  import java.sql.ResultSet;
     1.5  import java.sql.SQLException;
     1.6  import java.sql.Statement;
     1.7 -import java.util.AbstractMap;
     1.8  import java.util.ArrayList;
     1.9  import java.util.List;
    1.10  import java.util.Map;
    1.11 @@ -88,18 +87,16 @@
    1.12      }
    1.13      
    1.14      /**
    1.15 -     * Synchronizes a set of registered module classes with the database and gives a list of visible modules in return.
    1.16 +     * Synchronizes a set of registered module classes with the database.
    1.17       * 
    1.18       * Inserts module classes which are not known to the database and sets them to be visible by default.
    1.19       * Module classes known to the database, which are not in the given set, are ignored.
    1.20       * 
    1.21       * @param conn the connection to use
    1.22       * @param moduleSet the module set to synchronize
    1.23 -     * @return a list of elements from the given set, which should be visible in the menu
    1.24       * @throws SQLException
    1.25       */
    1.26 -    public final List<Map.Entry<String, LightPITModule>>
    1.27 -            syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException {
    1.28 +    public final void syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException {
    1.29                  
    1.30          PreparedStatement
    1.31                  check = moduleCheckStatement(conn),
    1.32 @@ -107,30 +104,17 @@
    1.33          insert.setBoolean(2, true);
    1.34          // update/delete not required, we do this in the module management UI
    1.35  
    1.36 -        final List<Map.Entry<String, LightPITModule>> visibleModules = new ArrayList<>();
    1.37 +        for (Map.Entry<String, LightPITModule> modEntry : moduleSet) {
    1.38 +            if (modEntry.getValue().systemModule()) continue;
    1.39  
    1.40 -        for (Map.Entry<String, LightPITModule> mod : moduleSet) {
    1.41 -            if (mod.getValue().systemModule()) continue;
    1.42 -
    1.43 -            check.setString(1, mod.getKey());
    1.44 +            check.setString(1, modEntry.getKey());
    1.45              try (ResultSet r = check.executeQuery()) {
    1.46 -                final boolean visible;
    1.47 -                if (r.next()) {
    1.48 -                    visible = r.getBoolean(1);
    1.49 -                } else {
    1.50 -                    insert.setString(1, mod.getKey());
    1.51 +                if (!r.next()) {
    1.52 +                    insert.setString(1, modEntry.getKey());
    1.53                      insert.executeUpdate();
    1.54 -                    visible = !mod.getValue().menuKey().isEmpty();
    1.55 -                }
    1.56 -                if (visible) {
    1.57 -                    visibleModules.add(new AbstractMap.SimpleEntry<>(
    1.58 -                            mod.getKey(),
    1.59 -                            mod.getValue()
    1.60 -                    ));
    1.61                  }
    1.62              }
    1.63          }
    1.64 -        return visibleModules;
    1.65      }
    1.66  
    1.67      /**
    1.68 @@ -144,8 +128,7 @@
    1.69       */
    1.70      public List<Module> listAll(Connection conn) throws SQLException {
    1.71          List<Module> list = new ArrayList<>();
    1.72 -        try (
    1.73 -                Statement stmt = conn.createStatement();
    1.74 +        try (Statement stmt = conn.createStatement();
    1.75                  ResultSet result = stmt.executeQuery("SELECT * FROM lpitcore_module")) {
    1.76              while (result.next()) {
    1.77                  final Module mod = new Module();

mercurial