Example usage for org.hibernate.type StandardBasicTypes DATE

List of usage examples for org.hibernate.type StandardBasicTypes DATE

Introduction

In this page you can find the example usage for org.hibernate.type StandardBasicTypes DATE.

Prototype

DateType DATE

To view the source code for org.hibernate.type StandardBasicTypes DATE.

Click Source Link

Document

The standard Hibernate type for mapping java.util.Date ( java.sql.Date ) to JDBC java.sql.Types#DATE DATE .

Usage

From source file:org.ambraproject.models.AnnotationTest.java

License:Apache License

@Test
@SuppressWarnings("unchecked")
public void testLoadTypeFromStringRepresentation() {
    final Long userId = (Long) hibernateTemplate
            .save(new UserProfile("email@LoadType.org", "displayNameForLoadType", "pass"));
    final Long articleId = (Long) hibernateTemplate.save(new Article("id:doi-for-LoadType"));

    hibernateTemplate.execute(new HibernateCallback() {
        @Override//from w w  w .  ja  va 2s .co m
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            session.createSQLQuery(
                    "insert into annotation (created, lastModified, userProfileID, articleID, type, annotationURI) "
                            + "values (?,?,?,?,?,?)")
                    .setParameter(0, Calendar.getInstance().getTime(), StandardBasicTypes.DATE)
                    .setParameter(1, Calendar.getInstance().getTime(), StandardBasicTypes.DATE)
                    .setParameter(2, userId, StandardBasicTypes.LONG)
                    .setParameter(3, articleId, StandardBasicTypes.LONG)
                    .setParameter(4, "Comment", StandardBasicTypes.STRING)
                    .setParameter(5, "unique-annotation-uri-for-loadTypeFromString", StandardBasicTypes.STRING)
                    .executeUpdate();
            return null;
        }
    });

    List<Annotation> results = (List<Annotation>) hibernateTemplate
            .find("from Annotation where annotationUri = ?", "unique-annotation-uri-for-loadTypeFromString");
    assertEquals(results.size(), 1, "didn't store annotation correctly");
    assertEquals(results.get(0).getType(), AnnotationType.COMMENT, "Type wasn't loaded correctly");
}

From source file:org.egov.egf.web.actions.report.BudgetAppropriationRegisterReportAction.java

License:Open Source License

