List of usage examples for org.apache.ibatis.session SqlSession getMapper
<T> T getMapper(Class<T> type);
From source file:com.bibisco.test.VersionManagerTest.java
License:GNU General Public License
@Before @After/*w ww. ja va2 s . c o m*/ public void init() { SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("version"); lProperties.setValue("1.3.0"); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); } catch (Throwable t) { lSqlSession.rollback(); } finally { lSqlSession.close(); } PropertiesManager.getInstance().reload(); }
From source file:com.comstar.mars.env.EnvMapperFactoryBean.java
License:Apache License
@SuppressWarnings("resource") private void installEnv() { String[] sqlSessionFactoryNames = context.getBeanNamesForType(SqlSessionFactory.class); if (sqlSessionFactoryNames == null || sqlSessionFactoryNames.length == 0) { throw new RuntimeException("?SqlSessionFactory??"); }//from www . j av a2 s. c o m for (String env : sqlSessionFactoryNames) { SqlSessionFactory sqlSessionFactory = context.getBean(env, SqlSessionFactory.class); SqlSession sqlSession = new SqlSessionTemplate(sqlSessionFactory); T mapper = sqlSession.getMapper(mapperInterface); if (!envMappers.containsKey(env)) { envMappers.put(env, new ConcurrentHashMap<>()); } envMappers.get(env).put(mapperInterface.getName(), mapper); } }
From source file:com.ehensin.paypal.account.repository.AccountRepository.java
License:Apache License
public CustomerAccountEntity getCustomerAccount(String entityId) throws Exception { String dbRepName = entityDBRepNameMap.get(CustomerAccountEntity.class); SplitFactor factor = new SplitFactor(SplitAlg.Hash, entityId); SqlSessionFactory factory = dbRepository.getSessionFactory(dbRepName, factor, false); SqlSession session = factory.openSession(); try {/*ww w . j a v a 2s.com*/ AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); CustomerAccountORMapping orm = mapper.getCustomerAccount(entityId); if (orm == null) throw new Exception("cannot find entity for uuid :" + entityId); CustomerAccountEntity entity = new CustomerAccountEntity(orm.getUuid(), orm.getPhone(), orm.getLoginName(), orm.getMail(), orm.getPassword(), orm.getStatus(), orm.getBalance1(), orm.getBalance2(), orm.getBalance3(), orm.getBalance4(), orm.getBalance5(), orm.getLastUpdateTime()); return entity; } catch (Exception e) { logger.error(e.getMessage(), e); throw e; } finally { session.close(); } }
From source file:com.ehensin.paypal.account.repository.AccountRepository.java
License:Apache License
public void addCustomerAccount(CustomerAccountEntity entity) throws Exception { String dbRepName = entityDBRepNameMap.get(CustomerAccountEntity.class); SplitFactor factor = new SplitFactor(SplitAlg.Hash, entity.getUuid()); SqlSessionFactory factory = dbRepository.getSessionFactory(dbRepName, factor, true); SqlSession session = factory.openSession(); try {/* w w w . ja v a 2s . co m*/ AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); CustomerAccountORMapping orm = new CustomerAccountORMapping(entity.getUuid(), entity.getPhone(), entity.getLoginName(), entity.getMail(), entity.getPassword(), entity.getStatus(), entity.getBalance1(), entity.getBalance2(), entity.getBalance3(), entity.getBalance4(), entity.getBalance5(), entity.getLastUpdateTime()); mapper.insert(orm); session.commit(true); } catch (PersistenceException e) { logger.error(e.getMessage(), e); throw e; } finally { session.close(); } }
From source file:com.ehensin.paypal.account.test.CustomerAccountTest.java
License:Apache License
@Test public void testInsert() throws Exception { DBRepositoryBuilder builder = new DBRepositoryBuilder(); DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" }); SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1); SqlSessionFactory factory = repository.getSessionFactory("account", factor, true); SqlSession session = factory.openSession(); AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); int count = mapper.getCount(); System.out.println("hash customer count : " + count); CustomerAccountORMapping orm = new CustomerAccountORMapping(); orm.setBalance1(0);/*www . j a va 2s.co m*/ orm.setBalance2(0); orm.setLastUpdateTime(new Timestamp(System.currentTimeMillis())); orm.setLoginName("hhb"); orm.setMail("huanghaibo@newcosoft.com"); orm.setPhone("13917310925"); orm.setStatus(0); orm.setUuid("123"); orm.setPassword("123456"); mapper.insert(orm); count = mapper.getCount(); System.out.println("hash customer count : " + count); session.commit(true); session.close(); }
From source file:com.ehensin.paypal.account.test.CustomerAccountTest.java
License:Apache License
@Test public void testSelect() { DBRepositoryBuilder builder = new DBRepositoryBuilder(); DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" }); SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1); SqlSessionFactory factory = repository.getSessionFactory("account", factor, true); SqlSession session = factory.openSession(); AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); int count = mapper.getCount(); System.out.println("hash customer count : " + count); CustomerAccountORMapping orm = mapper.getCustomerAccount("123"); /*new CustomerAccountORMapping(); orm.setBalance1(0);//from w w w . j a va 2 s . c o m orm.setBalance2(0); orm.setLastUpdateTime(new Timestamp(System.currentTimeMillis())); orm.setLoginName("hhb"); orm.setMail("huanghaibo@newcosoft.com"); orm.setPhone("13917310925"); orm.setStatus(0); orm.setUuid("123"); orm.setPassword("123456"); mapper.insert(orm); count = mapper.getCount();*/ System.out.println("login name : " + orm.getLoginName()); session.close(); }
From source file:com.ehensin.paypal.account.test.DBRepositoryTest.java
License:Apache License
@Test public void testHash() { DBRepositoryBuilder builder = new DBRepositoryBuilder(); DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" }); SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1); SqlSessionFactory factory = repository.getSessionFactory("account", factor, true); SqlSession session = factory.openSession(); AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); int count = mapper.getCount(); System.out.println("hash customer count : " + count); session.close();//from w ww . j ava2 s. c om factory = repository.getSessionFactory("account", factor, false); session = factory.openSession(); mapper = (AccountMapper) session.getMapper(AccountMapper.class); mapper.getCount(); session.close(); factory = repository.getSessionFactory("account", factor, false); session = factory.openSession(); mapper = (AccountMapper) session.getMapper(AccountMapper.class); mapper.getCount(); session.close(); }
From source file:com.ehensin.paypal.account.test.DBRepositoryTest.java
License:Apache License
@Test public void testName() { DBRepositoryBuilder builder = new DBRepositoryBuilder(); DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" }); SplitFactor factor = new SplitFactor(SplitAlg.Named, "portion1"); SqlSessionFactory factory = repository.getSessionFactory("account", factor, true); SqlSession session = factory.openSession(); AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); mapper.getCount();// www . j a va 2s. co m session.close(); factory = repository.getSessionFactory("account", factor, false); session = factory.openSession(); mapper = (AccountMapper) session.getMapper(AccountMapper.class); mapper.getCount(); session.close(); factory = repository.getSessionFactory("account", factor, false); session = factory.openSession(); mapper = (AccountMapper) session.getMapper(AccountMapper.class); mapper.getCount(); session.close(); }
From source file:com.eincs.athens.olympus.service.CheckService.java
License:Apache License
@Override public void doServe(PanteonRequest request, PanteonResponse response) throws Exception { final String accessTokenString = request.getHeaders().get(HeaderNames.ACCESS_TOKEN); final DBManager dbm = DBManager.getInstance(); final SqlSession session = dbm.openSession(); final JSONTokenFactory tokenFactory = new JSONTokenFactory(); try {/* w ww.j a va2 s . co m*/ final OlympusMapper mapper = session.getMapper(OlympusMapper.class); final JSONToken accessToken = tokenFactory.fromBytes(accessTokenString.getBytes()); if (!Tokens.verifyToken(accessToken)) { String responseString = DataUtils.toResponseString(false); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } String email = accessToken.getContent().getString(TokenNames.EMAIL); String sessionUuid = accessToken.getContent().getString(TokenNames.SESSION_UUID); User user = mapper.getUserByEmail(User.createByEmail(email)); if (user == null) { String responseString = DataUtils.toResponseString(false); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } Session userSession = mapper.getSessionByUUID(Session.create(sessionUuid)); if (userSession == null) { String responseString = DataUtils.toResponseString(false); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } session.commit(); String responseString = DataUtils.toResponseString(true); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); } finally { session.close(); } }
From source file:com.eincs.athens.olympus.service.ConfirmService.java
License:Apache License
@Override public void doServe(PanteonRequest request, PanteonResponse response) throws Exception { final String tokenString = request.getParams().getParam("token", String.class); final DBManager dbm = DBManager.getInstance(); final SqlSession session = dbm.openSession(); final JSONTokenFactory tokenFactory = new JSONTokenFactory(); try {/*from w ww . ja va 2 s. c o m*/ if (tokenString == null) { String responseString = DataUtils.toResponseStringError("invalid access"); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } JSONToken registrationToken = tokenFactory.fromBytes(tokenString.getBytes()); if (!Tokens.verifyToken(registrationToken)) { String responseString = DataUtils.toResponseStringError("invalid token"); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } String email = registrationToken.getContent().getString(TokenNames.EMAIL); String nickname = registrationToken.getContent().getString(TokenNames.NICKNAME); String sessionUuid = registrationToken.getContent().getString(TokenNames.SESSION_UUID); String sessionTag = registrationToken.getContent().getString(TokenNames.SESSION_TAG); final OlympusMapper mapper = session.getMapper(OlympusMapper.class); User user = mapper.getUserByEmail(User.createByEmail(email)); if (user == null) { mapper.insertUser(User.create(email, nickname)); user = mapper.getUserByEmail(User.createByEmail(email)); } mapper.insertSession(Session.create(user.getId(), sessionUuid, sessionTag)); session.commit(); String responseString = DataUtils.toResponseString(true); response.setContentType(PanteonContentType.TEXT_PLAIN); response.setContents(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8)); return; } finally { session.close(); } }