org.hibernate.type.IntegerType Java Examples

The following examples show how to use org.hibernate.type.IntegerType. 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: CollectionLogRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Integer> countTotalDownloadedItemsForCollectionIds(final List<Long> ids) {
    return (Map<Integer, Integer>) getHibernateTemplate().execute(new HibernateCallback<Object>() {
        @Override
        public Object doInHibernate(Session session) throws HibernateException {
            String sql = " select c.collection_id as id, " +
                    " sum(c.count) as count " +
                    " from collection_log c " +
                    " where c.collection_id in :ids " +
                    " group by c.collection_id ";
            SQLQuery sqlQuery = session.createSQLQuery(sql);
            sqlQuery.addScalar("id", new IntegerType());
            sqlQuery.addScalar("count", new IntegerType());
            sqlQuery.setParameterList("ids", ids);

            List<Object[]> list = sqlQuery.list();
            Map<Integer, Integer> result = new HashMap<Integer, Integer>();
            for (Object[] row : list) {
                result.put((Integer) row[0], (Integer) row[1]);
            }

            return result;
        }
    });
}
 
Example #2
Source File: ScratchieSessionDAOHibernate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
   public Object[] getStatsMarksForLeaders(Long toolContentId) {
NativeQuery<?> query = getSession().createNativeQuery(FIND_MARK_STATS)
	.addScalar("min_grade", FloatType.INSTANCE)
	.addScalar("avg_grade", FloatType.INSTANCE)
	.addScalar("max_grade", FloatType.INSTANCE)
	.addScalar("num_complete", IntegerType.INSTANCE);
query.setParameter("toolContentId", toolContentId);
@SuppressWarnings("unchecked")
List<Object[]> list = (List<Object[]>) query.list();
if ((list == null) || (list.size() == 0)) {
    return null;
} else {
    return (Object[]) list.get(0);
}
   }
 
Example #3
Source File: AssessmentUserDAOHibernate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
   @Override
   public Object[] getStatsMarksForLeaders(Long toolContentId) {
NativeQuery<Object[]> query = getSession().createNativeQuery(FIND_MARK_STATS_FOR_LEADERS)
	.addScalar("min_grade", FloatType.INSTANCE)
	.addScalar("avg_grade", FloatType.INSTANCE)
	.addScalar("max_grade", FloatType.INSTANCE)
	.addScalar("num_complete", IntegerType.INSTANCE);
query.setParameter("toolContentId", toolContentId);
List list = query.list();
if ((list == null) || (list.size() == 0)) {
    return null;
} else {
    return (Object[]) list.get(0);
}
   }
 
Example #4
Source File: CommentDAO.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked" })
   private SortedSet<Comment> getNextThreadByThreadIdNewestFirst(final Long rootTopicId,
    final Long previousThreadMessageId, Integer numberOfThreads, Integer sortBy, Integer userId) {

// the search to get to the top level is quite light, so get just the uids
// then build a complete set.
List<Number> threadUidList = null;
if (previousThreadMessageId == null || previousThreadMessageId == 0L) {
    threadUidList = getSession().createSQLQuery(SQL_QUERY_FIND_FIRST_THREAD_TOP_BY_UID)
	    .setParameter("rootUid", rootTopicId).setMaxResults(numberOfThreads).list();
} else {
    threadUidList = getSession().createSQLQuery(SQL_QUERY_FIND_NEXT_THREAD_TOP).setParameter("rootUid", rootTopicId)
	    .setParameter("lastUid", previousThreadMessageId).setMaxResults(numberOfThreads).list();
}

if (threadUidList != null && threadUidList.size() > 0) {
    NativeQuery<Object[]> query = getSession().createNativeQuery(SQL_QUERY_FIND_NEXT_THREAD_MESSAGES);
    query.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("userId", userId != null ? userId : 0)
	    .setParameterList("threadIds", threadUidList);
    List<Object[]> results = query.list();
    return upgradeComments(results, sortBy);
}
return new TreeSet<Comment>();
   }
 
