PostgreSQLJournal extends AbstractService implements Journal { @SneakyThrows @Override public <T extends Entity> Optional<T> get(UUID uuid) { Optional<T> result; Connection connection = dataSource.getConnection(); refreshConnectionRegistry(connection); PreparedStatement s = connection .prepareStatement("SELECT layout FROM layouts_v1 WHERE uuid = ?::UUID"); s.setString(1, uuid.toString()); try (ResultSet resultSet = s.executeQuery()) { if (resultSet.next()) { byte[] bytes = resultSet.getBytes(1); String hash = BaseEncoding.base16().encode(bytes); ReaderFunction reader = readerFunctions.get(hash); Layout<?> layout = getLayout(bytes); String columns = Joiner.on(", ") .join(layout.getProperties().stream() .map(p -> "\"" + p.getName() + "\"").collect(Collectors.toList())); String query = "SELECT " + columns + " FROM layout_v1_" + hash + " WHERE uuid = ?::UUID"; PreparedStatement s1 = connection.prepareStatement(query); s1.setString(1, uuid.toString()); try (ResultSet rs = s1.executeQuery()) { rs.next(); Entity o = (Entity) reader.apply(rs); o.uuid(uuid); result = Optional.of((T) o); } s1.close(); } else { result = Optional.empty(); } } s.close(); connection.close(); return result; } PostgreSQLJournal();  PostgreSQLJournal(PGDataSource dataSource);  PostgreSQLJournal(PGDataSource dataSource, HikariConfig hikariConfig); @Override void setRepository(Repository repository); @Override void onCommandsAdded(Set<Class<? extends Command>> commands); @Override void onEventsAdded(Set<Class<? extends Event>> events); @Override Journal.Transaction beginTransaction(); @Override Properties getProperties(); @Override Command<S, T> journal(Journal.Transaction tx, Command<S, T> command); @Override Event journal(Journal.Transaction tx, Event event); @SneakyThrows @Override Optional<T> get(UUID uuid); @Override CloseableIterator<EntityHandle<T>> commandIterator(Class<T> klass,
                                                                                                  QueryOptions queryOptions); @Override CloseableIterator<EntityHandle<T>> eventIterator(Class<T> klass, QueryOptions
            queryOptions); @SneakyThrows @Override void clear(); @SneakyThrows @Override long size(Class<T> klass); @Override boolean isEmpty(Class<T> klass); static final int MAX_FETCH_SIZE; }
@Test @SneakyThrows public void serializationValue() { assertEquals(serializationResult(TestClass.builder().pByte(Byte.MIN_VALUE).build()).pByte(), Byte.MIN_VALUE); assertEquals(serializationResult(TestClass.builder().pByte(Byte.MAX_VALUE).build()).pByte(), Byte.MAX_VALUE); assertEquals((byte)serializationResult(TestClass.builder().oByte(Byte.MIN_VALUE).build()).oByte(), Byte.MIN_VALUE); assertEquals((byte)serializationResult(TestClass.builder().oByte(Byte.MAX_VALUE).build()).oByte(), Byte.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pByteArr("Hello, world".getBytes()).build()).pByteArr(), "Hello, world".getBytes()); assertEquals(serializationResult(TestClass.builder().oByteArr(toObject(("Hello, world").getBytes())).build()).oByteArr(), "Hello, world".getBytes()); assertEquals(serializationResult(TestClass.builder().pShort(Short.MIN_VALUE).build()).pShort(), Short.MIN_VALUE); assertEquals((short)serializationResult(TestClass.builder().oShort(Short.MAX_VALUE).build()).oShort(), Short.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pInt(Integer.MIN_VALUE).build()).pInt(), Integer.MIN_VALUE); assertEquals((int)serializationResult(TestClass.builder().oInt(Integer.MAX_VALUE).build()).oInt(), Integer.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pLong(Long.MIN_VALUE).build()).pLong(), Long.MIN_VALUE); assertEquals((long)serializationResult(TestClass.builder().oLong(Long.MAX_VALUE).build()).oLong(), Long.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pFloat(Float.MIN_VALUE).build()).pFloat(), Float.MIN_VALUE); assertEquals(serializationResult(TestClass.builder().oFloat(Float.MAX_VALUE).build()).oFloat(), Float.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pDouble(Double.MIN_VALUE).build()).pDouble(), Double.MIN_VALUE); assertEquals(serializationResult(TestClass.builder().oDouble(Double.MAX_VALUE).build()).oDouble(), Double.MAX_VALUE); assertEquals(serializationResult(TestClass.builder().pBoolean(true).build()).pBoolean(), true); assertEquals(serializationResult(TestClass.builder().pBoolean(false).build()).pBoolean(), false); assertEquals((boolean)serializationResult(TestClass.builder().oBoolean(true).build()).oBoolean(), true); assertEquals((boolean)serializationResult(TestClass.builder().oBoolean(false).build()).oBoolean(), false); assertEquals(serializationResult(TestClass.builder().str("Hello, world").build()).str(), "Hello, world"); UUID uuid = UUID.randomUUID(); assertEquals(serializationResult(TestClass.builder().uuid(uuid).build()).uuid(), uuid); assertEquals(serializationResult(TestClass.builder().e(TestClass.E.B).build()).e(), TestClass.E.B); assertEquals(serializationResult(TestClass.builder().value(new SomeValue("test")).build()) .value().value(), "test"); assertEquals(serializationResult( TestClass.builder() .value1(new SomeValue1(Collections.singletonList(new SomeValue2(new SomeValue("test"))))) .build()).value1().value().get(0).value().value(), "test"); ArrayList<List<String>> l = new ArrayList<>(); ArrayList<String> l1 = new ArrayList<>(); l1.add("test"); l.add(l1); assertEquals(serializationResult(TestClass.builder().list(l).build()).list().get(0).get(0), "test"); Map<String, List<String>> map = new HashMap<>(); LinkedList<String> list = new LinkedList<>(Arrays.asList("Hello")); map.put("test", list); map.put("anothertest", list); assertEquals(serializationResult(TestClass.builder().map(map).build()).map().get("test").get(0), "Hello"); assertEquals(serializationResult(TestClass.builder().map(map).build()).map().get("anothertest").get(0), "Hello"); assertFalse(serializationResult(TestClass.builder().optional(Optional.empty()).build()).optional().isPresent()); assertTrue(serializationResult(TestClass.builder().optional(Optional.of("test")).build()).optional().isPresent()); assertEquals(serializationResult(TestClass.builder().optional(Optional.of("test")).build()).optional().get(), "test"); BigDecimal bigDecimal = new BigDecimal("0.00000000000000000000000000001"); assertEquals(serializationResult(TestClass.builder().bigDecimal(bigDecimal).build()).bigDecimal(), bigDecimal); BigInteger bigInteger = new BigInteger("100001"); assertEquals(serializationResult(TestClass.builder().bigInteger(bigInteger).build()).bigInteger(), bigInteger); Date date = new Date(); assertEquals(serializationResult(TestClass.builder().date(date).build()).date(), date); }