@Override public Condition visit(FalseQueryCriteria criteria, Boolean inArray) { return DSL.falseCondition(); }
@Override public final Condition in(Field<?>... values) { if (values == null || values.length == 0) { return falseCondition(); } else { return new InCondition<T>(this, nullSafe(values), IN); } }
@Override public final boolean exists(Table<?> table) { Boolean result = exists.get(table); if (result == null) { try { create(true) .selectOne() .from(table) .where(falseCondition()) .fetch(); result = true; } catch (DataAccessException e) { result = false; } exists.put(table, result); } return result; }
static Condition of(Operator operator, Collection<? extends Condition> conditions) { CombinedCondition result = null; Condition first = null; for (Condition condition : conditions) if (!(condition instanceof NoCondition)) if (first == null) first = condition; else if (result == null) (result = new CombinedCondition(operator, conditions.size())) .add(operator, first) .add(operator, condition); else result.add(operator, condition); if (result != null) return result; else if (first != null) return first; else if (operator == AND) return trueCondition(); else return falseCondition(); }
boolean is94() { if (is94 == null) { // [#4254] INFORMATION_SCHEMA.PARAMETERS.PARAMETER_DEFAULT was added // in PostgreSQL 9.4 only try { create(true) .select(PARAMETERS.PARAMETER_DEFAULT) .from(PARAMETERS) .where(falseCondition()) .fetch(); is94 = true; } catch (DataAccessException e) { is94 = false; } } return is94; }
boolean is1_4_197() { if (is1_4_197 == null) { // [#5874] The COLUMNS.COLUMN_TYPE column was introduced in H2 1.4.197 try { create(true) .select(Columns.COLUMN_TYPE) .from(COLUMNS) .where(falseCondition()) .fetch(); is1_4_197 = true; } catch (DataAccessException e) { is1_4_197 = false; } } return is1_4_197; } }
private Condition fieldMatchesPermission(Field<Object> field, Object permission) { //For now only support strings if(!(permission instanceof String)) return DSL.falseCondition(); return DSL.or( field.eq(permission), DSL.and( field.isNotNull(), field.notEqual(""), field.likeRegex(PERMISSION_START_REGEX + permission + PERMISSION_END_REGEX) ) ); }
boolean is11() { if (is11 == null) { // [#7785] pg_proc.prokind was added in PostgreSQL 11 only, and // pg_proc.proisagg was removed, incompatibly try { create(true) .select(PG_PROC.PROKIND) .from(PG_PROC) .where(falseCondition()) .fetch(); is11 = true; } catch (DataAccessException e) { is11 = false; } } return is11; }
private void addPkRecords(ReflectedTable t1, ReflectedTable t2, HashMap<Object, ArrayList<Object>> pkValues, Params params, DSLContext dsl, ArrayList<Record> records) { List<Field<Object>> fks = t2.getFksTo(t1.getName()); ArrayList<Field<?>> fields = columns.getNames(t2, false, params); Condition condition = DSL.falseCondition(); for (Field<Object> fk : fks) { condition = condition.or(fk.in(pkValues.keySet())); } ResultQuery<org.jooq.Record> query = dsl.select(fields).from(t2).where(condition); for (org.jooq.Record record : query.fetch()) { records.add(Record.valueOf(record.intoMap())); } }
ctx.visit(trueCondition()); else ctx.visit(falseCondition());
@Override public boolean isProjectMember(long projectId, Long usingAccount, boolean isAdmin, Set<Identity> identities) { if (identities == null) { return false; } if ((usingAccount != null && usingAccount.equals(projectId)) || isAdmin) { return true; } Set<ProjectMemberRecord> projectMembers = new HashSet<>(); Condition allMembers = DSL.falseCondition(); for (Identity id : identities) { allMembers = allMembers.or(PROJECT_MEMBER.EXTERNAL_ID.eq(id.getExternalId()) .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(id.getExternalIdType())) .and(PROJECT_MEMBER.PROJECT_ID.eq(projectId)) .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE)) .and(PROJECT_MEMBER.REMOVED.isNull())); } projectMembers.addAll(create().selectFrom(PROJECT_MEMBER).where(allMembers).fetch()); return !projectMembers.isEmpty(); }
public boolean hasProjectRole(long projectId, Long usingAccount, boolean isAdmin, Set<Identity> identities, List<String> roles) { if (identities == null) { return false; } if (isAdmin) { return true; } if (usingAccount != null && usingAccount.equals(projectId)) { return false; } Set<ProjectMemberRecord> projectMembers = new HashSet<>(); Condition allMembers = DSL.falseCondition(); for (Identity id : identities) { allMembers = allMembers.or(PROJECT_MEMBER.EXTERNAL_ID.eq(id.getExternalId()) .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(id.getExternalIdType())) .and(PROJECT_MEMBER.ROLE.in(roles)) .and(PROJECT_MEMBER.PROJECT_ID.eq(projectId)) .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE)) .and(PROJECT_MEMBER.REMOVED.isNull())); } projectMembers.addAll(create().selectFrom(PROJECT_MEMBER).where(allMembers).fetch()); return !projectMembers.isEmpty(); }
@Override protected List<TableDefinition> getTables0() throws SQLException { List<TableDefinition> result = new ArrayList<TableDefinition>(); for (Record record : create().select( Tables.TABLE_SCHEMA, Tables.TABLE_NAME, Tables.TABLE_COMMENT) .from(TABLES) // [#5213] Duplicate schema value to work around MySQL issue https://bugs.mysql.com/bug.php?id=86022 .where(Tables.TABLE_SCHEMA.in(getInputSchemata()).or( getInputSchemata().size() == 1 ? Tables.TABLE_SCHEMA.in(getInputSchemata()) : falseCondition())) .orderBy( Tables.TABLE_SCHEMA, Tables.TABLE_NAME) .fetch()) { SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA)); String name = record.get(Tables.TABLE_NAME); String comment = record.get(Tables.TABLE_COMMENT); MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment); result.add(table); } return result; }
Condition allMembers = DSL.falseCondition(); for (Member member : delete) { allMembers = allMembers.or(PROJECT_MEMBER.EXTERNAL_ID.eq(member.getExternalId())
@Override protected List<TableDefinition> getTables0() throws SQLException { List<TableDefinition> result = new ArrayList<TableDefinition>(); for (Record2<String, Boolean> record : create() .select( RDB$RELATIONS.RDB$RELATION_NAME.trim(), inline(false).as("table_valued_function")) .from(RDB$RELATIONS) .unionAll( select( RDB$PROCEDURES.RDB$PROCEDURE_NAME.trim(), inline(true).as("table_valued_function")) .from(RDB$PROCEDURES) // "selectable" procedures .where(RDB$PROCEDURES.RDB$PROCEDURE_TYPE.eq((short) 1)) .and(tableValuedFunctions() ? noCondition() : falseCondition()) ) .orderBy(1)) { if (record.value2()) { result.add(new FirebirdTableValuedFunction(getSchemata().get(0), record.value1(), "")); } else { result.add(new FirebirdTableDefinition(getSchemata().get(0), record.value1(), "")); } } return result; }
@Override public final void accept(Context<?> ctx) { if (right.size() == 0) { if (comparator == IN) ctx.visit(falseCondition()); else ctx.visit(trueCondition()); } else { ctx.visit(left) .sql(' ') .visit(comparator.toKeyword()) .sql(" (") .visit(right) .sql(')'); } }
private Result<Record4<String, String, String, String>> fetchKeys(boolean primary) { // [#3560] It has been shown that querying the STATISTICS table is much faster on // very large databases than going through TABLE_CONSTRAINTS and KEY_COLUMN_USAGE return create().select( Statistics.TABLE_SCHEMA, Statistics.TABLE_NAME, Statistics.COLUMN_NAME, Statistics.INDEX_NAME) .from(STATISTICS) // [#5213] Duplicate schema value to work around MySQL issue https://bugs.mysql.com/bug.php?id=86022 .where(Statistics.TABLE_SCHEMA.in(getInputSchemata()).or( getInputSchemata().size() == 1 ? Statistics.TABLE_SCHEMA.in(getInputSchemata()) : falseCondition())) .and(primary ? Statistics.INDEX_NAME.eq(inline("PRIMARY")) : Statistics.INDEX_NAME.ne(inline("PRIMARY")).and(Statistics.NON_UNIQUE.eq(inline("0")))) .orderBy( Statistics.TABLE_SCHEMA, Statistics.TABLE_NAME, Statistics.INDEX_NAME, Statistics.SEQ_IN_INDEX) .fetch(); }
private final Table<Record> table(Configuration configuration) { if (table == null) { Select<Record> select = null; for (Object element : array) { // [#1081] Be sure to get the correct cast type also for null Field<?> val = DSL.val(element, field.fields[0].getDataType()); Select<Record> subselect = using(configuration).select(val.as("COLUMN_VALUE")).select(); if (select == null) { select = subselect; } else { select = select.unionAll(subselect); } } // Empty arrays should result in empty tables if (select == null) { select = using(configuration).select(one().as("COLUMN_VALUE")).select().where(falseCondition()); } table = select.asTable(alias); } return table; } }
@Override public List<? extends ProjectMember> getProjectMembersByIdentity(long projectId, Set<Identity> identities) { Condition allMembers = DSL.falseCondition(); for (Identity identity : identities) { allMembers = allMembers.or(PROJECT_MEMBER.EXTERNAL_ID.eq(identity.getExternalId()) .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(identity.getExternalIdType())) .and(PROJECT_MEMBER.REMOVED.isNull()) .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE)) .and(PROJECT_MEMBER.PROJECT_ID.eq(projectId))); } SelectQuery<Record> query = create().selectQuery(); query.addFrom(PROJECT_MEMBER); query.addConditions(allMembers); query.setDistinct(true); return query.fetchInto(PROJECT_MEMBER); }
private final Table<Record> table(Configuration configuration) { if (table == null) { Select<Record> select = null; for (Object element : array) { // [#1081] Be sure to get the correct cast type also for null Field<?> val = DSL.val(element, field.fields[0].getDataType()); Select<Record> subselect = using(configuration).select(val.as("COLUMN_VALUE")).select(); if (select == null) { select = subselect; } else { select = select.unionAll(subselect); } } // Empty arrays should result in empty tables if (select == null) { select = using(configuration).select(one().as("COLUMN_VALUE")).select().where(falseCondition()); } table = DSL.table(select).as(alias); } return table; } }