Example #5
Source File: HQLUtilsTest.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
@Test
public void testCriteriaInTest() throws Exception {

    Object test = HQLUtils.criteriaInTest(null);
    assertTrue(test instanceof TypedParameterValue);
    assertTrue(((TypedParameterValue) test).getType() instanceof IntegerType);
    assertEquals(Integer.valueOf(0), ((TypedParameterValue) test).getValue());

    test = HQLUtils.criteriaInTest(Collections.emptyList());
    assertTrue(test instanceof TypedParameterValue);
    assertTrue(((TypedParameterValue) test).getType() instanceof IntegerType);
    assertEquals(Integer.valueOf(0), ((TypedParameterValue) test).getValue());

    test = HQLUtils.criteriaInTest(Collections.singletonList("aBc"));
    assertTrue(test instanceof TypedParameterValue);
    assertTrue(((TypedParameterValue) test).getType() instanceof IntegerType);
    assertEquals(Integer.valueOf(1), ((TypedParameterValue) test).getValue());

}
 
Example #6
Source File: Wikipedia.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
/**
 * Get the hibernate ID to a given pageID of a category.
 * We need different methods for pages and categories here, as a page and a category can have the same ID.
 *
 * @param pageID A pageID that should be mapped to the corresponding hibernate ID.
 * @return The hibernateID of the page with pageID or -1, if the pageID is not valid
 */
protected long __getCategoryHibernateId(int pageID) {
    long hibernateID = -1;

    // first look in the id mapping cache
    if (idMapCategories.containsKey(pageID)) {
        return idMapCategories.get(pageID);
    }

    // The id was not found in the id mapping cache.
    // It may not be in the cahe or may not exist at all.
    Session session = this.__getHibernateSession();
    session.beginTransaction();
    Object retObjectPage = session.createQuery(
            "select cat.id from Category as cat where cat.pageId = :pageId")
            .setParameter("pageId", pageID, IntegerType.INSTANCE)
            .uniqueResult();
    session.getTransaction().commit();
    if (retObjectPage != null) {
        hibernateID = (Long) retObjectPage;
        // add it to the cache
        idMapCategories.put(pageID, hibernateID);
    }

    return hibernateID;
}
 
Example #7
Source File: McUserDAO.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
   @Override
   public Object[] getStatsMarksForLeaders(Long toolContentId) {

Query<?> query = getSession().createSQLQuery(FIND_MARK_STATS_FOR_LEADERS)
	.addScalar("min_grade", FloatType.INSTANCE)
	.addScalar("avg_grade", FloatType.INSTANCE)
	.addScalar("max_grade", FloatType.INSTANCE)
	.addScalar("num_complete", IntegerType.INSTANCE);
query.setParameter("toolContentId", toolContentId);
List<?> list = query.list();
if ((list == null) || (list.size() == 0)) {
    return null;
} else {
    return (Object[]) list.get(0);
}
   }
 
Example #8
Source File: Wikipedia.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
/**
 * Tests, whether a page with the given pageID exists.
 * Trying to retrieve a pageID that does not exist in Wikipedia throws an exception.
 *
 * @param pageID A pageID.
 * @return {@code True}, if a page with that pageID exits, {@code false} otherwise.
 */
public boolean existsPage(int pageID) {

    // This is a hack to provide a much quicker way to test whether a page exists.
    // Encoding the title in this way surpasses the normal way of creating a title first.
    // Anyway, I do not like this hack :-|

    if (pageID < 0) {
        return false;
    }

    Session session = this.__getHibernateSession();
    session.beginTransaction();
    List returnList = session.createNativeQuery(
        "select p.id from PageMapLine as p where p.pageID = :pageId")
        .setParameter("pageId", pageID, IntegerType.INSTANCE)
        .list();
    session.getTransaction().commit();

    return returnList.size() != 0;
}
 
Example #9
Source File: CommentDAO.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked" })
   private SortedSet<Comment> getStickyByThreadIdNewestFirst(final Long rootTopicId, Integer sortBy, Integer userId) {

// the search to get to the top level is quite light, so get just the uids
// then build a complete set.
List<Number> threadUidList = getSession().createNativeQuery(SQL_QUERY_FIND_STICKY_BY_UID)
	.setParameter("rootUid", rootTopicId).list();

if (threadUidList != null && threadUidList.size() > 0) {
    NativeQuery<Object[]> query = getSession().createSQLQuery(SQL_QUERY_FIND_NEXT_THREAD_MESSAGES);
    query.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("userId", userId != null ? userId : 0)
	    .setParameterList("threadIds", threadUidList);
    List<Object[]> results = query.list();
    return upgradeComments(results, sortBy);
}
return new TreeSet<Comment>();
   }
 
