com.github.yydf.struts.jdbc.SqlSessionFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of struts Show documentation
Show all versions of struts Show documentation
A simple, light Java WEB + ORM framework.
package com.github.yydf.struts.jdbc;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.sql.DataSource;
import com.github.yydf.struts.logger.SqlLog;
import com.github.yydf.struts.util.Assert;
public class SqlSessionFactory {
private static SqlSession sessionImpl;
public static SqlSession getSession() {
Assert.notNull(sessionImpl);
return sessionImpl;
}
public static void createSession(DataSource ds) {
if (sessionImpl == null) {
sessionImpl = new SqlSession(ds);
}
}
public static void createSession(DataSource ds, SqlLog logger) {
if (sessionImpl == null) {
sessionImpl = new SqlSession(ds, logger);
}
}
public static void close() {
sessionImpl.clear();
Enumeration drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
try {
DriverManager.deregisterDriver(drivers.nextElement());
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}