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:view.PnStatistic.java

private CategoryDataset createDatasetMonth(int month, int year) {
    String categotyRoom = "Phng";
    String categoryService = "Dch v";
    String categoryAll = "Tng cng";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month - 1, calendar.get(Calendar.DATE));
    int maxDay = CommonFunction.getDateOfMonth(new Date(calendar.getTimeInMillis()));
    for (int i = 1; i <= maxDay; i++) {
        calendar.set(Calendar.DATE, i);
        double incomeRoom = mModelRoomStatus.getIncomeRoomByDay(new Date(calendar.getTimeInMillis()));
        double incomeService = mModelCustomerService.getIncomeByDate(new Date(calendar.getTimeInMillis()));
        dataset.addValue(incomeRoom, categotyRoom, "Ngy " + i);
        dataset.addValue(incomeService, categoryService, "Ngy " + i);
        dataset.addValue(incomeRoom + incomeService, categoryAll, "Ngy " + i);
    }//from   www.j  a v  a2 s  .c o m
    return dataset;
}

From source file:com.nabla.dc.server.xml.settings.XmlCompany.java

public boolean save(final Connection conn, final Map<String, Integer> companyIds, final SaveContext ctx)
        throws SQLException, DispatchException {
    Integer companyId = companyIds.get(getName());
    if (companyId != null) {
        if (ctx.getOption() == SqlInsertOptions.APPEND)
            return true;
        Database.executeUpdate(conn, "UPDATE company SET active=? WHERE id=?;", active, companyId);
        Database.executeUpdate(conn, "DELETE FROM financial_year WHERE company_id=?;", companyId);
        if (accounts != null) {
            if (log.isDebugEnabled())
                log.debug("deleting all accounts of company '" + getName() + "'");
            accounts.clear(conn, companyId);
        }/*from w  w w . jav  a 2  s .  c  om*/
        if (asset_categories != null)
            asset_categories.clear(conn, companyId);
        if (users != null)
            users.clear(conn, companyId);
    } else {
        companyId = Database.addRecord(conn, "INSERT INTO company (name,uname,active) VALUES(?,?,?);",
                getName(), getName().toUpperCase(), active);
        if (companyId == null)
            throw new InternalErrorException(Util.formatInternalErrorDescription("failed to insert company"));
        companyIds.put(getName(), companyId);
    }
    final Integer financialYearId = Database.addRecord(conn,
            "INSERT INTO financial_year (company_id, name) VALUES(?,?);", companyId, financial_year);
    final PreparedStatement stmt = conn
            .prepareStatement("INSERT INTO period_end (financial_year_id,name,end_date) VALUES(?,?,?);");
    try {
        stmt.setInt(1, financialYearId);
        final Calendar dt = new GregorianCalendar();
        dt.setTime(start_date);
        final SimpleDateFormat financialYearFormat = new SimpleDateFormat("MMM yyyy");
        for (int m = 0; m < 12; ++m) {
            dt.set(GregorianCalendar.DAY_OF_MONTH, dt.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
            final Date end = new Date(dt.getTime().getTime());
            stmt.setString(2, financialYearFormat.format(end));
            stmt.setDate(3, end);
            stmt.addBatch();
            dt.add(GregorianCalendar.MONTH, 1);
        }
        if (!Database.isBatchCompleted(stmt.executeBatch()))
            throw new InternalErrorException(Util
                    .formatInternalErrorDescription("fail to insert periods for company '" + getName() + "'"));
    } finally {
        stmt.close();
    }
    if (accounts != null)
        accounts.save(conn, companyId);
    return (asset_categories == null || asset_categories.save(conn, companyId, ctx))
            && (users == null || users.save(conn, companyId, ctx));
}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

private void verifyResult(ResultSet rs, int i) throws SQLException {
    assertTrue(rs.next());/*from  w w w.  j a v a 2 s  . c o  m*/
    assertEquals("VARCHAR" + String.valueOf(i) + "_" + StringUtils.rightPad("CHAR" + String.valueOf(i), 6, ' ')
            + "_A.VARCHAR" + String.valueOf(i) + "_"
            + StringUtils.rightPad("B.CHAR" + String.valueOf(i), 10, ' '), rs.getString(1));
    assertEquals(i * 3, rs.getInt(2));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i) * NUM_MILLIS_IN_DAY);
    assertEquals(date, rs.getDate(3));
    assertEquals(date, rs.getDate(4));
    assertEquals(date, rs.getDate(5));
    assertEquals("varchar" + String.valueOf(i), rs.getString(6));
    assertEquals("char" + String.valueOf(i), rs.getString(7));
    assertEquals(i, rs.getInt(8));
    assertEquals(i, rs.getLong(9));
    assertEquals(i * 0.5d, rs.getDouble(10), 0.000001);
    assertEquals(i, rs.getLong(11));
    assertEquals(i, rs.getLong(12));
}

From source file:org.pegadi.server.sources.SourceServerImpl.java

