Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

In this page you can find the example usage for java.sql Date Date.

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:org.beanfuse.security.service.UserServiceImpl.java

public void saveOrUpdate(User user) throws EntityExistException {
    try {//from   w ww.  ja  va  2 s .c  o m
        user.setUpdatedAt(new Date(System.currentTimeMillis()));
        if (user.isVO()) {
            user.setCreatedAt(new Date(System.currentTimeMillis()));
        }
        entityService.saveOrUpdate(user);
    } catch (DataIntegrityViolationException e) {
        throw new EntityExistException("User already exits:" + user);
    } catch (Exception e) {
        throw new EntityExistException("User already exits:" + user);
    }
}

From source file:org.beangle.emsapp.security.action.GroupAction.java

protected String saveAndForward(Entity<?> entity) {
    Group group = (Group) entity;
    if (entityDao.duplicate(Group.class, group.getId(), "name", group.getName())) {
        return redirect("edit", "error.notUnique");
    }//from  w  w w.j  a va2s .c om
    if (!group.isPersisted()) {
        User creator = userService.get(getUserId());
        userService.createGroup(creator, group);
    } else {
        group.setUpdatedAt(new Date(System.currentTimeMillis()));
        if (!group.isPersisted()) {
            group.setCreatedAt(new Date(System.currentTimeMillis()));
        }
        entityDao.saveOrUpdate(group);
    }
    return redirect("search", "info.save.success");
}

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLTransactionManager.java

/**
 * java.sql.connection? ? ./*ww w.ja  va  2  s . c  o m*/
 * 
 * @param userId
 * @param userDB
 * 
 * @return
 * @throws Exception
 */
public static Connection getInstance(final String userId, final UserDBDAO userDB) throws Exception {

    if (logger.isDebugEnabled())
        logger.debug("[userId]" + userId + "[userDB]" + userDB.getUrl() + " / " + userDB.getUsers());

    synchronized (dbManager) {
        final String searchKey = getKey(userId, userDB);
        TransactionDAO transactionDAO = dbManager.get(searchKey);
        if (transactionDAO == null) {
            try {
                DataSource ds = DBCPConnectionManager.getInstance().getDataSource(userId, userDB);

                transactionDAO = new TransactionDAO();

                Connection conn = ds.getConnection();
                conn.setAutoCommit(false);

                transactionDAO.setConn(conn);
                transactionDAO.setUserId(userId);
                transactionDAO.setUserDB(userDB);
                transactionDAO.setStartTransaction(new Date(System.currentTimeMillis()));

                transactionDAO.setKey(searchKey);

                dbManager.put(searchKey, transactionDAO);
                if (logger.isDebugEnabled())
                    logger.debug("\t New connection SQLMapSession.");
            } catch (Exception e) {
                logger.error("transaction connection", e);
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("\t Already register SQLMapSession.");
                logger.debug("\t Is auto commit " + transactionDAO.getConn().getAutoCommit());
            }
        }
        if (logger.isDebugEnabled())
            logger.debug("[conn code]" + transactionDAO.toString());

        return transactionDAO.getConn();
    }
}

From source file:ca.hec.cdm.jobs.CreateCatalogDescriptionJob.java

