View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.access.mcrimpl;
20  
21  import java.util.Collection;
22  
23  import org.apache.logging.log4j.LogManager;
24  import org.apache.logging.log4j.Logger;
25  import org.mycore.backend.jpa.access.MCRJPARuleStore;
26  import org.mycore.common.config.MCRConfiguration2;
27  
28  /**
29   * The purpose of this interface is to make the choice of the persistence layer
30   * configurable. Any concrete database-class which stores MyCoRe Access control
31   * must implement this interface. Which database actually will be used can then
32   * be configured by reading the value <code>MCR.Persistence.Rule.Store_Class</code>
33   * from mycore.properties.access
34   * 
35   * @author Arne Seifert
36   */
37  public abstract class MCRRuleStore {
38      private static final Logger LOGGER = LogManager.getLogger(MCRRuleStore.class);
39  
40      protected static final String SQL_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
41  
42      protected static final String RULETABLENAME = "MCRACCESSRULE";
43  
44      private static MCRRuleStore implementation;
45  
46      public abstract void createRule(MCRAccessRule rule);
47  
48      public abstract void updateRule(MCRAccessRule rule);
49  
50      public abstract void deleteRule(String ruleid);
51  
52      public abstract MCRAccessRule getRule(String ruleid);
53  
54      public abstract boolean existsRule(String ruleid);
55  
56      public abstract Collection<String> retrieveAllIDs();
57  
58      public abstract Collection<String> retrieveRuleIDs(String ruleExpression, String description);
59  
60      public abstract int getNextFreeRuleID(String prefix);
61  
62      public static MCRRuleStore getInstance() {
63          try {
64              if (implementation == null) {
65                  implementation = MCRConfiguration2
66                      .getSingleInstanceOf("MCR.Persistence.Rule.Store_Class", MCRJPARuleStore.class).get();
67              }
68          } catch (Exception e) {
69              LOGGER.error(e);
70          }
71  
72          return implementation;
73      }
74  }