Example usage for org.hibernate.type StandardBasicTypes LONG

List of usage examples for org.hibernate.type StandardBasicTypes LONG

Introduction

In this page you can find the example usage for org.hibernate.type StandardBasicTypes LONG.

Prototype

LongType LONG

To view the source code for org.hibernate.type StandardBasicTypes LONG.

Click Source Link

Document

The standard Hibernate type for mapping Long to JDBC java.sql.Types#BIGINT BIGINT .

Usage

From source file:org.ambraproject.models.AnnotationTest.java

License:Apache License

@Test
@SuppressWarnings("unchecked")
public void testLoadTypeFromStringRepresentation() {
    final Long userId = (Long) hibernateTemplate
            .save(new UserProfile("email@LoadType.org", "displayNameForLoadType", "pass"));
    final Long articleId = (Long) hibernateTemplate.save(new Article("id:doi-for-LoadType"));

    hibernateTemplate.execute(new HibernateCallback() {
        @Override//w  w w  .j  a va  2s.  com
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            session.createSQLQuery(
                    "insert into annotation (created, lastModified, userProfileID, articleID, type, annotationURI) "
                            + "values (?,?,?,?,?,?)")
                    .setParameter(0, Calendar.getInstance().getTime(), StandardBasicTypes.DATE)
                    .setParameter(1, Calendar.getInstance().getTime(), StandardBasicTypes.DATE)
                    .setParameter(2, userId, StandardBasicTypes.LONG)
                    .setParameter(3, articleId, StandardBasicTypes.LONG)
                    .setParameter(4, "Comment", StandardBasicTypes.STRING)
                    .setParameter(5, "unique-annotation-uri-for-loadTypeFromString", StandardBasicTypes.STRING)
                    .executeUpdate();
            return null;
        }
    });

    List<Annotation> results = (List<Annotation>) hibernateTemplate
            .find("from Annotation where annotationUri = ?", "unique-annotation-uri-for-loadTypeFromString");
    assertEquals(results.size(), 1, "didn't store annotation correctly");
    assertEquals(results.get(0).getType(), AnnotationType.COMMENT, "Type wasn't loaded correctly");
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.java

License:Open Source License