public void execute(JobExecutionContext arg0) throws JobExecutionException {
    List<CourseOffering> listCo = courseOfferingDao.getListCourseOffering();
    List<String> listCourseId = catalogDescriptionDao.getListCourseId();

    // First we set to "Inactive" status all catalog descriptions
    catalogDescriptionDao.setCatalogDescriptionToInactive();

    // Then we create or update catalog descriptions
    for (CourseOffering co : listCo) {
        cd = new CatalogDescription();
        cd.setCourseId(FormatUtils.formatCourseId(co.getCatalog_nbr()));
        cd.setTitle(co.getCourse_title_long());
        cd.setDepartment(co.getAcad_org());
        cd.setCareer(co.getAcad_career());
        cd.setCredits(co.getCredits());//from   www .  j a va2  s  .c o  m
        cd.setLanguage(co.getLanguage());
        cd.setRequirements(co.getRequirement());
        cd.setCreatedDate(new Date(java.util.Calendar.getInstance().getTimeInMillis()));
        cd.setActive(true);
        cd.setCreatedBy("quartz job");

        // we create catalog description only if it is not already created
        if (!listCourseId.contains(cd.getCourseId())) {
            try {
                catalogDescriptionDao.saveCatalogDescription(cd);
                log.debug("the folowing catalog description was created successfully: " + cd.getCourseId());
            } catch (StaleDataException e) {
                log.error("Exception during catalog description creation :" + e);
            } catch (DatabaseException e) {
                log.error("Exception during catalog description creation :" + e);
            }
            // otherwise, we update the catalog description and set "Active" status to true
        } else {
            CatalogDescription cdToUpdate = catalogDescriptionDao
                    .getLastVersionCatalogDescription(cd.getCourseId());

            cdToUpdate.setTitle(cd.getTitle());
            cdToUpdate.setDepartment(cd.getDepartment());
            cdToUpdate.setCareer(cd.getCareer());
            cdToUpdate.setCredits(cd.getCredits());
            cdToUpdate.setLanguage(cd.getLanguage());
            cdToUpdate.setRequirements(cd.getRequirements());

            cdToUpdate.setActive(true);

            try {
                catalogDescriptionDao.saveCatalogDescription(cdToUpdate);

                log.debug("the folowing catalog description was successfully updated to 'active' status: "
                        + cd.getCourseId());
            } catch (StaleDataException e) {
                log.error("Exception during catalog description update :" + e);
            } catch (DatabaseException e) {
                log.error("Exception during catalog description update :" + e);
            }
        }
    }
}

From source file:javasnack.cli.CliDbUnitCsvExportDemo.java

void setup(Connection conn) throws Exception {

    new T1().setup(conn);
    Calendar c = Calendar.getInstance();

    c.clear();//from   ww w.  j  a  va 2s .c om
    c.set(2000, 11, 31, 23, 59, 59);
    long insertTIM = c.getTimeInMillis();
    new T1(true, 10, new BigDecimal(20), 30.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \"World\"!").insertMe(conn);

    c.clear();
    c.set(2001, 0, 1, 12, 30, 15);
    insertTIM = c.getTimeInMillis();
    new T1(false, 20, new BigDecimal(30), 40.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \n\"World\"!").insertMe(conn);

    new T2().setup(conn);
    new T2(UnsignedByte.create0x00to0xFFString(), UnsignedByte.create0x00to0xFF(),
            UnsignedByte.create0x00to0xFF()).insertMe(conn);
}

From source file:com.brsanthu.dataexporter.DataExporterTestBase.java

protected void addData() {

    exporter.addRow(new Date(dateReference - 2397984), new Integer(1), "Laptop", new Boolean(false),
            new Integer(1), new Double(799.78));
    exporter.addRow(new Date(dateReference - 232042098), new Integer(2), "Mouse", new Boolean(true),
            new Integer(2), new Double(49.30));
    exporter.addRow(new Date(dateReference - 234084277), new Integer(3), "Keyboard", new Boolean(false),
            new Integer(5), new Double(75));
}

From source file:de.aw.awlib.events.EventDBSave.java

/**
 * Sichert die Datenbank. Wird nur auusgefuhrt, wenn Berechtigung vorhanden
 *
 * @param context Context/*from  ww w  .  j  av  a2 s .c  o m*/
 */
public void execute(Context context) {
    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        mContext = context.getApplicationContext();
        AWApplication mApplication = ((AWApplication) mContext.getApplicationContext());
        String BACKUPPATH = mApplication.getApplicationBackupPath() + "/";
        DATABASEFILENAME = mApplication.getApplicationDatabaseAbsoluteFilename();
        date = new Date(System.currentTimeMillis());
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy_MM_dd_HH_mm", Locale.getDefault());
        File backupFile = new File(BACKUPPATH + fmt.format(cal.getTime()) + ".zip");
        execute(backupFile);
    }
}

From source file:com.ar.hotwiredautorepairshop.controller.ServiceOrderController.java