Example #10
Source File: CommentDAO.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked" })
   private SortedSet<Comment> getStickyByThreadIdLikes(final Long rootTopicId, Integer sortBy, String extraSortParam,
    Integer userId) {

List<Object[]> topThreadObjects = getSession().createNativeQuery(SQL_QUERY_FIND_STICKY_BY_LIKES)
	.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	.addScalar("user_vote", IntegerType.INSTANCE).setParameter("rootUid", rootTopicId)
	.setParameter("userId", userId != null ? userId : 0).list();

if (topThreadObjects != null && topThreadObjects.size() > 0) {
    // build the list of uids
    List<Number> threadUidList = new ArrayList<Number>();
    for (Object[] rawObject : topThreadObjects) {
	Comment comment = (Comment) rawObject[0];
	threadUidList.add(comment.getUid());
    }
    NativeQuery<Object[]> query = getSession().createNativeQuery(SQL_QUERY_FIND_NEXT_THREAD_MESSAGES_REPLIES_ONLY);
    query.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("userId", userId != null ? userId : 0)
	    .setParameterList("threadIds", threadUidList);
    List<Object[]> results = query.list();
    topThreadObjects.addAll(results);
    return upgradeComments(topThreadObjects, sortBy);
}
return new TreeSet<Comment>();
   }
 
Example #11
Source File: SubmitUserDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   public List<StatisticDTO> getLeaderStatisticsBySession(final Long contentId) {
NativeQuery<StatisticDTO> query = getSession().createNativeQuery(GET_LEADER_STATISTICS);
query.addScalar("sessionId", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
	.addScalar("totalUploadedFiles", IntegerType.INSTANCE).addScalar("markedCount", IntegerType.INSTANCE)
	.setParameter("contentId", contentId).setResultTransformer(Transformers.aliasToBean(StatisticDTO.class));

List<StatisticDTO> list = query.list();
for (StatisticDTO dto : list) {
    dto.setNotMarkedCount(dto.getTotalUploadedFiles() - dto.getMarkedCount());
}
return list;
   }
 
Example #12
Source File: SystemManagerTest.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private Integer numberOfSnapshots(Long sid) {
    Session session = HibernateFactory.getSession();
    return (Integer) session.createSQLQuery("Select count(*) as cnt " +
                                                     "  from rhnSnapshot " +
                                                     " where server_id = " + sid)
                                     .addScalar("cnt", IntegerType.INSTANCE)
                                     .uniqueResult();
}
 
Example #13
Source File: CommentDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   public SortedSet<Comment> getThreadByThreadId(Long threadCommentId, Integer sortBy, Integer userId) {
NativeQuery<Object[]> query = getSession().createNativeQuery(SQL_QUERY_GET_COMPLETE_THREAD);
query.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	.addScalar("user_vote", IntegerType.INSTANCE).setParameter("userId", userId != null ? userId : 0)
	.setParameter("threadId", threadCommentId);
List<Object[]> results = query.list();
return upgradeComments(results, sortBy);
   }
 
Example #14
Source File: CommentDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
   private SortedSet<Comment> getNextThreadByThreadIdLikes(final Long rootTopicId, final Long previousThreadMessageId,
    Integer numberOfThreads, Integer sortBy, String extraSortParam, Integer userId) {

// the search to get to the top level is quite heavy and involves grouping the likes, so get all the data
// for the top level then get the child replies.
List<Object[]> topThreadObjects = null;
if (previousThreadMessageId == null || previousThreadMessageId == 0L) {
    topThreadObjects = getSession().createSQLQuery(SQL_QUERY_FIND_FIRST_THREAD_TOP_BY_LIKES)
	    .addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("rootUid", rootTopicId)
	    .setParameter("userId", userId != null ? userId : 0).setMaxResults(numberOfThreads).list();
} else {
    // get more entries with the same number of likes or less likes
    topThreadObjects = getSession().createSQLQuery(SQL_QUERY_FIND_NEXT_THREAD_TOP_BY_LIKE)
	    .addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("rootUid", rootTopicId)
	    .setParameter("lastUid", previousThreadMessageId).setParameter("like", extraSortParam)
	    .setParameter("userId", userId != null ? userId : 0).setMaxResults(numberOfThreads).list();
}
if (topThreadObjects != null && topThreadObjects.size() > 0) {
    // build the list of uids
    List<Number> threadUidList = new ArrayList<Number>();
    for (Object[] rawObject : topThreadObjects) {
	Comment comment = (Comment) rawObject[0];
	threadUidList.add(comment.getUid());
    }
   NativeQuery<Object[]> query = getSession().createNativeQuery(SQL_QUERY_FIND_NEXT_THREAD_MESSAGES_REPLIES_ONLY);
    query.addEntity("comment", Comment.class).addScalar("likes_total", IntegerType.INSTANCE)
	    .addScalar("user_vote", IntegerType.INSTANCE).setParameter("userId", userId != null ? userId : 0)
	    .setParameterList("threadIds", threadUidList);
    List<Object[]> results = query.list();
    topThreadObjects.addAll(results);
    return upgradeComments(topThreadObjects, sortBy);
}
return new TreeSet<Comment>();
   }
 
Example #15
Source File: IdOrVersionGenerator.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
	this.idColumn = getParam(dialect, OBJECT_ID_COLUMN, params);
	this.versionColumn = getParam(dialect, OBJECT_VERSION_COLUMN, params);
	this.tableName = getParam(dialect, OBJECT_TABLE_NAME, params);
	super.configure(IntegerType.INSTANCE, params, dialect);
}
 
