Skip to content

Instantly share code, notes, and snippets.

@wendal
Created April 6, 2012 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/2316487 to your computer and use it in GitHub Desktop.
Save wendal/2316487 to your computer and use it in GitHub Desktop.
基于ThreadLocal的简单NutDao单例封装
package org.nutz.dao.impl;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.nutz.dao.Dao;
import org.nutz.lang.Lang;
public final class DaoX {
public static Dao dao;
public static final ThreadLocal<Connection> conns = new ThreadLocal<Connection>();
static {
dao = new NutDao(new SDataSource());
}
static class SDataSource implements DataSource {
public Connection getConnection() throws SQLException {
return conns.get();
}
public PrintWriter getLogWriter() throws SQLException {
throw Lang.noImplement();
}
public void setLogWriter(PrintWriter out) throws SQLException {
throw Lang.noImplement();
}
public void setLoginTimeout(int seconds) throws SQLException {
throw Lang.noImplement();
}
public int getLoginTimeout() throws SQLException {
throw Lang.noImplement();
}
public <T> T unwrap(Class<T> iface) throws SQLException {
throw Lang.noImplement();
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw Lang.noImplement();
}
public Connection getConnection(String username, String password)
throws SQLException {
throw Lang.noImplement();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment