Example usage for java.lang Number longValue

List of usage examples for java.lang Number longValue

Introduction

In this page you can find the example usage for java.lang Number longValue.

Prototype

public abstract long longValue();

Source Link

Document

Returns the value of the specified number as a long .

Usage

From source file:javadz.beanutils.locale.converters.ShortLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type. This method will return values of type Short.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value/* w  w w.j  av  a  2 s.  c  o  m*/
 *
 * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 * @since 1.8.0
 */
protected Object parse(Object value, String pattern) throws ParseException {

    Object result = super.parse(value, pattern);

    if (result == null || result instanceof Short) {
        return result;
    }

    Number parsed = (Number) result;
    if (parsed.longValue() != parsed.shortValue()) {
        throw new ConversionException("Supplied number is not of type Short: " + parsed.longValue());
    }

    // now returns property Short
    return new Short(parsed.shortValue());
}

From source file:com.jagornet.dhcp.db.JdbcIdentityAssocDAO.java

public void create(final IdentityAssoc ia) {
    /**//from  w  w w. j a  v  a 2s  . c o m
     * Note: see https://issues.apache.org/jira/browse/DERBY-3609
     * "Formally, Derby does not support getGeneratedKeys since 
     * DatabaseMetaData.supportsGetGeneratedKeys() returns false. 
     * However, Statement.getGeneratedKeys() is partially implemented,
     * ... since it will only return a meaningful result when an single 
     * row insert is done with INSERT...VALUES"
     * 
     * Spring has thus provided a workaround as described here:
     * http://jira.springframework.org/browse/SPR-5306
     */
    GeneratedKeyHolder newKey = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(
                    "insert into identityassoc" + " (duid, iatype, iaid, state)" + " values (?, ?, ?, ?)",
                    PreparedStatement.RETURN_GENERATED_KEYS);
            ps.setBytes(1, ia.getDuid());
            ps.setByte(2, ia.getIatype());
            ps.setLong(3, ia.getIaid());
            ps.setByte(4, ia.getState());
            return ps;
        }
    }, newKey);
    Number newId = newKey.getKey();
    if (newId != null) {
        ia.setId(newId.longValue());
    }
}

From source file:net.solarnetwork.node.dao.jdbc.consumption.JdbcConsumptionDatumDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public List<ConsumptionDatum> getDatumNotUploaded(String destination) {
    return findDatumNotUploaded(new RowMapper<ConsumptionDatum>() {

        @Override/*from ww w. ja  v a2s  .com*/
        public ConsumptionDatum mapRow(ResultSet rs, int rowNum) throws SQLException {
            if (log.isTraceEnabled()) {
                log.trace("Handling result row " + rowNum);
            }
            ConsumptionDatum datum = new ConsumptionDatum();
            int col = 1;
            datum.setCreated(rs.getTimestamp(col++));
            datum.setSourceId(rs.getString(col++));

            Number val = (Number) rs.getObject(col++);
            datum.setLocationId(val == null ? null : val.longValue());

            val = (Number) rs.getObject(col++);
            datum.setWatts(val == null ? null : val.intValue());

            val = (Number) rs.getObject(col++);
            datum.setWattHourReading(val == null ? null : val.longValue());

            return datum;
        }
    });
}

From source file:com.cedarsoft.serialization.jackson.NumberSerializer.java

@Override
public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull Number object,
        @Nonnull Version formatVersion) throws IOException, VersionException, JsonProcessingException {
    if (isIntegerNumber(object)) {
        serializeTo.writeNumber(object.longValue());
    } else {/*from   ww  w .ja  va2  s . c  o  m*/
        serializeTo.writeNumber(object.doubleValue());
    }
}

From source file:ispok.dao.VisitorHibernateJpaDao.java

@Override
public <ENTITY> Long getCount(Map<String, Object> filters, Class<ENTITY> clazz) {

    logger.entry();// w ww.j  a  v  a  2 s .  com

    Session session = getEntityManager().unwrap(Session.class);
    Criteria criteria = session.createCriteria(clazz);
    criteria.setProjection(Projections.property("id"));

    for (Map.Entry<String, Object> filter : filters.entrySet()) {
        logger.debug("Filter: {}={}", filter.getKey(), filter.getValue());

        if ("id".equals(filter.getKey())) {
            criteria.add(Restrictions.eq("id", Long.parseLong(filter.getValue().toString())));
        } else {
            criteria.add(Restrictions.ilike(filter.getKey(), (String) filter.getValue(), MatchMode.START));
        }
    }

    criteria.setProjection(Projections.rowCount());
    Number number = (Number) criteria.uniqueResult();
    logger.debug("getCount(..): {}" + number);
    logger.exit();
    return number.longValue();
}

From source file:javadz.beanutils.locale.converters.IntegerLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type. This method will return Integer type.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value/*w ww . j av  a2 s.c  om*/
 *
 * @exception ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
