Created
April 6, 2012 03:08
-
-
Save wendal/2316487 to your computer and use it in GitHub Desktop.
基于ThreadLocal的简单NutDao单例封装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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