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
public class SomeJsonTest { | |
public void getJsonFromRecord(){ | |
SomethingDao somethingDao = new SomethingDao(); | |
//setConfiguration/ setVertx left out | |
CompletableFuture<JsonObject> jsonFuture = somethingDao.executeAsync(dslContext -> dslContext | |
.selectFrom(somethingDao.getTable()) | |
.where(Tables.SOMETHING.SOMEID.eq(1)) | |
.fetchOne()) | |
.thenApply(ISomething::toJson) |
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
public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO<R, P, T> { | |
// ... | |
@Override | |
public /* non-final */ <Z> P fetchOne(Field<Z> field, Z value) { | |
R record = using(configuration) | |
.selectFrom(table) | |
.where(field.equal(value)) | |
.fetchOne(); | |
return record == null ? null : mapper().map(record); |
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
public class SomeJsonTest { | |
public void getJsonFromPojo(){ | |
SomethingDao somethingDao = new SomethingDao(); | |
//setConfiguration/ setVertx left out | |
CompletableFuture<JsonObject> jsonFuture = somethingDao | |
.fetchOneBySomeidAsync(1) | |
.thenApply(ISomething::toJson); | |
} | |
} |
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
public class ClassicAsInDBVertxGenerator extends ClassicGeneratorStrategy{ | |
public ClassicAsInDBVertxGenerator() { | |
super(ClassicVertxGenerator.VERTX_DAO_NAME, new MemberAsInDBGeneratorStrategy()); | |
} | |
static class MemberAsInDBGeneratorStrategy extends DefaultGeneratorStrategy{ | |
@Override | |
public String getJavaMemberName(Definition definition, Mode mode) { | |
if(mode==Mode.POJO){ |
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
public class ClassicAsInDBGeneratorStrategy extends ClassicGeneratorStrategy { | |
@Override | |
public String getJsonKeyName(TypedElementDefinition<?> column) { | |
return column.getName(); | |
} | |
} |
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
public class ClassicAsInDBVertxGenerator extends ClassicVertxGenerator { | |
@Override | |
protected String getJsonKeyName(TypedElementDefinition<?> column) { | |
return column.getName(); | |
} | |
} |
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
public interface VertxDao<R extends UpdatableRecord<R>, P, T> extends DAO<R, P, T> { | |
/** | |
* Convenience method to execute any <code>DSLContext</code>-aware Function asynchronously | |
* using this DAO's <code>configuration</code>. | |
* | |
* @param function | |
* @param <X> | |
* @return Single | |
*/ |
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
@Test | |
public void asyncCRUDConditionShouldSucceed() throws InterruptedException { | |
CountDownLatch latch = new CountDownLatch(1); | |
CompletableFuture<Integer> insertFuture = dao.insertReturningPrimaryAsync(createSomething()); | |
insertFuture. | |
thenCompose(v -> dao.fetchOneAsync(Tables.SOMETHING.SOMEID.eq(insertFuture.join()))). | |
thenAccept(Assert::assertNotNull). | |
thenCompose(v -> dao.deleteExecAsync(Tables.SOMETHING.SOMEID.eq(insertFuture.join()))). | |
whenComplete(failOrCountDown(latch)); | |
await(latch); |
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 Map<Integer,Object> LOCKS = new ConcurrentHashMap<>(); | |
private static void mayLock(Integer arg) { | |
logger.info("entering method {} ", arg); | |
synchronized (LOCKS.computeIfAbsent(arg,f->new Object())){ | |
logger.info("entering lock "+Thread.currentThread().getName()); | |
try { | |
Thread.sleep(2000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} |
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
Integer i = 128; | |
Integer j = 128; | |
boolean same = (i == j); //false | |
boolean equal = i.equals(j); //true |