001    package railo.runtime.services;
002    
003    import java.io.PrintWriter;
004    import java.sql.Connection;
005    import java.sql.SQLException;
006    import java.sql.SQLFeatureNotSupportedException;
007    import java.util.logging.Logger;
008    
009    import railo.runtime.PageContext;
010    import railo.runtime.engine.ThreadLocalPageContext;
011    import railo.runtime.exp.PageException;
012    import coldfusion.sql.DataSource;
013    import coldfusion.sql.DataSourceDef;
014    
015    public class DataSourceImpl implements DataSource {
016    
017            private railo.runtime.db.DataSource ds;
018    
019            public DataSourceImpl(railo.runtime.db.DataSource ds) {
020                    this.ds=ds;
021            }
022    
023            public Connection getConnection() throws SQLException {
024                    return getConnection(ds.getUsername(), ds.getPassword());
025            }
026    
027            public Connection getConnection(String user, String pass)
028                            throws SQLException {
029                    try {
030                            PageContext pc = ThreadLocalPageContext.get();
031                            return pc.getDataSourceManager().getConnection(pc,ds.getName(),user, pass).getConnection();
032                    } catch (PageException e) {
033                            throw new SQLException(e.getMessage());
034                    }
035            }
036    
037            public DataSourceDef getDataSourceDef() {
038                    return new DatSourceDefImpl(ds);
039            }
040    
041            public PrintWriter getLogWriter() throws SQLException {
042                    // TODO Auto-generated method stub
043                    return null;
044            }
045    
046            public int getLoginTimeout() throws SQLException {
047                    // TODO Auto-generated method stub
048                    return 0;
049            }
050    
051            public boolean isDisabled() {
052                    // TODO Auto-generated method stub
053                    return false;
054            }
055    
056            public void remove() throws SQLException {
057                    // TODO Auto-generated method stub
058    
059            }
060    
061            public void setDataSourceDef(DataSourceDef dsDef) {
062                    // TODO Auto-generated method stub
063    
064            }
065    
066            public void setLogWriter(PrintWriter pw) throws SQLException {
067                    // TODO Auto-generated method stub
068    
069            }
070    
071            public void setLoginTimeout(int timeout) throws SQLException {
072                    // TODO Auto-generated method stub
073    
074            }
075    
076            public <T> T unwrap(Class<T> iface) throws SQLException {
077                    // TODO Auto-generated method stub
078                    return null;
079            }
080    
081            public boolean isWrapperFor(Class<?> iface) throws SQLException {
082                    // TODO Auto-generated method stub
083                    return false;
084            }
085    
086            public Logger getParentLogger() throws SQLFeatureNotSupportedException {
087                    throw new SQLFeatureNotSupportedException();
088            }
089    
090    }