@RequestMapping(value = "/serviceOrders/register/new", method = RequestMethod.POST)
public ServiceOrder registerServiceOrder(@RequestParam(value = "customerSSN") String customerSSN,
        @RequestParam(value = "licensePlate") String licensePlate,
        @RequestParam(value = "mechanicSSN") String mechanicSSN,
        @RequestParam(value = "serviceDate") String serviceDate,
        @RequestParam(value = "pickupDate") String pickupDate,
        @RequestParam(value = "workTypeIds") List<String> workTypeIds,
        @RequestParam(value = "complaintId") Integer complaintId) {
    ServiceOrder newServiceOrder = new ServiceOrder();
    java.util.Date utilDate = new java.util.Date();
    Date registrationDate = new Date(utilDate.getTime());
    newServiceOrder.setRegistrationDate(registrationDate);

    Customer customer = customerRepository.findOne(customerSSN);
    Mechanic mechanic = mechanicRepository.findOne(mechanicSSN);
    Car car = carRepository.findOne(licensePlate);

    if (!mechanic.getCarsInProgress().contains(car)) {
        mechanic.getCarsInProgress().add(car);
    }/*from   w w  w  .j  a  v a 2s .c  om*/

    if (complaintId != null) {
        newServiceOrder.setComplaint(complaintRepository.findOne(complaintId));
    }

    newServiceOrder.setCustomer(customer);
    newServiceOrder.setCar(car);

    newServiceOrder.setMechanic(mechanic);
    newServiceOrder.setServiceDate(Date.valueOf(serviceDate));
    newServiceOrder.setPickupDate(Date.valueOf(pickupDate));
    int totalPrice = 0;

    for (String workTypeId : workTypeIds) {
        WorkType workType = workTypeRepository.findOne(Integer.parseInt(workTypeId));
        newServiceOrder.getWorkTypes().add(workType);
        totalPrice += workType.getPrice();
    }
    newServiceOrder.setTotalPrice(totalPrice);
    newServiceOrder.setActive(true);
    serviceOrderRepository.save(newServiceOrder);

    return newServiceOrder;
}

From source file:com.ewcms.content.resource.web.QueryAction.java

@Override
protected Resultable queryResult(QueryFactory queryFactory, String cacheKey, int rows, int page, Order order) {

    EntityQueryable query = queryFactory.createEntityQuery(Resource.class).setPage(page).setRow(rows)
            .orderDesc("createTime");

    query.eq("site", getSite());
    if (removeEvent) {
        query.eq("status", Status.DELETE);
    } else {/*from w w w. j  a va  2 s  .  com*/
        query.eq("type", Type.valueOf(StringUtils.upperCase(type)));
        query.in("status", new Status[] { Status.NORMAL, Status.RELEASED });
    }

    String name = getParameterValue(String.class, "name");
    if (isStringNotEmpty(name)) {
        query.likeAnywhere("name", name);
    }

    String description = getParameterValue(String.class, "description");
    if (isStringNotEmpty(description)) {
        query.likeAnywhere("description", description);
    }

    Date fromDate = getParameterValue(Date.class, "fromDate");
    Date toDate = getParameterValue(Date.class, "toDate");
    if (isNotNull(fromDate) || isNotNull(toDate)) {
        fromDate = (fromDate == null ? MINI_DATE : fromDate);
        toDate = (toDate == null ? new Date(System.currentTimeMillis()) : toDate);
        query.between("createTime", fromDate, toDate);
    }

    return query.queryCacheResult(cacheKey);
}

From source file:gov.nih.nci.integration.invoker.CaTissueConsentStrategyTest.java

/**
 * Tests registerConsents using the ServiceInvocationStrategy class for the success scenario
 * /*from  w  w w .j  av  a 2  s.  co  m*/
 * @throws IntegrationException - IntegrationException
 * @throws JAXBException - JAXBException
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void registerConsents() throws IntegrationException, JAXBException {
    final Date stTime = new Date(new java.util.Date().getTime());

    xsltTransformer.transform(null, null, null);
    EasyMock.expectLastCall().andAnswer(new IAnswer() {

        public Object answer() {
            return getRegisterConsentXMLStr();
        }
    }).anyTimes();

    final ServiceInvocationResult clientResult = new ServiceInvocationResult();
    EasyMock.expect(caTissueConsentClient.registerConsents((String) EasyMock.anyObject()))
            .andReturn(clientResult);
    EasyMock.replay(caTissueConsentClient);
    final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID,
            getRegisterConsentXMLStr(), stTime, caTissueConsentStrategy.getStrategyIdentifier());
    final ServiceInvocationResult strategyResult = caTissueConsentStrategy.invoke(serviceInvocationMessage);
    Assert.assertNotNull(strategyResult);
}