Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.edu.agh.kis.florist.dao;
- import org.jooq.DSLContext;
- import org.jooq.impl.DSL;
- import pl.edu.agh.kis.florist.db.tables.pojos.FolderMetadata;
- import pl.edu.agh.kis.florist.db.tables.records.FolderMetadataRecord;
- import java.util.List;
- import java.util.stream.Collectors;
- import static pl.edu.agh.kis.florist.db.Tables.FOLDER_METADATA;
- public class FolderMetadataDAO {
- private final String DB_URL = "jdbc:sqlite:test.db";
- public FolderMetadata loadFolderOfID(int folderId) {
- try (DSLContext create = DSL.using(DB_URL)) {
- FolderMetadataRecord record = create.selectFrom(FOLDER_METADATA).where(FOLDER_METADATA.FOLDER_ID.equal(folderId)).fetchOne();
- FolderMetadata folderMetadata = record.into(FolderMetadata.class);
- return folderMetadata;
- }
- }
- public List<FolderMetadata> loadAllFolders() {
- try (DSLContext create = DSL.using(DB_URL)) {
- List<FolderMetadata> folders = create.select(FOLDER_METADATA.fields()).from(FOLDER_METADATA).fetchInto(FolderMetadata.class);
- return folders;
- }
- }
- public FolderMetadata storeFolderMetadata(FolderMetadata folderMetadata) {
- try (DSLContext create = DSL.using(DB_URL)) {
- FolderMetadataRecord record = create.newRecord(FOLDER_METADATA, folderMetadata);
- record.store();
- return record.into(FolderMetadata.class);
- }
- }
- public List<FolderMetadata> storeFolderMetadata(List<FolderMetadata> foldersMetadata) {
- //in the future can be optimized into single db query
- return foldersMetadata.stream().map(this::storeFolderMetadata).collect(Collectors.toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement