List of usage examples for java.lang Long longValue
@HotSpotIntrinsicCandidate public long longValue()
From source file:net.sf.sze.frontend.zeugnis.ZeugnisController.java
/** * Zeigt die BU und SoL-Bewertung an./*from w ww. j a va 2 s.c om*/ * @param halbjahrId die Id des Schulhalbjahres * @param klassenId die Id der Klasse * @param schuelerId die Id des Schuelers * @param model das Model * @return die logische View */ @RequestMapping(value = URL.ZeugnisPath.ZEUGNIS_EDIT_BU_SOL, method = RequestMethod.GET) public String editBuSoL(@PathVariable(URL.Session.P_HALBJAHR_ID) Long halbjahrId, @PathVariable(URL.Session.P_KLASSEN_ID) Long klassenId, @PathVariable(URL.Session.P_SCHUELER_ID) Long schuelerId, Model model) { final Zeugnis zeugnis = zeugnisErfassungsService.getZeugnis(halbjahrId, schuelerId); final SchuelerList schuelerList = schuelerService.getSchuelerWithZeugnis(halbjahrId.longValue(), klassenId.longValue(), schuelerId); fillBuSoLModel(model, halbjahrId, klassenId, schuelerId, zeugnis, schuelerList.getPrevSchuelerId(), schuelerList.getNextSchuelerId()); return EDIT_ZEUGNIS_BU_SOL; }
From source file:com.oodlemud.appengine.counter.service.ShardedCounterServiceImpl.java
/** * Increment the memcache version of the named-counter by {@code amount} * (positive or negative) in an atomic fashion. Use memcache as a * Semaphore/Mutex, and retry up to 10 times if other threads are attempting * to update memcache at the same time. If nothing is in Memcache when this * function is called, then do nothing because only #getCounter should "put" * a value to memcache.// ww w .j a v a2s .c o m * * @param counterName * @param amount * @return The new count of this counter as reflected by memcache */ @VisibleForTesting protected Optional<Long> incrementMemcacheAtomic(final String counterName, final long amount) { // Memcache update did not succeed! if (!isMemcacheAvailable()) { return Optional.absent(); } // Get the cache counter at a current point in time. String memCacheKey = this.assembleCounterKeyforMemcache(counterName); int numRetries = 10; while (numRetries > 0) { try { IdentifiableValue identifiableCounter = memcacheService.getIdentifiable(memCacheKey); // See Javadoc about a null identifiableCounter. If it's null, // then the named counter doesn't exist in memcache. if (identifiableCounter == null || (identifiableCounter != null && identifiableCounter.getValue() == null)) { if (getLogger().isLoggable(Level.FINE)) { getLogger().fine( "No identifiableCounter was found in Memcache. Unable to Atomically increment for CounterName \"" + counterName + "\". Memcache will be populated on the next called to getCounter()!"); } // This will return an absent value. Only #getCounter should // "put" a value to memcache. break; } // If we get here, the count exists in memcache, so it can be // atomically incremented. Long cachedCounterAmount = (Long) identifiableCounter.getValue(); long newMemcacheAmount = cachedCounterAmount.longValue() + amount; if (newMemcacheAmount < 0) { newMemcacheAmount = 0; } if (getLogger().isLoggable(Level.FINE)) { getLogger().fine("Just before Atomic Increment of " + amount + ", Memcache has value " + identifiableCounter.getValue()); } if (memcacheService.putIfUntouched(counterName, identifiableCounter, new Long(newMemcacheAmount), config.getDefaultExpiration())) { if (getLogger().isLoggable(Level.FINE)) { getLogger().fine("memcacheService.putIfUntouched SUCCESS! with value " + newMemcacheAmount); } // If we get here, the put succeeded... return Optional.of(new Long(newMemcacheAmount)); } else { if (getLogger().isLoggable(Level.WARNING)) { getLogger().log(Level.WARNING, "Unable to update memcache counter atomically. Retrying " + numRetries + " more times..."); } } } catch (MemcacheServiceException mse) { // Check and post-decrement the numRetries counter in one step if (numRetries-- > 0) { if (getLogger().isLoggable(Level.WARNING)) { getLogger().log(Level.WARNING, "Unable to update memcache counter atomically. Retrying " + numRetries + " more times...", mse); } // Keep trying... continue; } else { // Evict the counter here, and let the next call to // getCounter populate memcache getLogger().log(Level.SEVERE, "Unable to update memcache counter atomically, with no more allowed retries. Evicting counter named " + counterName + " from the cache!", mse); memcacheService.delete(memCacheKey); break; } } } // The increment did not work... return Optional.absent(); }
From source file:org.openregistry.core.repository.jpa.JpaPersonRepository.java
public Person fetchCompleteCalculatedPerson(Long id) { return (Person) this.entityManager.createQuery("Select p from person " + " p left join fetch p.identifiers i left join fetch i.type left join fetch p.names left join fetch p.roles r left join fetch p.disclosureSettings d left join fetch r.urls left join fetch r.emailAddresses " + "left join fetch r.phones left join fetch r.addresses left join fetch r.organizationalUnit left join fetch d.addressDisclosureSettings " + " left join fetch d.emailDisclosureSettings left join fetch d.phoneDisclosureSettings left join fetch d.urlDisclosureSettings where p.id = :id") .setParameter("id", id.longValue()).getSingleResult(); }
From source file:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java
public void testGettingMovieAndMaybeFavorite() { mContext.getContentResolver().delete(MovieContract.FavoriteEntry.CONTENT_URI, null, null); Map<Long, ContentValues> listContentValues = TestUtilities.createSortedMovieValues(getContext(), "popular"); ContentValues[] arr = (ContentValues[]) listContentValues.values().toArray(new ContentValues[0]); mContext.getContentResolver().bulkInsert(MovieContract.MovieEntry.CONTENT_URI, arr); ContentValues[] movie_ids = new ContentValues[arr.length]; for (int i = 0; i < arr.length; i++) (movie_ids[i] = new ContentValues()).put(MovieContract.RatingEntry.COLUMN_MOVIE_ID, arr[i].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID)); mContext.getContentResolver().bulkInsert(MovieContract.FavoriteEntry.CONTENT_URI, movie_ids); TestUtilities.verifyFavoriteValuesInDatabase(listContentValues, mContext); Long expected = movie_ids[0].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID); Cursor c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected), null, null, null, null);//from w w w .j av a2 s . c o m assertTrue(c.moveToFirst()); assertEquals(2, c.getCount()); assertEquals(expected.longValue(), c.getLong(0)); assertTrue(c.moveToNext()); assertTrue(c.getBlob(1).length > 0); c.close(); mContext.getContentResolver().delete(MovieContract.FavoriteEntry.buildUri(), MovieContract.FavoriteEntry.COLUMN_MOVIE_ID + "=?", new String[] { expected.toString() }); c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected), null, null, null, null); assertTrue(c.moveToFirst()); assertEquals(1, c.getCount()); assertTrue(c.getBlob(1).length > 0); }
From source file:com.wabacus.system.assistant.EditableReportAssistant.java
public synchronized String getAutoIncrementIdValue(ReportRequest rrequest, ReportBean rbean, String datasource, String paramname) {//from w w w. ja va 2 s .c o m if (paramname == null || paramname.trim().equals("")) return "-1"; if (datasource == null) datasource = ""; String key = datasource + "__" + paramname; Long lid = mAllAutoIncrementIdValues.get(key); if (lid == null || lid.longValue() < 0) { String realparamname = Tools.getRealKeyByDefine("increment", paramname); int idx = realparamname.indexOf("."); if (idx < 0) { throw new WabacusRuntimeException("" + rbean.getPath() + "?" + paramname + "??????."); } String tablename = realparamname.substring(0, idx).trim(); String columnname = realparamname.substring(idx + 1).trim(); if (tablename.trim().equals("") || columnname.trim().equals("")) { throw new WabacusRuntimeException("" + rbean.getPath() + "?" + paramname + "??????"); } String sid = "-1"; Connection conn = rrequest.getConnection(datasource); Statement stmt = null; ResultSet rs = null; String sql = "select max(" + columnname + ") from " + tablename; try { stmt = conn.createStatement(); rs = stmt.executeQuery(sql); if (rs.next()) { sid = rs.getString(1); } } catch (SQLException e) { throw new WabacusRuntimeException( "?" + rbean.getPath() + "?" + realparamname + "", e); } finally { try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); } WabacusAssistant.getInstance().release(null, stmt); } lid = Long.valueOf(sid); } mAllAutoIncrementIdValues.put(key, ++lid); return String.valueOf(lid); }
From source file:de.blizzy.backup.restore.RestoreDialog.java
private Entry toEntry(Record record, boolean fullPaths) { int id = record.getValue(Tables.ENTRIES.ID).intValue(); Integer parentIdInt = record.getValue(Tables.ENTRIES.PARENT_ID); int parentId = (parentIdInt != null) ? parentIdInt.intValue() : -1; String name = record.getValue(Tables.ENTRIES.NAME); EntryType type = EntryType.fromValue(record.getValue(Tables.ENTRIES.TYPE).intValue()); Timestamp createTime = record.getValue(Tables.ENTRIES.CREATION_TIME); Date creationTime = (createTime != null) ? new Date(createTime.getTime()) : null; Timestamp modTime = record.getValue(Tables.ENTRIES.MODIFICATION_TIME); Date modificationTime = (modTime != null) ? new Date(modTime.getTime()) : null; boolean hidden = record.getValue(Tables.ENTRIES.HIDDEN).booleanValue(); Long lengthLong = record.getValue(Tables.FILES.LENGTH); long length = (lengthLong != null) ? lengthLong.longValue() : -1; String backupPath = record.getValue(Tables.FILES.BACKUP_PATH); Byte compressionByte = record.getValue(Tables.FILES.COMPRESSION); Compression compression = (compressionByte != null) ? Compression.fromValue(compressionByte.intValue()) : null;/* ww w .j a v a2 s. c o m*/ Entry entry = new Entry(id, parentId, name, type, creationTime, modificationTime, hidden, length, backupPath, compression); if (fullPaths) { entry.fullPath = getFolderPath(parentId); } return entry; }
From source file:com.exp.tracker.services.impl.JpaExpenseService.java
@Transactional(readOnly = true) public ExpenseDetail getExpenseById(Long id) { ExpenseEntity returnExpenseEntity = null; Query queryGetExpenseById = em.createNamedQuery("getExpenseById"); queryGetExpenseById.setParameter("id", id); ExpenseEntity ee = (ExpenseEntity) queryGetExpenseById.getSingleResult(); if (null != ee.getSettlementId()) { // this means record has been settled. Query queryGetSettlementForId = em.createNamedQuery("getSettlementForId"); queryGetSettlementForId.setParameter("id", ee.getSettlementId()); SettlementEntity se = (SettlementEntity) queryGetSettlementForId.getSingleResult(); for (ExpenseEntity ee1 : se.getExpenseSet()) { if (id.longValue() == ee1.getId().longValue()) { returnExpenseEntity = ee1; break; }// www .ja v a 2s. co m } } else { returnExpenseEntity = ee; } return new ExpenseDetail(returnExpenseEntity); }
From source file:ar.com.zauber.commons.moderation.HibernateRepositoryModerationTest.java
/** Guardar una entrada de moderacion mediante un repositorio genrico */ @Test//from w w w . j a va2 s. c om public final void testSaveModerationEntry() { final Date date = new Date(); final DateProvider dateProvider = new InmutableDateProvider(date); final AuthenticationUserMapper<String> aum = new MockAuthenticationUser<String>(ANONYMOUS); final Moderateable entity = new MockRepositoryModerateableEntity(open, moderationEntryRepository); repository.saveOrUpdate(entity); final Long id = entity.getId(); final ModerationEntry entry = new MockInmutableModerationEntry( (Reference<Moderateable>) entity.generateReference(), open, closed, dateProvider.getDate(), aum.getUser()); repository.saveOrUpdate(entry); repository.getHibernateTemplate().flush(); repository.getHibernateTemplate().clear(); Reference<?> aRef = entry.generateReference(); final ModerationEntry entryFromDb = (ModerationEntry) repository.retrieve(aRef); Assert.assertEquals(open, entryFromDb.getInitialState()); Assert.assertEquals(closed, entryFromDb.getFinalState()); Assert.assertEquals(ANONYMOUS, entryFromDb.getModeratedBy()); Assert.assertEquals(date, entryFromDb.getModeratedAt()); Assert.assertEquals(id.longValue(), entryFromDb.getEntityReference().getId()); Assert.assertEquals(entity.getClass().getName(), entryFromDb.getEntityReference().getClazz().getName()); }
From source file:com.icesoft.faces.application.D2DViewHandler.java
protected long getTimeAttribute(UIComponent root, String key) { Long timeLong = (Long) root.getAttributes().get(key); long time = (null == timeLong) ? 0 : timeLong.longValue(); return time;/* w ww . ja va 2 s .co m*/ }
From source file:net.solarnetwork.node.power.enasolar.ws.EnaSolarXMLDatumDataSource.java
private EnaSolarPowerDatum validateDatum(EnaSolarPowerDatum datum) { final Long currValue = datum.getWattHourReading(); final Long zeroWattCount = zeroWattCount(); final Long lastKnownValue = lastKnownValue(); final boolean dailyResettingWh = datum.isUsingDailyResettingTotal(); // we've seen values reported less than last known value after // a power outage (i.e. after inverter turns off, then back on) // on single day, so we verify that current decaWattHoursTotal is not less // than last known decaWattHoursTotal value if (currValue != null && currValue.longValue() < lastKnownValue.longValue() && (dailyResettingWh == false || (dailyResettingWh && zeroWattCount < 1L))) { log.warn("Inverter [{}] reported value {} -- less than last known value {}. Discarding this datum.", sourceId, currValue, lastKnownValue); datum = null;/*from w ww . j a v a2 s . co m*/ } else if (currValue != null && currValue.longValue() < 1L && dailyResettingWh && isSampleOnSameDay(datum.getCreated()) == false) { log.debug("Resetting last known sample for new day zero Wh"); sample = datum; datum = null; } else if (datum.getWatts() == null || datum.getWatts() < 1) { final Long newCount = (zeroWattCount.longValue() + 1); if (zeroWattCount >= ZERO_WATT_THRESHOLD) { log.debug("Skipping zero-watt reading #{}", zeroWattCount); datum = null; } validationCache.put(SETTING_ZERO_WATT_COUNT, newCount); } else if (zeroWattCount > 0) { // reset zero-watt counter log.debug("Resetting zero-watt reading count from non-zero reading"); validationCache.remove(SETTING_ZERO_WATT_COUNT); } // everything checks out return datum; }