spring mybatis memcached

时间:2021-06-14 04:36:38

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:property-placeholder location="classpath*:jdbc.properties" /> <!-- proxool连接池 -->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver">
<value>${jdbc.driverClassName}</value>
</property>
<property name="driverUrl">
<value>${jdbc.url}</value>
</property>
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="alias" value="Pool_dbname" />
<property name="maximumActiveTime" value="600000" />
<property name="prototypeCount" value="0" />
<property name="maximumConnectionCount" value="50" />
<property name="minimumConnectionCount" value="2" />
<property name="simultaneousBuildThrottle" value="50" />
<property name="houseKeepingTestSql" value="select CURRENT_DATE" />
</bean> <!-- mybatis 配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:${jdbc.configLocation}" />
</bean> <bean id="sqlMapClient"
class="com.dc.appengine.oauth.dao.SqlMapClientTemplate">
<property name="sqlSession" ref="sqlSession" />
</bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean> <!-- 事务管理器 -->
<bean id="transactionmanager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 方法事务参数 -->
<tx:advice id="serviceAdvice" transaction-manager="transactionmanager">
<tx:attributes>
<tx:method name="updateAppScalableStatus" propagation="REQUIRES_NEW"
isolation="READ_UNCOMMITTED" rollback-for="Exception" />
<tx:method name="updateDefaultProtocol" propagation="REQUIRES_NEW"
isolation="READ_UNCOMMITTED" rollback-for="Exception" />
<tx:method name="saveProtocol" propagation="REQUIRES_NEW"
isolation="READ_UNCOMMITTED" rollback-for="Exception" />
<tx:method name="saveNewNode" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="run*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="save*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="saveUpgrade" propagation="SUPPORTS"
isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="start*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="stop*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="destroy*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="deploy*" propagation="REQUIRED" isolation="READ_COMMITTED"
rollback-for="Exception" />
<tx:method name="reapply" propagation="REQUIRED" isolation="READ_COMMITTED"
rollback-for="Exception" />
<tx:method name="redeploy*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="isolate*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="return*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="unisolate*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="*"/>
</tx:attributes>
</tx:advice> <!-- 配置切面 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="servicePointcut"
expression="execution(* com.dc.appengine.oauth.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="servicePointcut" advice-ref="serviceAdvice" />
</aop:config> <context:component-scan
base-package="com.dc.appengine.oauth.dao.impl, com.dc.appengine.oauth.service.impl" /> </beans>

jdbc.properties

#oracle
#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:PAAS
#jdbc.username=PAAS
#jdbc.password=PAAS
#jdbc.configLocation=sql-map-oracle-config.xml

#mysql
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/kfpt?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=root
jdbc.configLocation=sql-map-mysql-config.xml

sql-map-mysql-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "ibatis-3-config.dtd"> <configuration> <settings>
<setting name="lazyLoadingEnabled" value="false" />
<setting name="cacheEnabled" value="true"/>
</settings> <mappers>
<mapper resource="db/mapping/mysql/User.xml"/>
<mapper resource="db/mapping/mysql/AppInfo.xml"/>
<mapper resource="db/mapping/mysql/Service.xml"/>
<mapper resource="db/mapping/mysql/Resource.xml"/>
<mapper resource="db/mapping/mysql/Role.xml"/>
<mapper resource="db/mapping/mysql/Grant.xml"/>
</mappers> </configuration>

config.properties

#jetty
port=5022
contextPath=/oauth2
resourceBase=../web
descriptor=../web/WEB-INF/web.xml
threadPoolSize=10 #接口实现类
IUserImplClass=com.dc.appengine.oauth.interfaces.impl.UserImpl
IOAuthImplClass=com.dc.appengine.oauth.interfaces.impl.OAuthImpl #超时时间
code=600
token=3600 #https
keystore=oauth-server.keystore
KeyPassword=111111 #memcached 配置
cache.open = true
cache.servers = 10.126.253.49:11211
cache.pool.size = 10

log4j.properties

