Skip to content

Instantly share code, notes, and snippets.

// Example of the executor service
class UserRepository implements Closeable {
private FileStore fileStore;
private ConcurrentHashMap<UUID, User> cache = new ConcurrentHashMap<>();
private ReadWriteLock lock = new ReentrantReadWriteLock();
private ExecutorService executors = Executors.newFixedThreadPool(2);
UserRepository(FileStore fnileStore) {
this.fileStore = fileStore;
//Helper Class for read and write operations for a file.
class FileStore {
private File storeFolder;
// Locks is used so that only one thread can update the file at a
// time.
private ReadWriteLock lock = new ReentrantReadWriteLock();
DeleteListValue deleteList = DeleteListValue.builder().uid(uid)
.hobbies("Drawing").build();
if (daoOperation.deleteNode(deleteList)) {
]System.out.println("Update Transaction completed");
]}
@Builder
@Getter
public final class DeleteListValue {
private final String uid;
private final String hobbies;
}
if (daoOperation.deleteNode(Address.builder().uid(addressDeleteUid).build())) {
System.out.println("Delete Transaction for address completed");
}
public <T> boolean deleteNode(final T element) {
try (Transaction txn = dgraphClient.newTransaction()) {
try {
final DgraphProto.Mutation mutation = getDeleteMutation(element);
txn.mutate(mutation);
txn.commit();
return true;
DeleteAddressPojo deletePerson = DeleteAddressPojo.builder()
.address(DeleteAddress.builder().uid(addressUid).build()).uid(uid).build();
if (daoOperation.deleteNode(deletePerson)) {
System.out.println("Delete Transaction completed");
}
@Builder
@Getter
@AllArgsConstructor
public final class DeleteAddressPojo {
private final String uid;
private final DeleteAddress address;
}
@Builder
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>