Skip to content

Commit cbf8887

Browse files
authored
MCR-3348 rename static factory methods as per new convention and deprecate old methods (#2434)
1 parent 3a7adf8 commit cbf8887

File tree

362 files changed

+1979
-1240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+1979
-1240
lines changed

mycore-acl-editor2/src/main/java/org/mycore/frontend/acl2/resources/MCRAclEditorResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
@Path("ACLE")
6565
public class MCRAclEditorResource {
6666

67-
private static final MCRRuleStore RULE_STORE = MCRRuleStore.getInstance();
67+
private static final MCRRuleStore RULE_STORE = MCRRuleStore.obtainInstance();
6868

69-
private static final MCRAccessStore ACCESS_STORE = MCRAccessStore.getInstance();
69+
private static final MCRAccessStore ACCESS_STORE = MCRAccessStore.obtainInstance();
7070

7171
private static final String JSON_ACCESSID = "accessID";
7272

mycore-acl/src/main/java/org/mycore/mcr/acl/accesskey/restapi/v2/MCRAccessKeyRestExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static Response fromException(MCRAccessKeyException e) {
5252
}
5353

5454
private static Response getResponse(Exception e, int statusCode, String errorCode) {
55-
MCRErrorResponse response = MCRErrorResponse.fromStatus(statusCode)
55+
MCRErrorResponse response = MCRErrorResponse.ofStatusCode(statusCode)
5656
.withCause(e)
5757
.withMessage(e.getMessage())
5858
.withDetail(Optional.of(e)

mycore-acl/src/main/java/org/mycore/mcr/acl/accesskey/restapi/v2/MCRRestAccessKeyHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class MCRRestAccessKeyHelper {
5252
protected static final String QUERY_PARAM_SECRET_ENCODING = "secret_encoding";
5353

5454
private static WebApplicationException getUnknownObjectException(final MCRObjectID objectId) {
55-
return MCRErrorResponse.fromStatus(Response.Status.NOT_FOUND.getStatusCode())
55+
return MCRErrorResponse.ofStatusCode(Response.Status.NOT_FOUND.getStatusCode())
5656
.withMessage(objectId + " does not exist!")
5757
.withErrorCode("objectNotFound")
5858
.toException();

mycore-base/src/main/java/org/mycore/access/MCRAccessCacheHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void clearAllPermissionCaches(String id) {
6161

6262
private static void collectDescendants(List<String> idsToClear, String parent) {
6363
// get derivates
64-
final MCRLinkTableManager ltManager = MCRLinkTableManager.instance();
64+
final MCRLinkTableManager ltManager = MCRLinkTableManager.getInstance();
6565
idsToClear.addAll(ltManager.getDestinationOf(parent, MCRLinkTableManager.ENTRY_TYPE_DERIVATE));
6666

6767
// get children

mycore-base/src/main/java/org/mycore/access/facts/MCRFactsAccessSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void setProperties(Map<String, String> properties) {
120120
}
121121

122122
private MCRCondition buildRulesFromXML() {
123-
Element eRules = MCRURIResolver.instance().resolve(rulesURI);
123+
Element eRules = MCRURIResolver.obtainInstance().resolve(rulesURI);
124124
Objects.requireNonNull(eRules, "The rulesURI " + rulesURI + " resolved to null!");
125125
MCRJDOMContent content = new MCRJDOMContent(eRules);
126126
try {
@@ -227,7 +227,7 @@ private boolean isCategory(String checkID) {
227227
return false;
228228
}
229229
try {
230-
return MCRCategoryDAOFactory.getInstance().exist(MCRCategoryID.fromString(checkID));
230+
return MCRCategoryDAOFactory.getInstance().exist(MCRCategoryID.ofString(checkID));
231231
} catch (IllegalArgumentException e) {
232232
return false;
233233
}

mycore-base/src/main/java/org/mycore/access/facts/MCRObjectCacheFactory.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@ public final class MCRObjectCacheFactory extends MCREventHandlerBase {
4040

4141
private static final Logger LOGGER = LogManager.getLogger();
4242

43-
private static final MCRObjectCacheFactory SINGLETON = new MCRObjectCacheFactory();
43+
private static final MCRObjectCacheFactory SINGLETON_INSTANCE = new MCRObjectCacheFactory();
4444

4545
private static final int CACHE_MAX_SIZE = 100;
4646

4747
private final MCRCache<MCRObjectID, MCRObject> objectCache;
4848

4949
private MCRObjectCacheFactory() {
5050
objectCache = new MCRCache<>(CACHE_MAX_SIZE, this.getClass().getName());
51-
MCREventManager.instance().addEventHandler(MCREvent.ObjectType.OBJECT, this);
51+
MCREventManager.getInstance().addEventHandler(MCREvent.ObjectType.OBJECT, this);
5252
}
5353

54+
/**
55+
* @deprecated Use {@link #getInstance()} instead
56+
*/
57+
@Deprecated
5458
public static MCRObjectCacheFactory instance() {
55-
return SINGLETON;
59+
return getInstance();
60+
}
61+
62+
public static MCRObjectCacheFactory getInstance() {
63+
return SINGLETON_INSTANCE;
5664
}
5765

5866
public MCRObject getObject(MCRObjectID oid) {

mycore-base/src/main/java/org/mycore/access/facts/condition/fact/MCRCategoryCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Optional<MCRCategoryIDFact> computeFact(MCRFactsHolder facts) {
7171
if (idc.isPresent()) {
7272
MCRObjectID objectID = idc.get().getValue();
7373
if (objectID != null) {
74-
MCRCategoryID categoryID = MCRCategoryID.fromString(getTerm());
74+
MCRCategoryID categoryID = MCRCategoryID.ofString(getTerm());
7575
MCRCategLinkService linkService = MCRCategLinkServiceFactory.getInstance();
7676
if (linkService.isInCategory(new MCRCategLinkReference(objectID), categoryID)) {
7777
MCRCategoryIDFact result = new MCRCategoryIDFact(getFactName(), getTerm());

mycore-base/src/main/java/org/mycore/access/facts/fact/MCRObjectIDFact.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Optional<MCRObject> getObject() {
4949
if (objectID == null) {
5050
return Optional.empty();
5151
}
52-
return Optional.ofNullable(MCRObjectCacheFactory.instance().getObject(objectID));
52+
return Optional.ofNullable(MCRObjectCacheFactory.getInstance().getObject(objectID));
5353
}
5454

5555
}

mycore-base/src/main/java/org/mycore/access/mcrimpl/MCRAccessControlSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ private MCRAccessControlSystem() {
7575
disabled = true;
7676
}
7777

78-
accessStore = MCRAccessStore.getInstance();
79-
ruleStore = MCRRuleStore.getInstance();
78+
accessStore = MCRAccessStore.obtainInstance();
79+
ruleStore = MCRRuleStore.obtainInstance();
8080
dummyRule = new MCRAccessRule(null, null, null, null, "dummy rule, always true");
8181
}
8282

mycore-base/src/main/java/org/mycore/access/mcrimpl/MCRAccessStore.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public abstract class MCRAccessStore {
4949
protected static final String ACCESS_POOLS = MCRConfiguration2.getString("MCR.AccessPools")
5050
.orElse("read,write,delete");
5151

52-
private static volatile MCRAccessStore implementation;
53-
5452
public abstract String getRuleID(String objID, String acPool);
5553

5654
public abstract void createAccessDefinition(MCRRuleMapping accessdata);
@@ -77,16 +75,17 @@ public abstract class MCRAccessStore {
7775
*/
7876
public abstract Collection<String> getDistinctStringIDs();
7977

78+
79+
/**
80+
* @deprecated Use {@link #obtainInstance()} instead
81+
*/
82+
@Deprecated
8083
public static MCRAccessStore getInstance() {
81-
if (implementation == null) {
82-
synchronized (MCRAccessStore.class) {
83-
if(implementation == null) {
84-
implementation = MCRConfiguration2.getSingleInstanceOfOrThrow(
85-
MCRAccessStore.class, "MCR.Persistence.Access.Store.Class");
86-
}
87-
}
88-
}
89-
return implementation;
84+
return obtainInstance();
85+
}
86+
87+
public static MCRAccessStore obtainInstance() {
88+
return LazyInstanceHolder.SHARED_INSTANCE;
9089
}
9190

9291
public static Collection<String> getPools() {
@@ -104,21 +103,21 @@ public static Collection<String> getPools() {
104103
public Collection<MCRAccessDefinition> getDefinition(String type) {
105104
try {
106105
Map<String, Collection<String>> sqlDefinition = new HashMap<>();
107-
Collection<String> pools = getInstance().getDatabasePools();
106+
Collection<String> pools = obtainInstance().getDatabasePools();
108107
//merge pools
109108
pools.removeAll(getPools());
110109
pools.addAll(getPools());
111110

112111
for (String pool : pools) {
113-
sqlDefinition.put(pool, getInstance().getMappedObjectId(pool));
112+
sqlDefinition.put(pool, obtainInstance().getMappedObjectId(pool));
114113
}
115114

116115
Collection<MCRAccessDefinition> ret = new ArrayList<>();
117116
Collection<String> elements;
118117
MCRAccessDefinition def = null;
119118

120119
if (MCRConfiguration2.getOrThrow("MCR.Metadata.Type." + type, Boolean::parseBoolean)) {
121-
elements = MCRXMLMetadataManager.instance().listIDsOfType(type);
120+
elements = MCRXMLMetadataManager.getInstance().listIDsOfType(type);
122121
} else {
123122
return Collections.emptySet();
124123
}
@@ -145,7 +144,7 @@ public Collection<MCRAccessDefinition> getDefinition(String type) {
145144

146145
public Collection<MCRAccessDefinition> getRules(String objid) {
147146
try {
148-
Collection<String> pools = getInstance().getDatabasePools();
147+
Collection<String> pools = obtainInstance().getDatabasePools();
149148
//merge pools
150149
pools.removeAll(getPools());
151150
pools.addAll(getPools());
@@ -163,4 +162,9 @@ public Collection<MCRAccessDefinition> getRules(String objid) {
163162
}
164163
}
165164

165+
private static final class LazyInstanceHolder {
166+
public static final MCRAccessStore SHARED_INSTANCE = MCRConfiguration2.getInstanceOfOrThrow(
167+
MCRAccessStore.class, "MCR.Persistence.Access.Store.Class");
168+
}
169+
166170
}

0 commit comments

Comments
 (0)