List of usage examples for java.sql Date Date
public Date(long date)
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertToSqoop(Object val, HCatFieldSchema.Type fieldType, String javaColType, String hCatTypeString) throws IOException { if (val == null) { return null; }// ww w .jav a 2 s .c om switch (fieldType) { case INT: case TINYINT: case SMALLINT: case FLOAT: case DOUBLE: val = convertNumberTypes(val, javaColType); if (val != null) { return val; } break; case BOOLEAN: val = convertBooleanTypes(val, javaColType); if (val != null) { return val; } break; case BIGINT: if (javaColType.equals(DATE_TYPE)) { return new Date((Long) val); } else if (javaColType.equals(TIME_TYPE)) { return new Time((Long) val); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp((Long) val); } else { val = convertNumberTypes(val, javaColType); if (val != null) { return val; } } break; case DATE: Date date = (Date) val; if (javaColType.equals(DATE_TYPE)) { return date; } else if (javaColType.equals(TIME_TYPE)) { return new Time(date.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(date.getTime()); } break; case TIMESTAMP: Timestamp ts = (Timestamp) val; if (javaColType.equals(DATE_TYPE)) { return new Date(ts.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return new Time(ts.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return ts; } break; case STRING: case VARCHAR: case CHAR: val = convertStringTypes(val, javaColType); if (val != null) { return val; } break; case BINARY: val = convertBinaryTypes(val, javaColType); if (val != null) { return val; } break; case DECIMAL: val = convertDecimalTypes(val, javaColType); if (val != null) { return val; } break; case ARRAY: case MAP: case STRUCT: default: throw new IOException("Cannot convert HCatalog type " + fieldType); } LOG.error("Cannot convert HCatalog object of " + " type " + hCatTypeString + " to java object type " + javaColType); return null; }
From source file:com.heliumv.api.item.ItemApiV11.java
@GET @Path("/{" + Param.ITEMID + "}/price") public BigDecimal getPrice(@QueryParam(Param.USERID) String userId, @PathParam(Param.ITEMID) Integer itemId, @QueryParam(Param.CUSTOMERID) Integer customerId, @QueryParam("amount") BigDecimal amount, @QueryParam("unit") String unitCnr) throws NamingException, RemoteException, EJBExceptionLP { if (connectClient(userId) == null) return null; ArtikelDto itemDto = artikelCall.artikelFindByPrimaryKeySmallOhneExc(itemId); if (itemDto == null) { respondNotFound(Param.ITEMID, itemId.toString()); return null; }//from ww w . ja v a 2 s. c o m KundeDto customerDto = null; if (customerId == null) { if (!featureFactory.hasCustomerPartlist()) { respondBadRequestValueMissing(Param.CUSTOMERID); return null; } customerDto = kundeCall .kundeFindByAnsprechpartnerIdcNrMandantOhneExc(featureFactory.getAnsprechpartnerId()); } else { customerDto = kundeCall.kundeFindByPrimaryKeyOhneExc(customerId); } if (customerDto == null || !globalInfo.getMandant().equals(customerDto.getMandantCNr())) { respondNotFound(); return null; } // TODO Umrechnen in die Lagereinheit java.sql.Date d = new Date(System.currentTimeMillis()); Integer mwstsatzbeId = itemDto.getMwstsatzbezIId(); if (mwstsatzbeId == null) { mwstsatzbeId = customerDto.getMwstsatzbezIId(); } VkpreisfindungDto vkpreisfindungDto = vkpreisfindungCall.verkaufspreisfindung(itemDto.getIId(), customerDto.getIId(), amount, d, customerDto.getVkpfArtikelpreislisteIIdStdpreisliste(), mwstsatzbeId, customerDto.getCWaehrung()); BigDecimal p = getPriceFromPreisfindung(vkpreisfindungDto); return p; }
From source file:com.sfs.whichdoctor.dao.WorkshopDAOImpl.java
/** * Save the WorkshopBean.// ww w . jav a 2 s . c o m * * @param workshop the workshop * @param checkUser the check user * @param privileges the privileges * @param action the action * @return the int * @throws WhichDoctorDaoException the which doctor dao exception */ private int save(final WorkshopBean workshop, final UserBean checkUser, final PrivilegesBean privileges, final String action) throws WhichDoctorDaoException { /* Check required information within Memo bean is present */ if (workshop.getWorkshopDate() == null) { throw new WhichDoctorDaoException("Workshop requires a valid date"); } if (workshop.getType() == null) { throw new WhichDoctorDaoException("Workshop type cannot be null"); } if (workshop.getType().compareTo("") == 0) { throw new WhichDoctorDaoException("Workshop type cannot be an empty string"); } if (workshop.getReferenceGUID() == 0) { throw new WhichDoctorDaoException("Workshop requires a valid Reference GUID number"); } if (!privileges.getPrivilege(checkUser, "workshops", action)) { throw new WhichDoctorDaoException("Insufficient user credentials to " + action + " workshop entry"); } int workshopTypeId = 0; try { ObjectTypeBean object = this.getObjectTypeDAO().load("Workshop", "", workshop.getType()); workshopTypeId = object.getObjectTypeId(); } catch (Exception e) { dataLogger.error("Error loading objecttype for workshop type: " + e.getMessage()); throw new WhichDoctorDaoException("Workshop requires a valid type"); } int workshopId = 0; Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis()); ArrayList<Object> parameters = new ArrayList<Object>(); Date workshopDate = null; if (workshop.getWorkshopDate() != null) { workshopDate = new Date(workshop.getWorkshopDate().getTime()); } parameters.add(workshop.getReferenceGUID()); parameters.add(workshopTypeId); parameters.add(workshopDate); parameters.add(workshop.getMemo()); parameters.add(workshop.getActive()); parameters.add(sqlTimeStamp); parameters.add(checkUser.getDN()); parameters.add(workshop.getLogMessage(action)); try { Integer[] result = this.performUpdate("workshop", workshop.getGUID(), parameters, "Workshop", checkUser, action); /* Set the returned guid and id values */ workshop.setGUID(result[0]); workshopId = result[1]; } catch (Exception e) { dataLogger.error("Error processing workshop record: " + e.getMessage()); throw new WhichDoctorDaoException("Error processing workshop record: " + e.getMessage()); } return workshopId; }
From source file:ke.co.tawi.babblesms.server.persistence.contacts.GroupDAO.java
/** * @see ke.co.tawi.babblesms.server.persistence.contacts.BabbleGroupDAO#putGroup(ke.co.tawi.babblesms.server.beans.contact.Group) *//*www. j a v a2 s . c o m*/ @Override public boolean putGroup(Group group) { boolean success = true; try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO groups (Uuid, name, description," + "creationdate, accountuuid, statusuuid) VALUES (?,?,?,?,?,?);");) { pstmt.setString(1, group.getUuid()); pstmt.setString(2, group.getName()); pstmt.setString(3, group.getDescription()); pstmt.setDate(4, new Date(group.getCreationdate().getTime())); pstmt.setString(5, group.getAccountsuuid()); pstmt.setString(6, group.getStatusuuid()); pstmt.execute(); } catch (SQLException e) { logger.error("SQL Exception when trying to put: " + group); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } return success; }
From source file:gov.nih.nci.integration.invoker.CaTissueSpecimenStrategyTest.java
/** * Tests updateSpecimens using the ServiceInvocationStrategy class for the success scenario * /* w w w . j av a 2 s. com*/ * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void updateSpecimens() 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 getSpecimenXMLStr(); } }).anyTimes(); final ServiceInvocationResult clientResult = new ServiceInvocationResult(); EasyMock.expect(caTissueSpecimenClient.updateSpecimens((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueSpecimenClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueUpdateSpecimenStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueUpdateSpecimenStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListener.java
private ResourceEvent parseJSONToResourceEvent(String message) throws JsonParseException, IOException { log.debug("Parsing json message to ResourceEvent"); log.debug("Json message is: " + message); ResourceEvent event = new ResourceEvent(); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> mapObject = mapper.readValue(message, new TypeReference<Map<String, Object>>() { });/*from ww w . ja va 2 s .co m*/ if (mapObject.get("timestamp") != null) { event.setTimestamp(new Date((Long) mapObject.get("timestamp"))); } if (mapObject.get("correlationId") != null) { event.setCorrelationId((String) mapObject.get("correlationId")); } if (mapObject.get("eventType") != null) { event.setEventType(ResourceEventType.valueOf((String) mapObject.get("eventType"))); } if (mapObject.get("state") != null) { event.setRequestState(RequestState.valueOf((String) mapObject.get("state"))); } if (mapObject.get("message") != null) { event.setMessage((String) mapObject.get("message")); } if (mapObject.get("endpoint") != null) { event.setEndpoint((String) mapObject.get("endpoint")); } if (mapObject.get("resource") != null) { event.setResource((String) mapObject.get("resource")); } if (mapObject.get("ip") != null) { event.setIp((String) mapObject.get("ip")); } if (mapObject.get("httpStatus") != null) { event.setHttpStatus(Integer.valueOf((Integer) mapObject.get("httpStatus"))); } if (mapObject.get("request") != null) { event.setRequest((String) mapObject.get("request")); } if (mapObject.get("method") != null) { event.setMethod((String) mapObject.get("method")); } if (mapObject.get("logicalAddress") != null) { event.setLogicalAddress((String) mapObject.get("logicalAddress")); } if (mapObject.get("client") != null) { event.setClient((String) mapObject.get("client")); } if (mapObject.get("user") != null) { event.setUser((String) mapObject.get("user")); } if (mapObject.get("scopes") != null) { List<String> scopes = (List<String>) mapObject.get("scopes"); event.setScopes(StringUtils.collectionToCommaDelimitedString(scopes)); } return event; }
From source file:io.github.sislivros.persistencia.UsuarioBdDao.java
@Override public boolean alterar(Usuario usuario) { try {// ww w . ja v a 2 s. co m if (getConnection() == null || getConnection().isClosed()) { conectar(); } String sql = "UPDATE usuario SET email = ?, apelido = ?, data_nascimento = ?, cidade = ?" + ", estado = ?, nome = ?, foto_perfil = ?, foto_capa = ?, tipo = ? WHERE id = ?"; PreparedStatement ps = getConnection().prepareStatement(sql); Date dataNascimento = null; try { dataNascimento = new Date(usuario.getDataNascimento().getTime()); } catch (NullPointerException ex) { } ps.setString(1, usuario.getEmail()); ps.setString(2, usuario.getApelido()); ps.setDate(3, dataNascimento); ps.setString(4, usuario.getCidade()); ps.setString(5, usuario.getEstado()); ps.setString(6, usuario.getNome()); ps.setString(7, usuario.getFotoPerfil()); ps.setString(8, usuario.getFotoCapa()); ps.setInt(9, usuario.getTipo().id); ps.setInt(10, usuario.getId()); ps.executeUpdate(); return true; } catch (SQLException | URISyntaxException | IOException | ClassNotFoundException ex) { ex.printStackTrace(); return false; } finally { desconectar(); } }
From source file:gov.nih.nci.integration.invoker.CaTissueParticipantStrategyTest.java
/** * Tests updateRegistrationParticipant using the ServiceInvocationStrategy class for the success scenario * /*from w w w.ja va2 s. com*/ * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void updateParticipantRegistration() 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 getSpecimenXMLStr(); } }).anyTimes(); final ServiceInvocationResult clientResult = new ServiceInvocationResult(); EasyMock.expect(caTissueParticipantClient.updateRegistrationParticipant((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueParticipantClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueUpdateRegistrationStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueUpdateRegistrationStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }
From source file:org.beangle.ems.security.service.UserServiceImpl.java
public void createGroup(User owner, Group group) { group.setUpdatedAt(new Date(System.currentTimeMillis())); group.setCreatedAt(new Date(System.currentTimeMillis())); group.setOwner(owner);// w w w. j a v a2 s . c o m group.getMembers().add(new GroupMemberBean(group, owner, GroupMember.Ship.MANAGER)); entityDao.saveOrUpdate(group); publish(new GroupCreationEvent(group)); }
From source file:dialog.DialogFunctionUser.java
private void actionAddUser() { if (!isValidData()) { return;//www .j a v a 2 s . c om } if (isExistUsername(tfUsername.getText())) { JOptionPane.showMessageDialog(null, "Username tn ti", "Error", JOptionPane.ERROR_MESSAGE); return; } String username = tfUsername.getText(); String fullname = tfFullname.getText(); String password = new String(tfPassword.getPassword()); password = LibraryString.md5(password); int role = cbRole.getSelectedIndex(); User objUser; if (mAvatar != null) { objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role, new Date(System.currentTimeMillis()), mAvatar.getPath()); String fileName = FilenameUtils.getBaseName(mAvatar.getName()) + "-" + System.nanoTime() + "." + FilenameUtils.getExtension(mAvatar.getName()); Path source = Paths.get(mAvatar.toURI()); Path destination = Paths.get("files/" + fileName); try { Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING); } catch (IOException ex) { Logger.getLogger(DialogFunctionRoom.class.getName()).log(Level.SEVERE, null, ex); } } else { objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role, new Date(System.currentTimeMillis()), ""); } if (mControllerUser.addItem(objUser)) { ImageIcon icon = new ImageIcon(getClass().getResource("/images/ic_success.png")); JOptionPane.showMessageDialog(this.getParent(), "Thm thnh cng", "Success", JOptionPane.INFORMATION_MESSAGE, icon); } else { JOptionPane.showMessageDialog(this.getParent(), "Thm tht bi", "Fail", JOptionPane.ERROR_MESSAGE); } this.dispose(); }