Example usage for org.apache.ibatis.session SqlSession selectList

List of usage examples for org.apache.ibatis.session SqlSession selectList

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectList.

Prototype

<E> List<E> selectList(String statement, Object parameter);

Source Link

Document

Retrieve a list of mapped objects from the statement key and parameter.

Usage

From source file:gp.daoImpl.ReporteInversionDaoImpl.java

@Override
public List<MostrarDesdeDependencias> getListaDesdeDepes(Integer idOrigen) {
    List<MostrarDesdeDependencias> list = null;
    SqlSession session = sqlSessionFactory.openSession();
    try {//from   w w w .j  a va 2 s  . c o m
        list = session.selectList("ReporteInversion.getDatosDesdeDepes", idOrigen);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.out.println("ERROR EN EL IMPL");
    } finally {
        session.close();
    }
    return list;
}

From source file:gp.daoImpl.ReporteInversionDaoImpl.java

@Override
public List<GraficasMontosAnios> getAniosMontos(String codigo) {
    List<GraficasMontosAnios> list = null;
    SqlSession session = sqlSessionFactory.openSession();
    try {//from w  w w .j a v  a2 s.  c o m
        list = session.selectList("ReporteInversion.getMontosAnios", codigo);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.out.println("ERROR EN EL IMPL");
    } finally {
        session.close();
    }
    return list;
}

From source file:gp.daoImpl.ReporteInversionDaoImpl.java

@Override
public List<Ejecucion> getEjecucionXanios(String codigo, String anio) {
    List<Ejecucion> list = null;
    Map<String, String> map = new HashMap<String, String>();
    map.put("anio", anio);
    map.put("codigo", codigo);
    SqlSession session = sqlSessionFactory.openSession();
    try {//from  ww  w  .j a  v a  2  s . c om
        list = session.selectList("ReporteInversion.getEjecucionXanios", map);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.out.println("ERROR EN EL IMPL");
    } finally {
        session.close();
    }
    return list;
}

From source file:in.flipbrain.dao.MyBatisDao.java

License:Apache License

public TrailDto getUserTrailById(TrailDto t) {
    SqlSession session = sqlSessionFactory.openSession();
    try {//from  w w  w .jav  a2s  . com
        logActivity(session);
        TrailDto trail = session.selectOne("getUserTrailById", t);
        if (trail != null) {
            trail.videos = session.selectList("getVideosForTrail", t.trailId);
            trail.resources = session.selectList("getResourcesForTrail", t.trailId);
            trail.assessments = session.selectList("getAssessmentsForTrail", t.trailId);
        }
        return trail;
    } finally {
        session.close();
    }
}

From source file:in.flipbrain.dao.MyBatisDao.java

License:Apache License

public TrailDto getTrailForView(int tid) {
    SqlSession session = sqlSessionFactory.openSession();
    try {//from   w  ww . j  a v  a  2 s  .c o  m
        logActivity(session);
        TrailDto t = session.selectOne("getTrailById", tid);
        if (t != null) {
            t.videos = session.selectList("getVideosForTrail", tid);
            t.resources = session.selectList("getResourcesForTrail", tid);
            t.assessments = session.selectList("getAssessmentsForTrail", tid);
            //Get the stats
            t.viewsCount = session.selectOne("getTrailViewsCount", tid);
            t.commentsCount = session.selectOne("getTrailCommentsCount", tid);
            t.subsCount = session.selectOne("getTrailSubsCount", tid);
        }
        return t;
    } finally {
        session.close();
    }
}

From source file:in.flipbrain.dao.MyBatisDao.java

License:Apache License

protected <P, R> List<R> getEntityList(String stmtId, P dto) {
    SqlSession session = sqlSessionFactory.openSession();
    List<R> result;/*  w ww.j  ava 2  s  .com*/
    try {
        logActivity(session);
        result = session.selectList(stmtId, dto);
        session.commit();
    } finally {
        session.close();
    }
    return result;
}

From source file:io.starter.datamodel.ContentData.java

License:Open Source License

/**
 * return a list of content objects from the passed-in query
 * //from  w  w w  . jav  a2  s . c om
 * @param query
 * @param servletRequest
 * @param servletResponse
 * @throws IOException
 * @throws ServletException
 * @throws JSONException
 * @throws org.json.JSONException 
 */
