public boolean collectStatistics() { return Convert.toBoolean(properties.getProperty(PropertyName.CollectStatistics.name, "false")); }
/** * Read property as <code>Double</code>. * * @param propertyName name of property. * @return property as <code>Double</code>. */ public static Double pDouble(String propertyName){ return Convert.toDouble(p(propertyName)); }
/** * Read property as <code>Float</code>. * * @param propertyName name of property. * @return property as <code>Float</code>. */ public static Float pFloat(String propertyName){ return Convert.toFloat(p(propertyName)); }
/** * Converts value to bytes array if it can. If the value is byte array, it is simply returned, * if it is a <code>java.sql.Blob</code>, then data is read from it as bytes. * In all other cases the object is converted to <code>String</code>, then bytes are read from it. * * @param value value to be converted. * @return value converted to byte array. */ public static byte[] toBytes(Object value) { if (value == null) { return null; } else if (value instanceof byte[]) { return (byte[]) value; } else if (value instanceof Blob) { return toBytes((Blob) value); } else { return toString(value).getBytes(); } }
sb.append(attribute); } else if (attribute instanceof Date) { sb.append('"').append(Convert.toIsoString((Date) attribute)).append('"'); } else { sb.append('"'); sb.append(JsonHelper.sanitize(Convert.toString(attribute))); sb.append('"');
@Override public String format(Object value) { if(value.getClass() != clazz) throw new IllegalArgumentException("This formatted was configured for: " + clazz + ", but you are feeding it: " + value.getClass()); return prefix + Convert.toString(value) + suffix; }
/** * Read property as <code>Integer</code>. * * @param propertyName name of property. * @return property as <code>Integer</code>. */ public static Integer pInteger(String propertyName){ return Convert.toInteger(p(propertyName)); }
/** * Returns count of rows in table. * * @param table name of table. * @return count of rows in table. */ public Long count(String table){ String sql = "SELECT COUNT(*) FROM " + table ; return Convert.toLong(firstCell(sql)); }
/** * Gets a value as bytes. If the column is Blob, bytes are * read directly, if not, then the value is converted to String first, then * string bytes are returned. Be careful out there, this will read entire * Blob onto memory. * * @param attributeName name of attribute * @return value as bytes. */ //TODO: use converters here? public byte[] getBytes(String attributeName) { Object value = get(attributeName); return Convert.toBytes(value); }
/** * Returns string representation of an object, including {@link java.sql.Clob}. * For large CLOBs, be careful because this will load an entire CLOB in memory as <code>java.lang.String</code>. * * @param value value to convert. * @return string representation of an object, including {@link java.sql.Clob}. */ public static String toString(Object value) { if (value == null) { return null; } else if (value instanceof Clob) { return clobToString((Clob) value); } else { return value.toString(); } }
private static String clobToString(Clob clob) { Reader r = null; StringWriter sw = null; try { r = clob.getCharacterStream(); sw = new StringWriter(); copyStream(r, sw); return sw.toString(); } catch (Exception e) { throw new ConversionException(e); } finally { closeQuietly(sw); closeQuietly(r); } }
protected String replace(Object valueObject, String... replacements) { String value = Convert.toString(valueObject); if (replacements.length % 2 != 0) { throw new IllegalArgumentException("Number of elements in 'replacements' array is not even"); } if (replacements.length > 0) { String v = ""; for (int i = 0; i < (replacements.length - 1); i += 2) { v = value.replaceAll(replacements[i], replacements[(i + 1)]); } return v; } else { return value; } }
public RedisCacheManager() { try { String host = p("redis.cache.manager.host"); String port = p("redis.cache.manager.port"); jedisPool = blank(host) || blank(port) ? new JedisPool() : new JedisPool(host,toInteger(port)); } catch (Exception e) { throw new InitException("Failed to configure connection to Redis server", e); } }
/** * Convenience method: converts ID value to Long and returns it. * * @return value of attribute corresponding to <code>getIdName()</code>, converted to Long. */ public Long getLongId() { return getId() == null ? null: Convert.toLong(getId()); }
/** * Converts value to bytes array if it can. If the value is byte array, it is simply returned, * if it is a <code>java.sql.Blob</code>, then data is read from it as bytes. * In all other cases the object is converted to <code>String</code>, then bytes are read from it. * * @param value value to be converted. * @return value converted to byte array. */ public static byte[] toBytes(Object value) { if (value == null) { return null; } else if (value instanceof byte[]) { return (byte[]) value; } else if (value instanceof Blob) { return toBytes((Blob) value); } else { return toString(value).getBytes(); } }
/** * Gets a value as bytes. If the column is Blob, bytes are * read directly, if not, then the value is converted to String first, then * string bytes are returned. Be careful out there, this will read entire * Blob onto memory. * * @param attributeName name of attribute * @return value as bytes. */ //TODO: use converters here? public byte[] getBytes(String attributeName) { Object value = get(attributeName); return Convert.toBytes(value); }
/** * Returns string representation of an object, including {@link java.sql.Clob}. * For large CLOBs, be careful because this will load an entire CLOB in memory as <code>java.lang.String</code>. * * @param value value to convert. * @return string representation of an object, including {@link java.sql.Clob}. */ public static String toString(Object value) { if (value == null) { return null; } else if (value instanceof Clob) { return clobToString((Clob) value); } else { return value.toString(); } }
private static String clobToString(Clob clob) { Reader r = null; StringWriter sw = null; try { r = clob.getCharacterStream(); sw = new StringWriter(); copyStream(r, sw); return sw.toString(); } catch (Exception e) { throw new ConversionException(e); } finally { closeQuietly(sw); closeQuietly(r); } }
public boolean collectStatisticsOnHold() { return Convert.toBoolean(properties.getProperty(PropertyName.CollectStatisticsOnHold.name, "false")); }
/** * Sets attribute value as <code>Double</code>. * If there is a {@link Converter} registered for the attribute that converts from Class <code>S</code> to Class * <code>java.lang.Double</code>, given the value is an instance of <code>S</code>, then it will be used, * otherwise performs a conversion using {@link Convert#toDouble(Object)}. * * @param attributeName name of attribute. * @param value value to convert. * @return reference to this model. */ public <T extends Model> T setDouble(String attributeName, Object value) { Converter<Object, Double> converter = modelRegistryLocal.converterForValue(attributeName, value, Double.class); return setRaw(attributeName, converter != null ? converter.convert(value) : Convert.toDouble(value)); }