List of usage examples for com.mongodb MongoException getCode
public int getCode()
From source file:org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage.java
License:Apache License
@Override public void create(final Entity entity) throws EntityStorageException { requireNonNull(entity);// w ww . j a v a 2 s . c o m try { final boolean hasDuplicate = detectDuplicates(entity); if (!hasDuplicate) { mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME) .insertOne(ENTITY_CONVERTER.toDocument(entity)); } else { throw new EntityNearDuplicateException( "Duplicate data found and will not be inserted for Entity with Subject: " + entity); } } catch (final MongoException e) { final ErrorCategory category = ErrorCategory.fromErrorCode(e.getCode()); if (category == ErrorCategory.DUPLICATE_KEY) { throw new EntityAlreadyExistsException( "Failed to create Entity with Subject '" + entity.getSubject().getData() + "'.", e); } throw new EntityStorageException( "Failed to create Entity with Subject '" + entity.getSubject().getData() + "'.", e); } }
From source file:org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage.java
License:Apache License
@Override public void create(final Event event) throws EventStorageException { requireNonNull(event);// w ww.j a v a 2s . com try { mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME) .insertOne(EVENT_CONVERTER.toDocument(event)); } catch (final MongoException e) { final ErrorCategory category = ErrorCategory.fromErrorCode(e.getCode()); if (category == ErrorCategory.DUPLICATE_KEY) { throw new EventAlreadyExistsException( "Failed to create Event with Subject '" + event.getSubject().getData() + "'.", e); } throw new EventStorageException( "Failed to create Event with Subject '" + event.getSubject().getData() + "'.", e); } }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getSpaceRoom(String space) { String room = ChatUtils.getRoomId(space); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from www . j a v a2s . c om*/ basicDBObject.put("space", space); basicDBObject.put("type", TYPE_ROOM_SPACE); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { log.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getTeamRoom(String team, String user) { String room = ChatUtils.getRoomId(team, user); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from w ww . j ava 2s . co m*/ basicDBObject.put("team", team); basicDBObject.put("user", user); basicDBObject.put("type", TYPE_ROOM_TEAM); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { log.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getExternalRoom(String identifier) { String room = ChatUtils.getExternalRoomId(identifier); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from w ww .ja va 2s . c om*/ basicDBObject.put("identifier", identifier); basicDBObject.put("type", TYPE_ROOM_EXTERNAL); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { log.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getTeamCreator(String room) { if (room.indexOf(ChatService.TEAM_PREFIX) == 0) { room = room.substring(ChatService.TEAM_PREFIX.length()); }/*w w w.ja va 2s .c om*/ DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); String creator = ""; BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (cursor.hasNext()) { try { DBObject dbo = cursor.next(); creator = dbo.get("user").toString(); } catch (MongoException me) { log.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return creator; }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getRoom(List<String> users) { Collections.sort(users);//from w w w . j av a 2 s.c o m String room = ChatUtils.getRoomId(users); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try { basicDBObject.put("users", users); basicDBObject.put("type", TYPE_ROOM_USER); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { log.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getSpaceRoom(String space) { String room = ChatUtils.getRoomId(space); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from www .j ava 2 s. c om*/ basicDBObject.put("space", space); basicDBObject.put("type", TYPE_ROOM_SPACE); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { LOG.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getTeamRoom(String team, String user) { String room = ChatUtils.getRoomId(team, user); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from w w w . j a v a 2 s. co m*/ basicDBObject.put("team", team); basicDBObject.put("user", user); basicDBObject.put("type", TYPE_ROOM_TEAM); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { LOG.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }
From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java
License:Open Source License
public String getExternalRoom(String identifier) { String room = ChatUtils.getExternalRoomId(identifier); DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("_id", room); DBCursor cursor = coll.find(basicDBObject); if (!cursor.hasNext()) { try {/*from ww w . j a va2 s . c o m*/ basicDBObject.put("identifier", identifier); basicDBObject.put("type", TYPE_ROOM_EXTERNAL); coll.insert(basicDBObject); ensureIndexInRoom(room); } catch (MongoException me) { LOG.warning(me.getCode() + " : " + room + " : " + me.getMessage()); } } return room; }