Java源码示例:org.hibernate.type.TimestampType

示例1
@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);
        }
	}
 
示例2
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" );
}
 
示例3
@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" );
}
 
示例4
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" );
}
 
示例5
/********************** Member Functions **************************/
@Override
public int[] sqlTypes() {
       return new int[] {
       		TimestampType.INSTANCE.sqlType(),
       };
   }
 
示例6
@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();

   }
 
示例7
@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();
   }
 
示例8
@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();
   }
 
示例9
@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();
   }
 
示例10
@Override
public final TimestampType getHibernateType() {    	
	return TimestampType.INSTANCE;
}
 
示例11
/**
 * 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;
}
 
示例12
/**
 * 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;
}
 
示例13
/**
 * 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;
}
 
示例14
/**
 * 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;
}
 
示例15
/**
 * 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;
}
 
示例16
/**
 * 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;
}
 
示例17
/**
 * 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;
}
 
示例18
/**
 * 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;
}