parent
dc677002db
commit
475dbd3e5f
@ -1,11 +1,40 @@
|
||||
package ${basePackage}.frame.schedule;
|
||||
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import ${basePackage}.frame.auth.LocalData;
|
||||
import ${basePackage}.frame.utils.LogUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class RunSqlTask extends RunFixRepeatTask {
|
||||
|
||||
public abstract String getSql();
|
||||
private Connection connection;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//exec sql
|
||||
try {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
SqlSessionFactory factory = LocalData.getBean(SqlSessionFactory.class);
|
||||
SqlSession sqlSession = factory.openSession(true);
|
||||
connection = sqlSession.getConnection();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.e("schedule: get connection failed!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(getSql());
|
||||
preparedStatement.execute();
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.e("RunSqlTask exec failed! SQL:[" + getSql() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getSql();
|
||||
}
|
||||
|
Loading…
Reference in new issue