forked from MorphiaOrg/morphia
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes MorphiaOrg#25 support hashed index
- Loading branch information
Showing
4 changed files
with
144 additions
and
28 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/com/github/fakemongo/impl/index/HashedIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.fakemongo.impl.index; | ||
|
||
import com.mongodb.DBObject; | ||
import com.mongodb.MongoException; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* An index for the MongoDB. | ||
*/ | ||
public class HashedIndex extends IndexAbstract<DBObject> { | ||
private static final Logger LOG = LoggerFactory.getLogger(HashedIndex.class); | ||
|
||
HashedIndex(String name, DBObject keys, boolean unique, String hashed) { | ||
super(name, keys, unique, new LinkedHashMap<DBObject, List<DBObject>>(), hashed); | ||
//TreeMap<GeoUtil.GeoDBObject, List<GeoUtil.GeoDBObject>>(new GeoUtil.GeoComparator(hashed)), hashed); | ||
} | ||
|
||
/** | ||
* Create the key for the hashmap. | ||
* | ||
* @param object | ||
* @return | ||
*/ | ||
@Override | ||
protected DBObject getKeyFor(DBObject object) { | ||
return object; | ||
} | ||
|
||
@Override | ||
public DBObject embedded(DBObject object) { | ||
return object; | ||
} | ||
|
||
@Override | ||
public List<List<Object>> addOrUpdate(DBObject object, DBObject oldObject) { | ||
if (object.get(this.geoIndex) instanceof List) { | ||
throw new MongoException(16244, "Error: hashed indexes do not currently support array values"); | ||
} | ||
return super.addOrUpdate(object, oldObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters