List of usage examples for java.sql Date Date
public Date(long date)
From source file:net.nineapps.hystqio.controller.HibernateLinkDAO.java
public Link add(Link link) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*w w w. j a v a 2 s . com*/ Query query = session.createQuery("from Link where url = :url"); query.setString("url", link.getUrl()); Link oldLink = (Link) query.uniqueResult(); if (null != oldLink) return oldLink; session.save(link); if (null == link.getShortCode()) { link.setShortCode(generateShortcode(session)); link.setClicks(new Long(0)); link.setCreated(new Date(new java.util.Date().getTime())); session.save(link); } session.getTransaction().commit(); return link; }
From source file:su90.mybatisdemo.dao.Job_HistoryMapperTest.java
@Test(groups = { "find" }) public void testFindById01() { try {//from w ww. j a v a 2 s .c om SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); java.util.Date start_util_date = formatter.parse("20020701"); Job_History result = job_HistoryMapper.findByIdRaw(200L, new Date(start_util_date.getTime())); assertNotNull(result); } catch (ParseException ex) { assertTrue(false); } }
From source file:nl.tudelft.stocktrader.util.StockTraderUtility.java
public static Date convertToSqlDate(Calendar calendar) { return new Date(calendar.getTimeInMillis()); }
From source file:org.ujorm.hotels.services.DatabaseTest.java
/** Create a one reservation in the Prague */ @Before//from w w w . j a va2s . com @Transactional public void setUp() { final String login = "test"; final String city = "Prague"; if (!createQuery(Booking.ID.forAll()).exists()) { Customer customer = createQuery(Customer.LOGIN.whereEq(login)).uniqueResult(); Hotel hotel = createQuery(Hotel.CITY.add(City.NAME).whereEq(city)).setLimit(1).uniqueResult(); // Booking booking = new Booking(); booking.setCustomer(customer); booking.setHotel(hotel); booking.setDateFrom(new Date(System.currentTimeMillis() + ONE_DAY)); booking.setPrice(hotel.getPrice()); booking.setReservationDate(now()); getSession().save(booking); } }
From source file:org.mitre.uma.service.impl.DefaultPermissionService.java
@Override public PermissionTicket createTicket(ResourceSet resourceSet, Set<String> scopes) { // check to ensure that the scopes requested are a subset of those in the resource set if (!scopeService.scopesMatch(resourceSet.getScopes(), scopes)) { throw new InsufficientScopeException("Scopes of resource set are not enough for requested permission."); }/*from w w w. j a va 2 s .c o m*/ Permission perm = new Permission(); perm.setResourceSet(resourceSet); perm.setScopes(scopes); PermissionTicket ticket = new PermissionTicket(); ticket.setPermission(perm); ticket.setTicket(UUID.randomUUID().toString()); ticket.setExpiration(new Date(System.currentTimeMillis() + permissionExpirationSeconds * 1000L)); return repository.save(ticket); }
From source file:springfox.documentation.spring.web.dummy.controllers.BugsController.java
@RequestMapping(value = "1162", method = RequestMethod.POST) public ResponseEntity<Date> bug1162() { return ResponseEntity.ok(new Date(new java.util.Date().getTime())); }
From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java
public static void login(final BaseActivity activity, final String username, final String password, final boolean autoLogin) { Log.i(TAG, "call login func:" + username + "/" + password); ctx = activity;/* w w w . jav a2 s .c om*/ UmengEventSender.sendEvent(activity, UmengEventTypes.login); final ProgressDialog pd = new ProgressDialog(activity); pd.setMessage(activity.getString(R.string.logging_wait)); pd.show(); AsyncHttpClient client = activity.getAsyncHttpClient(); RequestParams params = new RequestParams(); try { JSONObject p = new JSONObject(); p.put("mobile", username); p.put("password", password); p.put("method", "login"); p.put("version", activity.getVersionName()); p.put("devicetype", "android"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis()); String time = formatter.format(curDate); p.put("time", time); Log.i(TAG, "request parameters: " + p.toString()); String data = Util.DesJiaMi(p.toString(), "czxms520"); Log.i(TAG, "post data:" + data); params.put("data", data); } catch (Exception e) { activity.showMessageBox(activity.getString(R.string.wrong_profile)); Log.e(TAG, e.getMessage()); e.printStackTrace(); return; } // params.put("xml", BaseActivity.getXML(map)); Log.i(TAG, "AsyncHttpClient post:" + BaseActivity.REQUESTURL); client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() { @Override public void onDispatchSuccess(int statusCode, Header[] headers, String result) { Log.i(TAG, "onDispatchSuccess: " + result); pd.dismiss(); try { Log.i(TAG, "decrypting..."); result = Util.decrypt(result, "czxms520"); Log.v(TAG, "result decrypted :" + result); JSONObject jo = new JSONObject(result); String code = jo.getString("code"); String msg = getJSONValueAsString(jo, "message"); if (code.equals("0")) { jo = new JSONObject(jo.getString("data")); // String loginTime = getJSONValueAsString(jo, "LastLogin"); // String lastLoginTime = getJSONValueAsString(jo, "LastLogin"); // SESSIONKEY /* * String sessionKey = getJSONValueAsString( jo, * "sessionkey"); */ // String urlHead = getJSONValueAsString(jo, "PhotoUrl"); String photoUrl = getJSONValueAsString(jo, "PhotoUrl"); String phone = getJSONValueAsString(jo, "Mobile"); Boolean vip = false; if (String.valueOf(jo.getInt("Vip")).equals("1")) { vip = true; } else { vip = false; } Env.isLogined = BaseActivity.isLogined = true; Log.v(TAG, ":1"); activity.markLogin(phone, phone, password, autoLogin, "", loginTime, lastLoginTime, vip); if (!photoUrl.equals("")) { String finalHeadUrl = URLDecoder.decode(photoUrl, "utf-8"); BaseActivity.setUserHeadUrl(finalHeadUrl); BaseActivity.setUserHeadDrawable(null); } else { BaseActivity.setUserHeadUrl(""); BaseActivity.setUserHeadDrawable(null); } // sendMsg(ConfigActivity.thiz,0); // start HomeActivity.now_mobile = phone; // end // // Log.v("", "kk" + phone); LoginActivity.instance.finish(); Util.saveFile(phone, Environment.getExternalStorageDirectory() + "/xmsphone.txt"); SharedPreferences.Editor sharedata = activity.getSharedPreferences("MyData", 0).edit(); sharedata.putString("isJZMM_czxms", "true"); sharedata.commit(); Log.i(TAG, ":2"); sendMsg(0); sendMsg(ConfigActivity.thiz, 2); activity.finish(); } else { Log.e(TAG, "server notify failed: error:" + msg); LoginActivity.pw.setText(""); activity.showMessageBox(msg); } } catch (JSONException e) { Log.e(TAG, "login error" + Log.getStackTraceString(e)); e.printStackTrace(); activity.showMessageBox(activity.getText(R.string.server404)); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); //e.printStackTrace(); activity.showMessageBox(",."); } } @Override public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable, BaseBinaryResponse jsonResponse) { Log.i(TAG, "onFailureAnyway: " + statusCode); pd.dismiss(); activity.showMessageBox(activity.getText(R.string.server404)); } @Override public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) { Log.i(TAG, "onSuccessAnyway: " + statusCode); } }); TimeCounter.countTime(activity, pd); }
From source file:bizlogic.Command.java
public static int Process(String _command, Connection con, PrintWriter out) throws SQLException { try {//from w ww. ja va 2s. co m System.out.print("Processing command: "); System.out.println(_command); String string = _command; String[] _array = string.split(","); String command = _array[0]; switch (command) { case "addSensor": bizlogic.Sensors.add(con, _array[1], _array[2], _array[3], _array[4], _array[5], _array[6]); bizlogic.Sensors.list(con); break; case "delSensor": bizlogic.Sensors.del(con, _array[1]); bizlogic.Sensors.list(con); break; case "listSensors": bizlogic.Sensors.list(con); out.println("sensors.json ok"); break; case "addRecord": bizlogic.Records.add(con, _array[1], _array[2], _array[3], _array[4]); bizlogic.Records.list(con); break; case "delRecord": bizlogic.Records.del(con, _array[1]); bizlogic.Records.list(con); break; case "startRecords": bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "true"); // (conDB, records, column, value) //bizlogic.Records.list(con); out.println("startRecords " + _array[1]); break; case "stopRecords": bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "false"); // (conDB, records, column, value) //bizlogic.Records.list(con); out.println("stopRecords " + _array[1]); break; case "listRecords": bizlogic.Records.list(con); out.println("listRecords ok"); break; case "writeCSV": bizlogic.Records.writeCSV(con, _array[1]); out.println("writeCSV " + _array[1] + " Value" + " Time"); break; case "setConf": String[] confString = new String[] { "date", "+%D", "--set", _array[3] + " " + _array[2] }; System.out.println("confString=" + Arrays.toString(confString)); Process p = java.lang.Runtime.getRuntime().exec(confString); int setConf_status = p.waitFor(); System.out.println("confStatus = " + Integer.toString(setConf_status)); if (setConf_status != -1) { out.println("setConf " + "ok"); } else { out.println("ERROR Date not set"); } break; case "serverTime": DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(System.currentTimeMillis()); out.println("Server time: " + sdf.format(date)); break; case "changeIP": if (bizlogic.modSettings.validateIP(_array[1])) { System.out.println("changeIP to " + _array[1]); bizlogic.modSettings.resetIP(); if (!_array[1].equals("0.0.0.0")) { bizlogic.modSettings.setIP(_array[1]); } out.println("Server rebooting to set the IP"); out.close(); con.close(); java.lang.Runtime.getRuntime().exec("sudo reboot"); } else { out.println("ERROR: Bad IP address." + " Enter a valid IPv4 addess"); System.out.println("Bad IP: " + _array[1]); java.lang.Runtime.getRuntime().exec( "pid2=`ps aux | " + "grep \"[d]l_hwlogic\" | awk '{print $2}'`\n" + "kill -9 $pid2"); } break; default: break; } return 1; } catch (IOException | ParseException | InterruptedException ex) { Logger.getLogger(Command.class.getName()).log(Level.WARNING, null, ex); return -1; } }
From source file:data.DefaultExchanger.java
protected Date date(long time) { if (time == 0l) { return null; } else {//from w ww .j a v a2 s . c o m return new Date(time); } }
From source file:eu.planets_project.pp.plato.action.project.NewProjectAction.java
public String createFTE() { createProject();//from w ww. j a va 2s. c o m // set Fast Track properties selectedPlan.getState().setValue(PlanState.FTE_INITIALISED); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd-kkmmss"); String timestamp = format.format(new Date(System.currentTimeMillis())); String identificationCode = Plan.fastTrackEvaluationPrefix + timestamp; selectedPlan.getProjectBasis().setIdentificationCode(identificationCode); // load the selected project (and keep the id!) loadPlan.setPlanPropertiesID(selectedPlan.getPlanProperties().getId()); // The outjection doesnt work here (since this is not an EJB), // so we set the member explicitly Contexts.getSessionContext().set("selectedPlan", selectedPlan); loadPlan.initializeProject(selectedPlan); FTrequirements.enter(); return "success"; }