Last active
November 3, 2020 02:51
-
-
Save devsprint/5363023 to your computer and use it in GitHub Desktop.
Write a blob content to Cassandra using datastax\java-driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String WRITE_STATEMENT = "INSERT INTO avatars (id, image_type, avatar) VALUES (?,?,?);"; | |
private final BoundStatement writeStatement=writeStatement = session.prepare(WRITE_STATEMENT) | |
.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).bind(); | |
try { | |
BoundStatement stmt = driver.getWriteStatement(); | |
stmt.enableTracing(); | |
stmt.setLong("id", accountId); | |
stmt.setString("image_type", image.getType()); | |
stmt.setBytes("avatar", ByteBuffer.wrap(image.getBytes())); | |
ResultSet result = driver.execute(stmt); | |
if (result.getQueryTrace() == null) { | |
LOG.error("Null result set!"); | |
} else { | |
if (result.getQueryTrace().getCoordinator() != null) { | |
LOG.info("UPLOAD COORDINATOR: {}", result.getQueryTrace() | |
.getCoordinator().getCanonicalHostName()); | |
} else { | |
LOG.error("Null COORDINATOR!"); | |
} | |
} | |
} catch (NoHostAvailableException e) { | |
LOG.error("Could not prepare the statement.", e); | |
throw new StorageUnavailableException(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment