Example usage for java.math BigInteger intValue

List of usage examples for java.math BigInteger intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Converts this BigInteger to an int .

Usage

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public String getURLForURLId(BigInteger urlId) throws ApolloDatabaseException {
    String urlAsString = "";

    try (Connection conn = datasource.getConnection()) {

        PreparedStatement pstmt = conn.prepareStatement("SELECT text_content FROM run_data_content WHERE id=?");

        pstmt.setInt(1, urlId.intValue());
        ResultSet resultSet = pstmt.executeQuery();

        while (resultSet.next()) {
            urlAsString = resultSet.getString("text_content");
        }// ww w  . ja va2s . c  o m
    } //        catch (ClassNotFoundException e) {
      //            throw new ApolloDatabaseException("ClassNotFoundException retrieving URL for URL ID " + urlId + ": " + e.getMessage());
      //        }
    catch (SQLException e) {
        throw new ApolloDatabaseException(
                "SQLException retrieving URL for URL ID " + urlId + ": " + e.getMessage());
    }
    return urlAsString;
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public String getFileContentForFileId(BigInteger fileId) throws ApolloDatabaseException {
    String fileContent = "";

    try (Connection conn = datasource.getConnection()) {

        PreparedStatement pstmt = conn.prepareStatement("SELECT text_content FROM run_data_content WHERE id=?");

        pstmt.setInt(1, fileId.intValue());
        ResultSet resultSet = pstmt.executeQuery();

        while (resultSet.next()) {
            fileContent = resultSet.getString("text_content");
        }// w  w w .j  a va  2s.  c o m
    } catch (SQLException e) {
        throw new ApolloDatabaseException(
                "SQLException retrieving file content for file ID " + fileId + ": " + e.getMessage());
    }
    //        catch (ClassNotFoundException e) {
    //            throw new ApolloDatabaseException("ClassNotFoundException retrieving file content for file ID " + fileId + ": " + e.getMessage());
    //        }
    return fileContent;
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public int getSoftwareIdForRunId(BigInteger runId) throws ApolloDatabaseException {
    String query = "SELECT software_id FROM run WHERE id = ?";

    PreparedStatement pstmt = null;
    try (Connection conn = datasource.getConnection()) {
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            return rs.getInt(1);
        } else {/*from w  w  w  . ja v  a2 s  .com*/
            throw new ApolloDatabaseKeyNotFoundException("No software_id key was found for run_id " + runId);
        }

    } catch (SQLException ex) {
        throw new ApolloDatabaseException("SQLException attempting to get software_id for run_id " + runId);
    }

}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public SoftwareIdentification getSoftwareIdentificationForRun(BigInteger runId)
        throws ApolloDatabaseKeyNotFoundException, ApolloDatabaseException {

    String query = "SELECT software_id from run WHERE " + "id = ?";

    try (Connection conn = datasource.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        ResultSet rs = pstmt.executeQuery();
        int softwareId = 0;
        if (rs.next()) {
            softwareId = rs.getInt("software_id");
        } else {//from   ww  w  .j  av  a 2 s.  co m
            throw new ApolloDatabaseKeyNotFoundException("No entry found in run where id = " + runId);
        }

        if (softwareId == 0) {
            return null;
        }

        return getSoftwareIdentification(softwareId);

    } catch (SQLException ex) {
        throw new ApolloDatabaseException(
                "SQLException getting software identification for run " + runId + ": " + ex.getMessage());
    }
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public int getIdOfLastServiceToBeCalledForRun(BigInteger runId)
        throws ApolloDatabaseKeyNotFoundException, ApolloDatabaseException {
    String query = "SELECT last_service_to_be_called FROM run WHERE id = ?";

    try (Connection conn = datasource.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            return rs.getInt(1);
        } else {/*from   w w w.ja  v a  2s. c o m*/
            throw new ApolloDatabaseKeyNotFoundException(
                    "No last_service_to_be_called found for simulation run where id = " + runId);
        }

    } catch (SQLException ex) {
        throw new ApolloDatabaseException("SQLException getting ID of last service to be called for run "
                + runId + ": " + ex.getMessage());
    }
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

/**
 * @param runId//from w  w  w. j  a v  a2 s  .c o  m
 * @param softwareIdentificationKey
 * @return The number of rows that were updated (either 1 or 0).
 * @throws SQLException
 * @throws ClassNotFoundException
 */
public int updateLastServiceToBeCalledForRun(BigInteger runId, Integer softwareIdentificationKey)
        throws ApolloDatabaseException {

    String query = "UPDATE run SET last_service_to_be_called = ? WHERE id = ?";

    try (Connection conn = datasource.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, softwareIdentificationKey);
        pstmt.setInt(2, runId.intValue());
        return pstmt.executeUpdate();

    } catch (SQLException ex) {
        throw new ApolloDatabaseException(
                "SQLException updating last service to be called for run " + runId + ": " + ex.getMessage());
    }

}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public BigInteger getContentIdFromRunIdAndDataDescriptionId(BigInteger runId, BigInteger runDataDescriptionId)
        throws ApolloDatabaseException {
    BigInteger contentId = new BigInteger("0");
    try (Connection conn = datasource.getConnection()) {
        PreparedStatement pstmt = conn
                .prepareStatement("SELECT content_id AS id FROM run_data WHERE run_id=? AND description_id=?");
        pstmt.setInt(1, runId.intValue());
        pstmt.setInt(2, runDataDescriptionId.intValue());

        ResultSet rs = pstmt.executeQuery();

        while (rs.next()) {
            contentId = BigInteger.valueOf(rs.getInt("id"));
        }/*from   ww  w. j  a va  2 s  .  c o  m*/

    } catch (SQLException ex) {
        throw new ApolloDatabaseException(
                "SQLException adding run IDs to simulation group: " + ex.getMessage());
    }
    return contentId;
}

From source file:jp.aegif.nemaki.cmis.aspect.impl.CompileServiceImpl.java

@Override
public <T extends Content> ObjectList compileObjectDataList(CallContext callContext, String repositoryId,
        List<T> contents, String filter, Boolean includeAllowableActions,
        IncludeRelationships includeRelationships, String renditionFilter, Boolean includeAcl,
        BigInteger maxItems, BigInteger skipCount, boolean folderOnly, String orderBy) {
    if (CollectionUtils.isEmpty(contents)) {
        //Empty list
        ObjectListImpl list = new ObjectListImpl();
        list.setObjects(new ArrayList<ObjectData>());
        list.setNumItems(BigInteger.ZERO);
        list.setHasMoreItems(false);/*from w ww.j a  va 2 s .  c o m*/
        return list;
    } else {
        List<ObjectData> ods = new ArrayList<ObjectData>();
        for (T c : contents) {
            //Filter by folderOnly
            if (folderOnly && !c.isFolder()) {
                continue;
            }

            //Get each ObjectData
            ObjectData _od;
            ObjectData v = nemakiCachePool.get(repositoryId).getObjectDataCache().get(c.getId());
            if (v == null) {
                _od = compileObjectDataWithFullAttributes(callContext, repositoryId, c);
            } else {
                _od = (ObjectDataImpl) v;
            }

            ObjectData od = filterObjectDataInList(callContext, repositoryId, _od, filter,
                    includeAllowableActions, includeRelationships, renditionFilter, includeAcl);
            if (od != null) {
                ods.add(od);
            }
        }

        //Sort
        sortUtil.sort(repositoryId, ods, orderBy);

        //Set metadata
        ObjectListImpl list = new ObjectListImpl();
        Integer _skipCount = skipCount.intValue();
        Integer _maxItems = maxItems.intValue();

        if (_skipCount >= ods.size()) {
            list.setHasMoreItems(false);
            list.setObjects(new ArrayList<ObjectData>());
        } else {
            //hasMoreItems
            Boolean hasMoreItems = _skipCount + _maxItems < ods.size();
            list.setHasMoreItems(hasMoreItems);
            //paged list
            Integer toIndex = Math.min(_skipCount + _maxItems, ods.size());
            list.setObjects(new ArrayList<>(ods.subList(_skipCount, toIndex)));
        }
        //totalNumItem
        list.setNumItems(BigInteger.valueOf(ods.size()));

        return list;
    }
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public void removeRunData(BigInteger runId) throws ApolloDatabaseException {
    // need to delete the data content
    // find out if there any other runs that reference this data content
    String query = "SELECT content_id FROM run_data WHERE run_id = ?";

    try (Connection conn = datasource.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            int content_id = rs.getInt(1);
            String innerQuery = "SELECT content_id FROM run_data WHERE run_id <> ? AND content_id = ?";
            PreparedStatement innerPstmt = conn.prepareStatement(innerQuery);
            innerPstmt.setInt(1, runId.intValue());
            innerPstmt.setInt(2, content_id);
            ResultSet innerRs = innerPstmt.executeQuery();
            if (!innerRs.next()) {
                // content_id is not used by any other run, delete it!
                String deleteQuery = "DELETE FROM run_data_content WHERE id = ?";
                PreparedStatement deletePstmt = conn.prepareStatement(deleteQuery);
                deletePstmt.setInt(1, content_id);
                deletePstmt.execute();//from   w  ww . j  a  v  a2s  .  c o  m
            }

        }
        query = "DELETE FROM run_data WHERE run_id = ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        pstmt.execute();

        query = "SELECT simulation_group_id FROM run WHERE id = ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        rs = pstmt.executeQuery();
        List<Integer> simulationGroupIds = new ArrayList<>();
        if (rs.next()) {
            if (!rs.wasNull()) {
                simulationGroupIds.add(rs.getInt(1));
            }

        }

        query = "DELETE FROM run_status WHERE run_id = ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        pstmt.execute();

        query = "DELETE FROM time_series WHERE run_id = ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        pstmt.execute();

        query = "DELETE FROM run WHERE id = ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        pstmt.execute();

        for (Integer simulation_group_id : simulationGroupIds) {
            // int simulation_group_id = rs.getInt(1);
            String innerQuery = "DELETE FROM simulation_group_definition WHERE simulation_group_id = ?";
            pstmt = conn.prepareStatement(innerQuery);
            pstmt.setInt(1, simulation_group_id);
            pstmt.execute();

            innerQuery = "DELETE FROM simulation_groups WHERE id = ?";
            pstmt = conn.prepareStatement(innerQuery);
            pstmt.setInt(1, simulation_group_id);
            pstmt.execute();

        }
    } catch (SQLException ex) {
        throw new ApolloDatabaseException(
                "SQLException attempting to remove all data for run " + runId + ": " + ex.getMessage());
    }

}

From source file:org.alfresco.opencmis.AlfrescoCmisServiceImpl.java

@Override
public TypeDefinitionList getTypeChildren(String repositoryId, String typeId,
        Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount,
        ExtensionsData extension) {//from   ww w. j  ava  2  s . co m
    checkRepositoryId(repositoryId);

    // convert BigIntegers to int
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());

    // set up the result
    TypeDefinitionListImpl result = new TypeDefinitionListImpl();
    List<TypeDefinition> list = new ArrayList<TypeDefinition>();
    result.setList(list);

    // get the types from the dictionary
    List<TypeDefinitionWrapper> childrenList;
    if (typeId == null) {
        childrenList = connector.getOpenCMISDictionaryService().getBaseTypes(true);
    } else {
        TypeDefinitionWrapper tdw = connector.getOpenCMISDictionaryService().findType(typeId);
        if (tdw == null) {
            throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
        }
        childrenList = connector.getOpenCMISDictionaryService().getChildren(typeId);
        //            childrenList = tdw.getChildren();
    }

    // create result
    if (max > 0) {
        int lastIndex = (max + skip > childrenList.size() ? childrenList.size() : max + skip) - 1;
        for (int i = skip; i <= lastIndex; i++) {
            list.add(childrenList.get(i).getTypeDefinition(includePropertyDefinitions));
        }
    }

    result.setHasMoreItems(childrenList.size() - skip > result.getList().size());
    result.setNumItems(BigInteger.valueOf(childrenList.size()));

    return result;
}