Example #16
Source File: IdOrVersionGenerator.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private String buildSelectVersionQuery(SessionImplementor session, String versionName, String idName, String tableName) {
	Dialect dialect = session.getFactory().getDialect();
	final String alias = "tbl";
	List<String> maxArgs = new ArrayList<>();
	maxArgs.add(StringHelper.qualify(alias, versionName));
	String maxFunction = dialect.getFunctions().get("max").render(IntegerType.INSTANCE, maxArgs, session.getFactory());
	String sql = "select " + maxFunction + " from " + tableName + ' ' + alias + " where " + StringHelper.qualify(alias, idName) + " = ?";
	return sql;
}
 
Example #17
Source File: SQLiteDialect.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public SQLiteDialect() {
	super();
	registerColumnType(Types.BIT, "integer");
	registerColumnType(Types.TINYINT, "tinyint");
	registerColumnType(Types.SMALLINT, "smallint");
	registerColumnType(Types.INTEGER, "integer");
	registerColumnType(Types.BIGINT, "bigint");
	registerColumnType(Types.FLOAT, "float");
	registerColumnType(Types.REAL, "real");
	registerColumnType(Types.DOUBLE, "double");
	registerColumnType(Types.NUMERIC, "numeric");
	registerColumnType(Types.DECIMAL, "decimal");
	registerColumnType(Types.CHAR, "char");
	registerColumnType(Types.VARCHAR, 255, "varchar($l)");
	registerColumnType(Types.LONGVARCHAR, "longvarchar");
	registerColumnType(Types.DATE, "date");
	registerColumnType(Types.TIME, "time");
	registerColumnType(Types.TIMESTAMP, "timestamp");
	registerColumnType(Types.BINARY, "blob");
	registerColumnType(Types.VARBINARY, "blob");
	registerColumnType(Types.LONGVARBINARY, "blob");
	registerColumnType(Types.BLOB, "blob");
	registerColumnType(Types.CLOB, "clob");
	registerColumnType(Types.BOOLEAN, "integer");
	registerHibernateType(Types.NULL, "null");
	
	registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE,
			"", "||", ""));
	registerFunction("mod", new SQLFunctionTemplate(IntegerType.INSTANCE,
			"?1 % ?2"));
	registerFunction("substr", new StandardSQLFunction("substr",
			StringType.INSTANCE));
	registerFunction("substring", new StandardSQLFunction("substr",
			StringType.INSTANCE));
}
 
Example #18
Source File: Page.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
private void fetchByPageId(int pageID)
	throws WikiApiException
{
       Session session = this.wiki.__getHibernateSession();
       session.beginTransaction();
	hibernatePage = (de.tudarmstadt.ukp.wikipedia.api.hibernate.Page) session
			.createQuery("from Page where pageId = :id").setParameter("id", pageID, IntegerType.INSTANCE).uniqueResult();
       session.getTransaction().commit();

       if (hibernatePage == null) {
           throw new WikiPageNotFoundException("No page with page id " + pageID + " was found.");
       }
}
 
Example #19
Source File: Wikipedia.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the title for a given pageId.
 *
 * @param pageId The id of the page.
 * @return The title for the given pageId.
 * @throws WikiApiException Thrown if errors occurred.
 */
public Title getTitle(int pageId) throws WikiApiException {
	Session session = this.__getHibernateSession();
    session.beginTransaction();
    Object returnValue = session.createNativeQuery(
        "select p.name from PageMapLine as p where p.pageId= :pId").setParameter("pId", pageId, IntegerType.INSTANCE).uniqueResult();
    session.getTransaction().commit();

    String title = (String)returnValue;
    if(title==null){
    	throw new WikiPageNotFoundException();
    }
    return new Title(title);
}
 
