org.hibernate.type.TimestampType Java Examples
The following examples show how to use
org.hibernate.type.TimestampType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrecisionTimestampType.java From core with GNU General Public License v3.0 | 6 votes |
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if ( value != null ) { // System.out.println("value.class=" + value.getClass().getName()); // System.out.println("value=" + value); if (!(value instanceof Date)) throw new HibernateException("Writing element " + value.getClass().getName() + " but was expecting a java.util.Date"); Date d = (Date) value; Timestamp ts = new Timestamp(d.getTime()); // System.out.println("d=" + Time.dateStrMsec(d) + " =" + d.getTime() + " msec"); // System.out.println("ts=" + ts); // Tried using the following line for dealing with prepared statement // but then could not log the parameter value when logging the sql. // Therefore need to use TimestampType.INSTANCE.set(). //st.setTimestamp(index, new Timestamp(d.getTime())); TimestampType.INSTANCE.set(st, ts, index, session); } else { TimestampType.INSTANCE.set(st, null, index, session); } }
Example #2
Source File: PrecisionTimestampType.java From core with GNU General Public License v3.0 | 5 votes |
/********************** Member Functions **************************/ @Override public int[] sqlTypes() { return new int[] { TimestampType.INSTANCE.sqlType(), }; }
Example #3
Source File: BindingTypeHelper.java From lams with GNU General Public License v2.0 | 5 votes |
public BasicType resolveTimeTemporalTypeVariant(Class javaType, Type baseType) { if ( Calendar.class.isAssignableFrom( javaType ) ) { return CalendarTimeType.INSTANCE; } if ( java.util.Date.class.isAssignableFrom( javaType ) ) { return TimestampType.INSTANCE; } throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#TIME" ); }
Example #4
Source File: BindingTypeHelper.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public BasicType resolveDateTemporalTypeVariant(Class javaType, Type baseType) { // prefer to use any Type already known if ( baseType != null && baseType instanceof BasicType ) { if ( baseType.getReturnedClass().isAssignableFrom( javaType ) ) { return (BasicType) baseType; } } if ( Calendar.class.isAssignableFrom( javaType ) ) { return CalendarDateType.INSTANCE; } if ( java.util.Date.class.isAssignableFrom( javaType ) ) { return TimestampType.INSTANCE; } if ( Instant.class.isAssignableFrom( javaType ) ) { return OffsetDateTimeType.INSTANCE; } if ( OffsetDateTime.class.isAssignableFrom( javaType ) ) { return OffsetDateTimeType.INSTANCE; } if ( ZonedDateTime.class.isAssignableFrom( javaType ) ) { return ZonedDateTimeType.INSTANCE; } throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#DATE" ); }
Example #5
Source File: BindingTypeHelper.java From lams with GNU General Public License v2.0 | 5 votes |
public BasicType resolveTimestampTemporalTypeVariant(Class javaType, Type baseType) { // prefer to use any Type already known - interprets TIMESTAMP as "no narrowing" if ( baseType != null && baseType instanceof BasicType ) { return (BasicType) baseType; } if ( Calendar.class.isAssignableFrom( javaType ) ) { return CalendarType.INSTANCE; } if ( java.util.Date.class.isAssignableFrom( javaType ) ) { return TimestampType.INSTANCE; } if ( Instant.class.isAssignableFrom( javaType ) ) { return InstantType.INSTANCE; } if ( OffsetDateTime.class.isAssignableFrom( javaType ) ) { return OffsetDateTimeType.INSTANCE; } if ( ZonedDateTime.class.isAssignableFrom( javaType ) ) { return ZonedDateTimeType.INSTANCE; } if ( OffsetTime.class.isAssignableFrom( javaType ) ) { return OffsetTimeType.INSTANCE; } throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#TIMESTAMP" ); }
Example #6
Source File: VoteUsrAttemptDAO.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") /** * Gets the basic details about an attempt for a nomination. questionUid must not be null, sessionUid may be NULL. * This is * unusual for these methods - usually sessionId may not be null. In this case if sessionUid is null then you get * the values for the whole class, not just the group. * * Will return List<[login (String), fullname(String), attemptTime(Timestamp]> */ public List<Object[]> getUserAttemptsForTablesorter(Long sessionUid, Long questionUid, int page, int size, int sorting, String searchString, IUserManagementService userManagementService) { String sortingOrder; switch (sorting) { case VoteAppConstants.SORT_BY_NAME_ASC: sortingOrder = "user.fullname ASC"; break; case VoteAppConstants.SORT_BY_NAME_DESC: sortingOrder = "user.fullname DESC"; break; case VoteAppConstants.SORT_BY_DATE_ASC: sortingOrder = "attempt.attempt_time ASC"; break; case VoteAppConstants.SORT_BY_DATE_DESC: sortingOrder = "attempt.attempt_time DESC"; break; default: sortingOrder = "user.uid"; } String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id"); // Basic select for the user records StringBuilder queryText = new StringBuilder(FIND_USER_ANSWERS_BY_QUESTION_UID_SELECT).append(portraitStrings[0]) .append(FIND_USER_ANSWERS_BY_QUESTION_UID_FROM).append(portraitStrings[1]); if (sessionUid != null) { queryText.append(FIND_USER_ANSWERS_BY_QUESTION_UID_SESSION_ADDITION); } // If filtering by name add a name based where clause buildNameSearch(searchString, queryText, true); // Now specify the sort based on the switch statement above. queryText.append(" ORDER BY " + sortingOrder); NativeQuery<Object[]> query = getSession().createSQLQuery(queryText.toString()); query.addScalar("user_id", IntegerType.INSTANCE).addScalar("username", StringType.INSTANCE) .addScalar("fullname", StringType.INSTANCE).addScalar("attemptTime", TimestampType.INSTANCE) .addScalar("portraitId", IntegerType.INSTANCE).setParameter("questionUid", questionUid) .setFirstResult(page * size).setMaxResults(size); if (sessionUid != null) { query.setParameter("sessionUid", sessionUid); } return query.list(); }
Example #7
Source File: AbstractTimestampColumnMapper.java From jadira with Apache License 2.0 | 4 votes |
@Override public final TimestampType getHibernateType() { return TimestampType.INSTANCE; }
Example #8
Source File: NotebookUserDAO.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") /** * Will return List<[NotebookUser, String, Date]> where the String is the notebook entry and the modified date. */ public List<Object[]> getUsersForTablesorter(final Long sessionId, int page, int size, int sorting, String searchString, ICoreNotebookService coreNotebookService, IUserManagementService userManagementService) { String sortingOrder; switch (sorting) { case NotebookConstants.SORT_BY_USERNAME_ASC: sortingOrder = "user.last_name ASC, user.first_name ASC"; break; case NotebookConstants.SORT_BY_USERNAME_DESC: sortingOrder = "user.last_name DESC, user.first_name DESC"; break; case NotebookConstants.SORT_BY_DATE_ASC: sortingOrder = "notebookModifiedDate ASC"; break; case NotebookConstants.SORT_BY_DATE_DESC: sortingOrder = "notebookModifiedDate DESC"; break; case NotebookConstants.SORT_BY_COMMENT_ASC: sortingOrder = "user.teachers_comment ASC"; break; case NotebookConstants.SORT_BY_COMMENT_DESC: sortingOrder = "user.teachers_comment DESC"; break; default: sortingOrder = "user.last_name, user.first_name"; } String[] notebookEntryStrings = coreNotebookService.getNotebookEntrySQLStrings(sessionId.toString(), NotebookConstants.TOOL_SIGNATURE, "user.user_id", true); String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id"); // Basic select for the user records StringBuilder queryText = new StringBuilder(); queryText.append("SELECT user.* "); queryText.append(notebookEntryStrings[0]); queryText.append(portraitStrings[0]); queryText.append(" FROM tl_lantbk11_user user "); queryText.append( " JOIN tl_lantbk11_session session ON user.notebook_session_uid = session.uid and session.session_id = :sessionId"); queryText.append(notebookEntryStrings[1]); queryText.append(portraitStrings[1]); // If filtering by name add a name based where clause buildNameSearch(searchString, queryText); // Now specify the sort based on the switch statement above. queryText.append(" ORDER BY " + sortingOrder); NativeQuery<Object[]> query = getSession().createNativeQuery(queryText.toString()); query.addEntity("user", NotebookUser.class).addScalar("notebookEntry", StringType.INSTANCE) .addScalar("notebookModifiedDate", TimestampType.INSTANCE).addScalar("portraitId", IntegerType.INSTANCE) .setParameter("sessionId", sessionId.longValue()) .setFirstResult(page * size).setMaxResults(size); return query.list(); }
Example #9
Source File: VoteUsrAttemptDAO.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") /** * Gets the details about an open text entry. Either sessionUid or toolContentId must be supplied - if sessionUid is * supplied * then it will be restricted to that session. Due to the large number of fields needed, a DTO will be returned. * * Will return List<OpenTextAnswerDTO> */ public List<OpenTextAnswerDTO> getUserOpenTextAttemptsForTablesorter(Long sessionUid, Long toolContentId, int page, int size, int sorting, String searchStringVote, String searchStringUsername, IUserManagementService userManagementService) { String sortingOrder; switch (sorting) { case VoteAppConstants.SORT_BY_NAME_ASC: sortingOrder = "user.fullname ASC"; break; case VoteAppConstants.SORT_BY_NAME_DESC: sortingOrder = "user.fullname DESC"; break; case VoteAppConstants.SORT_BY_DATE_ASC: sortingOrder = "attempt.attempt_time ASC"; break; case VoteAppConstants.SORT_BY_DATE_DESC: sortingOrder = "attempt.attempt_time DESC"; break; case VoteAppConstants.SORT_BY_ENTRY_ASC: sortingOrder = "attempt.userEntry ASC"; break; case VoteAppConstants.SORT_BY_ENTRY_DESC: sortingOrder = "attempt.userEntry DESC"; break; case VoteAppConstants.SORT_BY_VISIBLE_ASC: sortingOrder = "attempt.visible ASC"; break; case VoteAppConstants.SORT_BY_VISIBLE_DESC: sortingOrder = "attempt.visible DESC"; break; default: sortingOrder = "user.uid"; } String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id"); // Basic select for the user records StringBuilder queryText = new StringBuilder(FIND_USER_OPEN_TEXT_SELECT).append(portraitStrings[0]) .append(FIND_USER_OPEN_TEXT_FROM); if (sessionUid != null) { queryText.append(FIND_USER_OPEN_TEXT_SESSION_UID_ADD); } else { queryText.append(FIND_USER_OPEN_TEXT_CONTENT_UID_ADD); } queryText.append(portraitStrings[1]); // If filtering by name/entry add a where clause buildCombinedSearch(searchStringVote, searchStringUsername, queryText); // Now specify the sort based on the switch statement above. queryText.append(" ORDER BY " + sortingOrder); NativeQuery<OpenTextAnswerDTO> query = getSession().createSQLQuery(queryText.toString()); query.addScalar("userUid", LongType.INSTANCE).addScalar("login", StringType.INSTANCE) .addScalar("fullName", StringType.INSTANCE).addScalar("userEntryUid", LongType.INSTANCE) .addScalar("userEntry", StringType.INSTANCE).addScalar("attemptTime", TimestampType.INSTANCE) .addScalar("visible", BooleanType.INSTANCE).addScalar("portraitId", LongType.INSTANCE) .setFirstResult(page * size).setMaxResults(size) .setResultTransformer(Transformers.aliasToBean(OpenTextAnswerDTO.class)); if (sessionUid != null) { query.setParameter("sessionUid", sessionUid); } else { query.setParameter("toolContentId", toolContentId); } return query.list(); }
Example #10
Source File: PeerreviewUserDAOHibernate.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") /** * Will return List<[user.user_id, user.first_name, user.last_name, notebook entry, notebook date]> */ public List<Object[]> getUserNotebookEntriesForTablesorter(final Long toolSessionId, int page, int size, int sorting, String searchString, ICoreNotebookService coreNotebookService, IUserManagementService userManagementService) { String sortingOrder; switch (sorting) { case PeerreviewConstants.SORT_BY_USERNAME_ASC: sortingOrder = " ORDER BY user.first_name ASC"; break; case PeerreviewConstants.SORT_BY_USERNAME_DESC: sortingOrder = " ORDER BY user.first_name DESC"; break; case PeerreviewConstants.SORT_BY_NOTEBOOK_ENTRY_ASC: sortingOrder = " ORDER BY notebookEntry ASC"; break; case PeerreviewConstants.SORT_BY_NOTEBOOK_ENTRY_DESC: sortingOrder = " ORDER BY notebookEntry DESC"; break; case PeerreviewConstants.SORT_BY_NO: default: sortingOrder = " ORDER BY user.user_id"; } String[] notebookEntryStrings = coreNotebookService.getNotebookEntrySQLStrings(toolSessionId.toString(), PeerreviewConstants.TOOL_SIGNATURE, "user.user_id", true); String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id"); // Basic select for the user records StringBuilder queryText = new StringBuilder(); queryText.append("SELECT user.user_id, user.first_name, user.last_name ") .append(portraitStrings[0]) .append(notebookEntryStrings[0]) .append(" FROM tl_laprev11_user user ") .append(" JOIN tl_laprev11_session session ON session.session_id = :toolSessionId AND user.session_uid = session.uid"); queryText.append(portraitStrings[1]); queryText.append(notebookEntryStrings[1]); buildNameSearch(searchString, queryText, false); // Now specify the sort based on the switch statement above. queryText.append(sortingOrder); NativeQuery query = getSession().createNativeQuery(queryText.toString()); query.addScalar("user_id", LongType.INSTANCE) .addScalar("first_name", StringType.INSTANCE) .addScalar("last_name", StringType.INSTANCE) .addScalar("portraitId", LongType.INSTANCE) .addScalar("notebookEntry", StringType.INSTANCE) .addScalar("notebookModifiedDate", TimestampType.INSTANCE) .setParameter("toolSessionId", toolSessionId.longValue()) .setFirstResult(page * size).setMaxResults(size); return query.list(); }
Example #11
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Calendar-valued parameter using the full Timestamp portion. * * @param position The parameter position * @param val The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setCalendar(int position, Calendar val) { setParameter( position, val, TimestampType.INSTANCE ); return this; }
Example #12
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind the value and the time of a given Date object to a named query parameter. * * @param name The name of the parameter * @param value The value object * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(String, Object)} or {@link #setParameter(String, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(String name, Date value) { setParameter( name, value, TimestampType.INSTANCE ); return this; }
Example #13
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a named Calendar-valued parameter using the full Timestamp. * * @param name The parameter name * @param value The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(String, Object)} or {@link #setParameter(String, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setCalendar(String name, Calendar value) { setParameter( name, value, TimestampType.INSTANCE ); return this; }
Example #14
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Date-valued parameter using the full Timestamp. * * @param position The parameter position * @param val The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(int position, Date val) { setParameter( position, val, TimestampType.INSTANCE ); return this; }
Example #15
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a named Calendar-valued parameter using the full Timestamp. * * @param name The parameter name * @param value The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setCalendar(String name, Calendar value) { setParameter( name, value, TimestampType.INSTANCE ); return this; }
Example #16
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind the value and the time of a given Date object to a named query parameter. * * @param name The name of the parameter * @param value The value object * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(String name, Date value) { setParameter( name, value, TimestampType.INSTANCE ); return this; }
Example #17
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Calendar-valued parameter using the full Timestamp portion. * * @param position The parameter position * @param val The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setCalendar(int position, Calendar val) { setParameter( position, val, TimestampType.INSTANCE ); return this; }
Example #18
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Date-valued parameter using the full Timestamp. * * @param position The parameter position * @param val The bind value * * @return {@code this}, for method chaining * * @deprecated (since 5.2) use {@link #setParameter(int, Object)} or {@link #setParameter(int, Object, Type)} * instead */ @Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(int position, Date val) { setParameter( position, val, TimestampType.INSTANCE ); return this; }