protected Object parse(Object value, String pattern) throws ParseException {
    final Number parsed = (Number) super.parse(value, pattern);
    if (parsed.longValue() != parsed.intValue()) {
        throw new ConversionException("Suplied number is not of type Integer: " + parsed.longValue());
    }
    return new Integer(parsed.intValue()); // unlike superclass it will return proper Integer
}

From source file:org.ojbc.policyacknowledgement.dao.PolicyDAOImpl.java

private Long saveNewUser(String federationId) {
    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("federation_id", federationId);

    final Number key = this.insertUser.executeAndReturnKey(params);
    return key.longValue();
}

From source file:javadz.beanutils.locale.converters.ByteLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type. This method will return values of type Byte.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value/* w w w  . j av a2 s  .  c o m*/
 *
 * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
protected Object parse(Object value, String pattern) throws ParseException {
    final Number parsed = (Number) super.parse(value, pattern);
    if (parsed.longValue() != parsed.byteValue()) {
        throw new ConversionException("Supplied number is not of type Byte: " + parsed.longValue());
    }
    // now returns property Byte
    return new Byte(parsed.byteValue());
}

From source file:de.siemens.quantarch.bugs.dao.IssueTrackerDaoImpl.java

@Override
public long addIssue(Issue issue, long projectId, List<BugHistory> bugHistoryList) {

    // Step 4: Add the users
    // a> Created By
    long createdBy = PersonServiceClient.getPerson(issue.getReporterName(), issue.getReporter(), projectId,
            projectConfig.getPersonServiceURL());
    long assignee = PersonServiceClient.getPerson(issue.getAssigneeName(), issue.getAssignee(), projectId,
            projectConfig.getPersonServiceURL());

    // Step 5: Add the issue
    // now add the issue record
    SimpleJdbcInsert insertPerson = new SimpleJdbcInsert(getDataSource()).withTableName("issue")
            .usingGeneratedKeyColumns("id");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("bugId", issue.getId());
    parameters.put("creationDate", issue.getCreationTimestamp());
    parameters.put("modifiedDate", issue.getDeltaTimestamp());
    parameters.put("url", null);
    parameters.put("isRegression", 0);
    parameters.put("status", issue.getStatus());
    parameters.put("resolution", issue.getResolution());
    parameters.put("severity", issue.getSeverity());
    parameters.put("priority", issue.getPriority());
    parameters.put("createdBy", createdBy);
    parameters.put("assignedTo", assignee);
    parameters.put("projectId", projectId);

    if (projectConfig.isProductAsProject()) {
        // when product is parsed as a project
        // component becomes subComponent and subSubComponent is null
        parameters.put("subComponent", issue.getComponent());
    } else {//  w  ww. j  av  a  2s .c o  m
        parameters.put("subComponent", issue.getProduct());
        parameters.put("subSubComponent", issue.getComponent());
    }

    parameters.put("version", issue.getVersion());

    Number newId = insertPerson.executeAndReturnKey(parameters);
    long issueId = newId.longValue();

    // Step 6: Populate cc list of the issue
    Iterator<String> iter = issue.getCcIterator();
    while (iter.hasNext()) {
        String cc = iter.next();
        long ccUser = PersonServiceClient.getPerson(null, cc, projectId, projectConfig.getPersonServiceURL());
        getJdbcTemplate().update("INSERT INTO cc_list (issueId,who) VALUES(?,?)", issueId, ccUser);
    }

    // Step 7: Populate issue communication / comments
    Iterator<LongDescription> longDescIter = issue.getLongDescriptionIterator();
    while (longDescIter.hasNext()) {
        LongDescription desc = longDescIter.next();
        Date date = desc.getWhen();
        String who = desc.getWho();
        long commentUser = PersonServiceClient.getPerson(desc.getAuthorName(), who, projectId,
                projectConfig.getPersonServiceURL());
        getJdbcTemplate().update("INSERT INTO issue_comment (who,fk_issueId,commentDate) VALUES(?,?,?)",
                commentUser, issueId, date);
    }

    // Step 8: add the bug history
    for (BugHistory record : bugHistoryList) {
        addBugHistory(record, issueId, projectId);
    }

    return issueId;
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCJourneyDAO.java

@Override
public Journey create(Journey journey) throws DAOException, ValidationException {
    logger.debug("Creating Journey", journey);

    JourneyValidator.validate(journey);/*from w w w  . j  ava2s  .  c o m*/

    for (Journey element : readAll()) {
        if (element.getName().equals(journey.getName()) && element.getStartDate() == journey.getStartDate()
                && element.getEndDate() == journey.getStartDate())
            return element;
    }

    Map<String, Object> parameters = new HashMap<String, Object>(1);
    parameters.put("name", journey.getName());
    parameters.put("start", Timestamp.valueOf(journey.getStartDate()));
    parameters.put("end", Timestamp.valueOf(journey.getEndDate()));

    try {
        Number newId = insertJourney.executeAndReturnKey(parameters);
        journey.setId((int) newId.longValue());

        addedCallbacks.forEach(cb -> cb.accept(journey));

        return journey;
    } catch (DataAccessException ex) {
        logger.error("Failed to create journey", ex);
        throw new DAOException("Failed to create journey", ex);
    }
}