private void generateReport() {
    CFinancialYear financialYr = new CFinancialYear();
    financialYr = financialYearDAO.getFinancialYearByDate(dtAsOnDate);
    CFinancialYear financialYear = null;
    financialYear = financialYearDAO.getFinancialYearById(Long.valueOf(financialYr.getId()));
    finYearRange = financialYear.getFinYearRange();
    final Date dStartDate = financialYear.getStartingDate();
    final String strAODate = Constants.DDMMYYYYFORMAT1.format(dtAsOnDate);
    final String strStDate = Constants.DDMMYYYYFORMAT1.format(dStartDate);

    Query query = null;// www.ja  va 2  s. c  om

    if (budgetGroup != null) {
        budgetHead = budgetGroup.getName();
        StringBuilder strQuery = new StringBuilder();
        strQuery.append(
                "select vmis.budgetary_appnumber as bdgApprNumber, vh.vouchernumber as VoucherNumber, vh.voucherdate as voucherDate, vh.description as description,vh.createddate as createdDate, ");
        strQuery.append(
                " null as billNumber, null as billDate,null as billCreatedDate, gl.debitamount as debitAmount, gl.creditamount as creditAmount from generalledger gl, vouchermis vmis,  ");
        strQuery.append(
                " voucherheader vh  where vh.id = gl.voucherheaderid and vh.id = vmis.voucherheaderid and  gl.glcodeid =:glCodeId");
        strQuery.append(
                " and (vmis.budgetary_appnumber  != 'null' and vmis.budgetary_appnumber is not null) and vh.status != 4 and vh.voucherdate  >=:strStDate");
        strQuery.append(" and vh.voucherdate <=:strAODate");
        strQuery.append(getFunctionQuery("gl.functionid"));
        strQuery.append(getDepartmentQuery("vmis.departmentid"));
        strQuery.append(getFundQuery("vh.fundid"));
        strQuery.append(" ");
        strQuery.append(
                " union select distinct bmis.budgetary_appnumber as bdgApprNumber, vh1.vouchernumber as VoucherNumber, vh1.voucherdate as  voucherDate , br.narration as description,vh1.createddate as createdDate, br.billnumber as billNumber, br.billdate as billDate,br.createddate as billCreatedDate ,  bd.debitamount as debitAmount, bd.creditamount as creditAmount  ");
        strQuery.append(
                " from eg_billdetails bd, eg_billregistermis bmis, eg_billregister br, voucherHeader vh1 where br.id = bd.billid and br.id = bmis.billid and  bd.glcodeid =:glCodeId ");
        strQuery.append(
                " and (bmis.budgetary_appnumber != 'null' and bmis.budgetary_appnumber is not null) and br.statusid not in (select id from egw_status where description='Cancelled' and moduletype in ('EXPENSEBILL', 'SALBILL', 'WORKSBILL', 'PURCHBILL', 'CBILL', 'SBILL', 'CONTRACTORBILL')) and (vh1.id = bmis.voucherheaderid )  and br.billdate  >=:strStDate");
        strQuery.append(" and br.billdate  <=:strAODate");
        strQuery.append(getFunctionQuery("bd.functionid"));
        strQuery.append(getDepartmentQuery("bmis.departmentid"));
        strQuery.append(getFundQuery("bmis.fundid"));
        strQuery.append("  ");
        strQuery.append(
                " union select distinct bmis1.budgetary_appnumber as bdgApprNumber, null as VoucherNumber,cast( null as date) voucherDate , ");
        strQuery.append(
                " br.narration as description,cast( null as date) createdDate, br.billnumber as billNumber, br.billdate as billDate,br.createddate as billCreatedDate ,   bd1.debitamount as debitAmount, bd1.creditamount as creditAmount from eg_billdetails bd1, eg_billregistermis bmis1, eg_billregister br  ");
        strQuery.append(" where br.id = bd1.billid and br.id = bmis1.billid and  bd1.glcodeid =:glCodeId ");
        strQuery.append(
                " and (bmis1.budgetary_appnumber != 'null' and bmis1.budgetary_appnumber is not null) ");
        strQuery.append(
                " and br.statusid not in (select id from egw_status where description='Cancelled' and moduletype in ('EXPENSEBILL', 'SALBILL', 'WORKSBILL', 'PURCHBILL', 'CBILL', 'SBILL', 'CONTRACTORBILL')) and bmis1.voucherheaderid is null and br.billdate   >=:strStDate");
        strQuery.append(" and br.billdate <=:strAODate");
        strQuery.append(getFunctionQuery("bd1.functionid"));
        strQuery.append(getDepartmentQuery("bmis1.departmentid"));
        strQuery.append(getFundQuery("bmis1.fundid"));
        strQuery.append("  order by bdgApprNumber ");

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("BudgetAppropriationRegisterReportAction -- strQuery...." + strQuery);

        query = persistenceService.getSession().createSQLQuery(strQuery.toString()).addScalar("bdgApprNumber")
                .addScalar("voucherDate", StandardBasicTypes.DATE)
                .addScalar("billDate", StandardBasicTypes.DATE)
                .addScalar("createdDate", StandardBasicTypes.DATE)
                .addScalar("billCreatedDate", StandardBasicTypes.DATE).addScalar("description")
                .addScalar("VoucherNumber").addScalar("billNumber")
                .addScalar("debitAmount", BigDecimalType.INSTANCE)
                .addScalar("creditAmount", BigDecimalType.INSTANCE)
                .setResultTransformer(Transformers.aliasToBean(BudgetAppDisplay.class));
        query = setParameterForBudgetAppDisplay(query, dtAsOnDate, dStartDate);
    }
    budgetAppropriationRegisterList = query.list();

    List<BudgetAppDisplay> budgetApprRegNewList = new ArrayList<BudgetAppDisplay>();
    final List<BudgetAppDisplay> budgetApprRegUpdatedList1 = new ArrayList<BudgetAppDisplay>();
    final HashMap<String, BudgetAppDisplay> regMap = new HashMap<String, BudgetAppDisplay>();
    if (budgetAppropriationRegisterList.size() > 0) {
        StringBuilder strsubQuery = new StringBuilder();
        strsubQuery.append(
                "select vmis.budgetary_appnumber as bdgApprNumber, vh.vouchernumber as VoucherNumber, vh.voucherdate as voucherDate, vh.description as description,vh.createddate as createdDate, ");
        strsubQuery.append(
                " br.billnumber as billNumber, br.billdate as billDate,br.createddate as billCreatedDate, gl.debitamount as debitAmount, gl.creditamount as creditAmount from generalledger gl, vouchermis vmis,  ");
        strsubQuery.append(
                " voucherheader vh,  eg_billregistermis bmis, eg_billregister br  where vh.id = gl.voucherheaderid and vh.id = vmis.voucherheaderid and vh.id = bmis.voucherheaderid and bmis.billid = br.id ");
        strsubQuery.append(" and  gl.glcodeid =:glCodeId ");
        strsubQuery.append(" and  ");
        strsubQuery.append(
                " (vmis.budgetary_appnumber  != 'null' and vmis.budgetary_appnumber is not null) and vh.status != 4 and vh.voucherdate  >=:strStDate");
        strsubQuery.append(" and vh.voucherdate <=:strAODate");
        strsubQuery.append(getFunctionQuery("gl.functionid"));
        strsubQuery.append(getDepartmentQuery("vmis.departmentid"));
        strsubQuery.append(getFundQuery("vh.fundid"));
        strsubQuery.append("  order by bdgApprNumber ");

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("BudgetAppropriationRegisterReportAction -- strsubQuery...." + strsubQuery);

        query = persistenceService.getSession().createSQLQuery(strsubQuery.toString())
                .addScalar("bdgApprNumber").addScalar("voucherDate", StandardBasicTypes.DATE)
                .addScalar("billDate", StandardBasicTypes.DATE)
                .addScalar("createdDate", StandardBasicTypes.DATE)
                .addScalar("billCreatedDate", StandardBasicTypes.DATE).addScalar("description")
                .addScalar("VoucherNumber").addScalar("billNumber")
                .addScalar("debitAmount", BigDecimalType.INSTANCE)
                .addScalar("creditAmount", BigDecimalType.INSTANCE)
                .setResultTransformer(Transformers.aliasToBean(BudgetAppDisplay.class));
        query = setParameterForBudgetAppDisplay(query, dtAsOnDate, dStartDate);
        budgetApprRegNewList = query.list();
        if (budgetApprRegNewList.size() > 0) {
            for (final BudgetAppDisplay budgetAppRtDisp : budgetApprRegNewList)
                regMap.put(budgetAppRtDisp.getBdgApprNumber(), budgetAppRtDisp);

            for (final BudgetAppDisplay budgetAppropriationRegisterDisp : budgetAppropriationRegisterList)
                if (regMap.containsKey(budgetAppropriationRegisterDisp.getBdgApprNumber()))
                    budgetApprRegUpdatedList1
                            .add(regMap.get(budgetAppropriationRegisterDisp.getBdgApprNumber()));
                else
                    budgetApprRegUpdatedList1.add(budgetAppropriationRegisterDisp);
        }
    }
    if (budgetApprRegUpdatedList1.size() > 0) {
        budgetAppropriationRegisterList.clear();
        budgetAppropriationRegisterList.addAll(budgetApprRegUpdatedList1);
    }
    updateBdgtAppropriationList();
}