public CDOID createObjectID(String val) {
    final int index = val.lastIndexOf(CDOClassifierRef.URI_SEPARATOR);
    if (index == -1) {
        throw new IllegalArgumentException("Id string " + val + " is not a valid id");
    }//  w  w w  .  ja  v a2  s. c o m

    final String uriPart = val.substring(0, index);
    final String idPart = val.substring(index + 1);
    final CDOClassifierRef classifierRef = new CDOClassifierRef(uriPart);
    final String entityName = getEntityName(classifierRef);
    final EClass eClass = getEClass(entityName);
    final EAnnotation typeEAnnotation = eClass.getEAnnotation(ID_TYPE_EANNOTATION_SOURCE);
    if (typeEAnnotation == null) {
        throw new IllegalStateException("EClass " + eClass + " does not have a type annotation");
    }

    final String idTypeStr = typeEAnnotation.getDetails().get(ID_TYPE_EANNOTATION_KEY);
    if (StandardBasicTypes.STRING.getName().equals(idTypeStr)) {
        return HibernateUtil.getInstance().createCDOID(classifierRef, idPart);
    } else if (StandardBasicTypes.LONG.getName().equals(idTypeStr)) {
        return HibernateUtil.getInstance().createCDOID(classifierRef, new Long(idPart));
    } else {
        throw new IllegalArgumentException("ID type " + idTypeStr + " not supported ");
    }
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.assessment.AssessmentRepositoryHibernate.java

License:Open Source License

@Override
public List<Assessment> listAssessments(Map<String, String> filters) {
    Session session = getSession();/* ww w. j  ava 2 s  .  c o m*/

    Integer pageNum = 1;
    if (filters != null && filters.containsKey(AssessmentRepository.PAGE)) {
        pageNum = Integer.parseInt(filters.get(AssessmentRepository.PAGE));
    }
    Integer pageSize = 50;
    if (filters != null && filters.containsKey(AssessmentRepository.PAGE_SIZE)) {
        pageSize = Integer.parseInt(filters.get(AssessmentRepository.PAGE_SIZE));
    }

    Integer featured = null;

    if (filters.containsKey("featured")) {
        featured = Integer.valueOf(filters.get("featured"));
    }

    String importCode = null;
    if (filters.containsKey("importCode") && filters.get("importCode") != null) {
        importCode = filters.get("importCode");
    }

    if (filters.containsKey(AssessmentRepository.ACCESS_TYPE)
            && filters.get(AssessmentRepository.ACCESS_TYPE).equals("my")) {

        String userId = filters.get("userId");
        String sql = "SELECT distinct c.assessment_id as contentId FROM assessment c INNER JOIN resource cr ON ( c.assessment_id = cr.content_id ";
        if (featured != null) {
            sql += " AND cr.is_featured =  " + featured + " ";
        }
        sql += ") INNER JOIN content cc on c.assessment_id = cc.content_id LEFT JOIN annotation a on c.assessment_id = a.resource_id LEFT JOIN content ac on a.content_id = ac.content_id  where (ac.user_uid = "
                + userId + " or cc.user_uid = " + userId + " ) ";
        sql += " and (a.type_name ='subscription' or  a.type_name is null ) ";
        if (importCode != null) {
            sql += " and c.import_code = '" + importCode + "' ";
        }

        sql += generateAuthSqlQueryWithData("cc.");
        sql += "order by coalesce ( ac.last_modified , cc.last_modified ) desc limit "
                + pageSize * (pageNum - 1) + " , " + pageSize + "";
        Query query = session.createSQLQuery(sql).addScalar("contentId", StandardBasicTypes.LONG);
        List<Long> contentIds = query.list();
        StringBuffer contentIdBuffer = new StringBuffer();
        for (Long contentId : contentIds) {
            if (contentIdBuffer.length() > 0) {
                contentIdBuffer.append(",'" + contentId + "'");
            } else {
                contentIdBuffer.append("'" + contentId + "'");
            }
        }

        if (contentIdBuffer.length() > 1) {

            List<Assessment> myQuiz = getSession().createQuery(
                    "SELECT assessment FROM Assessment assessment   WHERE assessment.contentId IN ("
                            + contentIdBuffer.toString() + ") AND "
                            + generateAuthQueryWithDataNew("assessment"))
                    .list();
            List<Assessment> resultQuiz = new ArrayList<Assessment>();
            for (Long contentId : contentIds) {
                for (Assessment quiz : myQuiz) {
                    if (quiz.getContentId().equals(contentId)) {
                        resultQuiz.add(quiz);
                        break;
                    }
                }
            }

            return resultQuiz;
        } else {
            return new ArrayList<Assessment>();
        }
    }
    Criteria criteria = session.createCriteria(Assessment.class);
    Criteria taxCriteria = session.createCriteria(Assessment.class);
    if (filters.containsKey(TAXONOMY_CODE)) {
        String taxonomyCode = filters.get(TAXONOMY_CODE);
        if (taxonomyCode != null) {
            criteria.createAlias("taxonomySet", "taxonomy");
            criteria.add(Restrictions.eq("taxonomy.code", taxonomyCode));
        }
    }
    if (filters.containsKey(SEGMENT_ID)) {
        Integer segmentId = Integer.parseInt(filters.get(SEGMENT_ID));
        if (segmentId != null) {
            criteria.createAlias("segments", "segment");
            criteria.add(Restrictions.eq("segment.segmentId", segmentId));
        }
    }
    if (featured != null) {
        criteria.add(Restrictions.eq("isFeatured", featured));
    }
    if (importCode != null) {
        criteria.add(Restrictions.eq("importCode", importCode));
    }
    if (filters.containsKey(IS_LIVE)) {
        String isLive = filters.get(IS_LIVE);
        if (isLive != null) {
            criteria.add(Restrictions.eq("isLive", isLive));
        }
    }
    if (filters.containsKey(QUESTION_GOORU_ID)) {
        String gooruOid = filters.get(QUESTION_GOORU_ID);
        if (gooruOid != null) {
            taxCriteria.add(Restrictions.eq("gooruOid", gooruOid));
            List<Assessment> taxAssessments = taxCriteria.list();
            List<String> codes = new ArrayList<String>();
            if (taxAssessments != null && taxAssessments.size() > 0) {
                for (Code code : taxAssessments.get(0).getTaxonomySet()) {
                    codes.add(code.getCode());
                }
                criteria.createAlias("taxonomySet", "taxonomy");
                criteria.add(Restrictions.in("taxonomy.code", codes));
            }
        }
    }
    criteria.addOrder(Order.desc("questionCount"));
    criteria.setFirstResult(((pageNum - 1) * pageSize));
    criteria.setMaxResults(pageSize);
    addAuthCriterias(criteria);
    return criteria.list();
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.auth.OAuthRepositoryHibernate.java

License:Open Source License

@Override
public Long getOauthClientCount(String organizationUId, String grantType) {
    String sql = "SELECT count(1) as count from  oauth_client c WHERE organization_uid = '" + organizationUId
            + "'";
    if (grantType != null) {
        sql += "AND  c.grant_types = '" + grantType + "'";

    }//w ww.  j  a  va 2  s .c om
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    return (Long) query.list().get(0);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.classplan.LearnguideRepositoryHibernate.java

License:Open Source License

@Override
public List<Learnguide> listLearnguides(Map<String, String> filters) {
    Session session = getSession();/*  www  . ja va  2s.  c o  m*/

    Integer featured = null;

    if (filters.containsKey("featured")) {
        featured = Integer.valueOf(filters.get("featured"));
    }

    Integer pageNum = 1;
    if (filters != null && filters.containsKey(PAGE_NO)) {
        pageNum = Integer.parseInt(filters.get(PAGE_NO));
    }
    Integer pageSize = 50;
    if (filters != null && filters.containsKey(PAGE_SIZE)) {
        pageSize = Integer.parseInt(filters.get(PAGE_SIZE));
    }
    if (filters.get("accessType") != null && filters.get("accessType").equals("my")) {
        String userUid = filters.get("userId");
        String sql = "Select distinct c.content_id as contentId from learnguide c inner join resource cr on ( c.content_id = cr.content_id ";
        if (featured != null) {
            sql += " AND cr.is_featured =  " + featured + " ";
        }
        sql += " ) inner join content cc on c.content_id = cc.content_id left join annotation a on c.content_id = a.resource_id left join content ac on a.content_id = ac.content_id left join content_permission cps on cc.content_id = cps.content_id where ((cc.user_uid = '"
                + userUid + "' and cc.type_name != 'annotation') and " + generateAuthSqlQueryWithData("cc.");

        if (Boolean.parseBoolean(filters.get("excludeRating"))) {
            sql += " OR ( a.type_name='subscription' and ac.user_uid = '" + userUid + "')) ";
        }
        if (filters.containsKey("status")) {
            sql += " AND cc.sharing = '" + filters.get("status") + "' AND cc.creator_uid = '" + userUid + "' ";
        }

        if (filters.containsKey("myGroup") && userUid != null) {
            String myGroup = filters.get("myGroup");
            if (myGroup.equals("1")) {
                sql += " AND c.content_id = " + userUid;
            }
        }

        sql += "order by coalesce ( ac.last_modified , cc.last_modified ) desc limit "
                + pageSize * (pageNum - 1) + " , " + pageSize + "";

        Query query = session.createSQLQuery(sql).addScalar("contentId", StandardBasicTypes.LONG);
        Integer startAt = Integer.parseInt(filters.get(PAGE_START));
        if (startAt == 0) {
            startAt = ((pageNum - 1) * pageSize);
        } else {
            startAt = startAt - 1;
        }

        query.setFirstResult(startAt);
        List<Long> contentIds = query.list();
        StringBuffer contentIdBuffer = new StringBuffer();
        for (Long contentId : contentIds) {
            if (contentIdBuffer.length() > 0) {
                contentIdBuffer.append(",'" + contentId + "'");
            } else {
                contentIdBuffer.append("'" + contentId + "'");
            }
        }
        if (contentIdBuffer.length() > 1) {
            List<Learnguide> myCollections = getSession()
                    .createQuery("FROM Learnguide l WHERE l.contentId IN (" + contentIdBuffer.toString() + ") ")
                    .list();
            List<Learnguide> resultCollections = new ArrayList<Learnguide>();
            for (Long contentId : contentIds) {
                for (Learnguide collection : myCollections) {
                    if (collection.getContentId().equals(contentId)) {
                        resultCollections.add(collection);
                        break;
                    }
                }
            }

            return resultCollections;
        } else {
            return new ArrayList<Learnguide>();
        }

    } else {
        String hql = "SELECT distinct(learnguide) FROM Learnguide learnguide LEFT JOIN learnguide.taxonomySet taxonomySet  ";

        if (filters.containsKey("standards") && filters.get("standards") != null) {
            hql += " INNER JOIN taxonomySet.associatedCodes assocCodes";
        }

        hql += " WHERE 1 =1 ";

        if (filters.containsKey(RESOURCE_TYPE)) {
            String resourceType = filters.get(RESOURCE_TYPE);
            if (resourceType != null) {
                hql += " AND learnguide.resourceType.name = '" + resourceType + "'";
            }
        }
        if (filters.containsKey("isLive")) {
            String isLive = filters.get("isLive");
            if (isLive != null) {
                hql += " AND learnguide.isLive = '" + isLive + "'";
            }
        }
        if (featured != null) {
            hql += " AND learnguide.isFeatured = '" + featured + "'";
        }
        if (filters.containsKey("gooruOid")) {
            String gooruOid = filters.get("gooruOid");
            if (gooruOid != null) {
                Criteria taxCriteria = session.createCriteria(Learnguide.class);
                taxCriteria.add(Restrictions.eq("gooruOid", gooruOid));
                List<Assessment> taxAssessments = taxCriteria.list();
                String codes = "";
                if (taxAssessments != null && taxAssessments.size() > 0) {
                    for (Code code : taxAssessments.get(0).getTaxonomySet()) {
                        if (codes.length() == 0) {
                            codes += "'" + code.getCode() + "',";
                        } else {
                            codes += "'" + code.getCode() + "'";
                        }
                    }
                    hql += " AND taxonomySet.code = '" + codes + "'";
                }
            }
        }
        if (filters.containsKey("taxonomyParentId")) {
            String taxonomyParentIdString = filters.get("taxonomyParentId");
            try {
                Integer taxonomyParentId = Integer.valueOf(taxonomyParentIdString);
                hql += " AND taxonomySet.parentId = '" + taxonomyParentId + "'";
            } catch (NumberFormatException e) {
                // We're really not doing anything here since we don't
                // handle the invalid taxonomyParentId's passed.
                // TODO Validate to make sure this is an integer
            }
        }

        if (filters.containsKey("standards") && filters.get("standards") != null) {
            String[] standards = filters.get("standards").split(",");
            StringBuilder includesStandards = new StringBuilder();
            for (String standard : standards) {
                if (includesStandards.length() > 0) {
                    includesStandards.append(",");
                }
                includesStandards.append("'" + standard + "'");
            }
            hql += " AND assocCodes.code IN (" + includesStandards + ")";
        }

        hql += " AND " + generateAuthQueryWithDataNew("learnguide.");

        String orderBy = filters.get("orderBy");
        if (orderBy != null && orderBy.equalsIgnoreCase("lesson")) {
            hql += " ORDER BY taxonomySet.label ASC ";
        }
        Query query = getSession().createQuery(hql);
        query.setFirstResult(((pageNum - 1) * pageSize));
        query.setMaxResults(pageSize);
        return query.list();

    }
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.CollectionRepositoryHibernate.java

License:Open Source License

@Override
public Long getClasspageCount(String gooruOid, String itemType) {
    String sql = "select count(1) as count from collection_item ci inner join resource r on r.content_id = ci.resource_content_id  inner join content c on c.content_id = r.content_id inner join content rc on rc.content_id = ci.collection_content_id left join collection co on co.content_id = r.content_id   "
            + "where  c.sharing in ('public', 'anyonewithlink') and rc.gooru_oid='" + gooruOid + "'";

    if (itemType != null) {
        sql += " and r.type_name ='" + itemType + "'";
    } else {//from  w ww. j  ava 2s  . c  o  m
        sql += " and r.type_name != 'pathway'";
    }
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    return (Long) query.list().get(0);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.CollectionRepositoryHibernate.java

License:Open Source License

@Override
public Long getClasspageCollectionCount(String classpageGooruOid, String status, String userUid, String orderBy,
        String type) {/*  ww w .  j  a  va2s . c  o m*/
    String sql = "select count(1) as count from collection_item ci inner join resource r on r.content_id = ci.resource_content_id  inner join content c on c.content_id = r.content_id inner join content rc on rc.content_id = ci.collection_content_id left join collection co on co.content_id = r.content_id left join user_collection_item_assoc uc on uc.collection_item_uid = ci.collection_item_id and uc.user_uid = '"
            + userUid
            + "' left join custom_table_value ct on ct.custom_table_value_id = uc.status inner join user uu on uu.gooru_uid = c.user_uid  where  c.sharing in ('public', 'anyonewithlink') ";
    sql += " and rc.gooru_oid='" + classpageGooruOid + "'  ";

    if (type != null) {
        sql += " and r.type_name ='" + type + "'";
    } else {
        sql += " and r.type_name != 'pathway'";
    }

    if (status != null) {
        sql += " and IFNULL(ct.value, 'open') = '" + status + "' ";
    }
    if (orderBy != null
            && (orderBy.equalsIgnoreCase(DUE_DATE) || orderBy.equalsIgnoreCase(DUE_DATE_EARLIEST))) {
        sql += " and ci.planned_end_date IS NOT NULL ";
    }
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    return (Long) query.list().get(0);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.CollectionRepositoryHibernate.java

License:Open Source License

@Override
public Long getMyShelfCount(String gooruUid, String sharing, String collectionType) {
    String sql = "select count(1) as count from  resource r inner join collection c on c.content_id = r.content_id inner join content cc on cc.content_id =  c.content_id inner join collection_item ci on ci.collection_content_id = c.content_id inner join resource re on re.content_id = ci.resource_content_id inner join content cr on  cr.content_id = re.content_id inner join organization o  on  o.organization_uid = cr.organization_uid  where c.collection_type = 'shelf' and cr.sharing in ('"
            + sharing.replace(",", "','") + "') and cc.user_uid=:gooruUid";
    if (collectionType != null) {
        collectionType = collectionType.equalsIgnoreCase(COLLECTION) ? SCOLLECTION : collectionType;
        sql += " and re.type_name =:collectionType ";
    }/*from   w  w  w.  j a  v a2 s  .co  m*/
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    query.setParameter(_GOORU_UID, gooruUid);
    if (collectionType != null) {
        query.setParameter(COLLECTION_TYPE, collectionType);
    }
    return (Long) query.list().get(0);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.CollectionRepositoryHibernate.java

License:Open Source License

@Override
public Long getCollectionItemCount(String gooruOid, String sharing, String collectionType) {
    String sql = "select count(1) as count from collection_item ci inner join resource r on r.content_id = ci.resource_content_id  left join custom_table_value ct on ct.custom_table_value_id = r.resource_format_id inner join content c on c.content_id = r.content_id inner join content rc on rc.content_id = ci.collection_content_id where rc.gooru_oid=:gooruOid and c.sharing in ('"
            + sharing.replace(",", "','") + "')";
    if (collectionType != null) {
        collectionType = collectionType.equalsIgnoreCase(COLLECTION) ? SCOLLECTION : collectionType;
        sql += " and r.type_name =:collectionType ";
    }/*w  ww.  ja  v  a  2  s . c o  m*/
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    query.setParameter(GOORU_OID, gooruOid);
    if (collectionType != null) {
        query.setParameter(COLLECTION_TYPE, collectionType);
    }
    return (Long) query.list().get(0);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.CollectionRepositoryHibernate.java

License:Open Source License

@Override
public Long getPublicCollectionCount(String gooruOid, String sharing) {
    String sql = "select count(1) as count  from collection_item  ci inner join resource r  on r.content_id = ci.resource_content_id inner join content c on c.content_id = ci.resource_content_id inner join content cc on cc.content_id = ci.collection_content_id  where cc.gooru_oid =:gooruOid and c.sharing in  ('"
            + sharing//from   w  w w . j a  v  a  2s.c om
            + "') and (r.type_name = 'folder' or r.type_name = 'scollection') and ci.item_type != 'collaborator' ";
    Query query = getSession().createSQLQuery(sql).addScalar("count", StandardBasicTypes.LONG);
    query.setParameter(GOORU_OID, gooruOid);
    return (Long) query.list().get(0);
}