Skip to content

Instantly share code, notes, and snippets.

View example.java
// 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;
View executors.java
//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();
View DeleteValue
DeleteListValue deleteList = DeleteListValue.builder().uid(uid)
.hobbies("Drawing").build();
if (daoOperation.deleteNode(deleteList)) {
]System.out.println("Update Transaction completed");
]}
View gist:c1250c413b0ce36a8d98c9995051c6e9
@Builder
@Getter
public final class DeleteListValue {
private final String uid;
private final String hobbies;
}
View deletenode
if (daoOperation.deleteNode(Address.builder().uid(addressDeleteUid).build())) {
System.out.println("Delete Transaction for address completed");
}
View DeleteMethod
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;
View deleteCommand
DeleteAddressPojo deletePerson = DeleteAddressPojo.builder()
.address(DeleteAddress.builder().uid(addressUid).build()).uid(uid).build();
if (daoOperation.deleteNode(deletePerson)) {
System.out.println("Delete Transaction completed");
}
View deleteAddress
@Builder
@Getter
@AllArgsConstructor
public final class DeleteAddressPojo {
private final String uid;
private final DeleteAddress address;
}
@Builder
View file appender
<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>
View console 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>