List of usage examples for java.sql Date Date
public Date(long date)
From source file:org.apache.drill.exec.store.hive.HiveTestDataGenerator.java
private String generateTestDataFileForPartitionInput() throws Exception { final File file = getTempFile(); PrintWriter printWriter = new PrintWriter(file); String partValues[] = { "1", "2", "null" }; for (int c = 0; c < partValues.length; c++) { for (int d = 0; d < partValues.length; d++) { for (int e = 0; e < partValues.length; e++) { for (int i = 1; i <= 5; i++) { Date date = new Date(System.currentTimeMillis()); Timestamp ts = new Timestamp(System.currentTimeMillis()); printWriter.printf("%s,%s,%s,%s,%s", date.toString(), ts.toString(), partValues[c], partValues[d], partValues[e]); printWriter.println(); }//from w w w . ja v a2 s . c o m } } } printWriter.close(); return file.getPath(); }
From source file:org.apache.hawq.pxf.plugins.hive.HiveORCVectorizedResolver.java
private void populatePrimitiveColumn(PrimitiveCategory primitiveCategory, ObjectInspector oi, VectorizedRowBatch vectorizedBatch, int columnIndex) { ColumnVector columnVector = vectorizedBatch.cols[columnIndex]; Object fieldValue = null;//from w ww .java 2 s . co m DataType fieldType = null; switch (primitiveCategory) { case BOOLEAN: { fieldType = BOOLEAN; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = lcv.vector[rowId] == 1; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case SHORT: { fieldType = SMALLINT; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = (short) lcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case INT: { fieldType = INTEGER; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = (int) lcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case LONG: { fieldType = BIGINT; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = lcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case FLOAT: { fieldType = REAL; DoubleColumnVector dcv = (DoubleColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (dcv != null) { int rowId = dcv.isRepeating ? 0 : rowIndex; if (!dcv.isNull[rowId]) { fieldValue = (float) dcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case DOUBLE: { fieldType = FLOAT8; DoubleColumnVector dcv = (DoubleColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (dcv != null) { int rowId = dcv.isRepeating ? 0 : rowIndex; if (!dcv.isNull[rowId]) { fieldValue = dcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case DECIMAL: { fieldType = NUMERIC; DecimalColumnVector dcv = (DecimalColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (dcv != null) { int rowId = dcv.isRepeating ? 0 : rowIndex; if (!dcv.isNull[rowId]) { fieldValue = dcv.vector[rowId]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case VARCHAR: { fieldType = VARCHAR; BytesColumnVector bcv = (BytesColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (columnVector != null) { int rowId = bcv.isRepeating ? 0 : rowIndex; if (!bcv.isNull[rowId]) { Text textValue = new Text(); textValue.set(bcv.vector[rowIndex], bcv.start[rowIndex], bcv.length[rowIndex]); fieldValue = textValue; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case CHAR: { fieldType = BPCHAR; BytesColumnVector bcv = (BytesColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (columnVector != null) { int rowId = bcv.isRepeating ? 0 : rowIndex; if (!bcv.isNull[rowId]) { Text textValue = new Text(); textValue.set(bcv.vector[rowIndex], bcv.start[rowIndex], bcv.length[rowIndex]); fieldValue = textValue; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case STRING: { fieldType = TEXT; BytesColumnVector bcv = (BytesColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (columnVector != null) { int rowId = bcv.isRepeating ? 0 : rowIndex; if (!bcv.isNull[rowId]) { Text textValue = new Text(); textValue.set(bcv.vector[rowIndex], bcv.start[rowIndex], bcv.length[rowIndex]); fieldValue = textValue; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case BINARY: { fieldType = BYTEA; BytesColumnVector bcv = (BytesColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (columnVector != null) { int rowId = bcv.isRepeating ? 0 : rowIndex; if (!bcv.isNull[rowId]) { fieldValue = new byte[bcv.length[rowId]]; System.arraycopy(bcv.vector[rowId], bcv.start[rowId], fieldValue, 0, bcv.length[rowId]); } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case DATE: { fieldType = DATE; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = new Date(DateWritable.daysToMillis((int) lcv.vector[rowIndex])); } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } case BYTE: { fieldType = SMALLINT; LongColumnVector lcv = (LongColumnVector) columnVector; for (int rowIndex = 0; rowIndex < vectorizedBatch.size; rowIndex++) { fieldValue = null; if (lcv != null) { int rowId = lcv.isRepeating ? 0 : rowIndex; if (!lcv.isNull[rowId]) { fieldValue = (short) lcv.vector[rowIndex]; } } addValueToColumn(columnIndex, rowIndex, new OneField(fieldType.getOID(), fieldValue)); } break; } default: { throw new UnsupportedTypeException( oi.getTypeName() + " conversion is not supported by " + getClass().getSimpleName()); } } }
From source file:com.hbc.api.trade.pay.service.PaymentService.java
public TradePayment addTradePayment(OrderBean orderBean, GetWayEnum getWayNo, double payActual, String paySubject, String userAccountNo, PayStatus payStatus) { // TradePayment tradePaymentDb = queryTradePaymentByOrderNo(orderBean.getOrderNo()); // if(tradePaymentDb){ // /* w ww. j ava2 s .c o m*/ // } TradePayment tradePayment = new TradePayment(); Date curtime = new Date(System.currentTimeMillis()); tradePayment.setCreateTime(curtime); tradePayment.setOrderNo(orderBean.getOrderNo()); tradePayment.setOrderPrice(orderBean.getPriceChannel()); tradePayment.setPayActual(payActual); tradePayment.setPayFee(0.00); tradePayment.setPayNo(IDGenerotor.generatePayNo()); tradePayment.setPaySubject(paySubject); tradePayment.setPayShould(orderBean.getPriceChannel()); tradePayment.setPayGetway(getWayNo.value); tradePayment.setPayGatewayName(getWayNo.name); tradePayment.setUserAccountNo(userAccountNo); tradePayment.setPayStatus(payStatus.value); int optnum = tradePaymentMapper.insert(tradePayment); if (optnum == 1) { return tradePayment; } else { throw new PayException(PayReturnCodeEnum.PAY_INSERT_FAILED, orderBean.getOrderNo()); } }
From source file:com.taobao.android.apatch.FastBuild.java
@Override protected Manifest getMeta() { Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (ApkPatch)"); main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString()); main.putValue("Patch-Name", name); main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes)); main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses)); main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods)); main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses)); main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses)); main.putValue(name + "-add-classes", Formater.dotStringList(addClasses)); return manifest; }
From source file:com.taobao.android.apatch.MergePatch.java
@SuppressWarnings("deprecation") @Override/*from w w w . j av a2 s .c o m*/ protected Manifest getMeta() { Manifest retManifest = new Manifest(); Attributes main = retManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (ApkPatch)"); main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString()); main.putValue("Patch-Name", name); try { fillManifest(main); } catch (IOException e) { e.printStackTrace(); return null; } return retManifest; }
From source file:org.kuali.mobility.sakai.service.SakaiForumServiceImpl.java
@Override public Message findMessage(String messageId, String topicId, String userId) { Message m = new Message(); try {/* ww w .jav a 2 s . c o m*/ String url = configParamService.findValueByName("Sakai.Url.Base") + "forum_message/topic/" + topicId + ".json"; ResponseEntity<InputStream> is = oncourseOAuthService.oAuthGetRequest(userId, url, "text/html"); String json = IOUtils.toString(is.getBody(), "UTF-8"); JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(json); JSONArray itemArray = jsonObj.getJSONArray("forum_message_collection"); for (int i = 0; i < itemArray.size(); i++) { JSONObject message = itemArray.getJSONObject(i); if (message.getString("messageId").equals(messageId)) { m.setId(message.getString("messageId")); m.setTopicId(message.getString("topicId")); m.setCreatedBy(message.getString("authoredBy")); m.setTitle(message.getString("title")); m.setBody(message.getString("body")); if (m.getBody().equals("null")) { m.setBody("(No message)"); } Date cDate = new Date(message.getLong("createdOn")); DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a"); m.setCreatedDate(df.format(cDate)); break; } } } catch (Exception e) { LOG.error(e.getMessage(), e); } return m; }
From source file:eionet.meta.service.CSVVocabularyImportServiceTest.java
/** * In this test, one line CSV is imported. Row 1 includes a non existing concept to be imported with data elements, headers are * in arbitrary order//from ww w . ja v a 2 s . c om * * @throws Exception */ @Test @Rollback public void testIfNewConceptAddedInArbitraryOrder() throws Exception { // get vocabulary folder VocabularyFolder vocabularyFolder = vocabularyService.getVocabularyFolder(TEST_VALID_VOCABULARY_ID); // get initial values of concepts with attributes List<VocabularyConcept> concepts = getVocabularyConceptsWithAttributes(vocabularyFolder); // get reader for CSV file Reader reader = getReaderFromResource("csv_import/csv_import_test_13.csv"); // import CSV into database vocabularyImportService.importCsvIntoVocabulary(reader, vocabularyFolder, false, false); Assert.assertFalse("Transaction rolled back (unexpected)", transactionManager.getTransaction(null).isRollbackOnly()); // manually create values of new concept for comparison VocabularyConcept vc11 = new VocabularyConcept(); // vc11.setId(11); //this field will be updated after re-querying vc11.setIdentifier("csv_test_concept_4"); vc11.setLabel("csv_test_concept_label_4"); vc11.setDefinition("csv_test_concept_def_4"); vc11.setStatus(StandardGenericStatus.VALID); vc11.setAcceptedDate(new Date(System.currentTimeMillis())); vc11.setStatusModified(new Date(System.currentTimeMillis())); // create element attributes (there is only one concept) List<List<DataElement>> elementAttributes = new ArrayList<List<DataElement>>(); DataElement elem = null; String identifier = null; int dataElemId = -1; // skos:prefLabel identifier = "skos:prefLabel"; dataElemId = 8; List<DataElement> elements = new ArrayList<DataElement>(); elem = new DataElement(); elem.setId(dataElemId); elem.setIdentifier(identifier); elem.setAttributeValue("bg_csv_test_concept_4"); elem.setAttributeLanguage("bg"); elements.add(elem); elem = new DataElement(); elem.setId(dataElemId); elem.setIdentifier(identifier); elem.setAttributeValue("bg2_csv_test_concept_4"); elem.setAttributeLanguage("bg"); elements.add(elem); elementAttributes.add(elements); // skos:definition identifier = "skos:definition"; dataElemId = 9; elements = new ArrayList<DataElement>(); elem = new DataElement(); elem.setId(dataElemId); elem.setIdentifier(identifier); elem.setAttributeValue("de_csv_test_concept_4"); elem.setAttributeLanguage("de"); elements.add(elem); elementAttributes.add(elements); vc11.setElementAttributes(elementAttributes); concepts.add(vc11); // get updated values of concepts with attributes List<VocabularyConcept> updatedConcepts = getVocabularyConceptsWithAttributes(vocabularyFolder); Assert.assertEquals("Updated Concepts does not include 4 vocabulary concepts", updatedConcepts.size(), 4); // last object should be the inserted one, so use it is id to set (all other fields are updated manually) vc11.setId(updatedConcepts.get(3).getId()); // compare manually updated objects with queried ones (after import operation) ReflectionAssert.assertReflectionEquals(concepts, updatedConcepts, ReflectionComparatorMode.LENIENT_DATES, ReflectionComparatorMode.LENIENT_ORDER); }
From source file:gov.nih.nci.integration.caaers.CaAERSParticipantStrategyTest.java
/** * Tests rollback() of Register Participant using the ServiceInvocationStrategy class for failure case .i.e the * rollback() is failed// www . j ava 2 s.co m * * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException * @throws MalformedURLException - MalformedURLException * @throws SOAPFaultException - SOAPFaultException * * */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void rollbackRegisterParticipantFailure() throws IntegrationException, SOAPFaultException, MalformedURLException, 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 getParticipantXMLString(); } }).anyTimes(); final CaaersServiceResponse caaersServiceResponse = getDeleteParticipantResponse(FAILURE); EasyMock.expect(wsClient.deleteParticipant((String) EasyMock.anyObject())).andReturn(caaersServiceResponse); EasyMock.replay(wsClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getParticipantInterimMessage(), stTime, caAERSRegistrationServiceInvocationStrategy.getStrategyIdentifier()); final ServiceInvocationResult result = caAERSRegistrationServiceInvocationStrategy .rollback(serviceInvocationMessage); Assert.assertNotNull(result); }
From source file:org.apache.gobblin.converter.jdbc.AvroToJdbcEntryConverter.java
@Override public Iterable<JdbcEntryData> convertRecord(JdbcEntrySchema outputSchema, GenericRecord record, WorkUnitState workUnit) throws DataConversionException { if (LOG.isDebugEnabled()) { LOG.debug("Converting " + record); }/* w w w .jav a 2s . c o m*/ List<JdbcEntryDatum> jdbcEntryData = Lists.newArrayList(); for (JdbcEntryMetaDatum entry : outputSchema) { final String jdbcColName = entry.getColumnName(); final JdbcType jdbcType = entry.getJdbcType(); String avroColName = convertJdbcColNameToAvroColName(jdbcColName); final Object val = avroRecordValueGet(record, AVRO_RECORD_LEVEL_SPLITTER.split(avroColName).iterator()); if (val == null) { jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, null)); continue; } if (!JDBC_SUPPORTED_TYPES.contains(jdbcType)) { throw new DataConversionException("Unsupported JDBC type detected " + jdbcType); } switch (jdbcType) { case VARCHAR: jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, val.toString())); continue; case INTEGER: case BOOLEAN: case BIGINT: case FLOAT: case DOUBLE: jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, val)); continue; case DATE: jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Date((long) val))); continue; case TIME: jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Time((long) val))); continue; case TIMESTAMP: jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Timestamp((long) val))); continue; default: throw new DataConversionException(jdbcType + " is not supported"); } } JdbcEntryData converted = new JdbcEntryData(jdbcEntryData); if (LOG.isDebugEnabled()) { LOG.debug("Converted data into " + converted); } return new SingleRecordIterable<>(converted); }
From source file:edu.arizona.kra.institutionalproposal.negotiationlog.service.NegotiationLogMigrationServiceImpl.java
private void setNegotiationDates(Negotiation negotiation, NegotiationLog negotiationLog) { LOG.debug("Start setNegotiationDates"); Date startDate = negotiationLog.getDateReceived(); Date endDate = negotiationLog.getDateClosed(); if (startDate == null) { if (negotiationLog.getStartDate() == null) { if (negotiationLog.getNegotiationStart() == null) { if (negotiationLog.getBackstop() == null) { LOG.debug(negotiationLog.getNegotiationLogId() + ":Using default start date = " + DEFAULT_DATE); startDate = DEFAULT_DATE; } else { startDate = negotiationLog.getBackstop(); }/*from w ww. ja v a2 s . co m*/ } else { startDate = negotiationLog.getNegotiationStart(); } } else { startDate = negotiationLog.getStartDate(); } } negotiation.setNegotiationStartDate(startDate); if (negotiationLog.getClosed()) { if (endDate == null) { if (negotiationLog.getEndDate() == null) { if (negotiationLog.getNegotiationComplete() == null) { if (negotiationLog.getUpdateTimestamp() == null) { LOG.debug("Using default end date."); endDate = DEFAULT_END_DATE; } else { endDate = new Date(negotiationLog.getUpdateTimestamp().getTime()); } } else { endDate = negotiationLog.getNegotiationComplete(); } } else { endDate = negotiationLog.getEndDate(); } } negotiation.setNegotiationEndDate(endDate); } LOG.debug("Finished setNegotiationDates log=" + negotiationLog.getNegotiationLogId() + " CLosed=" + negotiationLog.getClosed() + " SD=" + negotiation.getNegotiationStartDate() + " ED=" + negotiation.getNegotiationEndDate()); }