001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.services; 020 021import java.io.PrintWriter; 022import java.sql.Connection; 023import java.sql.SQLException; 024import java.sql.SQLFeatureNotSupportedException; 025import java.util.logging.Logger; 026 027import lucee.runtime.PageContext; 028import lucee.runtime.engine.ThreadLocalPageContext; 029import lucee.runtime.exp.PageException; 030import coldfusion.sql.DataSource; 031import coldfusion.sql.DataSourceDef; 032 033public class DataSourceImpl implements DataSource { 034 035 private lucee.runtime.db.DataSource ds; 036 037 public DataSourceImpl(lucee.runtime.db.DataSource ds) { 038 this.ds=ds; 039 } 040 041 public Connection getConnection() throws SQLException { 042 return getConnection(ds.getUsername(), ds.getPassword()); 043 } 044 045 public Connection getConnection(String user, String pass) 046 throws SQLException { 047 try { 048 PageContext pc = ThreadLocalPageContext.get(); 049 return pc.getDataSourceManager().getConnection(pc,ds.getName(),user, pass).getConnection(); 050 } catch (PageException e) { 051 throw new SQLException(e.getMessage()); 052 } 053 } 054 055 public DataSourceDef getDataSourceDef() { 056 return new DatSourceDefImpl(ds); 057 } 058 059 public PrintWriter getLogWriter() throws SQLException { 060 // TODO Auto-generated method stub 061 return null; 062 } 063 064 public int getLoginTimeout() throws SQLException { 065 // TODO Auto-generated method stub 066 return 0; 067 } 068 069 public boolean isDisabled() { 070 // TODO Auto-generated method stub 071 return false; 072 } 073 074 public void remove() throws SQLException { 075 // TODO Auto-generated method stub 076 077 } 078 079 public void setDataSourceDef(DataSourceDef dsDef) { 080 // TODO Auto-generated method stub 081 082 } 083 084 public void setLogWriter(PrintWriter pw) throws SQLException { 085 // TODO Auto-generated method stub 086 087 } 088 089 public void setLoginTimeout(int timeout) throws SQLException { 090 // TODO Auto-generated method stub 091 092 } 093 094 public <T> T unwrap(Class<T> iface) throws SQLException { 095 // TODO Auto-generated method stub 096 return null; 097 } 098 099 public boolean isWrapperFor(Class<?> iface) throws SQLException { 100 // TODO Auto-generated method stub 101 return false; 102 } 103 104 public Logger getParentLogger() throws SQLFeatureNotSupportedException { 105 throw new SQLFeatureNotSupportedException(); 106 } 107 108}