From source file:org.egov.egf.web.actions.report.ChequeIssueRegisterReportAction.java

License:Open Source License

public void generateReport() throws JRException, IOException {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("----Inside generateReport---- ");

    accountNumber = (Bankaccount) persistenceService.find("from Bankaccount where id=?", accountNumber.getId());
    if (accountNumber.getChequeformat() != null && !accountNumber.getChequeformat().equals("")) {
        chequeFormat = accountNumber.getChequeformat().getId().toString();
    }/*from www  .  ja v  a  2  s . c om*/

    validateDates(fromDate, toDate);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Querying to date range " + getFormattedDate(fromDate) + "to date "
                + getFormattedDate(getNextDate(toDate)));
    // persistenceService.setType(InstrumentHeader.class);
    final List<AppConfigValues> printAvailConfig = appConfigValuesService
            .getConfigValuesByModuleAndKey(FinancialConstants.MODULE_NAME_APPCONFIG, "chequeprintavailableat");

    chequePrintingEnabled = isChequePrintEnabled();

    for (final AppConfigValues appConfigVal : printAvailConfig)
        chequePrintAvailableAt = appConfigVal.getValue();

    final Query query = persistenceService.getSession()
            .createSQLQuery("select ih.instrumentnumber as chequeNumber,ih.instrumentdate as chequeDate,"
                    + "ih.instrumentamount as chequeAmount,vh.vouchernumber as voucherNumber,vh.id as vhId,ih.serialno as serialNo,vh.voucherdate as voucherDate,vh.name as voucherName,ih.payto as payTo,mbd.billnumber as billNumber,"
                    + "mbd.billDate as billDate,vh.type as type,es.DESCRIPTION as chequeStatus,ih.id as instrumentheaderid from egf_instrumentHeader ih,egf_instrumentvoucher iv,EGW_STATUS es,"
                    + "voucherheader vh left outer join miscbilldetail mbd on  vh.id=mbd.PAYVHID ,vouchermis vmis where ih.instrumentDate <'"
                    + getFormattedDate(getNextDate(toDate)) + "' and ih.instrumentDate>='"
                    + getFormattedDate(fromDate) + "' and ih.isPayCheque='1' "
                    + "and ih.INSTRUMENTTYPE=(select id from egf_instrumenttype where TYPE='cheque' ) and vh.status not in ("
                    + getExcludeVoucherStatues() + ") and vh.id=iv.voucherheaderid and  bankAccountId="
                    + accountNumber.getId() + " and ih.id=iv.instrumentheaderid and ih.id_status=es.id "
                    + " and vmis.voucherheaderid=vh.id " + createQuery()
                    + " order by ih.instrumentDate,ih.instrumentNumber ")
            .addScalar("chequeNumber").addScalar("chequeDate", StandardBasicTypes.DATE)
            .addScalar("chequeAmount", BigDecimalType.INSTANCE).addScalar("voucherNumber")
            .addScalar("voucherDate", StandardBasicTypes.DATE).addScalar("voucherName").addScalar("payTo")
            .addScalar("billNumber").addScalar("billDate", StandardBasicTypes.DATE).addScalar("type")
            .addScalar("vhId", BigDecimalType.INSTANCE).addScalar("serialNo", LongType.INSTANCE)
            .addScalar("chequeStatus").addScalar("instrumentHeaderId", LongType.INSTANCE)
            .setResultTransformer(Transformers.aliasToBean(ChequeIssueRegisterDisplay.class));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Search query" + query.getQueryString());
    chequeIssueRegisterList = query.list();
    if (chequeIssueRegisterList == null)
        chequeIssueRegisterList = new ArrayList<ChequeIssueRegisterDisplay>();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Got Cheque list| Size of list is" + chequeIssueRegisterList.size());
    updateBillNumber();
    updateVoucherNumber();
    removeDuplicates();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("--End  generateReport--");
}