@GET
@Path("list")
@Produces(MediaType.APPLICATION_JSON)
public String list(@QueryParam("query") String query, @Context HttpServletRequest servletRequest,
        @Context HttpServletResponse servletResponse)
        throws IOException, ServletException, JSONException, org.json.JSONException {

    List results = null;

    int begin = 0;
    if (servletRequest.getParameter("offset") != null) {
        try {
            int offs = Integer.parseInt(servletRequest.getParameter("offset"));
            begin = offs;
        } catch (Exception x) {
            Logger.log("Could not parse list position from: " + servletRequest.getParameter("offset"));
        }
    }

    if (begin != 0) //  || (!query.equalsIgnoreCase("top") && (query.indexOf("userId") == -1)&& (query.indexOf("new") == -1))) // get
        results = getCachedContentList(query, servletRequest);

    User user = null;

    Object u = servletRequest.getAttribute(SESSION_VAR_USER);

    boolean categorySelected = false;
    int catId = -1;
    int userId = -1;
    String mimeType = null;
    boolean restrictToLocal = false;

    try {
        catId = Integer.parseInt(query);
        categorySelected = true;
    } catch (Exception e) {
        ;
    }

    try {
        if (query.indexOf("userId") > -1) {
            String uid = query.substring(query.indexOf("userId=") + 7);
            userId = Integer.parseInt(uid);
        } else if (query.indexOf("mimetype") > -1) {

            // web video picture sound joke
            // audio/mp4 image/jpeg image/png
            // video/quicktime, text/plain text/html
            String mtid = query.substring(query.indexOf("mimetype=") + 9);

            if (mtid.equalsIgnoreCase("video")) {
                mimeType = "video/quicktime";
            } else if (mtid.equalsIgnoreCase("picture")) {
                mimeType = "image";
            } else if (mtid.equalsIgnoreCase("web")) {
                mimeType = "text/html";
            } else if (mtid.equalsIgnoreCase("joke")) {
                mimeType = "text/html";
                restrictToLocal = true; // this allows us to differentiate
                // jokes with remote web clips
            } else if (mtid.equalsIgnoreCase("sound")) {
                mimeType = "audio/mp4";
            }
        }
    } catch (Exception e) {
        ;
    }

    // login the anon user to get public content
    if (u == null)
        throw new ServletException("No User in Request -- Cannot fetch content list anonymously.");
    user = (User) u;

    // TODO: test this for performance hit...
    user.clearCachedAuthorization();

    SqlSession session = (SqlSession) servletRequest.getAttribute(SESSION_VAR_SQLSESSION);

    if (results == null) {
        Logger.debug("Content List Cache Miss for: " + query);

        if (categorySelected) { // filtered by category id
            results = session.selectList("io.starter.dao.ContentMapper.selectObjByCategory", catId);
        } else { // return list by other means
            ContentExample example = new ContentExample();
            io.starter.model.ContentExample.Criteria criteria = example.createCriteria();

            if (query.equalsIgnoreCase("lbc")) { // location based starter
                criteria.andLatitudeIsNotNull();
                criteria.andLatitudeNotEqualTo(0.0d);
                criteria.andLongitudeIsNotNull();
                criteria.andLongitudeNotEqualTo(0.0d);
            } else if (query.indexOf("mimetype") > -1) { // mime type
                // based
                if (mimeType.indexOf("/") == -1) { // fuzzy match
                    criteria.andMimeTypeLike("%" + mimeType + "%");
                } else { // exact match
                    criteria.andMimeTypeEqualTo(mimeType);
                }
            } else if (userId > -1) {
                criteria.andUserIdEqualTo(userId);

            }

            if (!user.isAdmin()) {
                criteria.andFlagGreaterThanOrEqualTo(FLAG_NONE); // any
            }

            example.setOrderByClause("post_date DESC");
            example.setDistinct(true);
            results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example);

            // check if it's a local URL
            List retu = new ArrayList();
            Iterator itx = results.iterator();
            while (itx.hasNext()) {
                Content dx = (Content) itx.next();
                String rez = dx.getUrl();

                if (restrictToLocal) {
                    if (rez.indexOf("http") == -1) {
                        retu.add(dx);
                    }
                    ;
                } else {
                    // if(rez.indexOf("http") == 0){
                    retu.add(dx);
                    // };
                }
            }
            results = retu;

            // SORT by Top rated
            if (query.equalsIgnoreCase("top")) {
                Object[] ret = results.toArray();
                Arrays.sort(ret);
                results = Arrays.asList(ret);
            }

        }
        // add results list to caches
        addCachedContentList(query, results, servletRequest);
    }

    // call every time we return a list to avoid returning unauthorized
    // stuff
    List filteredResults = this.removeUnauthorized(servletRequest, results, SECURITY_ACL_READ,
            SECURITY_TARGET_TYPE_CONTENT);

    JSONArray j = new JSONArray();

    // add the 'isowner' request-specific field
    Iterator its = filteredResults.iterator();
    int countr = 0;
    while (its.hasNext()) {
        Content cx = (Content) its.next();

        if ((countr >= begin) && (countr < (begin + NUM_RETURN_ROWS))) {
            int uid = cx.getUserId();
            try {
                User udd = UserData.getUserObjectByID(uid, servletRequest, servletResponse);
                if (udd != null) {
                    cx.setUser(udd);
                }
            } catch (Exception e) {
                Logger.warn("ContentData.list: Could not get cached User object: " + e.toString());
            }

            // handle ownership here.
            JSONObject job = new JSONObject(cx);

            if (user != null) {
                Integer uidx = user.getId();
                if ((uidx != null && (uid == uidx)) || (user.isAdmin()))
                    job.put("isowner", true);
                else
                    job.put("isowner", false);
            } else {
                job.put("isowner", false);
            }
            job.put("isdeleted", (cx.getFlag() == FLAG_DELETED));

            // content display wrapper
            job.put("showWrapper", ContentData.getWrapper(cx.getId(), session));

            // set pretty date
            SimpleDateFormat sdf1 = new SimpleDateFormat(PRETTY_DATE_FORMAT);
            String postPrettyDate = sdf1.format(cx.getPostDate());
            job.put("prettyDate", postPrettyDate);

            // how many reshares
            job.put("reshare_ct", cx.getRepostCount());

            // how many ratings
            job.put("rating_ct", cx.getRatings().size());

            j.put(job);
        }

        countr++;
    }

    // return the JSON result
    return j.toString();
}

