List of usage examples for org.hibernate.type StandardBasicTypes DATE
DateType DATE
To view the source code for org.hibernate.type StandardBasicTypes DATE.
Click Source Link
From source file:edu.psu.iam.cpr.core.database.tables.UseridTable.java
License:Apache License
/** * This routine is to call a stored procedure to set the primary userid for a user. * @param db contains a reference to a open database connection. * @throws CprException will be thrown if there are any CPR related errors. * //from w w w. ja v a 2 s . co m */ public void setPrimaryUserid(final Database db) throws CprException { boolean recordExpired = false; boolean alreadyPrimary = false; boolean recordNotFound = false; final Session session = db.getSession(); final Userid bean = getUseridBean(); // For the selected userid, obtain the end date and their primary flag. final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT end_date, primary_flag "); sb.append("FROM {h-schema}userid "); sb.append("WHERE person_id = :person_id_in "); sb.append("AND userid = :userid_in "); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", bean.getPersonId()); query.setParameter("userid_in", bean.getUserid()); query.addScalar("end_date", StandardBasicTypes.DATE); query.addScalar("primary_flag", StandardBasicTypes.STRING); Iterator<?> it = query.list().iterator(); if (it.hasNext()) { Object[] res = (Object[]) it.next(); bean.setEndDate((Date) res[0]); bean.setPrimaryFlag((String) res[1]); // Expired, we have an error. if (bean.getEndDate() != null) { recordExpired = true; } // Already primary, we have an error. else if (Utility.isOptionYes(bean.getPrimaryFlag())) { alreadyPrimary = true; } else { // Switch the current primary record. String sqlQuery = "from Userid where personId = :person_id_in AND primaryFlag = 'Y' AND endDate IS NULL"; Query query1 = session.createQuery(sqlQuery); query1.setParameter("person_id_in", bean.getPersonId()); for (it = query1.list().iterator(); it.hasNext();) { Userid dbBean = (Userid) it.next(); dbBean.setPrimaryFlag("N"); dbBean.setLastUpdateBy(bean.getLastUpdateBy()); dbBean.setLastUpdateOn(bean.getLastUpdateOn()); session.update(dbBean); session.flush(); } // Make the new record primary. sqlQuery = "from Userid where personId = :person_id_in AND userid = :userid_in AND endDate IS NULL"; query1 = session.createQuery(sqlQuery); query1.setParameter("person_id_in", bean.getPersonId()); query1.setParameter("userid_in", bean.getUserid()); for (it = query1.list().iterator(); it.hasNext();) { Userid dbBean = (Userid) it.next(); dbBean.setPrimaryFlag("Y"); dbBean.setLastUpdateBy(bean.getLastUpdateBy()); dbBean.setLastUpdateOn(bean.getLastUpdateOn()); session.update(dbBean); session.flush(); } } } else { recordNotFound = true; } // Handle other errors. if (recordExpired) { throw new CprException(ReturnType.ALREADY_DELETED_EXCEPTION, TABLE_NAME); } if (alreadyPrimary) { throw new CprException(ReturnType.SET_PRIMARY_FAILED_EXCEPTION, TABLE_NAME); } if (recordNotFound) { throw new CprException(ReturnType.RECORD_NOT_FOUND_EXCEPTION, TABLE_NAME); } }
From source file:edu.psu.iam.cpr.core.database.tables.UseridTable.java
License:Apache License
/** * This routine is used to archive a userid. It is called by the ArchiveUserid service. * @param db contains a reference to an open database connection. * @throws CprException will be thrown for any CPR specific problems. *//*from w w w. ja va2 s .c o m*/ public void archiveUserid(final Database db) throws CprException { boolean noneActive = false; boolean notFound = false; boolean alreadyArchived = false; boolean cannotArchive = false; final Session session = db.getSession(); final Userid bean = getUseridBean(); // Determine how many userids are active for the current user. String sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE person_id = :person_id_in AND end_date IS NULL"; SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("person_id_in", bean.getPersonId()); query.addScalar("person_id", StandardBasicTypes.LONG); final int activeCount = query.list().size(); if (activeCount == 0) { noneActive = true; } else { // For the selected userid, obtain the end date and their primary flag. final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT end_date, primary_flag "); sb.append("FROM {h-schema}userid "); sb.append("WHERE person_id = :person_id_in "); sb.append("AND userid = :userid_in "); query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", bean.getPersonId()); query.setParameter("userid_in", bean.getUserid()); query.addScalar("end_date", StandardBasicTypes.DATE); query.addScalar("primary_flag", StandardBasicTypes.STRING); Iterator<?> it = query.list().iterator(); if (it.hasNext()) { Object[] res = (Object[]) it.next(); bean.setEndDate((Date) res[0]); bean.setPrimaryFlag((String) res[1]); // Error if the record already has an end date. if (bean.getEndDate() != null) { alreadyArchived = true; } // If there are more than one record and this one is primary, do not all the archival. else if (activeCount > 1 && Utility.isOptionYes(bean.getPrimaryFlag())) { cannotArchive = true; } // Otherwise we can do the archive. else { sqlQuery = "from Userid where personId = :person_id_in AND userid = :userid_in AND endDate IS NULL"; final Query query1 = session.createQuery(sqlQuery); query1.setParameter("person_id_in", bean.getPersonId()); query1.setParameter("userid_in", bean.getUserid()); for (it = query1.list().iterator(); it.hasNext();) { Userid dbBean = (Userid) it.next(); dbBean.setPrimaryFlag("N"); dbBean.setEndDate(bean.getLastUpdateOn()); dbBean.setLastUpdateBy(bean.getLastUpdateBy()); dbBean.setLastUpdateOn(bean.getLastUpdateOn()); session.update(dbBean); session.flush(); } } } else { notFound = true; } } if (notFound) { throw new CprException(ReturnType.RECORD_NOT_FOUND_EXCEPTION, TABLE_NAME); } if (noneActive) { throw new CprException(ReturnType.GENERAL_EXCEPTION, "Cannot archive userid, because there are no active userids."); } if (alreadyArchived) { throw new CprException(ReturnType.ALREADY_DELETED_EXCEPTION, TABLE_NAME); } if (cannotArchive) { throw new CprException(ReturnType.GENERAL_EXCEPTION, "Cannot archive userid, because its the primary userid."); } }
From source file:edu.psu.iam.cpr.core.database.tables.UseridTable.java
License:Apache License
/** * This routine is used to unarchive a userid. It is called by the UnarchiveUserid service. * @param db contains a reference to an open database connection. * @throws CprException will be thrown for any CPR specific problems. *//*from www. j a v a 2 s . c om*/ public void unarchiveUserid(final Database db) throws CprException { boolean alreadyUnarchived = false; boolean noArchivedRecords = false; boolean recordNotFound = false; final Session session = db.getSession(); final Userid bean = getUseridBean(); // See how any userids are archived for the user, if there are none that are archived, we have an error. String sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE person_id = :person_id_in AND end_date IS NOT NULL"; SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("person_id_in", bean.getPersonId()); query.addScalar("person_id", StandardBasicTypes.LONG); final int archivedCount = query.list().size(); if (archivedCount == 0) { noArchivedRecords = true; } else { // For the selected userid, obtain the end date and their primary flag. final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT end_date, primary_flag "); sb.append("FROM {h-schema}userid "); sb.append("WHERE person_id = :person_id_in "); sb.append("AND userid = :userid_in "); query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", bean.getPersonId()); query.setParameter("userid_in", bean.getUserid()); query.addScalar("end_date", StandardBasicTypes.DATE); query.addScalar("primary_flag", StandardBasicTypes.STRING); Iterator<?> it = query.list().iterator(); if (it.hasNext()) { Object[] res = (Object[]) it.next(); bean.setEndDate((Date) res[0]); bean.setPrimaryFlag((String) res[1]); if (bean.getEndDate() == null) { alreadyUnarchived = true; } else { // Determine how many userids are active for the current user. sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE person_id = :person_id_in AND end_date IS NULL"; query = session.createSQLQuery(sqlQuery); query.setParameter("person_id_in", bean.getPersonId()); query.addScalar("person_id", StandardBasicTypes.LONG); final int activeCount = query.list().size(); if (activeCount == 0) { bean.setPrimaryFlag("Y"); } else { bean.setPrimaryFlag("N"); } // Do the unarchive. sqlQuery = "from Userid where personId = :person_id AND userid = :userid_in AND endDate IS NOT NULL"; final Query query1 = session.createQuery(sqlQuery); query1.setParameter("person_id", bean.getPersonId()); query1.setParameter("userid_in", bean.getUserid()); for (it = query1.list().iterator(); it.hasNext();) { Userid dbBean = (Userid) it.next(); dbBean.setPrimaryFlag(bean.getPrimaryFlag()); dbBean.setEndDate(null); dbBean.setLastUpdateBy(bean.getLastUpdateBy()); dbBean.setLastUpdateOn(bean.getLastUpdateOn()); session.update(dbBean); session.flush(); } } } else { recordNotFound = true; } } if (alreadyUnarchived) { throw new CprException(ReturnType.UNARCHIVE_FAILED_EXCEPTION, "userid"); } if (noArchivedRecords) { throw new CprException(ReturnType.GENERAL_EXCEPTION, "There are no records that can be unarchived."); } if (recordNotFound) { throw new CprException(ReturnType.RECORD_NOT_FOUND_EXCEPTION, "userid"); } }
From source file:edu.utn.frba.grupo5303.serverenviolibre.config.LocalDateUserType.java
@Override public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, names, session, owner); if (timestamp == null) { return null; }//from www.j a v a2 s . co m Date date = (Date) timestamp; Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.config.LocalDateUserType.java
@Override public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value == null) { StandardBasicTypes.DATE.nullSafeSet(preparedStatement, null, index, session); } else {/*from w w w . java 2 s. c om*/ LocalDate ld = ((LocalDate) value); Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); Date time = Date.from(instant); StandardBasicTypes.DATE.nullSafeSet(preparedStatement, time, index, session); } }
From source file:es.jpons.temporal.types.PossibilisticTPType.java
License:Open Source License
public Type[] getPropertyTypes() { return new Type[] { StandardBasicTypes.DATE, StandardBasicTypes.DATE, StandardBasicTypes.DATE }; }
From source file:es.jpons.temporal.types.PossibilisticTPType.java
License:Open Source License
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor si, Object o) throws HibernateException, SQLException { Date mainpoint = (Date) StandardBasicTypes.DATE.nullSafeGet(rs, names[0], si); Date left = (Date) StandardBasicTypes.DATE.nullSafeGet(rs, names[1], si); Date right = (Date) StandardBasicTypes.DATE.nullSafeGet(rs, names[2], si); return new PossibilisticTP(mainpoint, left, right); }
From source file:es.jpons.temporal.types.PossibilisticTPType.java
License:Open Source License
public void nullSafeSet(PreparedStatement ps, Object o, int index, SessionImplementor si) throws HibernateException, SQLException { PossibilisticTP value = (PossibilisticTP) o; Date mainpoint = value.getMainPoint(); Date left = value.getLeftShift(); Date right = value.getRightShift(); StandardBasicTypes.DATE.nullSafeSet(ps, mainpoint, index, si); StandardBasicTypes.DATE.nullSafeSet(ps, left, index + 1, si); StandardBasicTypes.DATE.nullSafeSet(ps, right, index + 2, si); }
From source file:jp.xet.baseunits.hibernate.PersistentCalendarDate.java
License:Apache License
/** * ?? * * @since 1.2 */ public PersistentCalendarDate() { super(StandardBasicTypes.DATE); }
From source file:jp.xet.baseunits.hibernate.PersistentTimePoint.java
License:Apache License
/** * ?? * * @since 1.2 */ public PersistentTimePoint() { super(StandardBasicTypes.DATE); }