Example #20
Source File: Wikipedia.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
/**
 * Get the hibernate ID to a given pageID of a page.
 * We need different methods for pages and categories here, as a page and a category can have the same ID.
 *
 * @param pageID A pageID that should be mapped to the corresponding hibernate ID.
 * @return The hibernateID of the page with pageID or -1, if the pageID is not valid
 */
protected long __getPageHibernateId(int pageID) {
    long hibernateID = -1;

    // first look in the id mapping cache
    if (idMapPages.containsKey(pageID)) {
        return idMapPages.get(pageID);
    }

    // The id was not found in the id mapping cache.
    // It may not be in the cahe or may not exist at all.
    Session session = this.__getHibernateSession();
    session.beginTransaction();
    Object retObjectPage = session.createQuery(
            "select page.id from Page as page where page.pageId = :pageId")
            .setParameter("pageId", pageID, IntegerType.INSTANCE)
            .uniqueResult();
    session.getTransaction().commit();
    if (retObjectPage != null) {
        hibernateID = (Long) retObjectPage;
        // add it to the cache
        idMapPages.put(pageID, hibernateID);
        return hibernateID;
    }

    return hibernateID;
}
 
Example #21
Source File: HibernateUtil.java    From unitime with Apache License 2.0 5 votes vote down vote up
public static void addBitwiseOperationsToDialect() {
	SessionFactoryImplementor hibSessionFactory = (SessionFactoryImplementor)new _RootDAO().getSession().getSessionFactory();
	Dialect dialect = hibSessionFactory.getDialect();
	if (!dialect.getFunctions().containsKey("bit_and")) {
		if (isOracle())
			dialect.getFunctions().put("bit_and", new StandardSQLFunction("bitand", IntegerType.INSTANCE));
		else if (isPostgress())
			dialect.getFunctions().put("bit_and", new SQLFunctionTemplate(IntegerType.INSTANCE, "cast(?1 as int) & cast(?2 as int)"));
		else
			dialect.getFunctions().put("bit_and", new SQLFunctionTemplate(IntegerType.INSTANCE, "?1 & ?2"));
	}
}
 
Example #22
Source File: HibernateUtil.java    From unitime with Apache License 2.0 5 votes vote down vote up
public static void addAddDateToDialect() {
	SessionFactoryImplementor hibSessionFactory = (SessionFactoryImplementor)new _RootDAO().getSession().getSessionFactory();
	Dialect dialect = hibSessionFactory.getDialect();
	if (isPostgress() && !dialect.getFunctions().containsKey("adddate")) {
		dialect.getFunctions().put("adddate", new SQLFunctionTemplate(IntegerType.INSTANCE, "?1 + (?2) * interval '1 day'"));
	}
}
 
Example #23
Source File: SessionRestore.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected Object get(Class clazz, String id) {
	if (clazz.equals(String.class) || clazz.equals(StringType.class)) return id;
	if (clazz.equals(Character.class) || clazz.equals(CharacterType.class)) return (id == null || id.isEmpty() ? null : id.charAt(0));
	if (clazz.equals(Byte.class) || clazz.equals(ByteType.class)) return Byte.valueOf(id);
	if (clazz.equals(Short.class) || clazz.equals(ShortType.class)) return Short.valueOf(id);
	if (clazz.equals(Integer.class) || clazz.equals(IntegerType.class)) return Integer.valueOf(id);
	if (clazz.equals(Long.class) || clazz.equals(LongType.class)) return Long.valueOf(id);
	if (clazz.equals(Float.class) || clazz.equals(FloatType.class)) return Float.valueOf(id);
	if (clazz.equals(Double.class) || clazz.equals(DoubleType.class)) return Double.valueOf(id);
	if (clazz.equals(Boolean.class) || clazz.equals(BooleanType.class)) return Boolean.valueOf(id);
	
	Map<String, Entity> entities = iEntities.get(clazz.getName());
	if (entities != null) {
		Entity entity = entities.get(id);
		if (entity != null) return entity.getObject();
	}
       for (Map.Entry<String, Map<String, Entity>> entry: iEntities.entrySet()) {
       	Entity o = entry.getValue().get(id);
       	if (o != null && clazz.isInstance(o.getObject())) return o.getObject();
	}
       if (clazz.equals(Session.class))
       	return ((Entity)iEntities.get(Session.class.getName()).values().iterator().next()).getObject();
       if (clazz.equals(Student.class))
       	return checkUnknown(clazz, id, iStudents.get(id));
       if (iIsClone)
       	return checkUnknown(clazz, id,
       			iHibSession.get(clazz, clazz.equals(ItypeDesc.class) ? (Serializable) Integer.valueOf(id) : (Serializable) Long.valueOf(id)));
       return checkUnknown(clazz, id, null);
}
 