From source file:io.starter.datamodel.ContentData.java

License:Open Source License

/**
 * determine whether to show a wrapper and if so, which one
 * /*from  w w w  .j av a  2 s .c  o  m*/
 * currently we only have NSFW implemented as it is core
 * 
 * 'Rated G' : 0 'Rated PG' : -1 'Rated R' : -2 'N.S.F.W.' : -3 'Rated X' :
 * -4
 * 
 * 
 * @param session
 * 
 * @return
 */
public static String getWrapper(int id, SqlSession session) {

    try {
        List<Category> results = session.selectList("io.starter.dao.ContentMapper.getCategoriesForContent", id);

        Iterator its = results.iterator();
        while (its.hasNext()) {
            Category cat = (Category) its.next();
            int rating = cat.getSuitabilityRating();
            if (rating < -2)
                return "true"; // TODO: in the future implement custom
        }

    } catch (NullPointerException e) {
        ; // no categories
    }
    return "false";

}

From source file:io.starter.TestContent.java

License:Open Source License

@Test
public void testFixContentUrls() throws Exception {
    sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
    SqlSession session = sqlSessionFactory.openSession(true);

    String youBroken = "%http://youtu.be/%"; // bad

    ContentExample example = new ContentExample();
    io.starter.model.ContentExample.Criteria criteria = example.createCriteria();
    criteria.andUrlLike(youBroken);/*  w w  w . j a  va 2 s  .com*/

    List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example);

    Iterator its = results.iterator();
    while (its.hasNext()) {
        String url = ((Content) its.next()).getUrl();
        Logger.logInfo("Fixed Youtube URL: " + url + " -> " + ContentData.fixContentURLs(url));
    }

    session.close();
}

From source file:io.starter.TestContent.java

License:Open Source License

/**
 * //w w  w.j  ava2s  .  c om
 * An example of using the selectByExample, note the critera, if you use the
 * code autofill you will see all sorts of stuff in there you can select by
 * 
 * @throws Exception
 */
@Test
public void testGetContentsByContent() throws Exception {

    sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
    SqlSession session = sqlSessionFactory.openSession(true);
    // the 'example' is essentially the descriptino of the data object we
    // want
    ContentExample example = new ContentExample();
    io.starter.model.ContentExample.Criteria criteria = example.createCriteria();
    criteria.andIdEqualTo(1);
    List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example);
    Content contents = results.get(0);
    assertEquals("Knock Knock", contents.getDescription());

    session.close();

}