Example usage for java.math BigInteger longValue

List of usage examples for java.math BigInteger longValue

Introduction

In this page you can find the example usage for java.math BigInteger longValue.

Prototype

public long longValue() 

Source Link

Document

Converts this BigInteger to a long .

Usage

From source file:net.onrc.openvirtex.util.OVXFlowManager.java

public LinkedList<MACAddress> getFlowValues(final Integer flowId) {
    final LinkedList<MACAddress> macList = new LinkedList<MACAddress>();
    final BigInteger dualMac = this.flowValues.get(flowId);
    if (dualMac != null) {
        final MACAddress srcMac = MACAddress.valueOf(dualMac.shiftRight(48).longValue());
        final MACAddress dstMac = MACAddress.valueOf(dualMac.longValue());
        macList.add(srcMac);/*w  w  w. j  av a2 s .  com*/
        macList.add(dstMac);
    }
    return macList;
}

From source file:alpha.portal.dao.hibernate.PayloadDaoHibernate.java

/**
 * Internal function to load the highest sequenceNumber from the AlphaCard
 * table./*w w w. j a  va 2 s  .com*/
 * 
 * @param sessionFactory
 *            the session factory
 * @param column
 *            the column
 * @return 0 if no record is found
 */
private Long getLastValue(final SessionFactory sessionFactory, final String column) {
    Session session;
    boolean sessionOwn = false;
    try {
        session = sessionFactory.getCurrentSession();
    } catch (final Exception e) {
        session = sessionFactory.openSession();
        sessionOwn = true;
    }
    final Query q = session.createSQLQuery("select max(" + column + ") from payload");
    final List<Object> list = q.list();
    BigInteger value = (BigInteger) list.get(0);
    if (value == null) {
        value = new BigInteger("0");
    }
    if (sessionOwn) {
        session.close();
    }
    return value.longValue();
}

From source file:org.openhie.openempi.dao.hibernate.MatchPairStatHalfDaoHibernate.java

private void addMatchPairStatHalfInHibernate(Session session, String tableName,
        MatchPairStatHalf matchPairStatHalf) {
    log.debug("Saving matchPairStatHalf record: " + matchPairStatHalf);
    String tableFullName = getTableFullName(tableName);

    boolean generateId = (matchPairStatHalf.getMatchPairStatHalfId() == null);
    StringBuilder sqlInsert = new StringBuilder("INSERT INTO public." + tableFullName + " ("
            + MATCH_PAIR_STAT_HALF_ID_COLUMN_NAME + ", " + PERSON_PSEUDO_ID_COLUMN_NAME + ", "
            + MATCH_STATE_COLUMN_NAME + ") VALUES ("
            + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?") + ",?,?)"
            + (generateId ? (" RETURNING " + MATCH_PAIR_STAT_HALF_ID_COLUMN_NAME) : "") + ";");

    Query query = session.createSQLQuery(sqlInsert.toString());

    int position = 0;
    if (!generateId) {
        query.setLong(position, matchPairStatHalf.getMatchPairStatHalfId());
        position++;//w  w w  .  ja  v  a 2  s  . c om
    }
    query.setLong(position, matchPairStatHalf.getPersonPseudoId());
    position++;
    query.setBoolean(position, matchPairStatHalf.getMatchStatus());

    if (generateId) {
        BigInteger bigInt = (BigInteger) query.uniqueResult();
        long id = bigInt.longValue();
        matchPairStatHalf.setMatchPairStatHalfId(id);
        log.debug("Finished saving the matchPairStatHalf with id " + id);
    } else {
        query.executeUpdate();
        log.debug("Finished saving the matchPairStatHalf with id " + matchPairStatHalf.getPersonPseudoId());
    }
}

From source file:org.n52.lod.csw.CatalogInteractor.java

