List of usage examples for org.apache.ibatis.session SqlSession selectList
<E> List<E> selectList(String statement, Object parameter);
From source file:io.starter.TestContent.java
License:Open Source License
/** * //from ww w . j ava2 s .c o m * 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 testGetContentObjByContent() 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.selectObjByExample", example); Content contents = results.get(0); assertEquals("Gianni", contents.getUser().getFirstName()); session.close(); }
From source file:io.starter.TestContent.java
License:Open Source License
/** * /*from ww w. j a va2 s . c o m*/ * an example of a complex query * * @throws Exception */ @Test public void testGetSeveralContentsByList() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); ContentRatingExample example = new ContentRatingExample(); // get everything by user id 1, 2, or 3 List<Integer> contentIds = new ArrayList<Integer>(); contentIds.add(1); contentIds.add(2); contentIds.add(3); example.or().andIdIn(contentIds); List<ContentRating> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); assertEquals(2, results.size()); session.close(); }
From source file:io.starter.TestContent.java
License:Open Source License
/** * //from w ww. j a v a 2s . c om Note this is the same query as above, expressed with a critera * * @throws Exception */ @Test public void testGetSeveralContentsBySpan() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); ContentRatingExample example = new ContentRatingExample(); Criteria criteria = example.createCriteria(); criteria.andIdBetween(0, 4); List<ContentRating> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); assertEquals(2, results.size()); session.close(); }
From source file:io.starter.TestContent.java
License:Open Source License
/** * /*from w w w .j a va2 s. c o m*/ * * OUCH updating content objects totally broken. * * @throws Exception */ @Test @Ignore public void setImageNamesForStarterItems() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); // update for (Content c : results) { String stz = c.getUrl(); if (stz.indexOf(SystemConstants.S3_STARTER_SERVICE) > -1) { stz = stz.substring(stz.lastIndexOf("/") + 1); Logger.logInfo("Found Starter File: " + stz); c.setUrl(stz); try { ContentExample example1 = new ContentExample(); io.starter.model.ContentExample.Criteria criteria1 = example1.createCriteria(); criteria1.andIdEqualTo(c.getId()); example1.setDistinct(true); int rowsUpdated = session.update("io.starter.dao.ContentMapper.Update_By_Example_Where_Clause", example1); } catch (Exception e) { fail(e.toString()); } } } results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); // update for (Content c : results) { String stz = c.getUrl(); if (stz.indexOf(SystemConstants.S3_STARTER_SERVICE) > -1) { fail("Still Legacy Filenames Exist"); } } }
From source file:io.starter.TestContent.java
License:Open Source License
/** * convert to new folder structure for image uploads * /* w w w . j a va 2s . co m*/ * @throws Exception */ @Test @Ignore public void testContentImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); while (!resu.isEmpty()) { Thread.sleep(3000); Logger.logInfo(resu.size() + " items left"); Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Content c = (Content) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getUrl(); fin = new File(uploadedFileLocation); uploadedFileLocation = uploadedFileLocation.substring(0, uploadedFileLocation.indexOf(fin.getName())); uploadedFileLocation += "/" + fin.getName(); File fx = new File(uploadedFileLocation); // intercept and process the incoming IMAGE files if (uploadedFileLocation.toLowerCase().endsWith(".png") || uploadedFileLocation.toLowerCase().endsWith(".jpg") || uploadedFileLocation.toLowerCase().endsWith(".gif") || uploadedFileLocation.toLowerCase().endsWith(".jpeg")) { String urlstr = uploadedFileLocation; try { int userId = c.getUserId(); File[] modfiles = ImageUtils.getStarterPics(fx, userId); // upload with nice names for (File modfile : modfiles) { fx = new File(uploadedFileLocation); String fnstart = modfile.getPath() .substring("$$USER_DIR$$starter/server/test/testimages/processed".length()); fnstart = S3_STARTER_MEDIA_FOLDER + fnstart; s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), fnstart); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fnstart); } } catch (Exception x) { Logger.logErr("TestContent failure: " + x); } } else { // non image content... folderize try { String fnstart = fx.getPath(); String fnend = fx.getName(); fnend = fnend.substring(fnend.indexOf(".")); // file // type fnstart = fnstart.substring(0, fnstart.indexOf(fnend)); if (uploadedFileLocation.startsWith("http:")) { File finx = File.createTempFile("ck-", fnend); fx = ImageUtils.readFromUrl(uploadedFileLocation, finx); } // this is all it takes to create a nice folderizd // structure within the S3 Bucket. fnstart = "/userdata/" + c.getUser().getId() + "/" + fx.getName(); s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(fx)), fnstart); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fx.getName()); } catch (Exception e) { // Logger.logErr(e); // pretty normal for non // uploads } } } }); tp.start(); } }
From source file:io.starter.TestContent.java
License:Open Source License
/** * /* ww w .ja va 2 s . c o m*/ Note this is the same query as above, expressed with a critera * * @throws Exception */ @Ignore @Test public void testAvatarImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); UserExample example = new UserExample(); io.starter.model.UserExample.Criteria criteria = example.createCriteria(); criteria.andAvatarImageIsNotNull(); example.setDistinct(true); List<User> results = session.selectList("io.starter.dao.UserMapper.selectByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); int semaphore = resu.size(); System.setProperty("semaphore", String.valueOf(semaphore)); while (!resu.isEmpty() || semaphore > 0) { Thread.sleep(3000); String s = System.getProperty("semaphore"); semaphore = Integer.parseInt(s); Logger.logInfo(semaphore + " items left"); if (!resu.isEmpty()) { Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub User c = (User) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getAvatarImage(); if (uploadedFileLocation == null) return; fin = new File(uploadedFileLocation); // uploadedFileLocation = // uploadedFileLocation.substring(0, // uploadedFileLocation.indexOf(fin.getName())); // uploadedFileLocation += "/" + fin.getName(); File fx = new File(SystemConstants.S3_STARTER_SERVICE + S3_STARTER_MEDIA_BUCKET + "/" + uploadedFileLocation); // intercept and process the incoming IMAGE files if (uploadedFileLocation.toLowerCase().endsWith(".png") || uploadedFileLocation.toLowerCase().endsWith(".jpg") || uploadedFileLocation.toLowerCase().endsWith(".gif") || uploadedFileLocation.toLowerCase().endsWith(".jpeg")) { String urlstr = uploadedFileLocation; try { int userId = c.getId(); File[] modfiles = ImageUtils.processExistingStarterPics(fx, userId); // upload with nice names for (File modfile : modfiles) { fx = new File(uploadedFileLocation); String fnstart = modfile.getPath().substring( "$$USER_DIR$$starter/server/test/testimages/processed".length()); fnstart = S3_STARTER_MEDIA_FOLDER + fnstart; s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), fnstart); Logger.logInfo("UserData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fnstart); } String s = System.getProperty("semaphore"); int semaphore = Integer.parseInt(s); semaphore--; System.setProperty("semaphore", String.valueOf(semaphore)); } catch (Exception x) { Logger.logErr("TestContent User Image failure: " + x); } } } }); tp.start(); } } }
From source file:io.starter.TestContent.java
License:Open Source License
/** * /*from w ww . j a va2 s . c o m*/ Note this is the same query as above, expressed with a critera * * @throws Exception */ @Test @Ignore public void testNonImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); int semaphore = resu.size(); System.setProperty("semaphore", String.valueOf(semaphore)); while (!resu.isEmpty() || semaphore > 0) { Thread.sleep(3000); String s = System.getProperty("semaphore"); semaphore = Integer.parseInt(s); Logger.logInfo(semaphore + " items left"); if (!resu.isEmpty()) { Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Content c = (Content) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getUrl(); if (uploadedFileLocation == null) return; fin = new File(uploadedFileLocation); // uploadedFileLocation = // uploadedFileLocation.substring(0, // uploadedFileLocation.indexOf(fin.getName())); // uploadedFileLocation += "/" + fin.getName(); File fx = new File(SystemConstants.S3_STARTER_SERVICE + S3_STARTER_MEDIA_BUCKET + "/" + uploadedFileLocation); // intercept and process the incoming IMAGE files if ((uploadedFileLocation.toLowerCase().endsWith(".mov")) || (uploadedFileLocation.toLowerCase().endsWith(".html")) || (uploadedFileLocation.toLowerCase().endsWith(".m4a"))) { String urlstr = uploadedFileLocation; try { int userId = c.getUserId(); File[] modfiles = ImageUtils.processExistingStarterPics(fx, userId); String fnend = uploadedFileLocation; fnend = fnend.substring(fnend.lastIndexOf(".")); // file // type String fnstart = uploadedFileLocation.substring(0, uploadedFileLocation.lastIndexOf(".")); uploadedFileLocation = SystemConstants.S3_STARTER_MEDIA_FOLDER + "/" + userId + "/" + fnstart + "/" + "Standard" + fnend; // upload with nice names for (File modfile : modfiles) { s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), uploadedFileLocation); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + uploadedFileLocation); } } catch (Exception x) { Logger.logErr("TestContent Content Image failure: " + x); } } String s = System.getProperty("semaphore"); int semaphore = Integer.parseInt(s); semaphore--; System.setProperty("semaphore", String.valueOf(semaphore)); } }); tp.start(); } } }
From source file:mybatis.client.MyJFrame.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //? ?//from w ww . j a v a 2s.c o m String sname = JOptionPane.showInputDialog("?:"); System.out.println("?:" + sname); // 3) factory SqlSession? SqlSession ss = factory.openSession(true); // 4) sql List<MemVO> lists = ss.selectList("mem.searchName", sname); System.out.println("lists :" + lists.size()); if (lists.size() > 0) { viewData(lists); } else { ta.setText(""); JOptionPane.showMessageDialog(this, "? ? ."); } ss.close(); }
From source file:net.hasor.db.orm.mybatis3.SqlExecutorTemplate.java
License:Apache License
public <E> List<E> selectList(final String statement, final Object parameter) throws SQLException { return this.execute(new SqlSessionCallback<List<E>>() { public List<E> doSqlSession(SqlSession sqlSession) { return sqlSession.selectList(statement, parameter); }/*from ww w . jav a2 s .co m*/ }); }
From source file:net.nexxus.db.DBManagerImpl.java
License:Open Source License
/** * return a List of headers using an optional cutoff which * can be null/*from ww w.jav a 2 s .c o m*/ */ public List<NntpArticleHeader> getHeaders(NntpGroup group, Integer cutoff) { List resultSet = null; try { String cutoffPoint; HashMap map = new HashMap(); String table = DBUtils.convertGroup(group.getName()); map.put("table", table); SqlSession session = sqlFactory.openSession(); if (cutoff == null || cutoff.equals(Integer.valueOf(0))) { log.debug("not using cutoff selecting headers"); resultSet = session.selectList("getHeadersLite", map); } else { cutoffPoint = this.calculateCutoff(cutoff); log.debug("using " + cutoffPoint + " as cutoff for selecting headers"); map.put("cutoff", cutoffPoint); resultSet = session.selectList("getHeadersRangeLite", map); } session.close(); } catch (Exception e) { log.error("failed loading headers from DB: " + e.getMessage()); e.printStackTrace(); } return resultSet; }