log4j.rootLogger=info,console,debug,info,warn,error,fatal

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.File=./log/oauth/oauth_debug
log4j.appender.debug.DatePattern='.'yyyyMMdd'.log'
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n
log4j.appender.debug.filter.F1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.debug.filter.F1.LevelMin=debug
log4j.appender.debug.filter.F1.LevelMax=debug log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.File=./log/oauth/oauth_info
log4j.appender.info.DatePattern='.'yyyyMMdd'.log'
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n
log4j.appender.info.filter.F1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.info.filter.F1.LevelMin=info
log4j.appender.info.filter.F1.LevelMax=info log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
log4j.appender.warn.File=./log/oauth/oauth_warn
log4j.appender.warn.DatePattern='.'yyyyMMdd'.log'
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.warn.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n
log4j.appender.warn.filter.F1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.warn.filter.F1.LevelMin=warn
log4j.appender.warn.filter.F1.LevelMax=warn log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File=./log/oauth/oauth_error
log4j.appender.error.DatePattern='.'yyyyMMdd'.log'
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n
log4j.appender.error.filter.F1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.error.filter.F1.LevelMin=error
log4j.appender.error.filter.F1.LevelMax=error log4j.appender.fatal=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fatal.File=./log/oauth/oauth_fatal
log4j.appender.fatal.DatePattern='.'yyyyMMdd'.log'
log4j.appender.fatal.layout=org.apache.log4j.PatternLayout
log4j.appender.fatal.layout.ConversionPattern=%d [%-5p] (%F.%M:%L) - %m%n
log4j.appender.fatal.filter.F1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.fatal.filter.F1.LevelMin=fatal
log4j.appender.fatal.filter.F1.LevelMax=fatal #log4j.logger.com.dc.oauth.server=debug #----------------------------------------------------Ibaits----------------------------------------------------
#log4j.logger.com.ibatis=debug
#log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
#log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
#log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
#log4j.logger.java.sql.Connection=debug
#log4j.logger.java.sql.Statement=debug #log4j.logger.java.sql.PreparedStatement=debug,stdout
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n #log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.out
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601}[%-5p][%c][%t]:%m%n

appinfo.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "ibatis-3-mapper.dtd">
<mapper namespace="AppInfo">
<cache eviction="LRU" type="com.dc.appengine.oauth.cache.MemcacheCacheHelper4Mybatis" />
<select id="findByAppKey" parameterType="java.lang.String" resultType="java.util.HashMap">
select *
from appinfo
where appkey = #{appKey}
</select>
<select id="findBySecondDomain" parameterType="java.lang.String" resultType="java.util.HashMap">
select *
from appinfo
where second_domain = #{secondDomain}
</select>
<select id="findByAppId" parameterType="java.lang.String" resultType="java.util.HashMap">
select *
from appinfo
where appid = #{appId}
</select>
</mapper>

MemcacheCacheHelper4Mybatis.java