public long getNumberOfRecords() throws HttpClientException, IllegalStateException, IOException, XmlException {
    // ParameterContainer paramCon = new ParameterContainer();
    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_MAX_RECORDS,
    // 1);//from   w ww  .  j  av  a2s .com
    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_START_POSITION,
    // 0);
    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_RESULT_TYPE,
    // ResultType.HITS.toString());
    // TODO HITS not implemented in OX-F yet...

    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_OUTPUT_SCHEMA_FORMAT,
    // "http://www.opengis.net/cat/csw/2.0.2");
    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_QUERY_TYPE_NAMES_PARAMETER,
    // "csw:Record");
    // paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_ELEMENT_SET_NAME_FORMAT,
    // ElementSetNameType.BRIEF.toString());

    // csw?request=GetRecords&service=CSW
    // &version=2.0.2&namespace=xmlns(csw=http://www.opengis.net/cat/csw)
    // &resultType=results&outputSchema=http://www.opengis.net/cat/csw/2.0.2
    // &outputFormat=application/xml
    // catalog only support POST for GetRecords

    GetRecordsDocument xb_getRecordsDocument = GetRecordsDocument.Factory.newInstance();
    GetRecordsType xb_getRecords = xb_getRecordsDocument.addNewGetRecords();
    xb_getRecords.setService(CSWAdapter.SERVICE_TYPE);
    xb_getRecords.setVersion(CSWAdapter.SUPPORTED_VERSIONS[0]);
    xb_getRecords.setResultType(ResultType.HITS);
    QueryType xb_query = QueryType.Factory.newInstance();
    List<QName> typeNameList = new ArrayList<>();
    typeNameList.add(new QName(CSWAdapter.NAMESPACE, "Record"));
    xb_query.setTypeNames(typeNameList);
    AbstractQueryType abstractQuery = xb_getRecords.addNewAbstractQuery();
    abstractQuery.set(xb_query);
    XmlUtil.qualifySubstitutionGroup(xb_getRecords.getAbstractQuery(),
            QueryDocument.type.getDocumentElementName(), QueryType.type);

    String request = xb_getRecordsDocument.xmlText(new XmlOptions().setSavePrettyPrint());

    SimpleHttpClient httpClient = new SimpleHttpClient(20000);
    String cswUrl = config.getUrlCSW();
    HttpResponse response = httpClient.executePost(cswUrl, request, ContentType.TEXT_XML);
    GetRecordsResponseDocument doc = GetRecordsResponseDocument.Factory
            .parse(response.getEntity().getContent());

    BigInteger numberOfRecordsMatched = doc.getGetRecordsResponse().getSearchResults()
            .getNumberOfRecordsMatched();
    return numberOfRecordsMatched.longValue();
}

From source file:org.kuali.rice.kew.impl.document.attribute.DocumentAttributeIndexingQueueImpl.java

/**
 * Determines the {@link DocumentAttribute}s for the given document and returns a List of SearchableAttributeValue
 * which will be saved.//from ww w  .  j a  va2 s .  c  om
 */
private List<SearchableAttributeValue> buildSearchableAttributeValues(Document document,
        DocumentContent documentContent) {
    List<SearchableAttributeValue> searchableAttributeValues = new ArrayList<SearchableAttributeValue>();
    DocumentType documentTypeBo = KEWServiceLocator.getDocumentTypeService()
            .findByName(document.getDocumentTypeName());
    for (DocumentType.ExtensionHolder<SearchableAttribute> searchableAttributeHolder : documentTypeBo
            .loadSearchableAttributes()) {
        DocumentWithContent documentWithContent = DocumentWithContent.create(document, documentContent);
        SearchableAttribute searchableAttribute = searchableAttributeHolder.getExtension();
        if (searchableAttribute == null) {
            LOG.warn("Encountered a 'null' SearchableAttribute on " + document.getDocumentTypeName() + " : "
                    + searchableAttributeHolder.getExtensionDefinition().getName());
            continue;
        }
        List<DocumentAttribute> documentAttributes = searchableAttribute.extractDocumentAttributes(
                searchableAttributeHolder.getExtensionDefinition(), documentWithContent);
        if (documentAttributes != null) {
            for (DocumentAttribute documentAttribute : documentAttributes) {
                if (documentAttribute == null) {
                    LOG.warn("Encountered a 'null' DocumentAttribute on " + document.getDocumentTypeName()
                            + " from searchable attribute: " + searchableAttribute);
                    continue;
                }
                SearchableAttributeValue searchableAttributeValue = null;
                if (documentAttribute instanceof DocumentAttributeString) {
                    searchableAttributeValue = new SearchableAttributeStringValue();
                    ((SearchableAttributeStringValue) searchableAttributeValue).setSearchableAttributeValue(
                            ((DocumentAttributeString) documentAttribute).getValue());
                } else if (documentAttribute instanceof DocumentAttributeDateTime) {
                    searchableAttributeValue = new SearchableAttributeDateTimeValue();
                    DateTime dateTimeValue = ((DocumentAttributeDateTime) documentAttribute).getValue();
                    Timestamp timestamp = (dateTimeValue == null ? null
                            : new Timestamp(dateTimeValue.getMillis()));
                    ((SearchableAttributeDateTimeValue) searchableAttributeValue)
                            .setSearchableAttributeValue(timestamp);
                } else if (documentAttribute instanceof DocumentAttributeInteger) {
                    searchableAttributeValue = new SearchableAttributeLongValue();
                    BigInteger bigIntegerValue = ((DocumentAttributeInteger) documentAttribute).getValue();
                    Long longValue = (bigIntegerValue == null ? null : bigIntegerValue.longValue());
                    ((SearchableAttributeLongValue) searchableAttributeValue)
                            .setSearchableAttributeValue(longValue);
                } else if (documentAttribute instanceof DocumentAttributeDecimal) {
                    searchableAttributeValue = new SearchableAttributeFloatValue();
                    ((SearchableAttributeFloatValue) searchableAttributeValue).setSearchableAttributeValue(
                            ((DocumentAttributeDecimal) documentAttribute).getValue());
                } else {
                    throw new WorkflowRuntimeException(
                            "Encountered an invalid instance of DocumentAttribute, was: "
                                    + documentAttribute.getClass());
                }
                searchableAttributeValue.setSearchableAttributeKey(documentAttribute.getName());
                searchableAttributeValue.setDocumentId(document.getDocumentId());
                searchableAttributeValue.setRouteHeader(null); // let the documentId we set represent this reference
                searchableAttributeValues.add(searchableAttributeValue);
            }
        }
    }
    return searchableAttributeValues;
}