From source file:org.exoplatform.services.organization.hibernate.HibernateListAccess.java

License:Open Source License

/**
 * BindFields.//from w  w w  .  ja  v  a 2s. c o m
 * 
 * @param query
 *          Query
 */
private void bindFields(Query query) {
    for (Entry<String, Object> entry : binding.entrySet()) {
        if (entry.getValue() instanceof Date) {
            query.setParameter(entry.getKey(), entry.getValue(), StandardBasicTypes.DATE);
        } else {
            query.setParameter(entry.getKey(), entry.getValue());
        }
    }
}

From source file:org.jadira.usertype.spi.shared.AbstractDateColumnMapper.java

License:Apache License

@Override
public final DateType getHibernateType() {
    return StandardBasicTypes.DATE;
}

From source file:org.jboss.as.quickstart.hibernate4.util.vertica.VerticaDialect6.java

License:Open Source License

protected void registerFunctions() {
    registerFunction("abs", new StandardSQLFunction("abs"));
    registerFunction("sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER));

    registerFunction("acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE));
    registerFunction("asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE));
    registerFunction("atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE));
    registerFunction("cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE));
    registerFunction("exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE));
    registerFunction("ln", new StandardSQLFunction("ln", StandardBasicTypes.DOUBLE));
    registerFunction("sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE));
    registerFunction("stddev", new StandardSQLFunction("stddev", StandardBasicTypes.DOUBLE));
    registerFunction("sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE));
    registerFunction("tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE));
    registerFunction("variance", new StandardSQLFunction("variance", StandardBasicTypes.DOUBLE));

    registerFunction("round", new StandardSQLFunction("round"));
    registerFunction("trunc", new StandardSQLFunction("trunc"));
    registerFunction("ceil", new StandardSQLFunction("ceil"));
    registerFunction("floor", new StandardSQLFunction("floor"));

    registerFunction("chr", new StandardSQLFunction("chr", StandardBasicTypes.CHARACTER));
    registerFunction("initcap", new StandardSQLFunction("initcap"));
    registerFunction("lower", new StandardSQLFunction("lower"));
    registerFunction("ltrim", new StandardSQLFunction("ltrim"));
    registerFunction("rtrim", new StandardSQLFunction("rtrim"));
    registerFunction("upper", new StandardSQLFunction("upper"));
    registerFunction("ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER));

    registerFunction("to_char", new StandardSQLFunction("to_char", StandardBasicTypes.STRING));
    registerFunction("to_date", new StandardSQLFunction("to_date", StandardBasicTypes.TIMESTAMP));

    registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE, false));
    registerFunction("current_time", new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIME, false));
    registerFunction("current_timestamp",
            new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP, false));

    registerFunction("last_day", new StandardSQLFunction("last_day", StandardBasicTypes.DATE));
    registerFunction("sysdate", new NoArgSQLFunction("sysdate", StandardBasicTypes.DATE, false));
    registerFunction("user", new NoArgSQLFunction("user", StandardBasicTypes.STRING, false));

    // Multi-param string dialect functions...
    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
    registerFunction("instr", new StandardSQLFunction("instr", StandardBasicTypes.INTEGER));
    registerFunction("instrb", new StandardSQLFunction("instrb", StandardBasicTypes.INTEGER));
    registerFunction("lpad", new StandardSQLFunction("lpad", StandardBasicTypes.STRING));
    registerFunction("replace", new StandardSQLFunction("replace", StandardBasicTypes.STRING));
    registerFunction("rpad", new StandardSQLFunction("rpad", StandardBasicTypes.STRING));
    registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("substrb", new StandardSQLFunction("substrb", StandardBasicTypes.STRING));
    registerFunction("translate", new StandardSQLFunction("translate", StandardBasicTypes.STRING));

    registerFunction("substring", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("bit_length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "vsize(?1)*8"));
    registerFunction("coalesce", new NvlFunction());

    // Multi-param numeric dialect functions...
    registerFunction("atan2", new StandardSQLFunction("atan2", StandardBasicTypes.FLOAT));
    registerFunction("log", new StandardSQLFunction("log", StandardBasicTypes.INTEGER));
    registerFunction("mod", new StandardSQLFunction("mod", StandardBasicTypes.INTEGER));
    registerFunction("nvl", new StandardSQLFunction("nvl"));
    registerFunction("nvl2", new StandardSQLFunction("nvl2"));
    registerFunction("power", new StandardSQLFunction("power", StandardBasicTypes.FLOAT));

    // Multi-param date dialect functions...
    registerFunction("add_months", new StandardSQLFunction("add_months", StandardBasicTypes.DATE));
    registerFunction("months_between", new StandardSQLFunction("months_between", StandardBasicTypes.FLOAT));
    registerFunction("next_day", new StandardSQLFunction("next_day", StandardBasicTypes.DATE));

}

From source file:org.joda.time.contrib.hibernate.PersistentLocalDate.java

License:Apache License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Object timestamp = StandardBasicTypes.DATE.nullSafeGet(rs, names[0], session, owner);
    if (timestamp == null) {
        return null;
    }/*w w  w. ja  v a  2 s  .  co m*/
    return new LocalDate(timestamp);
}

From source file:org.joda.time.contrib.hibernate.PersistentLocalDate.java

License:Apache License

public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        StandardBasicTypes.DATE.nullSafeSet(statement, null, index, session);
    } else {//from   ww  w  .j a va  2s . c  om
        StandardBasicTypes.DATE.nullSafeSet(statement, ((LocalDate) value).toDateTimeAtStartOfDay().toDate(),
                index, session);
    }
}

From source file:org.joda.time.contrib.hibernate.PersistentYearMonthDay.java

License:Apache License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Object date = StandardBasicTypes.DATE.nullSafeGet(rs, names[0], session, owner);
    if (date == null) {
        return null;
    }//  ww w  .  ja  v  a2s .com
    return new YearMonthDay(date);
}

From source file:org.joda.time.contrib.hibernate.PersistentYearMonthDay.java

License:Apache License

public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        StandardBasicTypes.DATE.nullSafeSet(statement, null, index, session);
    } else {//from w ww.ja  v  a2  s .  c  om
        StandardBasicTypes.DATE.nullSafeSet(statement, ((YearMonthDay) value).toDateMidnight().toDate(), index,
                session);
    }
}