List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:net.paoding.rose.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime, Class<?> returnType) { Number result; DataAccess dataAccess = dataAccessProvider.getDataAccess(// runtime.getMetaData(), runtime.getProperties()); if (returnGeneratedKeys) { ArrayList<Number> keys = new ArrayList<Number>(1); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else {/* ww w.j a v a 2 s .c o m*/ result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (Number.class.isAssignableFrom(returnType)) { return result; } else { throw new DataRetrievalFailureException("The generated key is not of a supported numeric type. " + "Unable to cast [" + result.getClass().getName() + "] to [" + Number.class.getName() + "]"); } }
From source file:com.eryansky.core.db.DbUtilsDao.java
public long count(String sql, Object... params) throws DaoException { Number num = 0; try {/*from w ww .j a v a 2 s. c om*/ queryRunner = new QueryRunner(dataSource); if (params == null || params.length == 0) { num = (Number) queryRunner.query(sql, scalarHandler); } else { num = (Number) queryRunner.query(sql, scalarHandler, params); } } catch (SQLException e) { // e.printStackTrace(); logger.error(",SQL:" + sql, e); throw new DaoException(e); } return (num != null) ? num.longValue() : -1; }
From source file:com.sinosoft.one.data.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime, Class<?> returnType) { // DAOIdentity?1/20 if (returnType == Identity.class) { if (new Random().nextInt(20) == 1) { new IllegalArgumentException( "message by zhiliang.wang: change the deprecated Identity to @ReturnGeneratedKeys please: " + runtime.getMetaData()).printStackTrace(); }//from w w w . j a v a 2 s. c om } Number result; DataAccess dataAccess = new DataAccessImpl(em); if (returnGeneratedKeys) { //ArrayList<Number> keys = new ArrayList<Number>(1); List<Map<String, Object>> keys = new ArrayList<Map<String, Object>>(); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else { result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (returnType == Identity.class) { return new Identity((Number) result); } else if (Number.class.isAssignableFrom(returnType)) { return result; } else { throw new DataRetrievalFailureException("The generated key is not of a supported numeric type. " + "Unable to cast [" + result.getClass().getName() + "] to [" + Number.class.getName() + "]"); } }
From source file:com.gzj.tulip.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime) { Number result; DataAccess dataAccess = dataAccessFactory.getDataAccess(// runtime.getMetaData(), runtime.getAttributes()); if (returnGeneratedKeys.shouldReturnGerneratedKeys(runtime)) { ArrayList<Map<String, Object>> keys = new ArrayList<Map<String, Object>>(1); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else {// w ww . j ava2 s .c om result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (returnType == Number.class) { return result; } else if (returnType == String.class || returnType == CharSequence.class) { return String.valueOf(result); } else { throw new DataRetrievalFailureException( "The generated key is not of a supported numeric type: " + returnType.getName()); } }
From source file:com.btisystems.pronx.ems.AbstractMibCompiler.java
/** * Generate get accessor./*from w w w. j a v a 2 s . c o m*/ * * @param child the child * @param definedClass the defined class * @param type the type * @param field the field */ protected final void generateGetAccessor(final MibValueSymbol child, final JDefinedClass definedClass, final JType type, final String field) { final JMethod getMethod = definedClass.method(JMod.PUBLIC, type, getGetterName(field)); if (child != null) { final MibValue defaultValue = getFieldDefaultValue(child); if (defaultValue != null) { JExpression defaultReturnExpression = null; if (type == codeModel.INT || type == codeModel.LONG) { final Number javaNumber = (Number) defaultValue.toObject(); if (type == codeModel.INT) { defaultReturnExpression = JExpr.lit(javaNumber.intValue()); } else if (type == codeModel.LONG) { defaultReturnExpression = JExpr.lit(javaNumber.longValue()); } } else if (type == codeModel.ref(String.class) && defaultValue instanceof StringValue) { defaultReturnExpression = JExpr.lit(defaultValue.toString()); } if (defaultReturnExpression != null) { getMethod.body()._if(JExpr.refthis(field).eq(JExpr._null()))._then() ._return(defaultReturnExpression); generateIsDefinedAccessor(definedClass, field); } } else { generateDummyIsDefinedIfNecessary(definedClass, field); } } getMethod.body()._return(JExpr.refthis(field)); }
From source file:com.xtructure.xevolution.genetics.impl.AbstractPopulation.java
/** * Adds the attribute in the given {@link Genome} with the given * {@link XValId} to the corresponding value in the accumulation map. * // w w w . ja va 2 s .c om * @param <V> * the type of the attribute * @param valueId * the id of the attribute * @param accMap * the accumulation map * @param genome * the {@link Genome} from which to get the attribute */ private <V extends Comparable<V>> void updateAccMap(XValId<V> valueId, ValueMap accMap, Genome<D> genome) { getLogger().trace("begin %s.updateAccMap(%s, %s, %s)", getClass().getSimpleName(), valueId, accMap, genome); if (Number.class.isAssignableFrom(valueId.getType())) { if (accMap.get(valueId) == null) { accMap.set(// valueId, // genome.getAttribute(valueId)); } else { Number acc = (Number) accMap.get(valueId); Number nxt = (Number) genome.getAttribute(valueId); Number sum = null; ValueType type = ValueType.getValueType(valueId.getType()); if (type != null) { switch (type) { case DOUBLE: sum = acc.doubleValue() + nxt.doubleValue(); break; case FLOAT: sum = acc.floatValue() + nxt.floatValue(); break; case LONG: sum = acc.longValue() + nxt.longValue(); break; case INTEGER: sum = acc.intValue() + nxt.intValue(); break; case SHORT: sum = acc.shortValue() + nxt.shortValue(); break; case BYTE: sum = acc.byteValue() + nxt.byteValue(); break; default: break; } @SuppressWarnings("unchecked") V v = (V) sum; accMap.set(valueId, v); } } } getLogger().trace("end %s.updateAccMap()", getClass().getSimpleName()); }
From source file:org.op4j.functions.FnLong.java
private static Long fromNumber(final Number number) { if (number == null) { return null; }/*from w ww . java 2 s.c o m*/ return Long.valueOf(number.longValue()); }
From source file:org.freedesktop.dbus.Message.java
/** * If this is a reply to a message, this returns its serial. * /*from w w w . ja va2s . c o m*/ * @return The reply serial, or 0 if it is not a reply. */ public long getReplySerial() { Number l = (Number) this.headers.get(HeaderField.REPLY_SERIAL); if (null == l) return 0; return l.longValue(); }
From source file:cc.tooyoung.common.db.JdbcTemplate.java
public long queryForLong(String sql) throws DataAccessException { Number number = (Number) queryForObject(sql, Long.class); return (number != null ? number.longValue() : 0); }
From source file:cc.tooyoung.common.db.JdbcTemplate.java
public long queryForLong(String sql, Object[] args) throws DataAccessException { Number number = (Number) queryForObject(sql, args, Long.class); return (number != null ? number.longValue() : 0); }