Example #24
Source File: SystemManagerTest.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private Integer numberOfSnapshots(Long sid) {
    Session session = HibernateFactory.getSession();
    return (Integer) session.createSQLQuery("Select count(*) as cnt " +
                                                     "  from rhnSnapshot " +
                                                     " where server_id = " + sid)
                                     .addScalar("cnt", new IntegerType())
                                     .uniqueResult();
}
 
Example #25
Source File: AbstractReactiveSaveEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Serializable assignIdIfNecessary(Object generatedId, Object entity, String entityName, EventSource source) {
	EntityPersister persister = source.getEntityPersister(entityName, entity);
	if ( generatedId != null ) {
		if (generatedId instanceof Long) {
			Long longId = (Long) generatedId;
			Type identifierType = persister.getIdentifierType();
			if (identifierType == LongType.INSTANCE) {
				return longId;
			}
			else if (identifierType == IntegerType.INSTANCE) {
				return longId.intValue();
			}
			else {
				throw new HibernateException("cannot generate identifiers of type "
						+ identifierType.getReturnedClass().getSimpleName() + " for: " + entityName);
			}
		}
		else {
			return (Serializable) generatedId;
		}
	}
	else {
		Serializable assignedId = persister.getIdentifier( entity, source.getSession() );
		if (assignedId == null) {
			throw new IdentifierGenerationException("ids for this class must be manually assigned before calling save(): " + entityName);
		}
		return assignedId;
	}
}
 
Example #26
Source File: NotebookUserDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   public List<StatisticDTO> getStatisticsBySession(final Long contentId) {
NativeQuery<StatisticDTO> query = getSession().createNativeQuery(GET_STATISTICS);
query.addScalar("sessionId", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
	.addScalar("numLearners", IntegerType.INSTANCE).addScalar("numLearnersFinished", IntegerType.INSTANCE)
	.setParameter("contentId", contentId).setResultTransformer(Transformers.aliasToBean(StatisticDTO.class));
return query.list();
   }
 
Example #27
Source File: AbstractPersistentCollection.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static boolean mayUseIdDirect(Type idType) {
	return idType == StringType.INSTANCE
		|| idType == IntegerType.INSTANCE
		|| idType == LongType.INSTANCE
		|| idType == UUIDBinaryType.INSTANCE
		|| idType == UUIDCharType.INSTANCE
		|| idType == PostgresUUIDType.INSTANCE;
}
 
Example #28
Source File: SurveyUserDAOHibernate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   /** Returns < [surveySession, numUsers] ... [surveySession, numUsers]> */
   public List<Object[]> getStatisticsBySession(final Long contentId) {

NativeQuery<Object[]> query = getSession().createNativeQuery(GET_STATISTICS);
query.addEntity(SurveySession.class).addScalar("numUsers", IntegerType.INSTANCE).setParameter("contentId",
	contentId);
return query.list();
   }
 
Example #29
Source File: VoteUsrAttemptDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   public List<VoteStatsDTO> getStatisticsBySession(Long toolContentId) {

NativeQuery<VoteStatsDTO> query = getSession().createSQLQuery(GET_STATISTICS);
query.addScalar("sessionUid", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
	.addScalar("countUsersComplete", IntegerType.INSTANCE).setParameter("contentId", toolContentId)
	.setResultTransformer(Transformers.aliasToBean(VoteStatsDTO.class));

return query.list();
   }
 
Example #30
Source File: SubmitUserDAO.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   @SuppressWarnings("unchecked")
   public List<StatisticDTO> getStatisticsBySession(final Long contentId) {
NativeQuery<StatisticDTO> query = getSession().createNativeQuery(GET_STATISTICS);
query.addScalar("sessionId", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
	.addScalar("totalUploadedFiles", IntegerType.INSTANCE).addScalar("markedCount", IntegerType.INSTANCE)
	.setParameter("contentId", contentId).setResultTransformer(Transformers.aliasToBean(StatisticDTO.class));

List<StatisticDTO> list = query.list();
for (StatisticDTO dto : list) {
    dto.setNotMarkedCount(dto.getTotalUploadedFiles() - dto.getMarkedCount());
}
return list;
   }