org.hibernate.type.DateType Java Examples
The following examples show how to use
org.hibernate.type.DateType.
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: ProfileDaoImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ProfileStatus getUserStatus(final String userId, final Date oldestDate) { final HibernateCallback<ProfileStatus> hcb = session -> { final Query q = session.getNamedQuery(QUERY_GET_USER_STATUS); q.setParameter(USER_UUID, userId, StringType.INSTANCE); q.setParameter(OLDEST_STATUS_DATE, oldestDate, DateType.INSTANCE); q.setMaxResults(1); return (ProfileStatus) q.uniqueResult(); }; return getHibernateTemplate().execute(hcb); }
Example #2
Source File: ProfileDaoImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ProfileStatus getUserStatus(final String userId, final Date oldestDate) { final HibernateCallback<ProfileStatus> hcb = session -> { final Query q = session.getNamedQuery(QUERY_GET_USER_STATUS); q.setParameter(USER_UUID, userId, StringType.INSTANCE); q.setParameter(OLDEST_STATUS_DATE, oldestDate, DateType.INSTANCE); q.setMaxResults(1); return (ProfileStatus) q.uniqueResult(); }; return getHibernateTemplate().execute(hcb); }
Example #3
Source File: FumTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void testCompositeIDQuery() throws Exception { Session s = openSession(); Fum fee = new Fum( fumKey("fee",true) ); fee.setFum("fee"); s.save(fee); Fum fi = new Fum( fumKey("fi",true) ); fi.setFum("fi"); short fiShort = fi.getId().getShort(); s.save(fi); Fum fo = new Fum( fumKey("fo",true) ); fo.setFum("fo"); s.save(fo); Fum fum = new Fum( fumKey("fum",true) ); fum.setFum("fum"); s.save(fum); s.flush(); s.connection().commit(); s.close(); s = openSession(); // Try to find the Fum object "fo" that we inserted searching by the string in the id List vList = s.find("from Fum fum where fum.id.string='fo'" ); assertTrue( "find by composite key query (find fo object)", vList.size() == 1 ); fum = (Fum)vList.get(0); assertTrue( "find by composite key query (check fo object)", fum.getId().getString().equals("fo") ); // Try to find the Fum object "fi" that we inserted searching by the date in the id vList = s.find("from Fum fum where fum.id.short = ?",new Short(fiShort),Hibernate.SHORT); assertTrue( "find by composite key query (find fi object)", vList.size() == 1 ); fi = (Fum)vList.get(0); assertTrue( "find by composite key query (check fi object)", fi.getId().getString().equals("fi") ); // Make sure we can return all of the objects by searching by the date id assertTrue( "find by composite key query with arguments", s.find("from Fum fum where fum.id.date <= ? and not fum.fum='FRIEND'",new Date(),Hibernate.DATE).size()==4 ); s.flush(); s.connection().commit(); s.close(); s = openSession(); assertTrue( s.iterate("select fum.id.short, fum.id.date, fum.id.string from Fum fum").hasNext() ); assertTrue( s.iterate("select fum.id from Fum fum").hasNext() ); Query qu = s.createQuery("select fum.fum, fum , fum.fum, fum.id.date from Fum fum"); Type[] types = qu.getReturnTypes(); assertTrue(types.length==4); for ( int k=0; k<types.length; k++) { assertTrue( types[k]!=null ); } assertTrue(types[0] instanceof StringType); assertTrue(types[1] instanceof EntityType); assertTrue(types[2] instanceof StringType); assertTrue(types[3] instanceof DateType); Iterator iter = qu.iterate(); int j = 0; while ( iter.hasNext() ) { j++; assertTrue( ( (Object[]) iter.next() )[1] instanceof Fum ); } assertTrue( "iterate on composite key", j==8 ); fum = (Fum) s.load( Fum.class, fum.getId() ); s.filter( fum.getQuxArray(), "where this.foo is null" ); s.filter( fum.getQuxArray(), "where this.foo.id = ?", "fooid", Hibernate.STRING ); Query f = s.createFilter( fum.getQuxArray(), "where this.foo.id = :fooId" ); f.setString("fooId", "abc"); assertFalse( f.iterate().hasNext() ); iter = s.iterate("from Fum fum where not fum.fum='FRIEND'"); int i = 0; while ( iter.hasNext() ) { fum = (Fum) iter.next(); //iter.remove(); s.delete(fum); i++; } assertTrue( "iterate on composite key", i==4 ); s.flush(); s.iterate("from Fum fu, Fum fo where fu.fo.id.string = fo.id.string and fo.fum is not null"); s.find("from Fumm f1 inner join f1.fum f2"); s.connection().commit(); s.close(); }
Example #4
Source File: AbstractDateColumnMapper.java From jadira with Apache License 2.0 | 4 votes |
@Override public final DateType getHibernateType() { return DateType.INSTANCE; }
Example #5
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Date-valued parameter using just the Date 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> setDate(int position, Date val) { setParameter( position, val, DateType.INSTANCE ); return this; }
Example #6
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Calendar-valued parameter using just the Date 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> setCalendarDate(int position, Calendar val) { setParameter( position, val, DateType.INSTANCE ); return this; }
Example #7
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind the val (time is truncated) of a given Date object to a named query parameter. * * @param name The name of the parameter * @param val The val 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> setDate(String name, Date val) { setParameter( name, val, DateType.INSTANCE ); return this; }
Example #8
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a named Calendar-valued parameter using just the Date portion. * * @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> setCalendarDate(String name, Calendar value) { setParameter( name, value, DateType.INSTANCE ); return this; }
Example #9
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Date-valued parameter using just the Date 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> setDate(int position, Date val) { setParameter( position, val, DateType.INSTANCE ); return this; }
Example #10
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a positional Calendar-valued parameter using just the Date 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> setCalendarDate(int position, Calendar val) { setParameter( position, val, DateType.INSTANCE ); return this; }
Example #11
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind the val (time is truncated) of a given Date object to a named query parameter. * * @param name The name of the parameter * @param val The val 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> setDate(String name, Date val) { setParameter( name, val, DateType.INSTANCE ); return this; }
Example #12
Source File: Query.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Bind a named Calendar-valued parameter using just the Date portion. * * @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> setCalendarDate(String name, Calendar value) { setParameter( name, value, DateType.INSTANCE ); return this; }