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:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply payment charges by category./*from   w w  w . ja v a 2  s. com*/
 *
 * @param opSubscription the op subscription
 * @param categoryCharge the category charge
 * @param paymentRequestSet the payment request set
 * @throws Exception 
 */
private static void applyPaymentChargesByCategory(BillingSubscription.OperatorSubscription opSubscription,
        CategoryCharge categoryCharge, Set<PaymentRequestDTO> paymentRequestSet) throws Exception {

    ChargeRate rate = opSubscription.getRate();
    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    BigDecimal totalCharge = BigDecimal.ZERO;
    BigDecimal totalPrice = BigDecimal.ZERO;
    BigDecimal totalTax = BigDecimal.ZERO;

    for (PaymentRequestDTO paymentRequest : paymentRequestSet) {
        totalCharge = totalCharge.add(paymentRequest.getAmount());
        BigDecimal price = BigDecimal.ZERO;

        CategoryEntity rateCategories = new CategoryEntity();

        if (rateCategories == null) {
            throw new APIManagementException(
                    "Payment Categoreis required for QUOTA charging are not specified in rate-card.xml");
        }
        BigDecimal catpercent = rate.getValue().divide(new BigDecimal(100));

        Date date = new Date(paymentRequest.getDate().getTime());
        for (Tax tax : taxList) {
            // check if the date of payment request falls between this tax
            // validity period
            if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) {
                // totalTax += taxFraction x paymentAmount
                totalTax = totalTax.add(tax.getValue().multiply(price));
            }
        }
    }

    // Get the percentage from the rate value

    // apply category wise charge percentage
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private LegendItem createFlankedShapeLegendItem(String label, double minValue, double maxValue, Shape itemShape,
        Paint shapeFillPaint, boolean shapeOutlineVisible, DateFormat dateFormat) {
    // configure legend item
    String description = "";
    String toolTipText = "";
    String urlText = "";
    boolean shapeVisible = true;
    boolean shapeFilled = true;
    Paint outlinePaint = Color.BLACK;
    Stroke outlineStroke = DEFAULT_OUTLINE_STROKE;
    boolean lineVisible = false;
    Shape line = new Line2D.Float();
    Stroke lineStroke = new BasicStroke(); // basic stroke is fine here, since continuous legend
    // item does not show a line
    Paint linePaint = Color.BLACK;

    // create legend item
    FlankedShapeLegendItem legendItem = new FlankedShapeLegendItem(label, description, toolTipText, urlText,
            shapeVisible, itemShape, shapeFilled, shapeFillPaint, shapeOutlineVisible, outlinePaint,
            outlineStroke, lineVisible, line, lineStroke, linePaint);

    if (dateFormat != null) {
        legendItem.setLeftShapeLabel(dateFormat.format(new Date((long) minValue)));
        legendItem.setRightShapeLabel(dateFormat.format(new Date((long) maxValue)));
    } else {//www .  j  av  a 2 s . co m
        // set intelligently rounded strings as labels
        int powerOf10 = DataStructureUtils.getOptimalPrecision(minValue, maxValue);
        legendItem.setLeftShapeLabel(DataStructureUtils.getRoundedString(minValue, powerOf10 - 1));
        legendItem.setRightShapeLabel(DataStructureUtils.getRoundedString(maxValue, powerOf10 - 1));
    }

    return legendItem;
}

From source file:com.zimbra.qa.unittest.TestImap.java

