use of org.jooq.Field in project jOOQ by jOOQ.
the class CreateViewImpl method accept0.
private final void accept0(Context<?> ctx) {
// [#3835] SQLite doesn't like renaming columns at the view level
boolean rename = fields != null && fields.length > 0;
boolean renameSupported = ctx.family() != SQLITE;
// [#4806] CREATE VIEW doesn't accept parameters in most databases
ParamType paramType = ctx.paramType();
ctx.start(CREATE_VIEW_NAME).keyword("create view").sql(' ');
if (ifNotExists && supportsIfNotExists(ctx))
ctx.keyword("if not exists").sql(' ');
ctx.visit(view);
if (rename && renameSupported) {
boolean qualify = ctx.qualify();
ctx.sql('(').qualify(false).visit(new QueryPartList<Field<?>>(fields)).qualify(qualify).sql(')');
}
ctx.end(CREATE_VIEW_NAME).formatSeparator().keyword("as").formatSeparator().start(CREATE_VIEW_AS).paramType(INLINED).visit(rename && !renameSupported ? selectFrom(table(select).as("t", Tools.fieldNames(fields))) : select).paramType(paramType).end(CREATE_VIEW_AS);
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class ParserImpl method parseFieldAnd.
private static final Field<?> parseFieldAnd(ParserContext ctx) {
Field<?> r = parseFieldCondition(ctx);
Condition c = null;
while (parseKeywordIf(ctx, "AND")) c = ((c == null) ? condition((Field) r) : c).and((Field) parseFieldCondition(ctx));
return c == null ? r : field(c);
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class TableRecordImpl method storeInsert0.
final int storeInsert0(Field<?>[] storeFields) {
DSLContext create = create();
InsertQuery<R> insert = create.insertQuery(getTable());
addChangedValues(storeFields, insert);
// Don't store records if no value was set by client code
if (!insert.isExecutable()) {
if (log.isDebugEnabled())
log.debug("Query is not executable", insert);
return 0;
}
// [#1596] Set timestamp and/or version columns to appropriate values
BigInteger version = addRecordVersion(insert);
Timestamp timestamp = addRecordTimestamp(insert);
// [#814] Refresh identity and/or main unique key values
// [#1002] Consider also identity columns of non-updatable records
// [#1537] Avoid refreshing identity columns on batch inserts
Collection<Field<?>> key = setReturningIfNeeded(insert);
int result = insert.execute();
if (result > 0) {
for (Field<?> storeField : storeFields) changed(storeField, false);
// [#1596] If insert was successful, update timestamp and/or version columns
setRecordVersionAndTimestamp(version, timestamp);
// [#1859] If an insert was successful try fetching the generated values.
getReturningIfNeeded(insert, key);
fetched = true;
}
return result;
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class UpdatableRecordImpl method storeUpdate0.
private final int storeUpdate0(Field<?>[] storeFields, TableField<R, ?>[] keys) {
UpdateQuery<R> update = create().updateQuery(getTable());
addChangedValues(storeFields, update);
Tools.addConditions(update, this, keys);
// Don't store records if no value was set by client code
if (!update.isExecutable()) {
if (log.isDebugEnabled())
log.debug("Query is not executable", update);
return 0;
}
// [#1596] Set timestamp and/or version columns to appropriate values
BigInteger version = addRecordVersion(update);
Timestamp timestamp = addRecordTimestamp(update);
if (isExecuteWithOptimisticLocking()) {
// [#1596] Add additional conditions for version and/or timestamp columns
if (isTimestampOrVersionAvailable()) {
addConditionForVersionAndTimestamp(update);
} else // [#5384] Do this only if the exclusion flag for unversioned records is off
if (isExecuteWithOptimisticLockingIncludeUnversioned()) {
checkIfChanged(keys);
}
}
// [#1596] Check if the record was really changed in the database
// [#1859] Specify the returning clause if needed
Collection<Field<?>> key = setReturningIfNeeded(update);
int result = update.execute();
checkIfChanged(result, version, timestamp);
if (result > 0) {
for (Field<?> storeField : storeFields) changed(storeField, false);
// [#1859] If an update was successful try fetching the generated
getReturningIfNeeded(update, key);
}
return result;
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class ParserImpl method parseBooleanPrimary.
private static final Condition parseBooleanPrimary(ParserContext ctx) {
if (parseIf(ctx, '(')) {
Condition result = parseCondition(ctx);
parse(ctx, ')');
return result;
}
TruthValue truth = parseTruthValueIf(ctx);
if (truth != null) {
Comparator comp = parseComparatorIf(ctx);
switch(truth) {
case TRUE:
return comp == null ? condition(true) : inline(true).compare(comp, (Field<Boolean>) parseField(ctx));
case FALSE:
return comp == null ? condition(false) : inline(false).compare(comp, (Field<Boolean>) parseField(ctx));
case NULL:
return comp == null ? condition((Boolean) null) : inline((Boolean) null).compare(comp, (Field<Boolean>) parseField(ctx));
default:
throw ctx.exception();
}
}
return parsePredicate(ctx);
}
Aggregations