public void updateContacts(Source source) {

    final List<Contact> contacts = source.getContacts();
    template.update("DELETE FROM Source_Contact WHERE sourceID=?", source.getID());
    for (Contact contact : contacts) {
        template.update("INSERT INTO Source_Contact (sourceID,time_of_contact,notes) VALUES (?,?,?)",
                contact.getSourceID(), new Date(contact.getDate().getTime()), contact.getNotes());
    }//w  w w .jav  a2 s  . c  o  m
    log.info("Inserting {} contacts for source {}", contacts.size(), source.getID());
}

From source file:org.ujorm.hotels.services.DatabaseTest.java

/** Returns the current day */
private Date now() {
    return new Date(System.currentTimeMillis());
}

From source file:org.hibernate.search.test.performance.scenario.TestScenario.java

protected void initDatabase(SessionFactory sf) {
    log("starting initialize database");

    initDatabaseStopWatch.start();/*from   www .j  a v a  2 s  . c om*/

    BatchSupport batchSupport = new BatchSupport(sf, initialOffset);
    batchSupport.execute("insert into author(id, name) values(?, ?)", initialAutorCount, new BatchCallback() {
        @Override
        public void initStatement(PreparedStatement ps, long id) throws SQLException {
            ps.setLong(1, id);
            ps.setString(2, "autor" + id);
        }
    });
    batchSupport.execute(
            "insert into book(id, title, summary, rating, totalSold, publicationDate) values(?, ?, ?, ?, ?, ?)",
            initialBookCount, new BatchCallback() {
                @Override
                public void initStatement(PreparedStatement ps, long id) throws SQLException {
                    ps.setLong(1, id);
                    ps.setString(2, "title" + id);
                    ps.setString(3, reverse(SUMMARIES[(int) (id % SUMMARIES.length)]));
                    ps.setLong(4, -1);
                    ps.setLong(5, -1);
                    ps.setDate(6, new Date(PUBLICATION_DATE_ZERO.getTime()));
                }
            });
    batchSupport.execute("insert into book_author(book_id, authors_id) values(?, ?)", initialBookCount,
            new BatchCallback() {
                @Override
                public void initStatement(PreparedStatement ps, long id) throws SQLException {
                    ps.setLong(1, id);
                    ps.setLong(2, initialOffset + (id % initialAutorCount));
                }
            });

    initDatabaseStopWatch.stop();
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

private static void initDateTableValues(String tablename, Connection conn, String tenantId, Date startDate)
        throws Exception {
    double dateIncrement = 2.0;
    PreparedStatement stmt = conn.prepareStatement("upsert into " + tablename + "(" + "    ORGANIZATION_ID, "
            + "    \"DATE\", " + "    FEATURE, " + "    UNIQUE_USERS, " + "    TRANSACTIONS, "
            + "    CPU_UTILIZATION, " + "    DB_UTILIZATION, " + "    REGION, " + "    IO_TIME)"
            + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, tenantId);/*from ww  w. ja va 2  s  . c om*/
    stmt.setDate(2, startDate);
    stmt.setString(3, "A");
    stmt.setInt(4, 10);
    stmt.setLong(5, 100L);
    stmt.setBigDecimal(6, BigDecimal.valueOf(0.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.2));
    stmt.setString(8, R2);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();

    startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement));
    stmt.setString(1, tenantId);
    stmt.setDate(2, startDate);
    stmt.setString(3, "B");
    stmt.setInt(4, 20);
    stmt.setLong(5, 200);
    stmt.setBigDecimal(6, BigDecimal.valueOf(1.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.4));
    stmt.setString(8, null);
    stmt.setLong(9, 2000);
    stmt.execute();

    startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement));
    stmt.setString(1, tenantId);
    stmt.setDate(2, startDate);
    stmt.setString(3, "C");
    stmt.setInt(4, 30);
    stmt.setLong(5, 300);
    stmt.setBigDecimal(6, BigDecimal.valueOf(2.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.6));
    stmt.setString(8, R1);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();

    startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement));
    stmt.setString(1, tenantId);
    stmt.setDate(2, startDate);
    stmt.setString(3, "D");
    stmt.setInt(4, 40);
    stmt.setLong(5, 400);
    stmt.setBigDecimal(6, BigDecimal.valueOf(3.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.8));
    stmt.setString(8, R1);
    stmt.setLong(9, 4000);
    stmt.execute();

    startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement));
    stmt.setString(1, tenantId);
    stmt.setDate(2, startDate);
    stmt.setString(3, "E");
    stmt.setInt(4, 50);
    stmt.setLong(5, 500);
    stmt.setBigDecimal(6, BigDecimal.valueOf(3.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(1.2));
    stmt.setString(8, R2);
    stmt.setLong(9, 5000);
    stmt.execute();

    startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement));
    stmt.setString(1, tenantId);
    stmt.setDate(2, startDate);
    stmt.setString(3, "F");
    stmt.setInt(4, 60);
    stmt.setLong(5, 600);
    stmt.setBigDecimal(6, BigDecimal.valueOf(4.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(1.4));
    stmt.setString(8, null);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();
}

From source file:org.eluder.coveralls.maven.plugin.json.JsonWriterTest.java

