/** * Joins the items in array with a delimiter, and appends the result to StringBuilder. * * @param sb StringBuilder to append result to * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. */ public static void join(StringBuilder sb, Object[] array, String delimiter) { if (empty(array)) { return; } sb.append(array[0]); for (int i = 1; i < array.length; i++) { sb.append(delimiter); sb.append(array[i]); } }
/** * Joins the items in array with a delimiter. * * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. * @return string with array elements separated by delimiter. There is no trailing delimiter in the string. */ public static String join(String[] array, String delimiter) { if (empty(array)) { return ""; } StringBuilder sb = new StringBuilder(); join(sb, array, delimiter); return sb.toString(); }
/** * Looks for a localized property/message in <code>activejdbc_messages</code> bundle. * * @param key key of the property. * @param locale locale of a bundle, or null for default locale * @param params list of parameters for a message. The order of parameters in this list will correspond to the * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on. * @return localized message merged with parameters (if provided), or key if message not found. */ public static String message(String key, Locale locale, Object... params) { String pattern; try { pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key); } catch (MissingResourceException e) { pattern = key; } return empty(params) ? pattern : new MessageFormat(pattern).format(params); }
public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) { if (subquery.trim().equals("*")) { if (empty(params)) { return findAll(clazz); } else { throw new IllegalArgumentException( "cannot provide parameters with query: '*', use findAll() method instead"); } } return new LazyList<>(subquery, metaModelOf(clazz), params); }
if (pretty) { sb.append('\n'); } String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased(); for (String name : names) { if (pretty) { sb.append(" ").append(indent); }
/** * Runs a count query, returns a number of matching records. * * @param table table in which to count rows. * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example: * <code>"age > 65 AND department = 'accounting'"</code> * @param params parameters for placeholder substitution. * @return count number of records found in a table. */ public Long count(String table, String query, Object... params) { if (query.trim().equals("*")) { if (empty(params)) { return count(table); } else { throw new IllegalArgumentException("cannot use '*' and parameters"); } } String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query; return Convert.toLong(firstCell(sql, params)); }
sb.append('{'); String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased(); for (int i = 0; i < names.length; i++) { if (i > 0) { sb.append(','); }
/** * Joins the items in array with a delimiter, and appends the result to StringBuilder. * * @param sb StringBuilder to append result to * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. */ public static void join(StringBuilder sb, Object[] array, String delimiter) { if (empty(array)) { return; } sb.append(array[0]); for (int i = 1; i < array.length; i++) { sb.append(delimiter); sb.append(array[i]); } }
/** * Joins the items in array with a delimiter, and appends the result to StringBuilder. * * @param sb StringBuilder to append result to * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. */ public static void join(StringBuilder sb, Object[] array, String delimiter) { if (empty(array)) { return; } sb.append(array[0]); for (int i = 1; i < array.length; i++) { sb.append(delimiter); sb.append(array[i]); } }
/** * Looks for a localized property/message in <code>activejdbc_messages</code> bundle. * * @param key key of the property. * @param locale locale of a bundle, or null for default locale * @param params list of parameters for a message. The order of parameters in this list will correspond to the * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on. * @return localized message merged with parameters (if provided), or key if message not found. */ public static String message(String key, Locale locale, Object... params) { String pattern; try { pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key); } catch (MissingResourceException e) { pattern = key; } return empty(params) ? pattern : new MessageFormat(pattern).format(params); }
/** * Looks for a localized property/message in <code>activejdbc_messages</code> bundle. * * @param key key of the property. * @param locale locale of a bundle, or null for default locale * @param params list of parameters for a message. The order of parameters in this list will correspond to the * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on. * @return localized message merged with parameters (if provided), or key if message not found. */ public static String message(String key, Locale locale, Object... params) { String pattern; try { pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key); } catch (MissingResourceException e) { pattern = key; } return empty(params) ? pattern : new MessageFormat(pattern).format(params); }
/** * Joins the items in array with a delimiter. * * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. * @return string with array elements separated by delimiter. There is no trailing delimiter in the string. */ public static String join(String[] array, String delimiter) { if (empty(array)) { return ""; } StringBuilder sb = new StringBuilder(); join(sb, array, delimiter); return sb.toString(); }
static void logAccess(String query, Object[] params, String access) { if (logger.isInfoEnabled()) { StringBuilder log = new StringBuilder().append(access).append(", ").append('"').append(query).append('"'); if (!empty(params)) { log.append(", with parameters: ").append('<'); join(log, params, ">, <"); log.append('>'); } LogFilter.log(logger, log.toString()); } }
/** * Joins the items in array with a delimiter. * * @param array array of items to join. * @param delimiter delimiter to insert between elements of array. * @return string with array elements separated by delimiter. There is no trailing delimiter in the string. */ public static String join(String[] array, String delimiter) { if (empty(array)) { return ""; } StringBuilder sb = new StringBuilder(); join(sb, array, delimiter); return sb.toString(); }
public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) { if (subquery.trim().equals("*")) { if (empty(params)) { return findAll(clazz); } else { throw new IllegalArgumentException( "cannot provide parameters with query: '*', use findAll() method instead"); } } return new LazyList<>(subquery, metaModelOf(clazz), params); }
public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) { if (subquery.trim().equals("*")) { if (empty(params)) { return findAll(clazz); } else { throw new IllegalArgumentException( "cannot provide parameters with query: '*', use findAll() method instead"); } } return new LazyList<T>(subquery, metaModelOf(clazz), params); }
/** * Runs a count query, returns a number of matching records. * * @param table table in which to count rows. * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example: * <code>"age > 65 AND department = 'accounting'"</code> * @param params parameters for placeholder substitution. * @return count number of records found in a table. */ public Long count(String table, String query, Object... params) { if (query.trim().equals("*")) { if (empty(params)) { return count(table); } else { throw new IllegalArgumentException("cannot use '*' and parameters"); } } String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query; return Convert.toLong(firstCell(sql, params)); }
/** * Runs a count query, returns a number of matching records. * * @param table table in which to count rows. * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example: * <code>"age > 65 AND department = 'accounting'"</code> * @param params parameters for placeholder substitution. * @return count number of records found in a table. */ public Long count(String table, String query, Object... params) { if (query.trim().equals("*")) { if (empty(params)) { return count(table); } else { throw new IllegalArgumentException("cannot use '*' and parameters"); } } String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query; return Convert.toLong(firstCell(sql, params)); }
if (pretty) { sb.append('\n'); } String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased(); for (String name : names) { if (pretty) { sb.append(" ").append(indent); }
static void logQuery(Logger logger, String query, Object[] params, long queryStartTime){ long time = System.currentTimeMillis() - queryStartTime; if (Registry.instance().getConfiguration().collectStatistics()) { Registry.instance().getStatisticsQueue().enqueue(new QueryExecutionEvent(query, time)); } if (logger.isInfoEnabled()) { StringBuilder log = new StringBuilder().append("Query: \"").append(query).append('"'); if (!empty(params)) { log.append(", with parameters: ").append('<'); join(log, params, ">, <"); log.append('>'); } log(logger, log.append(", took: ").append(time).append(" milliseconds").toString()); } }