Codota Logo
WriteError.getCode
Code IndexAdd Codota 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)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
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

  • Reactive rest calls using spring rest template
  • putExtra (Intent)
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • SortedSet (java.util)
    A Set that further provides a total ordering on its elements. The elements are ordered using their C
  • Pattern (java.util.regex)
    A compiled representation of a regular expression. A regular expression, specified as a string, must
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now