Skip to content

Commit

Permalink
Renamed org.mongodb.MongoDocument to org.bson.types.Document
Browse files Browse the repository at this point in the history
  • Loading branch information
jyemin committed Dec 12, 2012
1 parent c460172 commit 5a5973f
Show file tree
Hide file tree
Showing 45 changed files with 241 additions and 281 deletions.
18 changes: 9 additions & 9 deletions src/main/com/mongodb/DBObjects.java
Expand Up @@ -17,29 +17,29 @@

package com.mongodb;

import org.mongodb.MongoDocument;
import org.mongodb.MongoFieldSelectorDocument;
import org.mongodb.MongoQueryFilterDocument;
import org.bson.types.Document;
import org.mongodb.FieldSelectorDocument;
import org.mongodb.QueryFilterDocument;
import org.mongodb.operation.MongoFieldSelector;

// TODO: Implement these methods
public class DBObjects {
private DBObjects() {
}

public static MongoDocument toDocument(final DBObject obj) {
return new MongoDocument();
public static Document toDocument(final DBObject obj) {
return new Document();
}

public static MongoQueryFilterDocument toQueryFilterDocument(final DBObject obj) {
return new MongoQueryFilterDocument();
public static QueryFilterDocument toQueryFilterDocument(final DBObject obj) {
return new QueryFilterDocument();
}

public static DBObject toDBObject(final MongoDocument document) {
public static DBObject toDBObject(final Document document) {
return new BasicDBObject();
}

public static MongoFieldSelector toFieldSelectorDocument(final DBObject fields) {
return new MongoFieldSelectorDocument();
return new FieldSelectorDocument();
}
}
49 changes: 0 additions & 49 deletions src/main/org/bson/io/OutputBuffer.java
Expand Up @@ -83,55 +83,6 @@ public String asString(final String encoding)
}


// public String hex(){
// final StringBuilder buf = new StringBuilder();
// try {
// pipe( new OutputStream(){
// public void write( int b ){
// String s = Integer.toHexString(0xff & b);
//
// if (s.length() < 2)
// buf.append("0");
// buf.append(s);
// }
// }
// );
// }
// catch ( IOException ioe ){
// throw new RuntimeException( "impossible" );
// }
// return buf.toString();
// }
//
// public String md5(){
// final MessageDigest md5 ;
// try {
// md5 = MessageDigest.getInstance("MD5");
// }
// catch (NoSuchAlgorithmException e) {
// throw new RuntimeException("Error - this implementation of Java doesn't support MD5.");
// }
// md5.reset();
//
// try {
// pipe( new OutputStream(){
// public void write( byte[] b , int off , int len ){
// md5.update( b , off , len );
// }
//
// public void write( int b ){
// md5.update( (byte)(b&0xFF) );
// }
// }
// );
// }
// catch ( IOException ioe ){
// throw new RuntimeException( "impossible" );
// }
//
// return org.mongodb.util.Util.toHex( md5.digest() );
// }
//
public void writeInt(final int x) {
write(x >> 0);
write(x >> 8);
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/bson/types/BSONTimestamp.java
Expand Up @@ -22,7 +22,7 @@
import java.util.Date;

/**
* this is used for internal increment values. for storing normal dates in MongoDB, you should use java.util.Date
* this is used for internal increment values. for normal dates you should use java.util.Date
* <b>time</b> is seconds since epoch <b>inc<b> is an ordinal
*/
public class BSONTimestamp implements Comparable<BSONTimestamp>, Serializable {
Expand Down
8 changes: 3 additions & 5 deletions src/main/org/bson/types/CodeWScope.java
Expand Up @@ -18,21 +18,19 @@

package org.bson.types;

import org.mongodb.MongoDocument;

/**
* for using the CodeWScope type
*/
public class CodeWScope extends Code {

private static final long serialVersionUID = -6284832275113680002L;

public CodeWScope(final String code, final MongoDocument scope) {
public CodeWScope(final String code, final Document scope) {
super(code);
_scope = scope;
}

public MongoDocument getScope() {
public Document getScope() {
return _scope;
}

Expand All @@ -49,6 +47,6 @@ public int hashCode() {
return _code.hashCode() ^ _scope.hashCode();
}

final MongoDocument _scope;
final Document _scope;
}

Expand Up @@ -15,18 +15,18 @@
*
*/

package org.mongodb;
package org.bson.types;

import java.util.LinkedHashMap;

public class MongoDocument extends LinkedHashMap<String, Object> {
public class Document extends LinkedHashMap<String, Object> {

private static final long serialVersionUID = -1492763563349589447L;

public MongoDocument() {
public Document() {
}

public MongoDocument(final String key, final Object value) {
public Document(final String key, final Object value) {
put(key, value);
}
}
Expand Up @@ -16,20 +16,22 @@

package org.mongodb;

import org.bson.types.Document;

// TODO: This probably should not subclass MongoQueryFilterDocument, since it's not... a query filter
// Did it this way so that I can pass it to MongoQueryMessage constructor
public class MongoCommandDocument extends MongoQueryFilterDocument implements org.mongodb.operation.MongoCommand {
public class CommandDocument extends QueryFilterDocument implements org.mongodb.operation.MongoCommand {
private static final long serialVersionUID = -986632617844878612L;

public MongoCommandDocument() {
public CommandDocument() {
}

public MongoCommandDocument(final String key, final Object value) {
public CommandDocument(final String key, final Object value) {
super(key, value);
}

@Override
public MongoDocument toMongoDocument() {
public Document toMongoDocument() {
return this;
}
}
4 changes: 3 additions & 1 deletion src/main/org/mongodb/ConvertibleToMongoDocument.java
Expand Up @@ -17,6 +17,8 @@

package org.mongodb;

import org.bson.types.Document;

public interface ConvertibleToMongoDocument {
MongoDocument toMongoDocument();
Document toMongoDocument();
}
Expand Up @@ -16,13 +16,14 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.operation.MongoFieldSelector;

public class MongoFieldSelectorDocument extends MongoDocument implements MongoFieldSelector {
public class FieldSelectorDocument extends Document implements MongoFieldSelector {
private static final long serialVersionUID = 3906786454116702406L;

@Override
public MongoDocument toMongoDocument() {
public Document toMongoDocument() {
return this;
}
}
5 changes: 3 additions & 2 deletions src/main/org/mongodb/MongoDatabase.java
Expand Up @@ -17,6 +17,7 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.operation.MongoCommandOperation;
import org.mongodb.result.CommandResult;
import org.mongodb.serialization.Serializer;
Expand All @@ -38,12 +39,12 @@ public interface MongoDatabase {

PrimitiveSerializers getPrimitiveSerializers();

MongoCollection<MongoDocument> getCollection(String name);
MongoCollection<Document> getCollection(String name);

<T> MongoCollection<T> getTypedCollection(String name, final PrimitiveSerializers basePrimitiveSerializers,
final Serializer<T> serializer);

MongoAsyncCollection<MongoDocument> getAsyncCollection(String name);
MongoAsyncCollection<Document> getAsyncCollection(String name);

<T> MongoAsyncCollection<T> getAsyncTypedCollection(String name, final PrimitiveSerializers basePrimitiveSerializers,
final Serializer<T> serializer);
Expand Down
9 changes: 5 additions & 4 deletions src/main/org/mongodb/MongoOperations.java
Expand Up @@ -16,6 +16,7 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.operation.GetMore;
import org.mongodb.operation.MongoCommandOperation;
import org.mongodb.operation.MongoFind;
Expand All @@ -33,9 +34,9 @@
public interface MongoOperations {

// TODO: should this really be a separate call from query?
MongoDocument executeCommand(String database, MongoCommandOperation commandOperation, Serializer<MongoDocument> serializer);
Document executeCommand(String database, MongoCommandOperation commandOperation, Serializer<Document> serializer);

<T> QueryResult<T> query(final MongoNamespace namespace, MongoFind find, Serializer<MongoDocument> baseSerializer,
<T> QueryResult<T> query(final MongoNamespace namespace, MongoFind find, Serializer<Document> baseSerializer,
Serializer<T> serializer);

// TODO: needs a ServerAddress or doesn't make sense for some MongoClient implementations
Expand All @@ -47,7 +48,7 @@ <T> QueryResult<T> query(final MongoNamespace namespace, MongoFind find, Seriali
<T> InsertResult insert(MongoNamespace namespace, MongoInsert<T> insert, Serializer<T> serializer);

// TODO: Need to handle update where you have to custom serialize the update document
UpdateResult update(final MongoNamespace namespace, MongoUpdate update, Serializer<MongoDocument> serializer);
UpdateResult update(final MongoNamespace namespace, MongoUpdate update, Serializer<Document> serializer);

RemoveResult remove(final MongoNamespace namespace, MongoRemove remove, Serializer<MongoDocument> serializer);
RemoveResult remove(final MongoNamespace namespace, MongoRemove remove, Serializer<Document> serializer);
}
Expand Up @@ -16,20 +16,21 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.operation.MongoQueryFilter;

public class MongoQueryFilterDocument extends MongoDocument implements MongoQueryFilter {
public class QueryFilterDocument extends Document implements MongoQueryFilter {
private static final long serialVersionUID = -4703247391554552538L;

public MongoQueryFilterDocument(final String key, final Object value) {
public QueryFilterDocument(final String key, final Object value) {
super(key, value);
}

public MongoQueryFilterDocument() {
public QueryFilterDocument() {
}

@Override
public MongoDocument toMongoDocument() {
public Document toMongoDocument() {
return this;
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/org/mongodb/ReadPreference.java
Expand Up @@ -17,6 +17,7 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.rs.ReplicaSet;
import org.mongodb.rs.ReplicaSetNode;

Expand All @@ -38,7 +39,7 @@ public abstract class ReadPreference {
/**
* @return <code>DBObject</code> representation of this preference
*/
public abstract MongoDocument toMongoDocument();
public abstract Document toMongoDocument();

/**
* The name of this read preference.
Expand Down Expand Up @@ -84,8 +85,8 @@ ReplicaSetNode getNode(final ReplicaSet set) {
}

@Override
public MongoDocument toMongoDocument() {
return new MongoDocument("mode", getName());
public Document toMongoDocument() {
return new Document("mode", getName());
}

@Override
Expand All @@ -112,7 +113,7 @@ public static ReadPreference primaryPreferred() {
/**
* @return ReadPreference which reads primary if available, otherwise a secondary respective of tags.
*/
public static TaggableReadPreference primaryPreferred(final MongoDocument firstTagSet, final MongoDocument... remainingTagSets) {
public static TaggableReadPreference primaryPreferred(final Document firstTagSet, final Document... remainingTagSets) {
return new TaggableReadPreference.PrimaryPreferredReadPreference(firstTagSet, remainingTagSets);
}

Expand All @@ -126,7 +127,7 @@ public static ReadPreference secondary() {
/**
* @return ReadPreference which reads secondary respective of tags.
*/
public static TaggableReadPreference secondary(final MongoDocument firstTagSet, final MongoDocument... remainingTagSets) {
public static TaggableReadPreference secondary(final Document firstTagSet, final Document... remainingTagSets) {
return new TaggableReadPreference.SecondaryReadPreference(firstTagSet, remainingTagSets);
}

Expand All @@ -141,7 +142,7 @@ public static ReadPreference secondaryPreferred() {
* @return ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective
* of tags.
*/
public static TaggableReadPreference secondaryPreferred(final MongoDocument firstTagSet, final MongoDocument... remainingTagSets) {
public static TaggableReadPreference secondaryPreferred(final Document firstTagSet, final Document... remainingTagSets) {
return new TaggableReadPreference.SecondaryPreferredReadPreference(firstTagSet, remainingTagSets);
}

Expand Down Expand Up @@ -178,8 +179,8 @@ public static ReadPreference valueOf(String name) {
throw new IllegalArgumentException("No match for read preference of " + name);
}

public static TaggableReadPreference valueOf(String name, final MongoDocument firstTagSet,
final MongoDocument... remainingTagSets) {
public static TaggableReadPreference valueOf(String name, final Document firstTagSet,
final Document... remainingTagSets) {
if (name == null) {
throw new IllegalArgumentException();
}
Expand All @@ -205,8 +206,8 @@ public static TaggableReadPreference valueOf(String name, final MongoDocument fi
/**
* @return ReadPreference which reads nearest node respective of tags.
*/
public static TaggableReadPreference nearest(final MongoDocument firstTagSet,
final MongoDocument... remainingTagSets) {
public static TaggableReadPreference nearest(final Document firstTagSet,
final Document... remainingTagSets) {
return new TaggableReadPreference.NearestReadPreference(firstTagSet, remainingTagSets);
}

Expand Down
Expand Up @@ -16,20 +16,21 @@

package org.mongodb;

import org.bson.types.Document;
import org.mongodb.operation.MongoSortCriteria;

public class MongoSortCriteriaDocument extends MongoDocument implements MongoSortCriteria {
public class SortCriteriaDocument extends Document implements MongoSortCriteria {
private static final long serialVersionUID = 6952982470406819852L;

public MongoSortCriteriaDocument() {
public SortCriteriaDocument() {
}

public MongoSortCriteriaDocument(final String key, final Object value) {
public SortCriteriaDocument(final String key, final Object value) {
super(key, value);
}

@Override
public MongoDocument toMongoDocument() {
public Document toMongoDocument() {
return this;
}
}

0 comments on commit 5a5973f

Please sign in to comment.