Skip to content

Commit 678847f

Browse files
committed
Fix alias resolution
1 parent 5f871f6 commit 678847f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

morphia/src/main/java/org/seedstack/mongodb/morphia/internal/MorphiaUtils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@ public static MorphiaDatastore getMongoDatastore(Application application, Class<
5050
}
5151

5252
/**
53-
* Resolve database alias.
53+
* Resolve the real database name given an alias.
5454
*
5555
* @param clientConfiguration the configuration of the client.
5656
* @param dbName the name of the alias or the database.
5757
* @return the resolved database name (may be the provided database name if no alias is defined).
5858
*/
5959
public static String resolveDatabaseAlias(Configuration clientConfiguration, String dbName) {
60-
return clientConfiguration.getString(String.format("alias.%s", dbName), dbName);
60+
String[] databases = clientConfiguration.getStringArray("databases");
61+
if (databases != null) {
62+
for (String database : databases) {
63+
if (dbName.equals(clientConfiguration.getString(String.format("alias.%s", database), dbName))) {
64+
return database;
65+
}
66+
}
67+
}
68+
return dbName;
6169
}
6270

6371
/**
@@ -92,7 +100,7 @@ private static void checkMongoClient(Configuration configuration, Class<?> mappe
92100
String[] dbNames = mongodbClientConfiguration.getStringArray("databases");
93101
boolean found = false;
94102
for (String nameToCheck : dbNames) {
95-
if (dbName.equals(resolveDatabaseAlias(mongodbClientConfiguration, nameToCheck))) {
103+
if (nameToCheck.equals(resolveDatabaseAlias(mongodbClientConfiguration, dbName))) {
96104
found = true;
97105
break;
98106
}

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<includedLicenses>
4848
<includedLicense>Apache 2</includedLicense>
4949
<includedLicense>BSD</includedLicense>
50+
<includedLicense>CDDL 1.0</includedLicense>
5051
<includedLicense>LGPL 3.0</includedLicense>
5152
<includedLicense>MIT License</includedLicense>
5253
<includedLicense>MPL 2.0</includedLicense>
@@ -63,6 +64,7 @@
6364
<licenseMerge>Apache 2|Apache License 2.0</licenseMerge>
6465
<licenseMerge>BSD|The New BSD License</licenseMerge>
6566
<licenseMerge>BSD|https://svn.codehaus.org/proxytoys/trunk/LICENSE.txt</licenseMerge>
67+
<licenseMerge>CDDL 1.0|CDDL + GPLv2 with classpath exception</licenseMerge>
6668
<licenseMerge>LGPL 3.0|GNU Lesser Public License</licenseMerge>
6769
<licenseMerge>IGNORED_LICENSE|MPL 1.1</licenseMerge>
6870
<licenseMerge>IGNORED_LICENSE|LGPL 2.1</licenseMerge>

0 commit comments

Comments
 (0)