List of usage examples for com.mongodb MongoWriteException getCode
public int getCode()
From source file:com.ibm.research.mongotx.lrc.LRCTxDBCollection.java
License:Open Source License
@Override public void insertOne(Tx tx_, Document value) throws TxRollback { LRCTx tx = (LRCTx) tx_;//from w w w.j a v a 2 s .co m synchronized (tx) { Object key = value.get(ATTR_ID); if (key == null) { key = new ObjectId(); value = new Document(value).append(ATTR_ID, key); } if (tx.getCache(this, key) != null) { if (updateSD2V(tx, key, null, new Document(value), new Document(ATTR_ID, key).append(ATTR_VALUE_TXID, new Document("$exists", false))) != 1) { tx.rollback(); throw new TxRollback("insert error: already exist"); } return; } Document sd2v = new Document()// .append(ATTR_ID, key)// .append(ATTR_VALUE_UNSAFE, new Document(value)// .append(ATTR_VALUE_UNSAFE_TXID, tx.txId)// .append(ATTR_VALUE_UNSAFE_INSERT, true)); //copy shared key fields for (String sharedKey : shardKeys) sd2v.append(sharedKey, value.get(sharedKey)); try { tx.insertTxStateIfNecessary(); baseCol.insertOne(sd2v); } catch (MongoWriteException ex) { if (ex.getCode() != 11000 || updateSD2V(tx, key, null, new Document(value), new Document(ATTR_ID, key)) != 1) { tx.rollback(); throw new TxRollback("insert error: " + ex.getMessage(), ex); } } tx.putDirty(this, key, sd2v); } }
From source file:net.springfieldusa.storage.mongodb.comp.MongoStorageComponent.java
License:Open Source License
@Override public <T extends EntityObject> T create(String collection, T data) throws DuplicateIdException { if (data.getId() == null) data.setId(UUID.randomUUID().toString()); Document dbObject = new Document(data.getAttributes()); dbObject.put(ID, data.getId());//from w w w . j av a 2 s. c om dbObject.put(META, data.getMeta()); dbObject.put(RELATIONSHIPS, createRelationships(data)); log(LogService.LOG_DEBUG, "Adding object: '" + data.getId() + "'"); try { getCollection(collection).insertOne(dbObject); return data; } catch (MongoWriteException e) { if (e.getCode() == 11000) throw new DuplicateIdException(); throw e; } }
From source file:org.opencb.opencga.catalog.db.mongodb.MongoDBUtils.java
License:Apache License
static boolean isDuplicateKeyException(MongoWriteException e) { return ErrorCategory.fromErrorCode(e.getCode()) == ErrorCategory.DUPLICATE_KEY; }