@Test
public void testAppendTags() throws Exception {
    Flags flags = Flags.fromSpec("afs");
    String tag1 = "APPENDTAG1"; //new tag; does not exist in mbox
    flags.set(tag1);//from ww  w .ja v a2 s.c  o  m
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(10);
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
        assertTrue(data.getFlags().isSet(tag1));
    } finally {
        msg.dispose();
    }

    //should not have created a visible tag
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);

    //now create a visible tag, add it to a message in inbox then try append to message in different folder
    String tag2 = "APPENDTAG2";
    ZTag tag = mbox.getTag(tag2);
    if (tag == null) {
        tag = mbox.createTag(tag2, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals(tag2, tags.get(0).getName());

    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(),
            simpleMessage("foo1"), true);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tag2, info.getFlags().isSet(tag2));

    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message,
            ZFolder.Color.DEFAULTCOLOR, null, null);

    info = connection.select(folderName);
    assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));

    msg = message(10);
    flags = Flags.fromSpec("afs");
    flags.set(tag2);
    try {
        AppendResult res = connection.append(folderName, flags, date, msg);
        MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
        assertTrue(data.getFlags().isSet(tag2));
    } finally {
        msg.dispose();
    }

    info = connection.select(folderName);
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void insertWoonplaatsen(final List<Woonplaats> woonplaatsen) throws DAOException {
    try {/* www  .  ja v a2s .  c o m*/
        jdbcTemplate.batchUpdate("insert into bag_woonplaats (" + "bag_woonplaats_id,"
                + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "woonplaats_naam,"
                + "woonplaats_geometrie," + "officieel," + "begindatum_tijdvak_geldigheid,"
                + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum,"
                + "bron_documentnummer," + "woonplaats_status" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)",
                new BatchPreparedStatementSetter() {
                    @Override
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
                        ps.setLong(1, woonplaatsen.get(i).getIdentificatie());
                        ps.setInt(2, woonplaatsen.get(i).getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, woonplaatsen.get(i).getAanduidingRecordCorrectie());
                        ps.setString(4, woonplaatsen.get(i).getWoonplaatsNaam());
                        ps.setString(5, woonplaatsen.get(i).getWoonplaatsGeometrie());
                        ps.setInt(6, woonplaatsen.get(i).getOfficieel().ordinal());
                        ps.setTimestamp(7,
                                new Timestamp(woonplaatsen.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                        if (woonplaatsen.get(i).getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(8, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(8, new Timestamp(
                                    woonplaatsen.get(i).getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(9, woonplaatsen.get(i).getInOnderzoek().ordinal());
                        ps.setDate(10, new Date(woonplaatsen.get(i).getDocumentdatum().getTime()));
                        ps.setString(11, woonplaatsen.get(i).getDocumentnummer());
                        ps.setInt(12, woonplaatsen.get(i).getWoonplaatsStatus().ordinal());
                    }

                    @Override
                    public int getBatchSize() {
                        return woonplaatsen.size();
                    }
                });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting woonplaatsen", e);
    }
}

From source file:org.apache.phoenix.util.TestUtil.java

public static void setRowKeyColumns(PreparedStatement stmt, int i) throws SQLException {
    // insert row
    stmt.setString(1, "varchar" + String.valueOf(i));
    stmt.setString(2, "char" + String.valueOf(i));
    stmt.setInt(3, i);//w w  w. jav  a2 s .c om
    stmt.setLong(4, i);
    stmt.setBigDecimal(5, new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
    stmt.setDate(6, date);
}

From source file:org.apache.phoenix.util.TestUtil.java

public static void validateRowKeyColumns(ResultSet rs, int i) throws SQLException {
    assertTrue(rs.next());/*  w  w  w.ja  va 2 s . c o m*/
    assertEquals(rs.getString(1), "varchar" + String.valueOf(i));
    assertEquals(rs.getString(2), "char" + String.valueOf(i));
    assertEquals(rs.getInt(3), i);
    assertEquals(rs.getInt(4), i);
    assertEquals(rs.getBigDecimal(5), new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
    assertEquals(rs.getDate(6), date);
}

From source file:com.zimbra.qa.unittest.TestImap.java

private void appendInvalidFlag(String flag) throws IOException {
    Literal msg = message(10);// w  w w. j  a  v a  2s  .c o  m
    Flags flags = Flags.fromSpec("afs");
    flags.set(flag);
    Date date = new Date(System.currentTimeMillis());
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        fail("server allowed client to set system flag " + flag);
    } catch (CommandFailedException e) {
        //expected
    } finally {
        msg.dispose();
    }
    connection.noop(); //do a no-op so we don't hit max consecutive error limit
}

From source file:eionet.meta.service.CSVVocabularyImportServiceTest.java

/**
 * In this test, two line CSV is imported. Rows are derived from base CSV. Just identifiers are updated. Both purge operations
 * are tested.//from   w ww.j  a v  a  2s.  c om
 *
 * @throws Exception
 */
@Test
@Rollback
public void testIfConceptsAddedBoundElementsRemovedAndNewElementsAddedAfterAllPurge() 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_5.csv");

    // import CSV into database
    vocabularyImportService.importCsvIntoVocabulary(reader, vocabularyFolder, true, true);
    Assert.assertFalse("Transaction rolled back (unexpected)",
            transactionManager.getTransaction(null).isRollbackOnly());

    // manually create values for data elements
    String[] boundElementIdentifiers = new String[] { "skos:relatedMatch", "skos:prefLabel", "skos:definition",
            "env:prefLabel", "env:definition", "env:declaration" };
    List<String> boundElements = new ArrayList<String>(Arrays.asList(boundElementIdentifiers));

    // get updated values of data elements of this vocabulary folder
    List<DataElement> boundElementsUpdated = vocabularyService
            .getVocabularyDataElements(vocabularyFolder.getId());
    Assert.assertEquals("Updated bound elements does not include 6 items", boundElementsUpdated.size(), 6);

    // compare manually updated objects with queried ones (after import operation)
    // just compare identifiers
    for (DataElement boundElem : boundElementsUpdated) {
        Assert.assertTrue("Does not contain element with identifier: " + boundElem.getIdentifier(),
                boundElements.remove(boundElem.getIdentifier()));
    }
    Assert.assertEquals("Some elements didn't match", boundElements.size(), 0);

    // manually create values of new concepts for comparison
    concepts.remove(2);// remove last object
    concepts.get(0).setIdentifier("csv_test_concept_1_after_purge_2");
    concepts.get(0).setStatus(StandardGenericStatus.VALID);
    concepts.get(0).setAcceptedDate(new Date(System.currentTimeMillis()));
    concepts.get(0).setStatusModified(new Date(System.currentTimeMillis()));
    concepts.get(1).setIdentifier("csv_test_concept_2_after_purge_2");
    concepts.get(1).setStatus(StandardGenericStatus.VALID);
    concepts.get(1).setAcceptedDate(new Date(System.currentTimeMillis()));
    concepts.get(1).setStatusModified(new Date(System.currentTimeMillis()));

    // create element attributes
    List<List<DataElement>> elementAttributes = null;
    DataElement elem = null;
    String identifier = null;
    int dataElemId = -1;
    List<DataElement> elements = null;

    // CONCEPT 1
    elementAttributes = new ArrayList<List<DataElement>>();
    // skos:relatedMatch
    identifier = "skos:relatedMatch";
    dataElemId = 6;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("csv_test_concept_1");
    elements.add(elem);

    elementAttributes.add(elements);

    // skos:prefLabel
    identifier = "skos:prefLabel";
    dataElemId = 8;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("bg_csv_test_concept_1");
    elem.setAttributeLanguage("bg");
    elements.add(elem);

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("en_csv_test_concept_1");
    elem.setAttributeLanguage("en");
    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("pl_csv_test_concept_1");
    elem.setAttributeLanguage("pl");
    elements.add(elem);

    elementAttributes.add(elements);

    // env:prefLabel
    identifier = "env:prefLabel";
    dataElemId = 10;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("en_csv_test_concept_1");
    elem.setAttributeLanguage("en");
    elements.add(elem);

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("lt_csv_test_concept_1");
    elem.setAttributeLanguage("lt");
    elements.add(elem);

    elementAttributes.add(elements);

    // env:definition
    identifier = "env:definition";
    dataElemId = 11;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("csv_test_concept_1");
    elements.add(elem);

    elementAttributes.add(elements);
    concepts.get(0).setElementAttributes(elementAttributes);

    // CONCEPT 2
    elementAttributes = new ArrayList<List<DataElement>>();
    // skos:relatedMatch
    identifier = "skos:relatedMatch";
    dataElemId = 6;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("csv_test_concept_2");
    elements.add(elem);

    elementAttributes.add(elements);

    // skos:prefLabel
    identifier = "skos:prefLabel";
    dataElemId = 8;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("et_csv_test_concept_2");
    elem.setAttributeLanguage("et");
    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("en_csv_test_concept_2");
    elem.setAttributeLanguage("en");
    elements.add(elem);

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("pl_csv_test_concept_2");
    elem.setAttributeLanguage("pl");
    elements.add(elem);

    elementAttributes.add(elements);

    // env:prefLabel
    identifier = "env:prefLabel";
    dataElemId = 10;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("en_csv_test_concept_2");
    elem.setAttributeLanguage("en");
    elements.add(elem);

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("de_csv_test_concept_2");
    elem.setAttributeLanguage("de");
    elements.add(elem);

    elementAttributes.add(elements);

    // env:declaration
    identifier = "env:declaration";
    dataElemId = 13;
    elements = new ArrayList<DataElement>();

    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("csv_test_concept_2");
    elements.add(elem);

    elementAttributes.add(elements);
    concepts.get(1).setElementAttributes(elementAttributes);

    // get updated values of concepts with attributes
    List<VocabularyConcept> updatedConcepts = getVocabularyConceptsWithAttributes(vocabularyFolder);
    Assert.assertEquals("Updated Concepts does not include 2 vocabulary concepts", 2, updatedConcepts.size());

    // concepts should be inserted in the same order as they are in csv file, get ids from updated beans
    concepts.get(0)
            .setId(findVocabularyConceptByIdentifier(updatedConcepts, concepts.get(0).getIdentifier()).getId());
    concepts.get(1)
            .setId(findVocabularyConceptByIdentifier(updatedConcepts, concepts.get(1).getIdentifier()).getId());

    // compare manually updated objects with queried ones (after import operation)
    ReflectionAssert.assertReflectionEquals(concepts, updatedConcepts, ReflectionComparatorMode.LENIENT_DATES,
            ReflectionComparatorMode.LENIENT_ORDER);
}

From source file:com.zimbra.qa.unittest.TestImap.java

@Test
public void testAppendTagsDirty() throws Exception {
    Flags flags = Flags.fromSpec("afs");
    final String tag1 = "NEWDIRTYTAG"; //new tag; does not exist in mbox
    MailboxInfo info = connection.select("INBOX");
    assertFalse("INBOX contains unexpected flag " + tag1, info.getFlags().isSet(tag1));

    flags.set(tag1);//from  w  w w.ja va2s . co  m
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(10);
    try {
        ImapRequest req = connection.newRequest("APPEND", "INBOX", flags, date, msg);
        req.setResponseHandler(new ResponseHandler() {
            @Override
            public void handleResponse(ImapResponse res) throws Exception {
                if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                    Flags flags = (Flags) res.getData();
                    assertTrue(flags.isSet(tag1));
                }
            }
        });
        req.sendCheckStatus();
    } finally {
        msg.dispose();
    }

}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void insertOpenbareRuimten(final List<OpenbareRuimte> openbareRuimten) throws DAOException {
    try {//  w w  w  .  ja  va 2  s  .c  o  m
        jdbcTemplate.batchUpdate("insert into bag_openbare_ruimte (" + "bag_openbare_ruimte_id,"
                + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "openbare_ruimte_naam,"
                + "officieel," + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid,"
                + "in_onderzoek," + "openbare_ruimte_type," + "bron_documentdatum," + "bron_documentnummer,"
                + "openbareruimte_status," + "bag_woonplaats_id," + "verkorte_openbare_ruimte_naam"
                + ") values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
                    @Override
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
                        ps.setLong(1, openbareRuimten.get(i).getIdentificatie());
                        ps.setInt(2, openbareRuimten.get(i).getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, openbareRuimten.get(i).getAanduidingRecordCorrectie());
                        ps.setString(4, openbareRuimten.get(i).getOpenbareRuimteNaam());
                        ps.setInt(5, openbareRuimten.get(i).getOfficieel().ordinal());
                        ps.setTimestamp(6, new Timestamp(
                                openbareRuimten.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                        if (openbareRuimten.get(i).getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(7, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(7, new Timestamp(
                                    openbareRuimten.get(i).getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(8, openbareRuimten.get(i).getInOnderzoek().ordinal());
                        ps.setInt(9, openbareRuimten.get(i).getOpenbareRuimteType().ordinal());
                        ps.setDate(10, new Date(openbareRuimten.get(i).getDocumentdatum().getTime()));
                        ps.setString(11, openbareRuimten.get(i).getDocumentnummer());
                        ps.setInt(12, openbareRuimten.get(i).getOpenbareruimteStatus().ordinal());
                        ps.setLong(13, openbareRuimten.get(i).getGerelateerdeWoonplaats());
                        ps.setString(14, openbareRuimten.get(i).getVerkorteOpenbareRuimteNaam());
                    }

                    @Override
                    public int getBatchSize() {
                        return openbareRuimten.size();
                    }
                });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting openbare ruimten", e);
    }
}