From source file:com.abiquo.api.services.appslibrary.event.TemplateFactory.java

private Long getRamInMb(final TemplateDto disk) {
    BigInteger byteRam = getBytes(String.valueOf(disk.getRam()), disk.getRamSizeUnit().name());
    return byteRam.longValue() / 1048576;
}

From source file:org.openhie.openempi.dao.hibernate.MatchPairStatDaoHibernate.java

private void addMatchPairStatInHibernate(Session session, String tableName, MatchPairStat matchPairStat) {
    log.debug("Saving matchPairStat record: " + matchPairStat);
    String tableFullName = getTableFullName(tableName);

    boolean generateId = (matchPairStat.getMatchPairStatId() == null);
    StringBuilder sqlInsert = new StringBuilder("INSERT INTO public." + tableFullName + " ("
            + MATCH_PAIR_STAT_ID_COLUMN_NAME + ", " + LEFT_PERSON_PSEUDO_ID_COLUMN_NAME + ", "
            + RIGHT_PERSON_PSEUDO_ID_COLUMN_NAME + ", " + MATCH_STATE_COLUMN_NAME + ") VALUES ("
            + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?") + ",?,?,?)"
            + (generateId ? (" RETURNING " + MATCH_PAIR_STAT_ID_COLUMN_NAME) : "") + ";");

    Query query = session.createSQLQuery(sqlInsert.toString());

    int position = 0;
    if (!generateId) {
        query.setLong(position, matchPairStat.getMatchPairStatId());
        position++;//w  ww .j av a  2s.c o  m
    }
    query.setLong(position, matchPairStat.getLeftPersonPseudoId());
    position++;
    query.setLong(position, matchPairStat.getRightPersonPseudoId());
    position++;
    query.setBoolean(position, matchPairStat.getMatchStatus());

    if (generateId) {
        BigInteger bigInt = (BigInteger) query.uniqueResult();
        long id = bigInt.longValue();
        matchPairStat.setMatchPairStatId(id);
        log.debug("Finished saving the matchPairStat with id " + id);
    } else {
        query.executeUpdate();
        log.debug("Finished saving the matchPairStat with id " + matchPairStat.getRightPersonPseudoId());
    }
}

From source file:ar.com.zauber.garfio.modules.mantis.model.actions.AddNoteToIssueAction.java

/** @see AbstractIssueAction#preExecutionValidation(List) */
@Override/*from   w ww .  jav a  2s . com*/
public final void preExecutionValidation(final List<Action> allActions) throws MustNotExecuteException {
    super.preExecutionValidation(allActions);

    try {
        boolean canComment = false;

        if (mantisIssue.isFixed()) {
            final BigInteger projId = mantisIssue.getIssueData().getProject().getId();

            final ObjectRef manager = session.getManagerAccess();
            final AccountData[] accounts = session.getSession().getProjectUsers(projId.longValue(),
                    manager.getId().intValue());

            for (final AccountData account : accounts) {
                if (account.getName().equals(session.getUsername())) {
                    canComment = true;
                    break;
                }
            }

            if (!canComment) {
                throw new MustNotExecuteException(
                        "only managers users can add " + "a comment on a closed issue...");
            }
        } else {
            canComment = true;
        }
    } catch (final JMTException e) {
        throw new UnhandledException(e);
    }

}

From source file:br.com.hslife.orcamento.repository.LancamentoContaRepository.java

public boolean existsLinkageFaturaCartao(LancamentoConta lancamento) {
    boolean result = true;

    String sqlLancamento = "select count(*) from detalhefatura where idLancamento = " + lancamento.getId();

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }//  w  ww . j  a v  a2 s.co m

    return result;
}

From source file:br.com.hslife.orcamento.repository.LancamentoContaRepository.java

public boolean existsLinkagePagamentoFaturaCartao(LancamentoConta lancamento) {
    boolean result = true;

    String sqlLancamento = "select count(*) from faturacartao where idLancamento = " + lancamento.getId();

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }//from w  w w  .  j a  va  2 s. c o m

    return result;
}