List of usage examples for java.math BigInteger intValue
public int intValue()
From source file:org.alfresco.opencmis.AlfrescoCmisServiceImpl.java
@Override public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId, BigInteger depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, ExtensionsData extension) { long start = System.currentTimeMillis(); checkRepositoryId(repositoryId);//from w w w. jav a 2 s .c o m List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>(); getDescendantsTree(repositoryId, getOrCreateFolderInfo(folderId, "Folder").getNodeRef(), depth.intValue(), filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, true, result); logGetObjectsCall("getFolderTree", start, folderId, countDescendantsTree(result), filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, extension, null, null, null, depth); return result; }
From source file:edu.pitt.apollo.db.ApolloDbUtils.java
public Map<String, ByteArrayOutputStream> getDataContentForSoftware(BigInteger runKey, int sourceSoftwareIdKey, int destinationSoftwareIdKey) throws ApolloDatabaseException { Map<String, ByteArrayOutputStream> result = new HashMap<>(); String query = "SELECT " + "rddv.label, " + "rdc.text_content " + "FROM " + "run_data_content rdc, " + "run_data rd, " + "run_data_description_view rddv " + "WHERE " + "rd.content_id = rdc.id AND " + "rd.run_id = ? AND " + "rddv.run_data_description_id = rd.description_id AND " + "rddv.source_software = ? AND " + "rddv.destination_software = ?"; PreparedStatement pstmt = null; try {//from ww w . j a v a2 s . com try (Connection conn = datasource.getConnection()) { pstmt = conn.prepareStatement(query); pstmt.setInt(1, runKey.intValue()); pstmt.setInt(2, sourceSoftwareIdKey); pstmt.setInt(3, destinationSoftwareIdKey); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { String label = rs.getString(1); String dataContent = rs.getString(2); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(dataContent.getBytes()); result.put(label, baos); } } finally { pstmt.close(); } } catch (IOException ex) { throw new ApolloDatabaseException("IOException attempting to get data content for software for run ID " + runKey + ": " + ex.getMessage()); } catch (SQLException ex) { throw new ApolloDatabaseException("SQLException attempting to get data content for software for run ID " + runKey + ": " + ex.getMessage()); } return result; }
From source file:jp.aegif.nemaki.cmis.aspect.query.solr.SolrQueryProcessor.java
@Override public ObjectList query(CallContext callContext, String repositoryId, String statement, Boolean searchAllVersions, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) { SolrServer solrServer = solrUtil.getSolrServer(); // TODO walker is required? QueryUtilStrict util = new QueryUtilStrict(statement, new CmisTypeManager(repositoryId, typeManager), null); QueryObject queryObject = util.getQueryObject(); // Get where caluse as Tree Tree whereTree = null;/* ww w. j a v a 2s .c o m*/ try { util.processStatement(); Tree tree = util.parseStatement(); whereTree = extractWhereTree(tree); } catch (Exception e) { e.printStackTrace(); } // Build solr statement of WHERE String whereQueryString = ""; if (whereTree == null || whereTree.isNil()) { whereQueryString = "*:*"; } else { try { SolrPredicateWalker solrPredicateWalker = new SolrPredicateWalker(repositoryId, queryObject, solrUtil, contentService); Query whereQuery = solrPredicateWalker.walkPredicate(whereTree); whereQueryString = whereQuery.toString(); } catch (Exception e) { e.printStackTrace(); // TODO Output more detailed exception exceptionService.invalidArgument("Invalid CMIS SQL statement!"); } } // Build solr query of FROM String fromQueryString = ""; String repositoryQuery = "repository_id:" + repositoryId; fromQueryString += repositoryQuery + " AND "; TypeDefinition td = queryObject.getMainFromName(); // includedInSupertypeQuery List<TypeDefinitionContainer> typeDescendants = typeManager.getTypesDescendants(repositoryId, td.getId(), BigInteger.valueOf(-1), false); Iterator<TypeDefinitionContainer> iterator = typeDescendants.iterator(); List<String> tables = new ArrayList<String>(); while (iterator.hasNext()) { TypeDefinition descendant = iterator.next().getTypeDefinition(); if (td.getId() != descendant.getId()) { boolean isq = (descendant.isIncludedInSupertypeQuery() == null) ? false : descendant.isIncludedInSupertypeQuery(); if (!isq) continue; } String table = descendant.getQueryName(); tables.add(table.replaceAll(":", "\\\\:")); } Term t = new Term(solrUtil.getPropertyNameInSolr(PropertyIds.OBJECT_TYPE_ID), StringUtils.join(tables, " ")); fromQueryString += new TermQuery(t).toString(); // Execute query SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(whereQueryString); solrQuery.setFilterQueries(fromQueryString); //TEST solrQuery.set(CommonParams.START, 0); solrQuery.set(CommonParams.ROWS, maxItems.intValue()); QueryResponse resp = null; try { resp = solrServer.query(solrQuery); } catch (SolrServerException e) { e.printStackTrace(); } // Output search results to ObjectList if (resp != null && resp.getResults() != null && resp.getResults().getNumFound() != 0) { SolrDocumentList docs = resp.getResults(); List<Content> contents = new ArrayList<Content>(); for (SolrDocument doc : docs) { String docId = (String) doc.getFieldValue("object_id"); Content c = contentService.getContent(repositoryId, docId); // When for some reason the content is missed, pass through if (c == null) { logger.warn("[objectId=" + docId + "]It is missed in DB but still rests in Solr."); } else { contents.add(c); } } List<Lock> locks = threadLockService.readLocks(repositoryId, contents); try { threadLockService.bulkLock(locks); // Filter out by permissions List<Content> permitted = permissionService.getFiltered(callContext, repositoryId, contents); // Filter return value with SELECT clause Map<String, String> requestedWithAliasKey = queryObject.getRequestedPropertiesByAlias(); String filter = null; if (!requestedWithAliasKey.keySet().contains("*")) { // Create filter(queryNames) from query aliases filter = StringUtils.join(requestedWithAliasKey.values(), ","); } // Build ObjectList String orderBy = orderBy(queryObject); ObjectList result = compileService.compileObjectDataList(callContext, repositoryId, permitted, filter, includeAllowableActions, includeRelationships, renditionFilter, false, maxItems, skipCount, false, orderBy); return result; } finally { threadLockService.bulkUnlock(locks); } } else { ObjectListImpl nullList = new ObjectListImpl(); nullList.setHasMoreItems(false); nullList.setNumItems(BigInteger.ZERO); return nullList; } }
From source file:edu.pitt.apollo.db.ApolloDbUtils.java
public Map<BigInteger, FileAndURLDescription> getListOfFilesForRunId(BigInteger runId) throws ApolloDatabaseException { HashMap<BigInteger, FileAndURLDescription> contentIdToFileDescriptionMap = new HashMap<>(); try (Connection conn = datasource.getConnection()) { PreparedStatement pstmt = conn.prepareStatement( "SELECT runData.content_id, rddv.source_software, rddv.destination_software, rddv.format, rddv.type, rddv.label FROM run_data runData " + "JOIN run_data_description_view rddv ON rddv.run_data_description_id=runData.description_id WHERE runData.run_id=? AND rddv.format='TEXT'"); // PreparedStatement pstmt = conn.prepareStatement( // "SELECT runData.content_id, rddv.label FROM run_data runData " + // "JOIN run_data_description_view rddv ON rddv.run_data_description_id=runData.description_id WHERE runData.run_id=? AND rddv.format='TEXT';"); pstmt.setInt(1, runId.intValue()); ResultSet resultSet = pstmt.executeQuery(); while (resultSet.next()) { FileAndURLDescription fileDescription = new FileAndURLDescription(); fileDescription.setContentFormat(ContentDataFormatEnum.valueOf(resultSet.getString("format"))); fileDescription.setContentType(ContentDataTypeEnum.fromValue(resultSet.getString("type"))); if (resultSet.getInt("source_software") != 0) { SoftwareIdentification source = getSoftwareIdentification(resultSet.getInt("source_software")); fileDescription.setSourceSoftwareIdentification(source); } else { fileDescription.setSourceSoftwareIdentification(null); }/* w w w .j a va2s. c o m*/ if (resultSet.getInt("destination_software") != 0) { SoftwareIdentification destination = getSoftwareIdentification( resultSet.getInt("destination_software")); fileDescription.setDestinationSoftwareIdentification(destination); } else { fileDescription.setDestinationSoftwareIdentification(null); } fileDescription.setName(resultSet.getString("label")); int content_id = resultSet.getInt("content_id"); contentIdToFileDescriptionMap.put(BigInteger.valueOf(content_id), fileDescription); } } catch (SQLException e) { throw new ApolloDatabaseException( "SQLException retrieving content ID and labels for run " + runId + ": " + e.getMessage()); } // catch (ClassNotFoundException e) { // throw new ApolloDatabaseException("ClassNotFoundException retrieving content ID and labels for run ID " + runId + ": " + e.getMessage()); // } return contentIdToFileDescriptionMap; }
From source file:edu.pitt.apollo.db.ApolloDbUtils.java
public HashMap<BigInteger, FileAndURLDescription> getListOfURLsForRunId(BigInteger runId) throws ApolloDatabaseException { HashMap<BigInteger, FileAndURLDescription> contentIdToURLDescriptionMap = new HashMap<BigInteger, FileAndURLDescription>(); try (Connection conn = datasource.getConnection()) { PreparedStatement pstmt = conn.prepareStatement( "SELECT runData.content_id, rddv.source_software, rddv.destination_software, rddv.format, rddv.type, rddv.label FROM run_data runData " + "JOIN run_data_description_view rddv ON rddv.run_data_description_id=runData.description_id WHERE runData.run_id=? AND (rddv.format='URL' OR rddv.format='ZIP')"); // PreparedStatement pstmt = conn.prepareStatement( // "SELECT runData.content_id, rddv.label FROM run_data runData " + // "JOIN run_data_description_view rddv ON rddv.run_data_description_id=runData.description_id WHERE runData.run_id=? AND (rddv.format='URL' OR rddv.format='ZIP');"); pstmt.setInt(1, runId.intValue()); ResultSet resultSet = pstmt.executeQuery(); while (resultSet.next()) { FileAndURLDescription urlDescription = new FileAndURLDescription(); urlDescription.setContentFormat(ContentDataFormatEnum.valueOf(resultSet.getString("format"))); urlDescription.setContentType(ContentDataTypeEnum.fromValue(resultSet.getString("type"))); if (resultSet.getInt("source_software") != 0) { SoftwareIdentification source = getSoftwareIdentification(resultSet.getInt("source_software")); urlDescription.setSourceSoftwareIdentification(source); } else { urlDescription.setSourceSoftwareIdentification(null); }/*from www . ja va 2s . co m*/ if (resultSet.getInt("destination_software") != 0) { SoftwareIdentification destination = getSoftwareIdentification( resultSet.getInt("destination_software")); urlDescription.setDestinationSoftwareIdentification(destination); } else { urlDescription.setDestinationSoftwareIdentification(null); } urlDescription.setName(resultSet.getString("label")); int content_id = resultSet.getInt("content_id"); contentIdToURLDescriptionMap.put(BigInteger.valueOf(content_id), urlDescription); } } catch (SQLException e) { throw new ApolloDatabaseException( "SQLException retrieving content ID and labels for run " + runId + ": " + e.getMessage()); } // catch (ClassNotFoundException e) { // throw new ApolloDatabaseException("ClassNotFoundException retrieving content ID and labels for run ID " + runId + ": " + e.getMessage()); // } return contentIdToURLDescriptionMap; }
From source file:edu.pitt.apollo.db.ApolloDbUtils.java
public ResultSet getRunIdAndRunSimulationMessagesForBatch(BigInteger batchRunId, int endUserSoftwareId, int translatorSoftwareId, Connection conn) throws ApolloDatabaseException { String query = "SELECT" + " sgd.run_id," + " rdc.text_content AS run_message," + " rsd.status," + " rs.message " + " FROM" + " run r," + " run_data_content rdc," + " run_data rd," + " simulation_group_definition sgd," + " run_data_description_view rddv," + " run_status rs," + " run_status_description rsd " + " WHERE" + " rd.content_id = rdc.id AND" + " rddv.run_data_description_id = rd.description_id AND" + " rddv.source_software = ? AND" + " rddv.destination_software = ? AND" + " rddv.label = \"run_message.json\" AND" + " rd.run_id = sgd.run_id AND" + " r.id = ? AND" + " sgd.simulation_group_id = r.simulation_group_id AND" + " rs.run_id = r.id AND" + " rsd.id = rs.status_id"; try {/*from w w w . j a v a2 s . c o m*/ PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, endUserSoftwareId); pstmt.setInt(2, translatorSoftwareId); pstmt.setInt(3, batchRunId.intValue()); ResultSet rs = pstmt.executeQuery(); return rs; } catch (SQLException ex) { throw new ApolloDatabaseException( "SQLException getting run IDs and runSimulationMessages for batch: " + ex.getMessage()); } }
From source file:edu.pitt.apollo.db.ApolloDbUtils.java
public PreparedStatement getDataContentForBatchSimulations(BigInteger batchRunId, List<String> fileNamesToMatch, Connection conn) throws ApolloDatabaseException { String query = "SELECT" + " rddav.value AS name," + " rdc.text_content," + " r2.id" + " FROM" + " run_data_description_axis_value rddav," + " run_data_description_axis rdda," + " run_data_content rdc," + " run_data rd," + " simulation_group_definition sgd," + " run r1," + " run r2" + " WHERE" + " rd.content_id = rdc.id AND" + " r2.id = sgd.run_id AND" + " rd.run_id = r2.id AND"; if (!fileNamesToMatch.isEmpty()) { query += " (rddav.value = '" + fileNamesToMatch.get(0) + "'"; for (int i = 1; i < fileNamesToMatch.size(); i++) { query += " OR rddav.value = '" + fileNamesToMatch.get(i) + "'"; }/*w ww .j a v a 2 s . c o m*/ query += ") AND"; } query += " rddav.run_data_description_axis_id = rdda.id AND" + " rddav.run_data_description_id = rd.description_id AND" + " sgd.simulation_group_id = r1.simulation_group_id AND" + " r1.id = ? AND" + " rdda.label = 'label'"; System.out.println(query); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); pstmt.setFetchSize(Integer.MIN_VALUE); pstmt.setInt(1, batchRunId.intValue()); return pstmt; } catch (SQLException ex) { throw new ApolloDatabaseException("SQLException attempting to get data content for batch run ID " + batchRunId + ": " + ex.getMessage()); } }
From source file:org.alfresco.opencmis.CMISConnector.java
@SuppressWarnings("unchecked") public ObjectList query(String statement, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount/*, CmisVersion cmisVersion*/) { // prepare results ObjectListImpl result = new ObjectListImpl(); result.setObjects(new ArrayList<ObjectData>()); // prepare query CMISQueryOptions options = new CMISQueryOptions(statement, getRootStoreRef()); CmisVersion cmisVersion = getRequestCmisVersion(); options.setCmisVersion(cmisVersion); options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS); int skip = 0; if ((skipCount != null) && (skipCount.intValue() >= 0)) { skip = skipCount.intValue();//from w w w. ja va 2s. com options.setSkipCount(skip); } if ((maxItems != null) && (maxItems.intValue() >= 0)) { options.setMaxItems(maxItems.intValue()); } boolean fetchObject = includeAllowableActions || (includeRelationships != IncludeRelationships.NONE) || (!RENDITION_NONE.equals(renditionFilter)); // query CMISResultSet rs = getOpenCMISQueryService().query(options); try { CMISResultSetColumn[] columns = rs.getMetaData().getColumns(); for (CMISResultSetRow row : rs) { NodeRef nodeRef = row.getNodeRef(); if (!nodeService.exists(nodeRef) || filter(nodeRef)) { continue; } TypeDefinitionWrapper type = getType(nodeRef); if (type == null) { continue; } ObjectDataImpl hit = new ObjectDataImpl(); PropertiesImpl properties = new PropertiesImpl(); hit.setProperties(properties); Map<String, Serializable> values = row.getValues(); for (CMISResultSetColumn column : columns) { AbstractPropertyData<?> property = getProperty(column.getCMISDataType(), column.getCMISPropertyDefinition(), values.get(column.getName())); property.setQueryName(column.getName()); properties.addProperty(property); } if (fetchObject) { // set allowable actions if (includeAllowableActions) { CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef); if (!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING)) { hit.setAllowableActions(getAllowableActions(nodeInfo)); } } // set relationships if (includeRelationships != IncludeRelationships.NONE) { hit.setRelationships(getRelationships(nodeRef, includeRelationships/*, cmisVersion*/)); } // set renditions if (!RENDITION_NONE.equals(renditionFilter)) { List<RenditionData> renditions = getRenditions(nodeRef, renditionFilter, null, null); if ((renditions != null) && (!renditions.isEmpty())) { hit.setRenditions(renditions); } else { hit.setRenditions(Collections.EMPTY_LIST); } } } result.getObjects().add(hit); } long numberFound = rs.getNumberFound(); if (numberFound != -1) { result.setNumItems(BigInteger.valueOf(numberFound)); } result.setHasMoreItems(rs.hasMore()); } finally { rs.close(); } return result; }
From source file:edu.hawaii.soest.kilonalu.ctd.CTDParser.java
public void setData(String dataString) throws ParseException { logger.debug("CTDParser.setData() called."); // make the observations available to the class this.observationsString = dataString; // build the list of data variable names and offsets // handle profile mode if (this.samplingMode.equals("profile")) { // handle the raw frquencies and voltages in Hex OUTPUTFORMAT (0) if (this.outputFormat.equals("raw HEX")) { this.dataVariableNames = new ArrayList<String>(); this.dataVariableNames.add(this.RAW_TEMPERATURE_FIELD_NAME); this.dataVariableNames.add(this.RAW_CONDUCTIVITY_FIELD_NAME); this.dataVariableUnits = new ArrayList<String>(); this.dataVariableUnits.add("counts"); this.dataVariableUnits.add("Hz"); this.currentOffset = 6; this.dataVariableOffsets = new ArrayList<Integer>(); this.dataVariableOffsets.add(currentOffset); this.currentOffset = currentOffset + 6; this.dataVariableOffsets.add(currentOffset); // Is pressure present? if (this.hasPressure) { this.dataVariableNames.add(this.RAW_PRESSURE_FIELD_NAME); this.dataVariableUnits.add("counts"); this.currentOffset = this.currentOffset + 6; this.dataVariableOffsets.add(this.currentOffset); // And is it a strain gauge sensor? if (this.hasStrainGaugePressure) { dataVariableNames.add(this.RAW_PRESSURE_TEMP_COMP_FIELD_NAME); dataVariableUnits.add("counts"); currentOffset = currentOffset + 4; dataVariableOffsets.add(currentOffset); }//from w w w . j a va2 s. co m } else { logger.info("There is no pressure sensor."); } // Is there a channel zero voltage present? if (this.hasVoltageChannelZero) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_ZERO_FIELD_NAME); this.dataVariableUnits.add("V"); this.currentOffset = this.currentOffset + 4; this.dataVariableOffsets.add(this.currentOffset); } // Is there a channel one voltage present? if (this.hasVoltageChannelOne) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_ONE_FIELD_NAME); this.dataVariableUnits.add("V"); this.currentOffset = this.currentOffset + 4; this.dataVariableOffsets.add(this.currentOffset); } // Is there a channel two voltage present? if (this.hasVoltageChannelTwo) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_TWO_FIELD_NAME); this.dataVariableUnits.add("V"); this.currentOffset = this.currentOffset + 4; this.dataVariableOffsets.add(this.currentOffset); } // Is there a channel three voltage present? if (this.hasVoltageChannelThree) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_THREE_FIELD_NAME); this.dataVariableUnits.add("V"); this.currentOffset = this.currentOffset + 4; this.dataVariableOffsets.add(this.currentOffset); } /* * @todo - handle SBE38, SBE50, and/or gasTensionDevice data */ // We now know the data variable names, units, and corresponding // character offsets for each Hex data string found in the // dataValuesMap. Build a raw matrix from the dataValuesMap by only // applying output factors. Conversion to useful variable units // will happen in the calling source driver since voltage channel // semantics are unknown to the parser int beginIndex = 0; int endIndex = 0; int offsetIndex = 0; String hexSubstring = ""; String hexDataString = ""; Hex decoder = new Hex(); double value = 0d; this.convertedDataValuesMatrix = new Array2DRowRealMatrix(this.dataValuesMap.size() - 1, this.dataVariableOffsets.size()); for (int rowIndex = 1; rowIndex < this.dataValuesMap.size(); rowIndex++) { hexDataString = this.dataValuesMap.get(rowIndex); logger.debug(rowIndex + ") hexDataString is: " + hexDataString); for (offsetIndex = 0; offsetIndex < this.dataVariableOffsets.size(); offsetIndex++) { endIndex = this.dataVariableOffsets.get(offsetIndex); hexSubstring = hexDataString.substring(beginIndex, endIndex); try { // convert the hex characters to bytes byte[] hexAsBytes = decoder.decodeHex(hexSubstring.toCharArray()); BigInteger bigInteger = new BigInteger(hexAsBytes); int intValue = bigInteger.intValue(); // the hex values are either 2 or 3 bytes long (AABBCC or AABB) // BigInteger fills in missing bits with 0xFF. Remove them. This // is only a problem with large bytes that cause the value to // become negative. if (hexAsBytes.length < 3) { intValue = (intValue & 0x0000FFFF); } else { intValue = (intValue & 0x00FFFFFF); } value = new Integer(intValue).doubleValue(); // convert the value based on the CTD User manual conversion using // the corresponding data variable name to determine which conversion double convertedValue = convert(value, this.dataVariableNames.get(offsetIndex)); convertedDataValuesMatrix.setEntry(rowIndex - 1, offsetIndex, convertedValue); logger.debug("\t" + this.dataVariableNames.get(offsetIndex) + " is:\t" + value + "\tConverted: " + convertedValue); // set the beginIndex to start at the endIndex beginIndex = endIndex; } catch (DecoderException de) { logger.debug("Could not decode the Hex string: " + hexSubstring); } } // for // reset the offsetIndex for the next hexDataString offsetIndex = 0; beginIndex = 0; } // for // handle the engineering units in Hex OUTPUTFORMAT (1) } else if (this.outputFormat.equals("converted Hex")) { /* * @todo - handle OUTPUTFORMAT (1) */ // handle the raw frquencies and voltages in decimal OUTPUTFORMAT (2) } else if (this.outputFormat.equals("raw decimal")) { /* * @todo - handle OUTPUTFORMAT (2) */ // handle the engineering units in decimal OUTPUTFORMAT (3) } else if (this.outputFormat.equals("converted decimal")) { /* * @todo - handle OUTPUTFORMAT (3) */ } // handle moored mode } else if (this.samplingMode.equals("moored")) { // handle the raw frequencies and voltages in Hex OUTPUTFORMAT (0) if (this.outputFormat.equals("raw HEX")) { // handle the engineering units in Hex OUTPUTFORMAT (1) } else if (this.outputFormat.equals("converted Hex")) { /* * @todo - handle OUTPUTFORMAT (1) */ // handle the raw frequencies and voltages in decimal OUTPUTFORMAT (2) } else if (this.outputFormat.equals("raw decimal")) { /* * @todo - handle OUTPUTFORMAT (2) */ // handle the engineering units in decimal OUTPUTFORMAT (3) } else if (this.outputFormat.equals("converted decimal")) { this.dataVariableNames = new ArrayList<String>(); this.dataVariableNames.add(this.TEMPERATURE_FIELD_NAME); this.dataVariableNames.add(this.CONDUCTIVITY_FIELD_NAME); this.dataVariableUnits = new ArrayList<String>(); this.dataVariableUnits.add("degrees C"); this.dataVariableUnits.add("S/m"); // Is pressure present? if (this.hasPressure) { this.dataVariableNames.add(this.PRESSURE_FIELD_NAME); this.dataVariableUnits.add("decibars"); } else { logger.info("There is no pressure sensor."); } // Is there a channel zero voltage present? if (this.hasVoltageChannelZero) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_ZERO_FIELD_NAME); this.dataVariableUnits.add("V"); } // Is there a channel one voltage present? if (this.hasVoltageChannelOne) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_ONE_FIELD_NAME); this.dataVariableUnits.add("V"); } // Is there a channel two voltage present? if (this.hasVoltageChannelTwo) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_TWO_FIELD_NAME); this.dataVariableUnits.add("V"); } // Is there a channel three voltage present? if (this.hasVoltageChannelThree) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_THREE_FIELD_NAME); this.dataVariableUnits.add("V"); } // Is there a channel four voltage present? if (this.hasVoltageChannelFour) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_FOUR_FIELD_NAME); this.dataVariableUnits.add("V"); } // Is there a channel five voltage present? if (this.hasVoltageChannelFive) { this.dataVariableNames.add(this.RAW_VOLTAGE_CHANNEL_FIVE_FIELD_NAME); this.dataVariableUnits.add("V"); } /* * @todo - handle SBE38, SBE50, and/or gasTensionDevice data */ // Will salinity be output? if (this.willOutputSalinity) { this.dataVariableNames.add(this.SALINITY_FIELD_NAME); this.dataVariableUnits.add("psu"); } // Will sound velocity be output? if (this.willOutputSalinity) { this.dataVariableNames.add(this.SOUND_VELOCITY_FIELD_NAME); this.dataVariableUnits.add("m/s"); } // Add the date and time fields this.dataVariableNames.add(this.DATE_FIELD_NAME); this.dataVariableUnits.add("dd MMM yyyy"); this.dataVariableNames.add(this.TIME_FIELD_NAME); this.dataVariableUnits.add("hh:mm:ss"); } this.convertedDataValuesMatrix = new Array2DRowRealMatrix(this.dataValuesMap.size() - 1, this.dataVariableOffsets.size()); // CSJ fix this } else { throw new ParseException( "There was an error parsing the data string. " + "The sampling mode is not recognized.", 0); } }
From source file:org.eclipse.smila.connectivity.framework.crawler.jdbc.JdbcCrawler.java
/** * Populates the {@link #_groupingRanges}-{@link ArrayList} according to the configuration specified in the * {@link Grouping}-attribute of the {@link DataSourceConnectionConfig}. The SQL-statements needed for this are * executed via a local {@link Statement}-object, just as the data is retrieved via a local {@link ResultSet}-object. * /*ww w .ja va 2s .c o m*/ * @throws CrawlerCriticalException * If any of the following conditions occur: * <ul> * <li>Any of the columns used for grouping has a data type which is not supported: !(Number||String)</li> * <li>A SQLException is raised while retrieving the grouping data from the database</li> * </ul> */ private void prepareGrouping() throws CrawlerCriticalException { final Grouping grouping = _process.getSelections().getGrouping(); BigInteger stepping = BigInteger.ONE; ResultSet groupingResultSet = null; ResultSetMetaData groupingMetaData = null; if (grouping != null) { _groupingRanges = new ArrayList<GroupingRange>(); final String groupingSQL = grouping.getSQL(); stepping = grouping.getStepping(); Statement groupingStatement = null; try { groupingStatement = _connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); _log.debug("Executing SQL for grouping preparation: [" + groupingSQL + "]"); groupingResultSet = groupingStatement.executeQuery(groupingSQL); groupingMetaData = groupingResultSet.getMetaData(); _log.debug("Retrieved groupingResultSet with [" + groupingMetaData.getColumnCount() + "] columns"); for (int i = 1; i <= groupingMetaData.getColumnCount(); i++) { Class<?> columnClass = null; try { columnClass = Class.forName(groupingMetaData.getColumnClassName(i)); } catch (final ClassNotFoundException e) { _log.error("This should never happen: the class[" + groupingMetaData.getColumnClassName(i) + "] for the column " + i + " in the grouping result set could not be resolved"); } if (Number.class.isAssignableFrom(columnClass)) { _log.debug("RowNr " + i + " of the grouping result set is of type [" + columnClass.getName() + "], which is derived from [Number]: fine for use in a grouping"); continue; } else if (String.class.equals(columnClass)) { _log.debug("RowNr " + i + " of the grouping result set is of type [String]: fine for use in a grouping"); } else { throw new CrawlerCriticalException("RowNr " + i + " of the grouping result set is of type [" + columnClass.getName() + "]: NOT supported as a grouping field"); } } int groupingRecords = 0; PreparedStatementTypedParameter[] startValues = null; PreparedStatementTypedParameter[] endValues = null; final PreparedStatementTypedParameter[] finalValues = new PreparedStatementTypedParameter[groupingMetaData .getColumnCount()]; while (groupingResultSet.next()) { if (groupingRecords == 0) { startValues = new PreparedStatementTypedParameter[groupingMetaData.getColumnCount()]; for (int i = 1; i <= groupingMetaData.getColumnCount(); i++) { startValues[i - 1] = new PreparedStatementTypedParameter(groupingResultSet.getObject(i), (i * 2) - 1, groupingMetaData.getColumnType(i)); } } groupingRecords++; if (groupingRecords == stepping.intValue()) { endValues = new PreparedStatementTypedParameter[groupingMetaData.getColumnCount()]; for (int i = 1; i <= groupingMetaData.getColumnCount(); i++) { endValues[i - 1] = new PreparedStatementTypedParameter(groupingResultSet.getObject(i), i * 2, groupingMetaData.getColumnType(i)); } final GroupingRange groupingRange = new GroupingRange(startValues, endValues); _groupingRanges.add(groupingRange); if (_log.isTraceEnabled()) { _log.trace( "Added GroupingRange: [" + groupingRange.toString() + "] to _groupingRanges"); } groupingRecords = 0; continue; } for (int i = 1; i <= groupingMetaData.getColumnCount(); i++) { finalValues[i - 1] = new PreparedStatementTypedParameter(groupingResultSet.getObject(i), i * 2, groupingMetaData.getColumnType(i)); } } if (groupingRecords != 0 && stepping.intValue() != 1) { final GroupingRange finalgroupingRange = new GroupingRange(startValues, finalValues); _groupingRanges.add(finalgroupingRange); _log.debug( "Added final GroupingRange [" + finalgroupingRange.toString() + "] to _groupingRanges"); } } catch (final SQLException e1) { throw new CrawlerCriticalException("Encountered SQLException while preparing Groupings"); } finally { try { if (groupingStatement != null) { groupingStatement.close(); } } catch (final SQLException e) { _log.error("Could not closeGrouping statement"); } try { groupingResultSet.close(); _log.debug("Closed Grouping Resultset"); } catch (final SQLException e) { _log.error("Could not close Resultset for Grouping statement"); } } } // set current grouping to first grouping in list (if list is not empty) _groupingRangesIterator = _groupingRanges.iterator(); if (_groupingRangesIterator.hasNext()) { _currentGroupingRange = _groupingRangesIterator.next(); } _log.debug(String.format("Prepared %d grouping ranges based on specified stepping of %d", _groupingRanges.size(), stepping.intValue())); }