use of org.jooq.InsertValuesStepN in project hmftools by hartwigmedical.
the class CopyNumberDAO method writeCopyNumberRegions.
void writeCopyNumberRegions(@NotNull final String sample, @NotNull List<FittedRegion> regions) {
Timestamp timestamp = new Timestamp(new Date().getTime());
context.delete(COPYNUMBERREGION).where(COPYNUMBERREGION.SAMPLEID.eq(sample)).execute();
for (List<FittedRegion> splitRegions : Iterables.partition(regions, DB_BATCH_INSERT_SIZE)) {
InsertValuesStepN inserter = context.insertInto(COPYNUMBERREGION, COPYNUMBERREGION.SAMPLEID, COPYNUMBERREGION.CHROMOSOME, COPYNUMBERREGION.START, COPYNUMBERREGION.END, COPYNUMBERREGION.GERMLINESTATUS, COPYNUMBERREGION.SVCLUSTER, COPYNUMBERREGION.RATIOSUPPORT, COPYNUMBERREGION.SEGMENTSTARTSUPPORT, COPYNUMBERREGION.BAFCOUNT, COPYNUMBERREGION.OBSERVEDBAF, COPYNUMBERREGION.OBSERVEDTUMORRATIO, COPYNUMBERREGION.OBSERVEDNORMALRATIO, COPYNUMBERREGION.OBSERVEDTUMORRATIOCOUNT, COPYNUMBERREGION.GCCONTENT, COPYNUMBERREGION.MODELPLOIDY, COPYNUMBERREGION.MODELBAF, COPYNUMBERREGION.MODELTUMORRATIO, COPYNUMBERREGION.ACTUALTUMORBAF, COPYNUMBERREGION.ACTUALTUMORCOPYNUMBER, COPYNUMBERREGION.REFNORMALISEDTUMORCOPYNUMBER, COPYNUMBERREGION.CNVDEVIATION, COPYNUMBERREGION.BAFDEVIATION, COPYNUMBERREGION.TOTALDEVIATION, COPYNUMBERREGION.PLOIDYPENALTY, COPYNUMBERREGION.FITTEDBAF, COPYNUMBERREGION.FITTEDCOPYNUMBER, COPYNUMBERREGION.MODIFIED);
splitRegions.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x));
inserter.execute();
}
}
use of org.jooq.InsertValuesStepN in project hmftools by hartwigmedical.
the class SomaticVariantDAO method write.
void write(@NotNull final String sample, @NotNull List<EnrichedSomaticVariant> variants) {
Timestamp timestamp = new Timestamp(new Date().getTime());
context.delete(SOMATICVARIANT).where(SOMATICVARIANT.SAMPLEID.eq(sample)).execute();
for (List<EnrichedSomaticVariant> splitRegions : Iterables.partition(variants, DB_BATCH_INSERT_SIZE)) {
InsertValuesStepN inserter = context.insertInto(SOMATICVARIANT, SOMATICVARIANT.SAMPLEID, SOMATICVARIANT.CHROMOSOME, SOMATICVARIANT.POSITION, SOMATICVARIANT.FILTER, SOMATICVARIANT.TYPE, SOMATICVARIANT.REF, SOMATICVARIANT.ALT, SOMATICVARIANT.GENE, SOMATICVARIANT.GENESEFFECTED, SOMATICVARIANT.COSMICID, SOMATICVARIANT.DBSNPID, SOMATICVARIANT.WORSTEFFECT, SOMATICVARIANT.WORSTCODINGEFFECT, SOMATICVARIANT.WORSTEFFECTTRANSCRIPT, SOMATICVARIANT.CANONICALEFFECT, SOMATICVARIANT.CANONICALCODINGEFFECT, SOMATICVARIANT.ALLELEREADCOUNT, SOMATICVARIANT.TOTALREADCOUNT, SOMATICVARIANT.ADJUSTEDCOPYNUMBER, SOMATICVARIANT.ADJUSTEDVAF, SOMATICVARIANT.HIGHCONFIDENCE, SOMATICVARIANT.TRINUCLEOTIDECONTEXT, SOMATICVARIANT.MICROHOMOLOGY, SOMATICVARIANT.REPEATSEQUENCE, SOMATICVARIANT.REPEATCOUNT, SOMATICVARIANT.CLONALITY, SOMATICVARIANT.BIALLELIC, SOMATICVARIANT.HOTSPOT, SOMATICVARIANT.MAPPABILITY, SOMATICVARIANT.GERMLINESTATUS, SOMATICVARIANT.MINORALLELEPLOIDY, SOMATICVARIANT.MODIFIED);
splitRegions.forEach(x -> addRecord(timestamp, inserter, sample, x));
inserter.execute();
}
}
use of org.jooq.InsertValuesStepN in project hmftools by hartwigmedical.
the class GeneCopyNumberDAO method writeCopyNumber.
void writeCopyNumber(@NotNull final String sample, @NotNull List<GeneCopyNumber> copyNumbers) {
Timestamp timestamp = new Timestamp(new Date().getTime());
context.delete(GENECOPYNUMBER).where(GENECOPYNUMBER.SAMPLEID.eq(sample)).execute();
for (List<GeneCopyNumber> splitCopyNumbers : Iterables.partition(copyNumbers, DB_BATCH_INSERT_SIZE)) {
InsertValuesStepN inserter = context.insertInto(GENECOPYNUMBER, GENECOPYNUMBER.SAMPLEID, GENECOPYNUMBER.CHROMOSOME, GENECOPYNUMBER.START, GENECOPYNUMBER.END, GENECOPYNUMBER.GENE, GENECOPYNUMBER.MINCOPYNUMBER, GENECOPYNUMBER.MAXCOPYNUMBER, GENECOPYNUMBER.SOMATICREGIONS, GENECOPYNUMBER.GERMLINEHOMREGIONS, GENECOPYNUMBER.GERMLINEHETREGIONS, GENECOPYNUMBER.TRANSCRIPTID, GENECOPYNUMBER.TRANSCRIPTVERSION, GENECOPYNUMBER.CHROMOSOMEBAND, GENECOPYNUMBER.MINREGIONS, GENECOPYNUMBER.MINREGIONSTART, GENECOPYNUMBER.MINREGIONEND, GENECOPYNUMBER.MINREGIONSTARTSUPPORT, GENECOPYNUMBER.MINREGIONENDSUPPORT, GENECOPYNUMBER.MINREGIONMETHOD, GENECOPYNUMBER.NONSENSEBIALLELICVARIANTS, GENECOPYNUMBER.NONSENSENONBIALLELICVARIANTS, GENECOPYNUMBER.NONSENSENONBIALLELICPLOIDY, GENECOPYNUMBER.SPLICEBIALLELICVARIANTS, GENECOPYNUMBER.SPLICENONBIALLELICVARIANTS, GENECOPYNUMBER.SPLICENONBIALLELICPLOIDY, GENECOPYNUMBER.MISSENSEBIALLELICVARIANTS, GENECOPYNUMBER.MISSENSENONBIALLELICVARIANTS, GENECOPYNUMBER.MISSENSENONBIALLELICPLOIDY, GENECOPYNUMBER.MINMINORALLELEPLOIDY, COPYNUMBER.MODIFIED);
splitCopyNumbers.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x));
inserter.execute();
}
}
use of org.jooq.InsertValuesStepN in project jOOQ by jOOQ.
the class DefaultParseContext method parseInsert.
private final Query parseInsert(WithImpl with, boolean parseResultQuery) {
scopeStart();
parseKeyword("INSERT", "INS");
parseKeywordIf("INTO");
Table<?> table = parseTableNameIf();
if (table == null)
table = table(parseSelect());
Name alias;
if (parseKeywordIf("AS"))
table = table.as(parseIdentifier());
else if (!peekKeyword("DEFAULT VALUES", "SEL", "SELECT", "SET", "VALUES") && (alias = parseIdentifierIf()) != null)
table = table.as(alias);
scope(table);
InsertSetStep<?> s1 = (with == null ? dsl.insertInto(table) : with.insertInto(table));
Field<?>[] fields = null;
if (!peekSelectOrWith(true) && parseIf('(') && !parseIf(')')) {
fields = parseList(',', c -> parseField()).toArray(EMPTY_FIELD);
parse(')');
}
InsertOnDuplicateStep<?> onDuplicate;
InsertReturningStep<?> returning;
try {
// [#11821] The Teradata INSERT INTO t (1, 2) syntax can be recognised:
// When there are non-references fields
boolean hasExpressions = anyMatch(fields, f -> !(f instanceof TableField));
if (hasExpressions || parseKeywordIf("VALUES")) {
List<List<Field<?>>> allValues = new ArrayList<>();
if (hasExpressions) {
allValues.add(asList(fields));
fields = null;
}
valuesLoop: do {
if (hasExpressions && !parseIf(','))
break valuesLoop;
parse('(');
// [#6936] MySQL treats an empty VALUES() clause as the same thing as the standard DEFAULT VALUES
if (fields == null && parseIf(')'))
break valuesLoop;
List<Field<?>> values = parseList(',', c -> c.parseKeywordIf("DEFAULT") ? default_() : c.parseField());
if (fields != null && fields.length != values.size())
throw exception("Insert field size (" + fields.length + ") must match values size (" + values.size() + ")");
allValues.add(values);
parse(')');
} while (parseIf(','));
InsertValuesStepN<?> step2 = (fields != null) ? s1.columns(fields) : (InsertValuesStepN<?>) s1;
for (List<Field<?>> values : allValues) step2 = step2.values(values);
returning = onDuplicate = step2;
} else if (parseKeywordIf("SET")) {
Map<Field<?>, Object> map = parseSetClauseList();
returning = onDuplicate = s1.set(map);
} else if (peekSelectOrWith(true)) {
// [#10954] These are moved into the INSERT .. SELECT clause handling. They should not be necessary here
// either, but it seems we currently don't correctly implement nesting scopes?
scopeEnd(null);
scopeStart();
Select<?> select = parseWithOrSelect();
returning = onDuplicate = (fields == null) ? s1.select(select) : s1.columns(fields).select(select);
} else if (parseKeywordIf("DEFAULT VALUES")) {
if (fields != null)
throw notImplemented("DEFAULT VALUES without INSERT field list");
else
returning = onDuplicate = s1.defaultValues();
} else
throw expected("DEFAULT VALUES", "WITH", "SELECT", "SET", "VALUES");
if (parseKeywordIf("ON")) {
if (parseKeywordIf("DUPLICATE KEY UPDATE")) {
parseKeywordIf("SET");
InsertOnConflictWhereStep<?> where = onDuplicate.onDuplicateKeyUpdate().set(parseSetClauseList());
if (parseKeywordIf("WHERE"))
returning = where.where(parseCondition());
else
returning = where;
} else if (parseKeywordIf("DUPLICATE KEY IGNORE")) {
returning = onDuplicate.onDuplicateKeyIgnore();
} else if (parseKeywordIf("CONFLICT")) {
InsertOnConflictDoUpdateStep<?> doUpdate;
if (parseKeywordIf("ON CONSTRAINT")) {
doUpdate = onDuplicate.onConflictOnConstraint(parseName());
} else if (parseIf('(')) {
InsertOnConflictWhereIndexPredicateStep<?> where = onDuplicate.onConflict(parseList(',', c -> parseFieldName()));
parse(')');
doUpdate = parseKeywordIf("WHERE") ? where.where(parseCondition()) : where;
} else {
doUpdate = onDuplicate.onConflict();
}
parseKeyword("DO");
if (parseKeywordIf("NOTHING")) {
returning = doUpdate.doNothing();
} else if (parseKeywordIf("UPDATE SET")) {
InsertOnConflictWhereStep<?> where = doUpdate.doUpdate().set(parseSetClauseList());
if (parseKeywordIf("WHERE"))
returning = where.where(parseCondition());
else
returning = where;
} else
throw expected("NOTHING", "UPDATE");
} else
throw expected("CONFLICT", "DUPLICATE");
}
return (parseResultQuery ? parseKeyword("RETURNING") : parseKeywordIf("RETURNING")) ? returning.returning(parseSelectList()) : returning;
} finally {
scopeEnd(((InsertImpl) s1).getDelegate());
}
}
Aggregations