/**
*
*/
package com.dc.appengine.oauth.cache; import java.util.LinkedList;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.ibatis.cache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import com.dc.appengine.oauth.util.ConfigUtil; /**
* @author Administrator
*2014-10-20
*/
public class MemcacheCacheHelper4Mybatis implements Cache{ private static Logger LOG = LoggerFactory.getLogger( MemcacheCacheHelper4Mybatis.class ); private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private String id; private LinkedList<String> cacheKeys = new LinkedList<String>(); private MemcachedManager cache; private boolean openCache = Boolean.valueOf(ConfigUtil.getInstance().getProperty("cache.open")); public MemcacheCacheHelper4Mybatis( String id ){
this.id = id;
this.cache = MemcachedManager.getInstance();
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#clear()
*/
@Override
public void clear() {
if( openCache ){
if( cacheKeys != null && cacheKeys.size() > 0 ){
for( String key : cacheKeys ){
try {
cache.getClient().delete( key );
} catch ( Exception e ) {
e.printStackTrace();
LOG.error( "delete " + key + " error! ", e );
}
}
cacheKeys.clear();
LOG.debug("clear");
}
}
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#getId()
*/
@Override
public String getId() {
LOG.debug("getId:" + this.id);
return this.id;
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#getObject(java.lang.Object)
*/
@Override
public Object getObject( Object key ) {
if( this.openCache ){
String cacheKey = String.valueOf(key.hashCode());
try {
Object obj = cache.getClient().get( cacheKey );
if( obj != null && !cacheKeys.contains( cacheKey ) ){
cacheKeys.add( cacheKey );
} else if( obj == null && cacheKeys.contains( cacheKey ) ){
cacheKeys.remove( cacheKey );
}
LOG.debug("getObject:" + obj);
return obj;
} catch ( Exception e ) {
e.printStackTrace();
LOG.error( "get " + key.toString() + " error!", e );
}
}
return null;
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#getReadWriteLock()
*/
@Override
public ReadWriteLock getReadWriteLock() {
LOG.debug("getReadWriteLock");
return this.readWriteLock;
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#getSize()
*/
@Override
public int getSize() {
LOG.debug("getSize:" + cacheKeys.size());
return cacheKeys.size();
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#putObject(java.lang.Object, java.lang.Object)
*/
@Override
public void putObject(Object key, Object value) {
if( this.openCache ){
if( value != null && !"SERIALIZABLE_NULL_OBJECT".equals( value ) ){
String cacheKey = String.valueOf(key.hashCode());
cacheKeys.add( cacheKey );
try {
cache.getClient().set( cacheKey, 0, value );
LOG.debug("set " + key + "=" + value);
} catch ( Exception e ) {
e.printStackTrace();
LOG.error( "set " + cacheKey + " error!", e );
}
} }
} /* (non-Javadoc)
* @see org.apache.ibatis.cache.Cache#removeObject(java.lang.Object)
*/
@Override
public Object removeObject(Object key) {
if( this.openCache ){
String cacheKey = String.valueOf(key.hashCode());
try {
Object obj = cache.getClient().delete( cacheKey );
cacheKeys.remove( cacheKey );
LOG.debug("remove " + cacheKey);
return obj;
} catch ( Exception e ) {
e.printStackTrace();
LOG.error( "delete " + cacheKey + " error!", e);
}
}
return null;
} }

MemcachedManager.java

/**
*
*/
package com.dc.appengine.oauth.cache; import java.io.IOException; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import com.dc.appengine.oauth.util.ConfigUtil; import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.command.BinaryCommandFactory;
import net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator;
import net.rubyeye.xmemcached.utils.AddrUtil; /**
* @author Administrator
*2014-10-8
*/
public class MemcachedManager { private final Logger logger = LoggerFactory.getLogger( MemcachedManager.class ); private String servers; private int poolSize; private boolean openCache = false; private MemcachedClient client; private static MemcachedManager instance; public static MemcachedManager getInstance(){
if( instance == null ){
synchronized( MemcachedManager.class ){
if( instance == null ){
instance = new MemcachedManager();
}
}
}
return instance;
} private MemcachedManager(){
try {
init();
} catch (IOException e) {
logger.error( "cache manager init failed!", e );
}
} public MemcachedClient getClient(){
return client;
} private void init() throws IOException{
// openCache = Boolean.parseBoolean( ConfigHelper.getValue("cache.open") );
openCache = Boolean.parseBoolean(ConfigUtil.getInstance().getProperty("cache.open"));
if( openCache ){
// servers = ConfigHelper.getValue("cache.servers");
servers = ConfigUtil.getInstance().getProperty("cache.servers");
// poolSize = Integer.parseInt( ConfigHelper.getValue("cache.pool.size") );
poolSize = Integer.parseInt(ConfigUtil.getInstance().getProperty("cache.pool.size"));
MemcachedClientBuilder builder = new XMemcachedClientBuilder( AddrUtil.getAddresses( servers ) );
builder.setCommandFactory( new BinaryCommandFactory() );
builder.setConnectionPoolSize( poolSize );
builder.setSessionLocator( new KetamaMemcachedSessionLocator() );
client = builder.build();
}
} public void closePool() throws IOException {
client.shutdown();
client = null;
logger.info("Ibatis memcached pool closed");
} }

SqlMapClientDaoSupport.java

/**
*
*/
package com.dc.appengine.oauth.dao; import com.ibatis.sqlmap.client.SqlMapClient; /**
* @author Administrator
*2014-10-17
*/
public class SqlMapClientDaoSupport { private SqlMapClient sqlMapClient; public SqlMapClientTemplate getSqlMapClientTemplate() {
return (SqlMapClientTemplate) sqlMapClient;
} public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
} }

SqlMapClientTemplate.java

/**
*
*/
package com.dc.appengine.oauth.dao; import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map; import javax.sql.DataSource; import org.apache.ibatis.executor.BatchResult;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport; import com.ibatis.common.util.PaginatedList;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapSession;
import com.ibatis.sqlmap.client.event.RowHandler; /**
* @author Administrator
*2014-10-17
*/ @SuppressWarnings("deprecation")
public class SqlMapClientTemplate extends SqlSessionDaoSupport implements SqlMapClient{ private SqlSessionTemplate sqlSession; public void setSqlSession(SqlSessionTemplate sqlSession) {
this.sqlSession = sqlSession;
super.setSqlSessionTemplate( sqlSession );
} public SqlSessionTemplate getSqlSession() {
return sqlSession;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapClient#flushDataCache()
*/
@Override
public void flushDataCache() {
super.getSqlSession().clearCache();
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapClient#flushDataCache(java.lang.String)
*/
@Override
public void flushDataCache(String arg0) { } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapClient#getSession()
*/
@Override
public SqlMapSession getSession() {
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapClient#openSession()
*/
@Override
public SqlMapSession openSession() {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapClient#openSession(java.sql.Connection)
*/
@Override
public SqlMapSession openSession(Connection arg0) {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#delete(java.lang.String)
*/
@Override
public int delete(String arg0) {
return super.getSqlSession().delete(arg0);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#delete(java.lang.String, java.lang.Object)
*/
@Override
public int delete(String arg0, Object arg1) {
// TODO Auto-generated method stub
return super.getSqlSession().delete(arg0, arg1);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#executeBatch()
*/
@Override
public int executeBatch() throws SQLException {
// TODO Auto-generated method stub
List<BatchResult> list = super.getSqlSession().flushStatements();
int i = 0;
for( BatchResult br : list ){
int[] counts = br.getUpdateCounts();
for( int count : counts ){
i += count;
}
}
return i;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#executeBatchDetailed()
*/
@Override
public List executeBatchDetailed() {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#insert(java.lang.String)
*/
@Override
public Object insert(String statement) {
return super.getSqlSession().insert( statement );
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#insert(java.lang.String, java.lang.Object)
*/
@Override
public Object insert(String statement, Object object) {
return super.getSqlSession().insert( statement, object );
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForList(java.lang.String)
*/
@Override
public List queryForList(String arg0) {
// TODO Auto-generated method stub
return super.getSqlSession().selectList(arg0);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForList(java.lang.String, java.lang.Object)
*/
@Override
public List queryForList(String statement, Object object){
return super.getSqlSession().selectList( statement, object );
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForList(java.lang.String, int, int)
*/
@Override
public List queryForList(String arg0, int arg1, int arg2)
throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForList(java.lang.String, java.lang.Object, int, int)
*/
@Override
public List queryForList(String arg0, Object arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
RowBounds rb = new RowBounds( arg2, arg3);
return super.getSqlSession().selectList(arg0, arg1, rb);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForMap(java.lang.String, java.lang.Object, java.lang.String)
*/
@Override
public Map queryForMap(String arg0, Object arg1, String arg2)
throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForMap(java.lang.String, java.lang.Object, java.lang.String, java.lang.String)
*/
@Override
public Map queryForMap(String arg0, Object arg1, String arg2, String arg3)
throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForObject(java.lang.String)
*/
@Override
public Object queryForObject(String arg0) {
// TODO Auto-generated method stub
return super.getSqlSession().selectOne(arg0);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForObject(java.lang.String, java.lang.Object)
*/
@Override
public Object queryForObject(String arg0, Object arg1) {
// TODO Auto-generated method stub
return super.getSqlSession().selectOne(arg0, arg1);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForObject(java.lang.String, java.lang.Object, java.lang.Object)
*/
@Override
public Object queryForObject(String arg0, Object arg1, Object arg2)
throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForPaginatedList(java.lang.String, int)
*/
@SuppressWarnings("deprecation")
@Override
public PaginatedList queryForPaginatedList(String arg0, int arg1)
throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForPaginatedList(java.lang.String, java.lang.Object, int)
*/
@SuppressWarnings("deprecation")
@Override
public PaginatedList queryForPaginatedList(String arg0, Object arg1,
int arg2) throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#startBatch()
*/
@Override
public void startBatch() throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#update(java.lang.String)
*/
@Override
public int update(String arg0) throws SQLException {
// TODO Auto-generated method stub
return super.getSqlSession().update(arg0);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#update(java.lang.String, java.lang.Object)
*/
@Override
public int update(String arg0, Object arg1) {
// TODO Auto-generated method stub
return super.getSqlSession().update(arg0, arg1);
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#commitTransaction()
*/
@Override
public void commitTransaction() throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#endTransaction()
*/
@Override
public void endTransaction() throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#getCurrentConnection()
*/
@Override
public Connection getCurrentConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#getDataSource()
*/
@Override
public DataSource getDataSource() {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#getUserConnection()
*/
@Override
public Connection getUserConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
} /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#setUserConnection(java.sql.Connection)
*/
@Override
public void setUserConnection(Connection arg0) throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#startTransaction()
*/
@Override
public void startTransaction() throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapTransactionManager#startTransaction(int)
*/
@Override
public void startTransaction(int arg0) throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryWithRowHandler(java.lang.String, com.ibatis.sqlmap.client.event.RowHandler)
*/
@Override
public void queryWithRowHandler(String arg0, RowHandler arg1)
throws SQLException {
// TODO Auto-generated method stub } /* (non-Javadoc)
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryWithRowHandler(java.lang.String, java.lang.Object, com.ibatis.sqlmap.client.event.RowHandler)
*/
@Override
public void queryWithRowHandler(String arg0, Object arg1, RowHandler arg2)
throws SQLException {
// TODO Auto-generated method stub }
}

AppInfoDAO.java

package com.dc.appengine.oauth.dao.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import com.dc.appengine.oauth.dao.SqlMapClientDaoSupport;
import com.ibatis.sqlmap.client.SqlMapClient; @Component("AppInfoDAO")
public class AppInfoDAO extends SqlMapClientDaoSupport { @Autowired
public AppInfoDAO(@Qualifier("sqlMapClient") SqlMapClient sqlMapClient) {
super();
super.setSqlMapClient(sqlMapClient);
} @SuppressWarnings("unchecked")
public Map<String, Object> findByAppKey(String appKey) {
Object result = getSqlMapClientTemplate().queryForObject("AppInfo.findByAppKey", appKey);
if (result == null) {
return null;
} else {
return (Map<String, Object>) result;
}
} @SuppressWarnings("unchecked")
public Map<String, Object> findBySecondDomain(String secondDomain) {
Object result = getSqlMapClientTemplate().queryForObject("AppInfo.findBySecondDomain", secondDomain);
if (result == null) {
return null;
} else {
return (Map<String, Object>) result;
}
} @SuppressWarnings("unchecked")
public Map<String, Object> findByAppId(String appId) {
Object result = getSqlMapClientTemplate().queryForObject("AppInfo.findByAppId", appId);
if (result == null) {
return null;
} else {
return (Map<String, Object>) result;
}
} }

AppInfoService.java

package com.dc.appengine.oauth.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import com.dc.appengine.oauth.dao.impl.AppInfoDAO; @Service("AppInfoService")
public class AppInfoService { @Autowired
@Qualifier("AppInfoDAO")
private AppInfoDAO appInfoDAO; public Map<String, Object> findBySecondDomain(String secondDomain) {
return appInfoDAO.findBySecondDomain(secondDomain);
} public Map<String, Object> findByAppKey(String appKey) {
return appInfoDAO.findByAppKey(appKey);
} public Map<String, Object> findByAppId(String appId) {
return appInfoDAO.findByAppId(appId);
} public boolean hasApp(String appKey) {
Map<String, Object> appInfo = findByAppKey(appKey);
if (appInfo == null) {
return false;
} else {
return true;
}
} public boolean checkApp(String appKey, String appSecret) {
Map<String, Object> appInfo = findByAppKey(appKey);
if (appInfo == null) {
return false;
} else {
String secret = (String) appInfo.get("appSecretKey");
if (appSecret != null && appSecret.equals(secret)) {
return true;
} else {
return false;
}
}
} }