List of usage examples for java.lang Long intValue
public int intValue()
From source file:dbsimulator.dal.mysql.MySqlSimDal.java
@Override public int loginStudent(String keyValuesString, _Ref<String> error) { try (SQLConnection connection = getSQLConnection()) { Map<String, String> keyValues = new HashMap<>(); for (String line : StringUtils.split(keyValuesString, ';')) { String[] parts = StringUtils.split(line, ":", 2); if (parts.length < 2 || StringUtils.isEmpty(parts[0])) { continue; }// w w w .j a v a 2s. c om keyValues.put(parts[0], parts[1]); } MultiDataResultSet sets = _studentdll.T_Login_SP(connection, getClientName(), keyValues, getSessionID()); Iterator<SingleDataResultSet> iter = sets.getResultSets(); // First set if (iter.hasNext()) { SingleDataResultSet rs = iter.next(); DbResultRecord rec = rs.getRecords().next(); String status = rec.<String>get("status"); if ("failed".equalsIgnoreCase(status)) { error.set(status); return 0; } if (rec.hasColumn("entitykey")) { Long ent = rec.<Long>get("entityKey"); return ent.intValue(); } } } catch (SQLException se) { _logger.error(se.getMessage()); } catch (ReturnStatusException re) { _logger.error(re.getMessage()); } return 0; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
public long getBiospecimenCount(Biospecimen biospecimenCriteria) { // Handle for study not in context if (biospecimenCriteria.getStudy() == null) { return 0; }//from w w w . j a v a 2 s . co m Criteria criteria = buildBiospecimenCriteria(biospecimenCriteria); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); return totalCount.intValue(); }
From source file:eu.europa.ec.markt.dss.validation102853.https.CommonDataLoader.java
/** * Configure the proxy with the required credential if needed * * @param httpClientBuilder/*from w w w . j a v a2 s .co m*/ * @param credentialsProvider * @param uri * @return */ private HttpClientBuilder configureProxy(final HttpClientBuilder httpClientBuilder, final CredentialsProvider credentialsProvider, final URI uri) throws DSSException { if (proxyPreferenceManager == null) { return httpClientBuilder; } final String protocol = uri.getScheme(); final boolean proxyHTTPS = Protocol.isHttps(protocol) && proxyPreferenceManager.isHttpsEnabled(); final boolean proxyHTTP = Protocol.isHttp(protocol) && proxyPreferenceManager.isHttpEnabled(); if (!proxyHTTPS && !proxyHTTP) { return httpClientBuilder; } String proxyHost = null; int proxyPort = 0; String proxyUser = null; String proxyPassword = null; if (proxyHTTPS) { LOG.debug("Use proxy https parameters"); final Long port = proxyPreferenceManager.getHttpsPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpsHost(); proxyUser = proxyPreferenceManager.getHttpsUser(); proxyPassword = proxyPreferenceManager.getHttpsPassword(); } else if (proxyHTTP) { // noinspection ConstantConditions LOG.debug("Use proxy http parameters"); final Long port = proxyPreferenceManager.getHttpPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpHost(); proxyUser = proxyPreferenceManager.getHttpUser(); proxyPassword = proxyPreferenceManager.getHttpPassword(); } if (DSSUtils.isNotEmpty(proxyUser) && DSSUtils.isNotEmpty(proxyPassword)) { AuthScope proxyAuth = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); credentialsProvider.setCredentials(proxyAuth, proxyCredentials); } LOG.debug("proxy host/port: " + proxyHost + ":" + proxyPort); // TODO SSL peer shut down incorrectly when protocol is https final HttpHost proxy = new HttpHost(proxyHost, proxyPort, Protocol.HTTP.getName()); httpClientBuilder.setProxy(proxy); updated = false; return httpClientBuilder; }
From source file:com.tesora.dve.sql.statement.dml.SelectStatement.java
private void normalizeSorts(SchemaContext pc, Map<RewriteKey, ExpressionNode> projMap, Edge<?, ?> in) { @SuppressWarnings("unchecked") MultiEdge<?, SortingSpecification> min = (MultiEdge<?, SortingSpecification>) in; for (SortingSpecification ss : min.getMulti()) { ExpressionNode target = ss.getTarget(); if (target instanceof AliasInstance) continue; else if (target instanceof LiteralExpression) { // i.e. order by 1,2,3 LiteralExpression le = (LiteralExpression) target; Object value = le.getValue(pc.getValues()); if (value instanceof Long) { Long index = (Long) value; if ((index.intValue() - 1) < projection.size()) { target = ExpressionUtils.getTarget(projection.get(index.intValue() - 1)); }/*from w w w . j av a 2s . com*/ } } ExpressionNode inProjection = projMap.get(target.getRewriteKey()); if (inProjection != null) { ExpressionAlias ea = (ExpressionAlias) inProjection.getParent(); AliasInstance ai = ea.buildAliasInstance(); ss.getTargetEdge().set(ai); } } }
From source file:com.fer.hr.web.rest.resources.Query2Resource.java
/** * Drill through on the query result set. * @summary Drill through/*from w ww . ja v a 2 s. c o m*/ * @param queryName The query name * @param maxrows The max rows returned * @param position The position * @param returns The returned dimensions and levels * @return A query result set. */ @GET @Produces({ "application/json" }) @Path("/{queryname}/drillthrough") public QueryResult drillthrough(@PathParam("queryname") String queryName, @QueryParam("maxrows") @DefaultValue("100") Integer maxrows, @QueryParam("position") String position, @QueryParam("returns") String returns) { if (log.isDebugEnabled()) { log.debug("TRACK\t" + "\t/query/" + queryName + "/drillthrough\tGET"); } QueryResult rsc; ResultSet rs = null; try { Long start = (new Date()).getTime(); if (position == null) { rs = thinQueryService.drillthrough(queryName, maxrows, returns); } else { String[] positions = position.split(":"); List<Integer> cellPosition = new ArrayList<>(); for (String p : positions) { Integer pInt = Integer.parseInt(p); cellPosition.add(pInt); } rs = thinQueryService.drillthrough(queryName, cellPosition, maxrows, returns); } rsc = RestUtil.convert(rs); Long runtime = (new Date()).getTime() - start; rsc.setRuntime(runtime.intValue()); } catch (Exception e) { log.error("Cannot execute query (" + queryName + ")", e); String error = ExceptionUtils.getRootCauseMessage(e); rsc = new QueryResult(error); } finally { if (rs != null) { Statement statement = null; try { statement = rs.getStatement(); } catch (Exception e) { throw new SaikuServiceException(e); } finally { try { rs.close(); if (statement != null) { statement.close(); } } catch (Exception ee) { } } } } return rsc; }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp getDayEnd(Timestamp stamp, Long daysLater, TimeZone timeZone, Locale locale) { Calendar tempCal = toCalendar(stamp, timeZone, locale); tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 23, 59, 59);/*w w w . ja va2 s . c o m*/ tempCal.add(Calendar.DAY_OF_MONTH, daysLater.intValue()); Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis()); retStamp.setNanos(0); // MSSQL datetime field has accuracy of 3 milliseconds and setting the // nano seconds cause the date to be rounded to next day // retStamp.setNanos(999999999); return retStamp; }
From source file:cache.service.impl.JedisServiceImpl.java
@Override public int zaddAndRem(String key, double score, String member, int maxLength) { if (enabled) { notEmptyKey(key);// w ww.jav a 2 s. c o m ShardedJedis jedis = null; try { int newElementNum = 0; int elementNum = 0; jedis = shardedJedisPool.getResource(); ShardedJedisPipeline pipeline = jedis.pipelined(); Response<Long> zaddResponse = pipeline.zadd(key, score, member); Response<Long> zcardResponse = pipeline.zcard(key); pipeline.sync(); Long zaddRes = zaddResponse.get(); if (zaddRes != null) { newElementNum = zaddRes.intValue(); } Long zcardRes = zcardResponse.get(); if (zcardRes != null) { elementNum = zcardRes.intValue(); } if (newElementNum > 0 && elementNum > maxLength) { this.asynShrinkZset(key, elementNum, maxLength); } return newElementNum; } catch (JedisException e) { logger.error("'zaddAndRem' key fail, key: {}, score: {}, member: {}, maxLength: {}", key, score, member, maxLength); logger.error(e.getMessage(), e); } finally { close(jedis); } } return 0; }
From source file:cache.service.impl.JedisServiceImpl.java
@Override public int zaddAndRem(String key, Map<String, Double> scoreMembers, int maxLength) { if (enabled) { notEmptyKey(key);//from w w w . j a v a 2 s . com ShardedJedis jedis = null; try { int newElementNum = 0; int elementNum = 0; jedis = shardedJedisPool.getResource(); ShardedJedisPipeline pipeline = jedis.pipelined(); Response<Long> zaddResponse = pipeline.zadd(key, scoreMembers); Response<Long> zcardResponse = pipeline.zcard(key); pipeline.sync(); Long zaddRes = zaddResponse.get(); if (zaddRes != null) { newElementNum = zaddRes.intValue(); } Long zcardRes = zcardResponse.get(); if (zcardRes != null) { elementNum = zcardRes.intValue(); } if (newElementNum > 0 && elementNum > maxLength) { this.asynShrinkZset(key, elementNum, maxLength); } return newElementNum; } catch (JedisException e) { logger.error("'zaddAndRem' key fail, key: {}, scoreMembers: {}, maxLength: {}", key, scoreMembers, maxLength); logger.error(e.getMessage(), e); } finally { close(jedis); } } return 0; }
From source file:com.twineworks.kettle.ruby.step.execmodels.SimpleExecutionModel.java
private void applyRubyHashToRow(Object[] r, RubyHash resultRow, List<ValueMetaInterface> forFields, RowMetaInterface forRow) throws KettleException { // set each field's value from the resultRow for (ValueMetaInterface outField : forFields) { IRubyObject rubyVal = resultRow.fastARef(data.rubyStringCache.get(outField.getName())); // convert simple cases automatically Object javaValue = null;//from w w w . j av a 2s . c o m // for nil values just put null into the row if (rubyVal != null && !rubyVal.isNil()) { // TODO: provide a meaningful error message if conversion fails because the user put non-convertible results in there (like a string saying "true"/"false" for the bool type) switch (outField.getType()) { case ValueMetaInterface.TYPE_BOOLEAN: javaValue = JavaEmbedUtils.rubyToJava(data.runtime, rubyVal, Boolean.class); break; case ValueMetaInterface.TYPE_INTEGER: javaValue = JavaEmbedUtils.rubyToJava(data.runtime, rubyVal, Long.class); break; case ValueMetaInterface.TYPE_STRING: javaValue = rubyVal.toString(); break; case ValueMetaInterface.TYPE_NUMBER: javaValue = JavaEmbedUtils.rubyToJava(data.runtime, rubyVal, Double.class); break; case ValueMetaInterface.TYPE_SERIALIZABLE: String marshalled = getMarshal().callMethod(data.runtime.getCurrentContext(), "dump", rubyVal) .toString(); javaValue = new RubyStepMarshalledObject(marshalled); break; case ValueMetaInterface.TYPE_BINARY: // TODO: provide meaningful error message if this fails RubyArray arr = rubyVal.convertToArray(); byte[] bytes = new byte[arr.size()]; for (int i = 0; i < bytes.length; i++) { Object rItem = arr.get(i); if (rItem instanceof Number) { bytes[i] = ((Number) rItem).byteValue(); } else { throw new KettleException("Found a non-number in Binary field " + outField.getName() + ": " + rItem.toString()); } } javaValue = bytes; break; case ValueMetaInterface.TYPE_BIGNUMBER: if (rubyVal instanceof RubyFloat) { javaValue = new BigDecimal((Double) rubyVal.toJava(Double.class)); } else { javaValue = new BigDecimal(rubyVal.toString()); } break; case ValueMetaInterface.TYPE_DATE: if (rubyVal instanceof RubyFixnum) { javaValue = new Date(((RubyFixnum) rubyVal).getLongValue()); } else if (rubyVal instanceof RubyTime) { javaValue = ((RubyTime) rubyVal).getJavaDate(); } else { throw new KettleException( "cannot convert ruby value " + rubyVal.toString() + " to java Date"); } break; case ValueMetaInterface.TYPE_TIMESTAMP: if (rubyVal instanceof RubyFixnum) { javaValue = new java.sql.Timestamp(((RubyFixnum) rubyVal).getLongValue()); } else if (rubyVal instanceof RubyTime) { RubyTime time = (RubyTime) rubyVal; long millis = time.getDateTime().getMillis(); Timestamp ts = new java.sql.Timestamp(millis / 1000 * 1000); ts.setNanos((int) ((time.getNSec()) + (millis % 1000 * 1000000))); javaValue = ts; } else { throw new KettleException( "cannot convert ruby value " + rubyVal.toString() + " to java.sql.Timestamp"); } break; case ValueMetaInterface.TYPE_INET: Long longNum = (Long) data.container.callMethod(rubyVal, "to_i"); javaValue = toInetAddress(longNum.intValue()); break; } } r[data.fieldIndexCache.get(forRow).get(outField.getName())] = javaValue; } }
From source file:com.ikanow.aleph2.shared.crud.mongodb.services.MongoDbCrudService.java
@Override public CompletableFuture<Cursor<O>> getObjectsBySpec(final QueryComponent<O> spec, final List<String> field_list, final boolean include) { try {//w ww. j av a2s .co m final Tuple2<DBObject, DBObject> query_and_meta = MongoDbUtils.convertToMongoQuery(spec); final DBCursor<O> cursor = Optional.of(Patterns.match(query_and_meta).<DBCursor<O>>andReturn() .when(qm -> field_list.isEmpty(), qm -> _state.coll.find(qm._1())).otherwise(qm -> { final BasicDBObject fields = getFields(field_list, include); return _state.coll.find(qm._1(), fields); })) // (now we're processing on a cursor "c") .map(c -> { final DBObject sort = (DBObject) query_and_meta._2().get("$sort"); return (null != sort) ? c.sort(sort) : c; }).map(c -> { final Long limit = (Long) query_and_meta._2().get("$limit"); return (null != limit) ? c.limit(limit.intValue()) : c; }).get(); return CompletableFuture.completedFuture(new MongoDbCursor<O>(cursor)); } catch (Exception e) { return FutureUtils.<Cursor<O>>returnError(e); } }