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.db;
020
021import java.util.TimeZone;
022
023import lucee.commons.lang.ClassException;
024import lucee.runtime.config.ConfigWebFactory;
025import lucee.runtime.exp.ApplicationException;
026import lucee.runtime.exp.PageRuntimeException;
027import lucee.runtime.type.Struct;
028
029public class ApplicationDataSource extends DataSourceSupport {
030
031        private String connStr;
032
033        private ApplicationDataSource(String name, String className, String connStr, String username, String password,
034                        boolean blob, boolean clob, int connectionLimit, int connectionTimeout, long metaCacheTimeout, TimeZone timezone, int allow, boolean storage, boolean readOnly) throws ClassException {
035                this(name, toClass(className), connStr, username, password,
036                                blob, clob, connectionLimit, connectionTimeout, metaCacheTimeout, timezone, allow, storage, readOnly);
037        }
038
039        private ApplicationDataSource(String name, Class clazz, String connStr, String username, String password,
040                        boolean blob, boolean clob, int connectionLimit, int connectionTimeout, long metaCacheTimeout, TimeZone timezone, int allow, boolean storage, boolean readOnly) {
041                super(name, clazz,username,ConfigWebFactory.decrypt(password),
042                                blob,clob,connectionLimit, connectionTimeout, metaCacheTimeout, timezone, allow<0?ALLOW_ALL:allow, storage, readOnly);
043                
044                this.connStr = connStr;
045        }
046        
047
048        public static DataSource getInstance(String name, String className, String connStr, String username, String password,
049                        boolean blob, boolean clob, int connectionLimit, int connectionTimeout, long metaCacheTimeout, TimeZone timezone, int allow, boolean storage, boolean readOnly) throws ClassException {
050                
051                return new ApplicationDataSource(name, className, connStr, username, password, blob, clob, connectionLimit, connectionTimeout, metaCacheTimeout, timezone, allow, storage, readOnly);
052        }
053
054        @Override
055        public String getDsnOriginal() {
056                throw exp();
057        }
058
059        @Override
060        public String getConnectionString() {
061                throw exp();
062        }
063
064        @Override
065        public String getDsnTranslated() {
066                return getConnectionStringTranslated();
067        }
068
069        @Override
070        public String getConnectionStringTranslated() {
071                return connStr;
072        }
073
074        @Override
075        public String getDatabase() {
076                throw new PageRuntimeException(new ApplicationException("Datasource defined in the Application.cfc has no name."));
077        }
078
079        @Override
080        public int getPort() {
081                throw exp();
082        }
083
084        @Override
085        public String getHost() {
086                throw exp();
087        }
088
089        @Override
090        public DataSource cloneReadOnly() {
091                return new ApplicationDataSource(getName(), getClazz(), connStr, getUsername(), getPassword(),
092                                isBlob(), isClob(), getConnectionLimit(), getConnectionTimeout(), getMetaCacheTimeout(), getTimeZone(), allow, isStorage(), isReadOnly());
093        }
094
095        @Override
096        public String getCustomValue(String key) {
097                throw exp();
098        }
099
100        @Override
101        public String[] getCustomNames() {
102                throw exp();
103        }
104
105        @Override
106        public Struct getCustoms() {
107                throw exp();
108        }
109
110        @Override
111        public boolean validate() {
112                throw exp();
113        }
114
115
116        private PageRuntimeException exp() {
117                //return new MethodNotSupportedException();
118                throw new PageRuntimeException(new ApplicationException("method not supported"));
119        }
120}