org.sql2o.ResultSetIterable Java Examples
The following examples show how to use
org.sql2o.ResultSetIterable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Sql2oIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void whenLazyFetch_thenResultsAreObjects() { Sql2o sql2o = new Sql2o("jdbc:hsqldb:mem:testDB", "sa", ""); try(Connection connection = sql2o.open()) { connection.createQuery("create table PROJECT_16 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_16 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_16 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')").executeUpdate(); Query query = connection.createQuery("select * from PROJECT_16 order by id"); try(ResultSetIterable<Project> projects = query.executeAndFetchLazy(Project.class)) { for(Project p : projects) { assertNotNull(p.getName()); assertNotNull(p.getUrl()); assertNull(p.getCreationDate()); } } connection.createQuery("drop table PROJECT_16").executeUpdate(); } }
Example #2
Source File: CacheService.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public ArchiveFiles getArchiveFiles(ArchiveEntry archiveEntry) throws IOException { CacheDAO cacheDao = new CacheDAO(); try (Connection con = sql2o.open(); ResultSetIterable<FileEntry> files = cacheDao.findFilesForArchive(con, archiveEntry)) { byte[] archiveData = getArchive(archiveEntry); if (archiveData == null) { return null; } Container result = Container.decompress(archiveData, null); if (result == null) { return null; } byte[] decompressedData = result.data; ArchiveFiles archiveFiles = new ArchiveFiles(); for (FileEntry fileEntry : files) { FSFile file = new FSFile(fileEntry.getFileId()); archiveFiles.addFile(file); file.setNameHash(fileEntry.getNameHash()); } archiveFiles.loadContents(decompressedData); return archiveFiles; } }
Example #3
Source File: CacheService.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public List<ArchiveEntry> findArchivesForIndex(IndexEntry indexEntry) { try (Connection con = sql2o.open()) { CacheDAO cacheDao = new CacheDAO(); ResultSetIterable<ArchiveEntry> archiveEntries = cacheDao.findArchivesForIndex(con, indexEntry); List<ArchiveEntry> archives = new ArrayList<>(); Iterables.addAll(archives, archiveEntries); return archives; } }
Example #4
Source File: CacheDAO.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public ResultSetIterable<ArchiveEntry> findArchivesForIndex(Connection con, IndexEntry indexEntry) { return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," + " archive.crc, archive.revision, archive.hash from index_archive " + "join archive on index_archive.archive = archive.id " + "where index_archive.index = :id") .addParameter("id", indexEntry.getId()) .executeAndFetchLazy(ArchiveEntry.class); }
Example #5
Source File: CacheDAO.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public ResultSetIterable<ArchiveEntry> findArchivesForIndex(Connection con, IndexEntry indexEntry) { return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," + " archive.crc, archive.revision, archive.hash from index_archive " + "join archive on index_archive.archive = archive.id " + "where index_archive.index = :id") .addParameter("id", indexEntry.getId()) .executeAndFetchLazy(ArchiveEntry.class); }
Example #6
Source File: CacheStorage.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void load(Store store) throws IOException { List<IndexEntry> indexes = cacheDao.findIndexesForCache(con, cacheEntry); for (IndexEntry indexEntry : indexes) { Index index = store.addIndex(indexEntry.getIndexId()); index.setCrc(indexEntry.getCrc()); index.setRevision(indexEntry.getRevision()); try (ResultSetIterable<ArchiveEntry> archives = cacheDao.findArchivesForIndex(con, indexEntry)) { for (ArchiveEntry archiveEntry : archives) { if (index.getArchive(archiveEntry.getArchiveId()) != null) { throw new IOException("Duplicate archive " + archiveEntry + " on " + indexEntry); } Archive archive = index.addArchive(archiveEntry.getArchiveId()); archive.setNameHash(archiveEntry.getNameHash()); archive.setCrc(archiveEntry.getCrc()); archive.setRevision(archiveEntry.getRevision()); archive.setHash(archiveEntry.getHash()); // File data is not necessary for cache updating } } } }
Example #7
Source File: ProductStockSql2oEventsStore.java From ddd-wro-warehouse with MIT License | 5 votes |
@Override public List<Object> readEventsInStock(String refNo) { try (Connection connection = sql2o.open(); Query query = connection.createQuery( "select * from warehouse.ProductStockHistory where refNo = :refNo and inStock = true order by id"); ResultSetIterable<ProductStockHistoryEvent> result = query .addParameter("refNo", refNo) .executeAndFetchLazy(ProductStockHistoryEvent.class)) { return deserialize(result); } }
Example #8
Source File: ProductStockSql2oEventsStore.java From ddd-wro-warehouse with MIT License | 5 votes |
@Override public List<Object> readEventsSince(String refNo, EventId since) { try (Connection connection = sql2o.open(); Query query = connection.createQuery( "select * from warehouse.ProductStockHistory where refNo = :refNo and id > :since order by id"); ResultSetIterable<ProductStockHistoryEvent> result = query .addParameter("refNo", refNo) .addParameter("since", since.getId()) .executeAndFetchLazy(ProductStockHistoryEvent.class)) { return deserialize(result); } }
Example #9
Source File: ProductStockSql2oEventsStore.java From ddd-wro-warehouse with MIT License | 4 votes |
private List<Object> deserialize(ResultSetIterable<ProductStockHistoryEvent> result) { return StreamSupport.stream(result.spliterator(), false) .map(entry -> Persistence.serialization.deserialize(entry.getContent(), entry.getType())) .collect(Collectors.toList()); }