congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
WriteError.getCode
Code IndexAdd Tabnine to your IDE (free)

How to use
getCode
method
in
com.mongodb.WriteError

Best Java code snippets using com.mongodb.WriteError.getCode (Showing top 11 results out of 315)

origin: org.mongodb/mongo-java-driver

/**
 * Construct an instance
 * @param error the error
 * @param serverAddress the server address
 */
public MongoWriteException(final WriteError error, final ServerAddress serverAddress) {
  super(error.getCode(), error.getMessage(), serverAddress);
  this.error = error;
}
origin: liuyangming/ByteTCC

private boolean lockTransactionInMongoDB(TransactionXid transactionXid, String identifier) {
  byte[] global = transactionXid.getGlobalTransactionId();
  String instanceId = ByteUtils.byteArrayToString(global);
  try {
    String application = CommonUtils.getApplication(this.endpoint);
    String databaseName = application.replaceAll("\\W", "_");
    MongoDatabase mdb = this.mongoClient.getDatabase(databaseName);
    MongoCollection<Document> collection = mdb.getCollection(CONSTANTS_TB_LOCKS);
    Document document = new Document();
    document.append(CONSTANTS_FD_GLOBAL, instanceId);
    document.append("identifier", identifier);
    collection.insertOne(document);
    return true;
  } catch (com.mongodb.MongoWriteException error) {
    com.mongodb.WriteError writeError = error.getError();
    if (MONGODB_ERROR_DUPLICATE_KEY != writeError.getCode()) {
      logger.error("Error occurred while locking transaction(gxid= {}).", instanceId, error);
    }
    return false;
  } catch (RuntimeException rex) {
    logger.error("Error occurred while locking transaction(gxid= {}).", instanceId, rex);
    return false;
  }
}
origin: eclipse/ditto

private static boolean hasErrorCode(final WriteError error, final int expectedErrorCode) {
  return expectedErrorCode == error.getCode();
}
origin: org.eclipse.ditto/ditto-services-thingsearch-persistence

private static boolean hasErrorCode(final WriteError error, final int expectedErrorCode) {
  return expectedErrorCode == error.getCode();
}
origin: org.mongodb/mongodb-driver-core

/**
 * Construct an instance
 * @param error the error
 * @param serverAddress the server address
 */
public MongoWriteException(final WriteError error, final ServerAddress serverAddress) {
  super(error.getCode(), error.getMessage(), serverAddress);
  this.error = error;
}
origin: de.bwaldvogel/mongo-java-server-test-common

private static void assertMongoWriteException(Callable callable, int expectedErrorCode, String expectedMessage) {
  try {
    callable.call();
    fail("MongoWriteException expected");
  } catch (MongoWriteException e) {
    assertThat(e).hasMessage(expectedMessage);
    assertThat(e.getError().getCode()).isEqualTo(expectedErrorCode);
  }
}
origin: opencb/opencga

} catch (MongoWriteException e) {
  if (e.getError().getCode() != 11000) {
    throw e;
origin: org.axonframework/axon-mongo

private void updateOrInsertTokenEntry(TrackingToken token, String processorName, int segment) {
  AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token,
                                serializer,
                                contentType,
                                processorName,
                                segment);
  tokenEntry.claim(nodeId, claimTimeout);
  Bson update = combine(set("owner", nodeId),
             set("timestamp", tokenEntry.timestamp().toEpochMilli()),
             set("token", tokenEntry.getSerializedToken().getData()),
             set("tokenType", tokenEntry.getSerializedToken().getType().getName()));
  UpdateResult updateResult = mongoTemplate.trackingTokensCollection()
                       .updateOne(claimableTokenEntryFilter(processorName, segment), update);
  if (updateResult.getModifiedCount() == 0) {
    try {
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
}
origin: org.axonframework.extensions.mongo/axon-mongo

private void updateOrInsertTokenEntry(TrackingToken token, String processorName, int segment) {
  AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token,
                                serializer,
                                contentType,
                                processorName,
                                segment);
  tokenEntry.claim(nodeId, claimTimeout);
  Bson update = combine(set("owner", nodeId),
             set("timestamp", tokenEntry.timestamp().toEpochMilli()),
             set("token", tokenEntry.getSerializedToken().getData()),
             set("tokenType", tokenEntry.getSerializedToken().getType().getName()));
  UpdateResult updateResult = mongoTemplate.trackingTokensCollection()
                       .updateOne(claimableTokenEntryFilter(processorName, segment), update);
  if (updateResult.getModifiedCount() == 0) {
    try {
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
}
origin: org.axonframework/axon-mongo

private AbstractTokenEntry<?> loadOrInsertTokenEntry(String processorName, int segment) {
  Document document = mongoTemplate.trackingTokensCollection()
                   .findOneAndUpdate(claimableTokenEntryFilter(processorName, segment),
                            combine(set("owner", nodeId),
                                set("timestamp", clock.millis())),
                            new FindOneAndUpdateOptions()
                                .returnDocument(ReturnDocument.AFTER));
  if (document == null) {
    try {
      AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(null,
                                    serializer,
                                    contentType,
                                    processorName,
                                    segment);
      tokenEntry.claim(nodeId, claimTimeout);
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
      return tokenEntry;
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
  return documentToTokenEntry(document);
}
origin: org.axonframework.extensions.mongo/axon-mongo

private AbstractTokenEntry<?> loadOrInsertTokenEntry(String processorName, int segment) {
  Document document = mongoTemplate.trackingTokensCollection()
                   .findOneAndUpdate(claimableTokenEntryFilter(processorName, segment),
                            combine(set("owner", nodeId),
                                set("timestamp", clock.millis())),
                            new FindOneAndUpdateOptions()
                                .returnDocument(ReturnDocument.AFTER));
  if (document == null) {
    try {
      AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(null,
                                    serializer,
                                    contentType,
                                    processorName,
                                    segment);
      tokenEntry.claim(nodeId, claimTimeout);
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
      return tokenEntry;
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
  return documentToTokenEntry(document);
}
com.mongodbWriteErrorgetCode

Javadoc

Gets the code associated with this error.

Popular methods of WriteError

  • getCategory
    Gets the category of this error.
  • <init>
    Construct an instance that is a shallow copy of the given instance.
  • equals
  • getMessage
    Gets the message associated with this error.
  • hashCode

Popular in Java

  • Creating JSON documents from java classes using gson
  • getApplicationContext (Context)
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JFrame (javax.swing)
  • Option (scala)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now