public Pair<GroupBy<?, ?, ?>, List<Object>> getGroupBy() { return _groupBy == null ? null : new Pair<>(_groupBy, _groupByValues); }
private void log(final String msg, final Object... params) { final Pair<String, Object[]> entry = new Pair<>(msg, params); assert msg != null : "Message can not be null or else it's useless!"; _entries.add(entry); }
public CloudRuntimeException add(final Class<?> entity, final String uuid) { uuidList.add(new Pair<>(entity, uuid)); return this; }
public Pair<String, ArrayList<Object>> toSql() { final StringBuilder sql = new StringBuilder(); return new Pair<>(sql.toString(), null); }
void registerLock(final String sql) { if (_txn && logger.isDebugEnabled()) { final Pair<String, Long> time = new Pair<>(sql, System.currentTimeMillis()); _lockTimes.add(time); } }
public Map<Pair<String, String>, Attribute> getAllColumns() { final Map<Pair<String, String>, Attribute> attrs = new LinkedHashMap<>(_attributes.size()); for (final Attribute attr : _attributes) { if (attr.columnName != null) { attrs.put(new Pair<>(attr.table, attr.columnName), attr); } } return attrs; }
public static Pair<String, Integer> getCidr(final String cidr) { final String[] tokens = cidr.split("/"); return new Pair<>(tokens[0], Integer.parseInt(tokens[1])); }
public Pair<String, Attribute> getRemovedAttribute() { final Attribute removed = findAttribute(GenericDao.REMOVED_COLUMN); if (removed == null) { return null; } if (removed.field.getType() != Date.class) { return null; } final StringBuilder sql = new StringBuilder(); sql.append(removed.table).append(".").append(removed.columnName).append(" IS NULL "); return new Pair<>(sql.toString(), removed); }
private void getParams(final ArrayList<Pair<Attribute, Object>> params, final Condition condition, final Object[] objs) { if (condition.op == Op.SC) { assert (objs != null && objs.length > 0) : " Where's your search criteria object? " + condition.name; params.addAll(((SearchCriteria<?>) objs[0]).getValues()); return; } if (objs != null && objs.length > 0) { for (final Object obj : objs) { if ((condition.op != Op.EQ && condition.op != Op.NEQ) || (obj != null)) { params.add(new Pair<>(condition.attr, obj)); } } } }
public Pair<StringBuilder, Attribute[]> buildSelectSql(final Attribute[] attrs) { final StringBuilder sql = new StringBuilder("SELECT "); for (final Attribute attr : attrs) { sql.append(attr.table).append(".").append(attr.columnName).append(", "); } if (attrs.length > 0) { sql.delete(sql.length() - 2, sql.length()); } sql.append(" FROM ").append(buildTableReferences()); sql.append(" WHERE "); sql.append(buildDiscriminatorClause().first()); return new Pair<>(sql, attrs); }
public GroupBy<J, T, R> group(final Func func, final Object useless) { _groupBys.add(new Pair<>(func, _builder.getSpecifiedAttributes().get(0))); _builder.getSpecifiedAttributes().clear(); return this; }
protected void init(final J builder) { _builder = builder; _groupBys = new ArrayList<>(); _having = null; for (final Attribute attr : _builder.getSpecifiedAttributes()) { _groupBys.add(new Pair<>(null, attr)); } _builder.getSpecifiedAttributes().clear(); }
public GroupBy<J, T, R> group(final Object useless) { _groupBys.add(new Pair<>(null, _builder.getSpecifiedAttributes().get(0))); _builder.getSpecifiedAttributes().clear(); return this; }
@DB() protected void setField(final Object entity, final ResultSet rs, final ResultSetMetaData meta, final int index) throws SQLException { Attribute attr = _allColumns.get(new Pair<>(meta.getTableName(index), meta.getColumnName(index))); if (attr == null) { // work around for mysql bug to return original table name instead of view name in db view case final Table tbl = entity.getClass().getSuperclass().getAnnotation(Table.class); if (tbl != null) { attr = _allColumns.get(new Pair<>(tbl.name(), meta.getColumnLabel(index))); } } assert (attr != null) : "How come I can't find " + meta.getCatalogName(index) + "." + meta.getColumnName(index); setField(entity, attr.field, rs, index); }
public Pair<StringBuilder, Attribute[]> buildSelectSql(final boolean enableQueryCache) { final StringBuilder sql = new StringBuilder("SELECT "); sql.append(enableQueryCache ? "SQL_CACHE " : ""); final ArrayList<Attribute> attrs = new ArrayList<>(); for (final Attribute attr : _attributes) { if (attr.isSelectable()) { attrs.add(attr); sql.append(attr.table).append(".").append(attr.columnName).append(", "); } } if (attrs.size() > 0) { sql.delete(sql.length() - 2, sql.length()); } sql.append(" FROM ").append(buildTableReferences()); sql.append(" WHERE "); sql.append(buildDiscriminatorClause().first()); return new Pair<>(sql, attrs.toArray(new Attribute[attrs.size()])); }
public static Pair<Class<?>, Field> getAnyField(final Class<?> clazz, final String fieldName) { try { return new Pair<>(clazz, clazz.getDeclaredField(fieldName)); } catch (final SecurityException e) { throw new CloudRuntimeException("How the heck?", e); } catch (final NoSuchFieldException e) { // Do I really want this? No I don't but what can I do? It only throws the NoSuchFieldException. final Class<?> parent = clazz.getSuperclass(); if (parent != null) { return getAnyField(parent, fieldName); } return null; } }
@Override @DB() public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter) { final List<T> objects = search(sc, filter, null, false); final Integer count = getCount(sc); return new Pair<>(objects, count); }
@Override @DB() public Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T> sc, final Filter filter) { final List<T> objects = search(sc, filter, null, false); final Integer count = getDistinctCount(sc); return new Pair<>(objects, count); }
@DB() protected Pair<List<T>, Integer> listAndCountIncludingRemovedBy(final SearchCriteria<T> sc, final Filter filter) { final List<T> objects = searchIncludingRemoved(sc, filter, null, false); final Integer count = getCount(sc); return new Pair<>(objects, count); }
@Test public void testEquals() { Assert.assertEquals(new Ternary<>("a", "b", "c"), new Ternary<>("a", "b", "c")); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(new Ternary<>("a", "b", "d"))); Assert.assertFalse(new Ternary<>("a", "b", "c").equals("")); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(null)); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(new Pair<>("a", "b"))); } }