List of usage examples for java.sql Date Date
public Date(long date)
From source file:nl.strohalm.cyclos.setup.migrations.version3_6.ClosedAccountBalancesMigration.java
private Date nextDay(final Date date) { final Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w . ja v a 2 s . c o m*/ calendar.add(Calendar.DAY_OF_MONTH, 1); return new Date(calendar.getTimeInMillis()); }
From source file:javadz.beanutils.locale.converters.SqlDateLocaleConverter.java
/** * Convert the specified locale-sensitive input object into an output object of the * specified type.// ww w. jav a2 s .co m * * @param value The input object to be converted * @param pattern The pattern is used for the convertion * @return The converted value * * @exception org.apache.commons.beanutils.ConversionException if conversion * cannot be performed successfully * @throws ParseException if an error occurs parsing a String to a Number */ protected Object parse(Object value, String pattern) throws ParseException { return new Date(((java.util.Date) super.parse(value, pattern)).getTime()); }
From source file:com.error.hunter.ListenService.java
@SuppressLint("SimpleDateFormat") private void writeLogsToFile(String errorType, String process) { try {/*from w ww . j a va 2s . co m*/ File root = new File(Environment.getExternalStorageDirectory(), this.getString(R.string.app_name)); if (!root.exists()) { root.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssZ"); String date = sdf.format(new Date(System.currentTimeMillis())); date = date.substring(0, 12); File errorFile = null; if (errorType.equals("ANR")) { strBuf.append(getCPUUsage()); errorFile = new File(root, "ANR_" + process + "_" + date + ".txt"); } else if (errorType.equals("CRASHED")) { errorFile = new File(root, "CRASH_" + process + "_" + date + ".txt"); } else if (errorType.equals("<unknown>")) { errorFile = new File(root, "unknown_" + process + "_" + date + ".txt"); } FileWriter writer = new FileWriter(errorFile); writer.append(strBuf.toString()); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:eu.supersede.dm.DMGame.java
public HProcess createEmptyProcess(String name) { HProcess proc = new HProcess(); proc.setObjective(DMObjective.PrioritizeRequirements.toString()); proc.setStartTime(new Date(System.currentTimeMillis())); proc.setPhaseName(lifecycle.getInitPhase().getName()); proc = jpa.processes.save(proc);/* w ww . ja v a 2 s . co m*/ if (name == null) { proc.setName("Process " + proc.getId()); } else { proc.setName(name); } proc = jpa.processes.save(proc); return proc; }
From source file:gov.nih.nci.integration.caaers.CaAERSParticipantStrategyTest.java
/** * Tests Update Participant Registration using the ServiceInvocationStrategy class for success case * /*from ww w . j a va2s .co m*/ * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException * @throws MalformedURLException - MalformedURLException * @throws SOAPFaultException - SOAPFaultException * @throws DatatypeConfigurationException - DatatypeConfigurationException * */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void updateParticipantRegistrationSuccess() throws IntegrationException, SOAPFaultException, MalformedURLException, JAXBException, DatatypeConfigurationException { final Date stTime = new Date(new java.util.Date().getTime()); xsltTransformer.transform(null, null, null); EasyMock.expectLastCall().andAnswer(new IAnswer() { public Object answer() { return getParticipantXMLString(); } }).anyTimes(); final CaaersServiceResponse updateParticipantResponse = getUpdateParticipantResponse(SUCCESS); final CaaersServiceResponse getParticipantResponse = getParticipantResponse(SUCCESS); EasyMock.expect(wsClient.updateParticipant((String) EasyMock.anyObject())) .andReturn(updateParticipantResponse).anyTimes(); EasyMock.expect(wsClient.getParticipant((String) EasyMock.anyObject())).andReturn(getParticipantResponse); EasyMock.replay(wsClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getParticipantInterimMessage(), stTime, caAERSUpdateRegistrationServiceInvocationStrategy.getStrategyIdentifier()); final ServiceInvocationResult result = caAERSUpdateRegistrationServiceInvocationStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(result); }
From source file:org.kuali.coeus.common.budget.impl.nonpersonnel.BudgetJustificationServiceImpl.java
/** * This method updates the Justification text meta-data with the user and date/time * @param budgetJustificationWrapper/*from ww w .java 2 s . c o m*/ */ protected void updateJustficationMetaData(BudgetJustificationWrapper budgetJustificationWrapper) { String updateUser = getLoggedInUserNetworkId(); budgetJustificationWrapper.setLastUpdateUser(updateUser); budgetJustificationWrapper.setLastUpdateTime(new Date(System.currentTimeMillis())); }
From source file:com.tremolosecurity.provisioning.core.providers.BasicDB.java
private void insertCreate(User user, Set<String> attributes, Map<String, Attribute> attrs, Connection con, Map<String, Object> request) throws SQLException, ProvisioningException { int approvalID = 0; if (request.containsKey("APPROVAL_ID")) { approvalID = (Integer) request.get("APPROVAL_ID"); }/* ww w. ja v a 2 s . c o m*/ Workflow workflow = (Workflow) request.get("WORKFLOW"); StringBuffer insert = new StringBuffer(); insert.append("INSERT INTO ").append(this.userTable).append(" ("); for (String attr : attributes) { if (attrs.get(attr) != null) { getFieldName(attr, insert).append(","); } } insert.setLength(insert.length() - 1); insert.append(") values ("); for (String attr : attributes) { if (attrs.get(attr) != null) { insert.append("?,"); } } insert.setLength(insert.length() - 1); insert.append(")"); PreparedStatement ps = con.prepareStatement(insert.toString(), Statement.RETURN_GENERATED_KEYS); int i = 1; for (String attr : attributes) { if (attrs.get(attr) != null) { Attribute.DataType dataType = attrs.get(attr).getDataType(); switch (dataType) { case string: ps.setString(i, attrs.get(attr).getValues().get(0)); break; case intNum: ps.setInt(i, Integer.parseInt(attrs.get(attr).getValues().get(0))); break; case longNum: ps.setLong(i, Long.parseLong(attrs.get(attr).getValues().get(0))); break; case date: ps.setDate(i, new Date(ISODateTimeFormat.date() .parseDateTime(attrs.get(attr).getValues().get(0)).getMillis())); break; case timeStamp: ps.setTimestamp(i, new Timestamp(ISODateTimeFormat.dateTime() .parseDateTime(attrs.get(attr).getValues().get(0)).getMillis())); break; } i++; } } ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); int id; if (rs.next() && !this.driver.contains("oracle")) { id = (int) rs.getInt(1); } else { StringBuffer select = new StringBuffer(); select.append("SELECT "); this.getFieldName(this.userPrimaryKey, select).append(" FROM ").append(this.userTable) .append(" WHERE "); this.getFieldName(this.userName, select).append("=?"); PreparedStatement getUserId = con.prepareStatement(select.toString()); //con.prepareStatement( + this.userPrimaryKey + " FROM " + this.userTable + " WHERE " + this.userName + "=?"); getUserId.setString(1, user.getUserID()); ResultSet userResult = getUserId.executeQuery(); userResult.next(); id = (int) userResult.getInt(this.userPrimaryKey); userResult.close(); getUserId.close(); } this.cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Add, approvalID, workflow, "userName", user.getUserID()); for (String attr : attributes) { if (attrs.get(attr) != null) { this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, attr, attrs.get(attr).getValues().get(0)); } } if (user.getGroups().size() > 0) { switch (this.groupMode) { case None: break; case One2Many: insert.setLength(0); insert.append("INSERT INTO ").append(this.groupTable).append(" (").append(this.groupUserKey) .append(",").append(this.groupName).append(") VALUES (?,?)"); ps = con.prepareStatement(insert.toString()); for (String groupName : user.getGroups()) { ps.setInt(1, id); ps.setString(2, groupName); ps.executeUpdate(); this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, "group", groupName); } break; case Many2Many: many2manySetGroupsCreate(user, insert, con, id, request); break; } } }
From source file:su90.mybatisdemo.dao.Job_HistoryMapperTest.java
@Test(groups = { "delete" }, dependsOnGroups = { "update", "insert" }, enabled = false) public void testDelete() { Employee emp = employeesMapper.findById(167L); try {/*from ww w . j a v a2 s.c o m*/ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); java.util.Date start_util_date = formatter.parse("19900101071010"); Job_History.Key thekey = new Job_History.Key(emp, new Date(start_util_date.getTime())); job_HistoryMapper.deleteById(thekey); assertNull(job_HistoryMapper.findById(thekey)); } catch (ParseException ex) { assertTrue(false); } }
From source file:commondb.mock.MockResultSet.java
@Override /**//from w ww.jav a2 s . c om * Dates are expected to be formatted as yyyy-MM-dd. * See http://en.wikipedia.org/wiki/ISO_8601#Calendar_dates */ public Date getDate(int columnIndex) throws SQLException { try { String value = getValue(columnIndex); Date date = null; if ((value != null) && (value.trim().length() >= 0)) { date = new Date(DATE_ISO_8601.parse(value).getTime()); } return date; } catch (Exception e) { throw new SQLException(e); } }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
private Date getSystemReleaseDate(String releaseId) throws Exception { String sYear = releaseId.substring(0, 4); int year = new Integer(sYear).intValue(); String sMonth = releaseId.substring(4); int mon = 0;/* w w w. java2 s .co m*/ Calendar cal = Calendar.getInstance(); if ("AA".equalsIgnoreCase(sMonth)) { mon = Calendar.JANUARY; } else if ("AB".equalsIgnoreCase(sMonth)) { mon = Calendar.APRIL; } else if ("AC".equalsIgnoreCase(sMonth)) { mon = Calendar.JULY; } else if ("AD".equalsIgnoreCase(sMonth)) { mon = Calendar.OCTOBER; } else { try { int i = Integer.parseInt(sMonth); switch (i) { case 1: mon = Calendar.JANUARY; break; case 2: mon = Calendar.FEBRUARY; break; case 3: mon = Calendar.MARCH; break; case 4: mon = Calendar.APRIL; break; case 5: mon = Calendar.MAY; break; case 6: mon = Calendar.JUNE; break; case 7: mon = Calendar.JULY; break; case 8: mon = Calendar.AUGUST; break; case 9: mon = Calendar.SEPTEMBER; break; case 10: mon = Calendar.OCTOBER; break; case 11: mon = Calendar.NOVEMBER; break; case 12: mon = Calendar.DECEMBER; break; default: throw new Exception("Release ID is not in required format: " + sMonth); } } catch (NumberFormatException e) { throw new Exception("Release ID is not in required format." + sMonth); } } cal.set(year, mon, 01, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); return new Date(cal.getTimeInMillis()); }