use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord in project ehrbase by ehrbase.
the class FolderAccess method saveFolderItems.
private void saveFolderItems(final UUID folderId, final UUID old_contribution, final UUID new_contribution, final Timestamp transactionTime, DSLContext context) {
for (ObjectRef or : this.getItems()) {
// insert in object_ref
ObjectRefRecord orr = new ObjectRefRecord(or.getNamespace(), or.getType(), UUID.fromString(or.getId().getValue()), new_contribution, transactionTime, folderRecord.getSysPeriod());
context.attach(orr);
orr.store();
// insert in folder_item
FolderItemsRecord fir = new FolderItemsRecord(folderId, UUID.fromString(or.getId().getValue()), new_contribution, transactionTime, folderRecord.getSysPeriod());
context.attach(fir);
fir.store();
}
}
use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord in project ehrbase by ehrbase.
the class FolderAccess method retrieveItemsByFolderAndContributionId.
/**
* Retrieves a list containing the items as ObjectRefs of the folder corresponding to the id
* provided.
*
* @param folderId of the FOLDER that the items correspond to.
* @param in_contribution contribution that establishes the reference between a FOLDER and its
* item.
* @param domainAccess connection DB data.
* @return
*/
private static List<ObjectRef<?>> retrieveItemsByFolderAndContributionId(UUID folderId, UUID in_contribution, I_DomainAccess domainAccess) {
Result<Record> retrievedRecords = domainAccess.getContext().with("folderItemsSelect").as(select(FOLDER_ITEMS.OBJECT_REF_ID.as("object_ref_id"), FOLDER_ITEMS.IN_CONTRIBUTION.as("item_in_contribution")).from(FOLDER_ITEMS).where(FOLDER_ITEMS.FOLDER_ID.eq(folderId))).select().from(OBJECT_REF, table(name("folderItemsSelect"))).where(field(name("object_ref_id"), FOLDER_ITEMS.OBJECT_REF_ID.getType()).eq(OBJECT_REF.ID).and(field(name("item_in_contribution"), FOLDER_ITEMS.IN_CONTRIBUTION.getType()).eq(OBJECT_REF.IN_CONTRIBUTION))).fetch();
List<ObjectRef<?>> result = new ArrayList<>();
for (Record recordRecord : retrievedRecords) {
Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID> recordParam = (Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID>) recordRecord;
ObjectRefRecord objectRef = new ObjectRefRecord();
objectRef.setIdNamespace(recordParam.value1());
objectRef.setType(recordParam.value2());
objectRef.setId(recordParam.value3());
objectRef.setInContribution(recordParam.value4());
objectRef.setSysTransaction(recordParam.value5());
objectRef.setSysPeriod(new SysPeriodBinder().converter().from(recordParam.value6()));
objectRef.setId(recordParam.value7());
result.add(parseObjectRefRecordIntoObjectRef(objectRef, domainAccess));
}
return result;
}
use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord in project ehrbase by ehrbase.
the class FolderHistoryAccess method retrieveItemsByFolderAndContributionId.
/**
* Retrieves a list containing the items as ObjectRefs of the folder corresponding to the id
* provided.
*
* @param folderId of the FOLDER that the items correspond to.
* @param in_contribution contribution that establishes the reference between a FOLDER and its
* item.
* @param domainAccess connection DB data.
* @return
*/
private static List<ObjectRef<?>> retrieveItemsByFolderAndContributionId(UUID folderId, UUID in_contribution, I_DomainAccess domainAccess) {
Table<?> table_items_and_objref = table(select(FOLDER_ITEMS.FOLDER_ID, FOLDER_ITEMS.OBJECT_REF_ID.as("item_object_ref_id"), FOLDER_ITEMS.IN_CONTRIBUTION.as("item_in_contribution"), FOLDER_ITEMS.SYS_TRANSACTION, FOLDER_ITEMS.SYS_PERIOD, OBJECT_REF.ID_NAMESPACE, OBJECT_REF.TYPE, OBJECT_REF.ID.as("obj_ref_id"), OBJECT_REF.IN_CONTRIBUTION.as("obj_ref_in_cont"), OBJECT_REF.SYS_TRANSACTION.as("objRefSysTran"), OBJECT_REF.SYS_PERIOD.as("oref_sysperiod")).from(FOLDER_ITEMS).leftJoin(OBJECT_REF).on(FOLDER_ITEMS.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS.IN_CONTRIBUTION.eq(in_contribution).and(OBJECT_REF.ID.eq(FOLDER_ITEMS.OBJECT_REF_ID).and(OBJECT_REF.IN_CONTRIBUTION.eq(FOLDER_ITEMS.IN_CONTRIBUTION))))).where(FOLDER_ITEMS.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS.IN_CONTRIBUTION.eq(in_contribution))));
Table<?> table_items_and_objref_hist = table(select(FOLDER_ITEMS_HISTORY.FOLDER_ID, FOLDER_ITEMS_HISTORY.OBJECT_REF_ID.as("item_object_ref_id"), FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.as("item_in_contribution"), FOLDER_ITEMS_HISTORY.SYS_TRANSACTION, FOLDER_ITEMS_HISTORY.SYS_PERIOD, OBJECT_REF_HISTORY.ID_NAMESPACE, OBJECT_REF_HISTORY.TYPE, OBJECT_REF_HISTORY.ID.as("obj_ref_id"), OBJECT_REF_HISTORY.IN_CONTRIBUTION.as("obj_ref_in_cont"), OBJECT_REF_HISTORY.SYS_TRANSACTION.as("objRefSysTran"), OBJECT_REF_HISTORY.SYS_PERIOD.as("oref_sysperiod")).from(FOLDER_ITEMS_HISTORY).leftJoin(OBJECT_REF_HISTORY).on(FOLDER_ITEMS_HISTORY.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.eq(in_contribution).and(OBJECT_REF_HISTORY.ID.eq(FOLDER_ITEMS_HISTORY.OBJECT_REF_ID).and(OBJECT_REF_HISTORY.IN_CONTRIBUTION.eq(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION))))).where(FOLDER_ITEMS_HISTORY.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.eq(in_contribution))));
Table<?> table_all_items_and_objref = table(select().from(table_items_and_objref).union(select().from(table_items_and_objref_hist)));
Result<Record> retrievedRecords = domainAccess.getContext().select().from(table_all_items_and_objref).fetch();
List<ObjectRef<?>> result = new ArrayList<>();
for (Record recordRecord : retrievedRecords) {
Record11<UUID, UUID, UUID, Timestamp, Timestamp, String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>> recordParam = (Record11<UUID, UUID, UUID, Timestamp, Timestamp, String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>>) recordRecord;
ObjectRefRecord objectRef = new ObjectRefRecord();
objectRef.setIdNamespace(recordParam.value6());
objectRef.setType(recordParam.value7());
objectRef.setId(recordParam.value8());
objectRef.setInContribution(recordParam.value9());
objectRef.setSysTransaction(recordParam.value10());
objectRef.setSysPeriod(recordParam.value11());
objectRef.setId(recordParam.value8());
result.add(parseObjectRefRecordIntoObjectRef(objectRef, domainAccess));
}
return result;
}
Aggregations