Java Code Examples for org.jooq.DSLContext#newRecord()

The following examples show how to use org.jooq.DSLContext#newRecord() . 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: WaltzUtilities.java    From waltz with Apache License 2.0 6 votes vote down vote up
public static Long getOrCreateMeasurableCategory(DSLContext dsl, String externalId, String name) {

        Long categoryId = dsl
                .select(MEASURABLE_CATEGORY.ID)
                .from(MEASURABLE_CATEGORY)
                .where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(externalId))
                .fetchOne(MEASURABLE_CATEGORY.ID);


        if (categoryId != null) {
            return categoryId;
        } else {
            MeasurableCategoryRecord measurableCategoryRecord = dsl.newRecord(MEASURABLE_CATEGORY);
            measurableCategoryRecord.setName(name);
            measurableCategoryRecord.setDescription(name);
            measurableCategoryRecord.setExternalId(externalId);
            measurableCategoryRecord.setRatingSchemeId(1L);
            measurableCategoryRecord.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
            measurableCategoryRecord.setLastUpdatedBy("admin");
            measurableCategoryRecord.store();
            return measurableCategoryRecord.getId();
        }
    }
 
Example 2
Source File: ChangeUnitGenerator.java    From waltz with Apache License 2.0 6 votes vote down vote up
private AttributeChangeRecord mkDataTypeChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    List<DataType> allDataTypes = dsl.selectFrom(DATA_TYPE)
            .fetch(DataTypeDao.TO_DOMAIN);

    List<DataType> newDataTypes = randomPick(allDataTypes, randomIntBetween(1, 5));
    String json = "["
            + joinUsing(newDataTypes, d -> String.format("{\"dataTypeId\": %s}", d.id().get()), ",")
            + "]";

    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("json");
    record.setOldValue("[]");
    record.setNewValue(json);
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
 
Example 3
Source File: XlsImporter.java    From waltz with Apache License 2.0 5 votes vote down vote up
private MeasurableRecord newMeasurableRecord(DSLContext dsl, Long categoryId) {
    MeasurableRecord record = dsl.newRecord(MEASURABLE);
    record.setProvenance(PROVENANCE);
    record.setLastUpdatedBy("admin");
    record.setLastUpdatedAt(nowUtcTimestamp());
    record.setMeasurableCategoryId(categoryId);
    record.setConcrete(false);
    return record;
}
 
Example 4
Source File: ChangeUnitGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private AttributeChangeRecord mkFrequencyChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("string");
    record.setOldValue(flow.frequency().name());
    record.setNewValue(randomPick(FrequencyKind.values()).name());
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
 
Example 5
Source File: ChangeUnitGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private AttributeChangeRecord mkCriticalityChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("string");
    record.setOldValue(flow.criticality().name());
    record.setNewValue(randomPick(Criticality.values()).name());
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
 
Example 6
Source File: ProcessGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private void setupMeasurables(DSLContext dsl, long category) {
    List<MeasurableRecord> records = new ArrayList<>();

    for (long g = 1; g <= NUM_PROCESS_GROUPS; g++ ) {
        System.out.println("mkGroup: " + g);
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setDescription("Process Group: " + g);
        record.setName("Process Group " + g);
        record.setMeasurableCategoryId(category);
        record.setConcrete(false);
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setLastUpdatedBy("admin");
        record.insert();

        long groupId = record.getId();

        for (long p = 0; p < NUM_PROCESSES_IN_GROUP; p++) {
            MeasurableRecord record2 = dsl.newRecord(MEASURABLE);
            String name = randomPick(p1)
                    + " "
                    + randomPick(p2);
            record2.setDescription("Process: " + name);
            record2.setName(name);
            record2.setParentId(groupId);
            record2.setMeasurableCategoryId(category);
            record2.setConcrete(true);
            record2.setProvenance(SAMPLE_DATA_PROVENANCE);
            record2.setLastUpdatedBy("admin");
            records.add(record2);
            System.out.print(".");
        }

    }
    int[] rcs = dsl.batchInsert(records).execute();
    System.out.println("\nBatch inserted: "+rcs.length);
}
 
Example 7
Source File: SurveyRunGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static SurveyRunRecord mkRandomSurveyRunRecord(DSLContext dsl,
                                                       List<AppGroup> appGroups,
                                                       List<InvolvementKind> involvementKinds,
                                                       SurveyTemplate surveyTemplate,
                                                       Person owner) {
    SurveyRunRecord surveyRunRecord = dsl.newRecord(SURVEY_RUN);
    surveyRunRecord.setOwnerId(owner.id().get());
    surveyRunRecord.setContactEmail(owner.email());
    surveyRunRecord.setSurveyTemplateId(surveyTemplate.id().get());
    surveyRunRecord.setName(String.format("%s %s %s",
            randomPick(SURVEY_RUN_PREFIXES),
            surveyTemplate.name(),
            SURVEY_RUN_SUFFIX));
    surveyRunRecord.setDescription(surveyTemplate.description());
    surveyRunRecord.setSelectorEntityKind(EntityKind.APP_GROUP.name());
    surveyRunRecord.setSelectorEntityId(appGroups.get(random.nextInt(appGroups.size())).id().get());
    surveyRunRecord.setSelectorHierarchyScope(HierarchyQueryScope.EXACT.name());

    Collections.shuffle(involvementKinds, random);
    surveyRunRecord.setInvolvementKindIds(involvementKinds.stream()
            .limit(random.nextInt(MAX_INVOLVEMENT_KINDS_PER_RUN) + 1)
            .map(kind -> kind.id().get().toString())
            .collect(joining(ID_SEPARATOR)));

    surveyRunRecord.setIssuanceKind(randomPick(SurveyIssuanceKind.values()).name());
    LocalDate issuedOn = LocalDate.now().minusDays(random.nextInt(MAX_SURVEY_AGE_IN_DAYS));
    surveyRunRecord.setIssuedOn(java.sql.Date.valueOf(issuedOn));
    surveyRunRecord.setDueDate(java.sql.Date.valueOf(issuedOn.plusDays(random.nextInt(MAX_SURVEY_LIFESPAN_IN_DAYS))));
    surveyRunRecord.setStatus(randomPick(SurveyRunStatus.ISSUED.name(), SurveyRunStatus.COMPLETED.name()));

    return surveyRunRecord;
}
 
Example 8
Source File: JooqUnmapperTest.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Test
public void testUnmapping() throws Exception {
	Connection conn = DbHelper.objectDb();

	Configuration cfg = new DefaultConfiguration()
			.set(conn)
			.set(SQLDialect.HSQLDB);

	cfg.set(JooqMapperFactory.newInstance().newRecordUnmapperProvider(new DSLContextProvider() {
		@Override
		public DSLContext provide() {
			return DSL.using(cfg);
		}
	}));

	DSLContext dsl = DSL.using(cfg);

	Label label = new Label(1, UUID.randomUUID(), "label", false);

	LabelsRecord labelsRecord = dsl.newRecord(Labels.LABELS, label);

	assertEquals(label.getId(), labelsRecord.getId());
	assertEquals(label.getName(), labelsRecord.getName());
	assertEquals(label.getUuid(), labelsRecord.getUuid());
	assertEquals(label.getObsolete(), labelsRecord.getObsolete());


}