Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014 Grigory Pykhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.s1.mongodb;
import com.mongodb.*;
import org.s1.cluster.dds.beans.CollectionId;
import org.s1.cluster.dds.beans.Id;
import org.s1.misc.Closure;
import org.s1.objects.Objects;
import org.s1.table.errors.AlreadyExistsException;
import org.s1.table.errors.MoreThanOneFoundException;
import org.s1.table.errors.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* MongoDB Query helper
* DEBUG - results
*/
public class MongoDBQueryHelper {
private static final Logger LOG = LoggerFactory.getLogger(MongoDBQueryHelper.class);
/**
*
* @param id
* @return
* @throws NotFoundException
* @throws MoreThanOneFoundException
*/
public static Map get(Id id)
throws NotFoundException, MoreThanOneFoundException {
return get(id, Objects.newHashMap(String.class,Object.class,
"id",id.getEntity()
));
}
/**
* Select exactly one record from collection
*
* @param c
* @param search
* @throws NotFoundException
* @throws MoreThanOneFoundException
* @return
*/
public static Map get(CollectionId c, Map search)
throws NotFoundException, MoreThanOneFoundException {
ensureOnlyOne(c, search);
DBCollection coll = MongoDBConnectionHelper.getConnection(c.getDatabase()).getCollection(c.getCollection());
Map m = MongoDBFormat.toMap(coll.findOne(MongoDBFormat.fromMap(search)));
if(LOG.isDebugEnabled())
LOG.debug("MongoDB get result ("+c+", search:"+search+"\n\t> "+m);
return m;
}
public static final String SCORE = "_score";
/*public static long fullTextSearch(List