private Job job() {
    Git.Head head = new Git.Head("aefg837fge", "john", "john@mail.com", "john", "john@mail.com", "test commit");
    Git.Remote remote = new Git.Remote("origin", "git@git.com:foo.git");
    Properties environment = new Properties();
    environment.setProperty("custom_property", "foobar");
    return new Job().withServiceName("service").withServiceJobId("job123").withServiceBuildNumber("build5")
            .withServiceBuildUrl("http://ci.com/build5").withServiceEnvironment(environment)
            .withBranch("master").withPullRequest("pull10").withTimestamp(new Date(TEST_TIME))
            .withGit(new Git(null, head, "af456fge34acd", Arrays.asList(remote)));
}

From source file:com.antsdb.saltedfish.storage.Helper.java

public static Object hBaseDataToObject(int valueType, byte[] value) {

    if (valueType == Value.TYPE_NULL) {
        return null;
    }/*from   w ww .j ava  2  s . c o m*/

    if (value == null
            || (value.length == 0 && (valueType != Value.FORMAT_UNICODE16 && valueType != Value.FORMAT_UTF8))) {
        return null;
    }

    Object result = null;
    if (valueType == Value.FORMAT_INT4) {
        result = Bytes.toInt(value);
    } else if (valueType == Value.FORMAT_INT8) {
        result = Bytes.toLong(value);
    } else if (valueType == Value.FORMAT_NULL) {
        result = null;
    } else if (valueType == Value.FORMAT_BOOL) {
        result = Bytes.toBoolean(value);
    } else if (valueType == Value.FORMAT_DECIMAL) {
        result = Bytes.toBigDecimal(value);
    } else if (valueType == Value.FORMAT_FAST_DECIMAL) {
        result = Bytes.toBigDecimal(value);
        //         FastDecimal fastDecimal = (FastDecimal)FishObject.get(null, valueAddr);
        // convert fastDecimal to bytes...
        //valueByte = ByteBuffer.wrap(Bytes.toBytes(fastDecimal));
    } else if (valueType == Value.FORMAT_FLOAT4) {
        result = Bytes.toFloat(value);
    } else if (valueType == Value.FORMAT_FLOAT8) {
        result = Bytes.toDouble(value);
    } else if (valueType == Value.FORMAT_UNICODE16) {
        result = value;
        char[] chars = new char[value.length / 2];
        for (int i = 0; i < value.length / 2; i++) {
            chars[i] = (char) ((((int) value[i * 2 + 1]) << 8) | value[i * 2]);
        }
        result = new String(chars);
    } else if (valueType == Value.FORMAT_DATE) {
        long time = Bytes.toLong(value);
        result = new Date(time);
    } else if (valueType == Value.FORMAT_TIMESTAMP) {
        long time = Bytes.toLong(value);
        result = new Timestamp(time);
    } else if (valueType == Value.FORMAT_BYTES) {
        result = value;
    } else {
        throw new NotImplementedException();
    }
    return result;
}

From source file:com.heliumv.api.machine.MachineApi.java

private MachineAvailabilityEntryList getAvailabilitiesImpl(Integer machineId, Long dateMs, Integer days,
        Boolean withDescription) throws NamingException, RemoteException {
    MachineAvailabilityEntryList entries = new MachineAvailabilityEntryList();

    Date d = null;/*from ww  w.  ja  v  a  2s  . c  o  m*/
    if (dateMs == null) {
        d = new Date(System.currentTimeMillis());
    } else {
        d = new Date(dateMs);
    }

    if (days == null) {
        days = new Integer(1);
    } else {
        if (days < 0) {
            respondBadRequest("days", "value = '" + days + "' is not >= 0.");
            return entries;
        }
    }

    if (withDescription == null) {
        withDescription = new Boolean(false);
    }

    List<MaschinenVerfuegbarkeitsStundenDto> dtos = maschineCall.getVerfuegbarkeitStunden(machineId, d, days);

    Map<Integer, DayTypeEntry> mapTypes = null;

    if (withDescription) {
        List<DayTypeEntry> dayTypes = zeiterfassungCall.getAllSprTagesarten();
        mapTypes = new HashMap<Integer, DayTypeEntry>();
        for (DayTypeEntry dayTypeEntry : dayTypes) {
            mapTypes.put(dayTypeEntry.getId(), dayTypeEntry);
        }
    }

    List<MachineAvailabilityEntry> apiDtos = new ArrayList<MachineAvailabilityEntry>();
    for (MaschinenVerfuegbarkeitsStundenDto dto : dtos) {
        MachineAvailabilityEntry entry = new MachineAvailabilityEntry();
        entry.setMachineId(dto.getMaschineId());
        entry.setDayTypeId(dto.getTagesartId());
        entry.setAvailabilityHours(dto.getVerfuegbarkeitH());
        entry.setDateMs(dto.getDate().getTime());
        if (mapTypes != null) {
            if (mapTypes.get(dto.getTagesartId()) == null) {
                entry.setDayTypeDescription("Unbekannt (" + dto.getTagesartId() + ").");
            } else {
                entry.setDayTypeDescription(mapTypes.get(dto.getTagesartId()).getDescription());
            }
        }
        apiDtos.add(entry);
    }

    entries.setEntries(apiDtos);
    return entries;
}