List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
public OAuth2AccessToken readAccessToken(String tokenValue) { OAuth2AccessToken accessToken = null; try {/*from www. j a v a 2 s. c om*/ DBObject query = new BasicDBObject(tokenIdFieldName, extractTokenKey(tokenValue)); DBObject projection = new BasicDBObject(tokenFieldName, 1); DBObject token = getAccessTokenCollection().findOne(query, projection); if (token != null) { accessToken = deserializeAccessToken((byte[]) token.get(tokenFieldName)); } else { LOG.info("Failed to find access token for token {}", tokenValue); } } catch (IllegalArgumentException e) { LOG.warn("Failed to deserialize access token for " + tokenValue, e); removeAccessToken(tokenValue); } return accessToken; }
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
public OAuth2Authentication readAuthentication(String token) { OAuth2Authentication authentication = null; try {/*from w ww . ja va 2s. com*/ DBObject query = new BasicDBObject(tokenIdFieldName, extractTokenKey(token)); DBObject projection = new BasicDBObject(authenticationFieldName, 1); DBObject accessToken = getAccessTokenCollection().findOne(query, projection); if (accessToken != null) { authentication = deserializeAuthentication((byte[]) accessToken.get(authenticationFieldName)); } else { LOG.info("Failed to find access token for token {}", token); } } catch (IllegalArgumentException e) { LOG.warn("Failed to deserialize authentication for " + token, e); removeAccessToken(token); } return authentication; }
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
public OAuth2RefreshToken readRefreshToken(String token) { OAuth2RefreshToken refreshToken = null; try {//from ww w . j a v a 2 s .c om DBObject query = new BasicDBObject(tokenIdFieldName, extractTokenKey(token)); DBObject projection = new BasicDBObject(tokenFieldName, 1); DBObject savedToken = getRefreshTokenCollection().findOne(query, projection); if (savedToken != null) { refreshToken = deserializeRefreshToken((byte[]) savedToken.get(tokenFieldName)); } else { LOG.info("Failed to find refresh token for token {}", token); } } catch (IllegalArgumentException e) { LOG.warn("Failed to deserialize refresh token for token " + token, e); removeRefreshToken(token); } return refreshToken; }
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
public OAuth2Authentication readAuthenticationForRefreshToken(String value) { OAuth2Authentication authentication = null; try {//w w w . j a v a 2s . c om DBObject query = new BasicDBObject(tokenIdFieldName, extractTokenKey(value)); DBObject projection = new BasicDBObject(authenticationFieldName, 1); DBObject savedToken = getRefreshTokenCollection().findOne(query, projection); if (savedToken != null) { authentication = deserializeAuthentication((byte[]) savedToken.get(authenticationFieldName)); } else { LOG.info("Failed to find access token for token {}", value); } } catch (IllegalArgumentException e) { LOG.warn("Failed to deserialize access token for " + value, e); removeRefreshToken(value); } return authentication; }
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
private final OAuth2AccessToken mapAccessToken(DBObject token) { try {//from w w w .j a v a 2 s . c om return deserializeAccessToken((byte[]) token.get(tokenFieldName)); } catch (IllegalArgumentException e) { getAccessTokenCollection().remove(token); return null; } }
From source file:com.chdi.kundenverwaltung.KundenVerwaltungsLogic.java
public Customer findById(String id) { DBCollection table = db.getCollection("user"); BasicDBObject searchQuery2 = new BasicDBObject().append("ID", id); DBObject user = table.findOne(searchQuery2); return new Customer(user.get("ID").toString(), user.get("CompanyName").toString(), user.get("Name").toString(), user.get("Adress").toString()); }
From source file:com.chdi.kundenverwaltung.KundenVerwaltungsLogic.java
public List<Customer> findAllCustomer() { List<Customer> customers = new ArrayList<Customer>(); DBCollection table = db.getCollection("user"); DBCursor cursor = table.find();/*from w w w. j a v a 2 s . com*/ while (cursor.hasNext()) { DBObject tobj = cursor.next(); Customer tmp = new Customer((String) tobj.get("ID"), (String) tobj.get("CompanyName"), (String) tobj.get("Name"), (String) tobj.get("Adress")); customers.add(tmp); } return customers; }
From source file:com.ciphertool.sherlock.dao.NGramDao.java
License:Open Source License
/** * Returns a list of top N NGrams. We have to use the low-level MongoDB API because otherwise the query takes * forever due to the limitation of Spring Data not providing cursor functionality. *///from w w w . j a v a2 s . c o m public List<NGram> findTopMostFrequentByNumWords(int numWordsQueryParam, int top) { DBCollection collection = mongoOperations.getCollection(DatabaseConstants.NGRAM_COLLECTION); DBCursor cursor; if (top > 0) { cursor = collection.find(new BasicDBObject("numWords", numWordsQueryParam)) .sort(new BasicDBObject("frequencyWeight", -1)).limit(top); } else { cursor = collection.find(new BasicDBObject("numWords", numWordsQueryParam)) .sort(new BasicDBObject("frequencyWeight", -1)); } List<NGram> results = new ArrayList<NGram>(); while (cursor.hasNext()) { DBObject next = cursor.next(); String nGram = (String) next.get("nGram"); Integer numWords = (Integer) next.get("numWords"); Long frequencyWeight = (Long) next.get("frequencyWeight"); results.add(new NGram(nGram, numWords, frequencyWeight)); } return results; }
From source file:com.cloudbees.demo.beesshop.domain.ProductRepository.java
License:Apache License
public void insert(@Nonnull Product product) { DBObject dbObject = new Product.ToDBObjectFunction().apply(product); collection.insert(WriteConcern.SAFE, dbObject); product.setId((ObjectId) dbObject.get("_id")); }
From source file:com.continuent.tungsten.replicator.applier.MongoApplier.java
License:Open Source License
/** * {@inheritDoc}/* w w w .j ava 2 s . com*/ * * @see com.continuent.tungsten.replicator.applier.RawApplier#getLastEvent() */ @Override public ReplDBMSHeader getLastEvent() throws ReplicatorException, InterruptedException { // Connect to the schema and collection. DB db = m.getDB(serviceSchema); DBCollection trepCommitSeqno = db.getCollection("trep_commit_seqno"); // Construct query. DBObject query = new BasicDBObject(); query.put("task_id", taskId); // Find matching trep_commit_seqno value. DBObject doc = trepCommitSeqno.findOne(query); // Return a constructed header or null, depending on whether we found // anything. if (doc == null) { if (logger.isDebugEnabled()) logger.debug("trep_commit_seqno is empty: taskId=" + taskId); return null; } else { if (logger.isDebugEnabled()) logger.debug("trep_commit_seqno entry found: doc=" + doc); long seqno = (Long) doc.get("seqno"); // Cast to integer in MongoDB. int fragno = (Integer) doc.get("fragno"); boolean lastFrag = (Boolean) doc.get("last_frag"); String sourceId = (String) doc.get("source_id"); long epochNumber = (Long) doc.get("epoch_number"); String eventId = (String) doc.get("event_id"); String shardId = (String) doc.get("shard_id"); long extractTimestamp = (Long) doc.get("extract_timestamp"); ReplDBMSHeaderData header = new ReplDBMSHeaderData(seqno, (short) fragno, lastFrag, sourceId, epochNumber, eventId, shardId, new Timestamp(extractTimestamp), 0); return header; } }