List of usage examples for java.lang Long Long
@Deprecated(since = "9") public Long(String s) throws NumberFormatException
From source file:de.iritgo.aktario.jdbc.LoadUser.java
/** * Perform the command./* w w w . j av a 2 s . c o m*/ */ public void perform() { if (properties.get("id") == null) { Log.logError("persist", "LoadUser", "Missing unique id for the user to load"); return; } long uniqueId = ((Long) properties.get("id")).longValue(); JDBCManager jdbcManager = (JDBCManager) Engine.instance().getManager("persist.JDBCManager"); DataSource dataSource = jdbcManager.getDefaultDataSource(); try { QueryRunner query = new QueryRunner(dataSource); final User user = (User) query.query("select * from IritgoUser where id=?", new Long(uniqueId), new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { if (rs.next()) { User user = new User(rs.getString("name"), rs.getString("email"), rs.getInt("id"), rs.getString("password"), 0); Server.instance().getUserRegistry().addUser(user); Engine.instance().getBaseRegistry().add(user); return user; } else { return null; } } }); if (user == null) { Log.logError("persist", "LoadUser", "Unable to find user with id " + uniqueId); return; } Log.logVerbose("persist", "LoadUser", "Successfully loaded user " + user.getName() + ":" + user.getUniqueId()); } catch (SQLException x) { Log.logError("persist", "LoadUser", "Error while loading the users: " + x); } }
From source file:net.sourceforge.fenixedu.util.CalendarUtil.java
public static Integer getNumberOfDaysBetweenDates(Date beginDate, Date endDate) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(beginDate);/*from w w w. jav a2s . c om*/ c2.setTime(endDate); long timeBetweenInMillis = c2.getTimeInMillis() - c1.getTimeInMillis(); Integer numberDaysBetweenDates = new Integer(new Long(timeBetweenInMillis / (3600000 * 24)).intValue()); return numberDaysBetweenDates; }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }/*from w w w . j a va2 s . c o m*/ if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:com.healthcit.cacure.model.TableQuestionTest.java
@Test @DataSet("classpath:skips_on_tables.xml") public void testGetSkipAffectees_multi() { TableQuestion tquest = em.find(TableQuestion.class, 1020L); Set<BaseSkipPatternDetail> skipAffectees = tquest.getSkipAffectees(); assertNotNull(skipAffectees);/*from w ww. ja va 2 s . c o m*/ assertEquals(1, skipAffectees.size()); BaseSkipPatternDetail detail = skipAffectees.toArray(new BaseSkipPatternDetail[0])[0]; assertEquals(new Long(1055), detail.getId()); assertEquals(new Long(1055), detail.getSkip().getId()); assertEquals(new Long(1035), detail.getFormElementId()); assertNull(detail.getFormId()); assertEquals(new Long(1008), detail.getSkipTriggerForm().getId()); assertEquals(new Long(1020), detail.getSkipTriggerQuestion().getId()); }
From source file:org.sakaiproject.imagegallery.springutil.BaseJdbcTemplate.java
/** * The default implementation assumes that the DB vendor and table definition * support JDBC 3.0 generated keys. Non-JDBC-3.0 DBs will need to hack another * implementation of this method.//from w w w . ja v a 2 s .c o m * * @param pscf object that provides SQL and the types of any required parameters * @param keyColumnName not used by some non-JDBC-3.0 DBs; needed for Oracle * even if there's only one candidate column since otherwise ROWNUM is returned * @param args the parameters for the query * @return the generated ID for the new record */ public Long insertAndReturnGeneratedId(PreparedStatementCreatorFactory pscf, String keyColumnName, Object... args) { pscf.setGeneratedKeysColumnNames(new String[] { keyColumnName }); KeyHolder keyHolder = new GeneratedKeyHolder(); getJdbcOperations().update(pscf.newPreparedStatementCreator(args), keyHolder); return new Long(keyHolder.getKey().longValue()); }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static boolean TakeSpawnerOutOfService(String spawnerType) { // Read ./SpawnerDropper.SpawnerStack.json into a string // get the value of JSON->{spawnerType} and subtract 1 to it unless it is 0. // If it's zero, return false // Write file back to disk try {/*from ww w . j a va 2 s .c o m*/ // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long numberInService = (Long) jsonObj.get(spawnerType); if (numberInService <= 0) { return false; } else { // System.out.println("[SD DBG MSG] TSOOS numberInServer("+numberInService+")"); numberInService -= 1; jsonObj.put(spawnerType, new Long(numberInService)); FileWriter file = new FileWriter("./plugins/SpawnerDropper/SpawnerStack.json"); file.write(jsonObj.toJSONString()); file.flush(); file.close(); return true; } } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return false; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } }
From source file:org.myjerry.evenstar.web.author.DeletePostController.java
public ModelAndView confirmedDeletePost(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = null;/*from w ww . ja va2 s . co m*/ String blogID = request.getParameter("blogID"); String postID = request.getParameter("postID"); boolean result = this.blogPostService.deletePost(new Long(postID), new Long(blogID)); if (result) { response.sendRedirect("/author/editPosts.html?blogID=" + blogID); } else { mav = new ModelAndView(); mav.addObject("errorString", "Unable to delete the post"); mav.setViewName(".author.deletePost"); } // delete the post // if successful redirect to editPosts.html return mav; }
From source file:com.glweb.module.forum.provider.hibernate.dao.CategoryDAOImpl.java
public Category getCategory(long categoryId) throws GLWebPersistenceException { Session _session = null;/*ww w. j a va 2s. co m*/ try { _session = HibernateUtil.retrieveDefaultSession(); return (Category) _session.load(Category.class, new Long(categoryId)); } catch (ObjectNotFoundException onfe) { return null; } catch (HibernateException he) { throw new GLWebPersistenceException(he); } finally { HibernateUtil.commitCloseSession(_session); } }
From source file:com.jiwhiz.domain.account.impl.UserAccountServiceImplTest.java
@Test public void createUserAccount_ShouldCreateNewUser() { ConnectionData data = new ConnectionData("google", "jiwhiz", "Yuan Ji", "https://plus.google.com/+YuanJi", "https://someurl", null, null, null, null); when(accountRepositoryMock.count()).thenReturn(new Long(1l)); when(accountRepositoryMock.save(isA(UserAccount.class))).thenAnswer(new Answer<UserAccount>() { @Override/* w ww . ja v a 2s . co m*/ public UserAccount answer(InvocationOnMock invocation) throws Throwable { UserAccount account = (UserAccount) invocation.getArguments()[0]; account.setId("user123"); return account; } }); UserAccount newAccount = serviceToTest.createUserAccount(data, UserProfile.EMPTY); assertEquals("Yuan Ji", newAccount.getDisplayName()); assertEquals("https://plus.google.com/+YuanJi", newAccount.getWebSite()); assertFalse(newAccount.isAdmin()); assertFalse(newAccount.isAuthor()); assertFalse(newAccount.isTrustedAccount()); verify(accountRepositoryMock, times(1)).save(isA(UserAccount.class)); }
From source file:com.jfootball.dao.hibernate.DivisionDaoImpl.java
/** * hibernateTemplate.find("from Division d order by d.id").list() * /* ww w . j a v a 2 s . co m*/ * @see com.jfootball.dao.DivisionDao#listDivisions() */ @SuppressWarnings("unchecked") public List<Division> listDivisions() { Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Division.class); criteria.add(Restrictions.gt("level", new Long(0))); criteria.addOrder(Order.asc("id")); return criteria.list(); }