本文整理了Java中org.javalite.common.Util.blank()
方法的一些代码示例,展示了Util.blank()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.blank()
方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:blank
[英]Returns true if value is either null or it's String representation is blank.
[中]如果值为null或其字符串表示形式为空,则返回true。
代码示例来源:origin: javalite/activejdbc
/**
* @param source instance of String
* @return null if source is empty or contains only whitespaces, source otherwise
*/
@Override
public Object convert(String source) {
return blank(source) ? null : source;
}
}
代码示例来源:origin: javalite/activejdbc
/**
* @param source instance of String or null
* @return source converted to java.sql.Date, or null if source is blank
* @throws ParseException if conversion failed
*/
@Override
public java.sql.Date doConvert(String source) throws ParseException {
return blank(source) ? null : new java.sql.Date(threadLocalFormat.get().parse(source).getTime());
}
}
代码示例来源:origin: javalite/activejdbc
/**
* @param source instance of String or null
* @return source converted to java.sql.Timestamp, or null if source is blank
* @throws ParseException if conversion failed
*/
@Override
public java.sql.Timestamp doConvert(String source) throws ParseException {
return blank(source) ? null : new java.sql.Timestamp(threadLocalFormat.get().parse(source).getTime());
}
}
代码示例来源:origin: javalite/activejdbc
/**
* @return current environment as specified by environment variable <code>ACTIVE_ENV</code>
* of <code>active_env</code> system property. System property value overrides environment variable.
*
* Defaults to "development" if no environment variable provided.
*/
public String getEnvironment(){
String env = "development";
if(!blank(System.getenv("ACTIVE_ENV"))){
env = System.getenv("ACTIVE_ENV");
}
if(!blank(System.getProperty("active_env"))){
env = System.getProperty("active_env");
}
return env;
}
代码示例来源:origin: javalite/activejdbc
protected void appendSubQuery(StringBuilder queryBuilder, String subQuery) {
if (!blank(subQuery)) {
// this is only to support findFirst("order by..."), might need to revisit later
if (!GROUP_BY_PATTERN.matcher(subQuery).find() && !ORDER_BY_PATTERN.matcher(subQuery).find()) {
queryBuilder.append(" WHERE");
}
queryBuilder.append(' ').append(subQuery);
}
}
代码示例来源:origin: javalite/activejdbc
/**
* Returns name of environment, such as "development", "production", etc.
* This is a value that is usually setup with an environment variable <code>ACTIVE_ENV</code>.
*
* @return name of environment
*/
public static String getEnv(){
if(ENV == null){
if(!blank(System.getenv("ACTIVE_ENV"))) {
ENV = System.getenv("ACTIVE_ENV");
}
if(!blank(System.getProperty("ACTIVE_ENV"))) {
ENV = System.getProperty("ACTIVE_ENV");
}
if(!blank(System.getProperty("active_env"))) {
ENV = System.getProperty("active_env");
}
if(blank(ENV)){
ENV = "development";
LogFilter.log(LOGGER, LogLevel.INFO, "Environment variable ACTIVE_ENV not provided, defaulting to '" + ENV + "'");
}
}
return ENV;
}
代码示例来源:origin: javalite/activejdbc
/**
* Overrides current environment's connection spec from system properties.
*/
private void overrideFromEnvironmentVariables() {
String url = System.getenv("ACTIVEJDBC.URL");
String user = System.getenv("ACTIVEJDBC.USER");
String password = System.getenv("ACTIVEJDBC.PASSWORD");
String driver = System.getenv("ACTIVEJDBC.DRIVER");
if(!blank(url) && !blank(user) && !blank(password) && !blank(driver)){
connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password));
}
String jndi = System.getenv("ACTIVEJDBC.JNDI");
if(!blank(jndi)){
connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi));
}
}
代码示例来源:origin: javalite/activejdbc
/**
* Overrides current environment's connection spec from system properties.
*/
private void overrideFromSystemProperties() {
String url = System.getProperty("activejdbc.url");
String user = System.getProperty("activejdbc.user");
String password = System.getProperty("activejdbc.password");
String driver = System.getProperty("activejdbc.driver");
if(!blank(url) && !blank(user) && !blank(driver)){
connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password));
}
String jndi = System.getProperty("activejdbc.jndi");
if(!blank(jndi)){
connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi));
}
}
代码示例来源:origin: javalite/activejdbc
/**
* TDS converts a number of important data types to String. This isn't what we want, nor helpful. Here, we change them back.
*/
@Override
public Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value) {
if (value instanceof String && !Util.blank(value)) {
String typeName = mm.getColumnMetadata().get(attributeName).getTypeName();
if ("date".equalsIgnoreCase(typeName)) {
return java.sql.Date.valueOf((String) value);
} else if ("datetime2".equalsIgnoreCase(typeName)) {
return java.sql.Timestamp.valueOf((String) value);
}
}
return value;
}
代码示例来源:origin: javalite/activejdbc
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);
}
}
代码示例来源:origin: javalite/activejdbc
@Override
public void convert(Model m) {
Object val = m.get(attributeName);
if (!(val instanceof java.util.Date) && !blank(val)) {
try {
long time = df.parse(val.toString()).getTime();
java.sql.Date d = new java.sql.Date(time);
m.set(attributeName, d);
} catch (ParseException e) {
m.addValidator(this, attributeName);
}
}
}
代码示例来源:origin: javalite/activejdbc
@Override
public void convert(Model m) {
Object val = m.get(attributeName);
if (!(val instanceof Timestamp) && !blank(val)) {
try {
long time = df.parse(val.toString()).getTime();
Timestamp t = new Timestamp(time);
m.set(attributeName, t);
} catch(ParseException e) {
m.addValidator(this, attributeName);
}
}
}
代码示例来源:origin: javalite/activejdbc
@Override
public void validate(Model m) {
if (blank(m.get(attribute))) {
//TODO: use resource bundles for messages
m.addValidator(this, attribute);
}
}
代码示例来源:origin: javalite/activejdbc
for (String line : lines) {
line = line.trim();
if (!commentLine(line) && !blank(line)) {
if (line.startsWith(DELIMITER_KEYWORD)) {
delimiter = line.substring(10).trim();
} else if (line.endsWith(delimiter)) {
currentStatement += line.substring(0, line.length() - delimiter.length()) ;
if(!blank(currentStatement)){
statements.add(currentStatement);
if(!blank(currentStatement)){
statements.add(currentStatement);
代码示例来源:origin: javalite/activejdbc
break;
case XMLStreamConstants.END_ELEMENT:
if (attr != null && !blank(chars)) {
res.put(attr, chars);
代码示例来源:origin: javalite/activejdbc
private static String exec(String command) {
Runtime runtime = Runtime.getRuntime();
try {
Process p = runtime.exec(command);
String output = read(p.getInputStream());
String error = read(p.getErrorStream());
if (!blank(error)) {
throw new ExecException(error);
}
return output;
} catch (ExecException e) {
throw e;
} catch (Exception e) {
throw new ExecException(e);
}
}
}
代码示例来源:origin: javalite/activejdbc
@Override
public Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value) {
// SQLite returns DATE and DATETIME as String or Number values
if (value instanceof String && !Util.blank(value) || value instanceof Number) {
String typeName = mm.getColumnMetadata().get(attributeName).getTypeName();
if ("DATE".equalsIgnoreCase(typeName)) {
return Convert.toSqlDate(value);
} else if ("DATETIME".equalsIgnoreCase(typeName)) {
return Convert.toTimestamp(value);
} else if ("TIME".equalsIgnoreCase(typeName)) {
return Convert.toTime(value);
}
}
return value;
}
代码示例来源:origin: javalite/activejdbc
private static int update(MetaModel metaModel, String updates, String conditions, Object... params) {
StringBuilder sql = new StringBuilder().append("UPDATE ").append(metaModel.getTableName()).append(" SET ");
Object[] allParams;
if (metaModel.hasAttribute("updated_at")) {
sql.append("updated_at = ?, ");
allParams = new Object[params.length + 1];
allParams[0] = new Timestamp(System.currentTimeMillis());
System.arraycopy(params, 0, allParams, 1, params.length);
} else {
allParams = params;
}
sql.append(updates);
if (!blank(conditions)) {
sql.append(" WHERE ").append(conditions);
}
int count = new DB(metaModel.getDbName()).exec(sql.toString(), allParams);
if (metaModel.cached()) {
Registry.cacheManager().purgeTableCache(metaModel);
}
return count;
}
代码示例来源:origin: com.github.tchoulihan/activejdbc
/**
* @param source instance of String or null
* @return source converted to java.sql.Date, or null if source is blank
* @throws ParseException if conversion failed
*/
@Override
public java.sql.Date doConvert(String source) throws ParseException {
return blank(source) ? null : new java.sql.Date(threadLocalFormat.get().parse(source).getTime());
}
}
代码示例来源:origin: org.javalite/activejdbc
protected void appendSubQuery(StringBuilder queryBuilder, String subQuery) {
if (!blank(subQuery)) {
// this is only to support findFirst("order by..."), might need to revisit later
if (!GROUP_BY_PATTERN.matcher(subQuery).find() && !ORDER_BY_PATTERN.matcher(subQuery).find()) {
queryBuilder.append(" WHERE");
}
queryBuilder.append(' ').append(subQuery);
}
}
内容来源于网络,如有侵权,请联系作者删除!