Search in sources :

Example 16 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class XMLConfigWebFactory method loadCache.

/*private static ClassDefinition matchJDBCBundle(Config config, ClassDefinition cd) {
		if(!cd.isBundle()) {
			if("org.hsqldb.jdbcDriver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "hypersonic.hsqldb", null, config.getIdentification());
			if("org.gjt.mm.mysql.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "com.mysql.jdbc", null, config.getIdentification());
			if("org.h2.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "org.h2", null, config.getIdentification());
			if("net.sourceforge.jtds.jdbc.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "jtds", null, config.getIdentification());
			if("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "microsoft.sqljdbc", null, config.getIdentification());
		
		}
		return cd;
	}*/
/**
 * @param configServer
 * @param config
 * @param doc
 */
/**
 * @param configServer
 * @param config
 * @param doc
 */
private static void loadCache(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    boolean hasCS = configServer != null;
    // load Cache info
    {
        Element parent = getChildByName(doc.getDocumentElement(), "caches");
        Element[] children = getChildren(parent, "cache");
        Map<String, ClassDefinition> map = new HashMap<String, ClassDefinition>();
        // first add the server drivers, so they can be overwritten
        if (configServer != null) {
            Iterator<ClassDefinition> it = configServer.getCacheDefinitions().values().iterator();
            ClassDefinition cd;
            while (it.hasNext()) {
                cd = it.next();
                map.put(cd.getClassName(), cd);
            }
        }
        ClassDefinition cd;
        String label;
        for (Element child : children) {
            cd = getClassDefinition(child, "", config.getIdentification());
            // check if it is a bundle
            if (!cd.isBundle()) {
                log.error("Datasource", "[" + cd + "] does not have bundle info");
                continue;
            }
            map.put(cd.getClassName(), cd);
        }
        config.setCacheDefinitions(map);
    }
    Map<String, CacheConnection> caches = new HashMap<String, CacheConnection>();
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_CACHE);
    // print.o("LOAD CACHE:"+hasAccess+":"+hasCS);
    Element eCache = getChildByName(doc.getDocumentElement(), "cache");
    // has changes
    String md5 = getMD5(eCache, hasCS ? configServer.getCacheMD5() : "");
    if (md5.equals(config.getCacheMD5()))
        return;
    config.setCacheMD5(md5);
    String[] typeNames = new String[] { "resource", "function", "include", "query", "template", "object", "file", "http", "webservice" };
    int[] types = new int[] { ConfigImpl.CACHE_TYPE_RESOURCE, ConfigImpl.CACHE_TYPE_FUNCTION, ConfigImpl.CACHE_TYPE_INCLUDE, ConfigImpl.CACHE_TYPE_QUERY, ConfigImpl.CACHE_TYPE_TEMPLATE, ConfigImpl.CACHE_TYPE_OBJECT, ConfigImpl.CACHE_TYPE_FILE, ConfigImpl.CACHE_TYPE_HTTP, ConfigImpl.CACHE_TYPE_WEBSERVICE };
    // default cache
    for (int i = 0; i < types.length; i++) {
        String def = getAttr(eCache, "default-" + typeNames[i]);
        if (hasAccess && !StringUtil.isEmpty(def)) {
            config.setCacheDefaultConnectionName(types[i], def);
        } else if (hasCS) {
            if (eCache.hasAttribute("default-" + typeNames[i]))
                config.setCacheDefaultConnectionName(types[i], "");
            else
                config.setCacheDefaultConnectionName(types[i], configServer.getCacheDefaultConnectionName(types[i]));
        } else
            config.setCacheDefaultConnectionName(+types[i], "");
    }
    // cache connections
    Element[] eConnections = getChildren(eCache, "connection");
    // if(hasAccess) {
    ClassDefinition cd;
    String name;
    CacheConnection cc;
    // caches
    if (hasAccess)
        for (int i = 0; i < eConnections.length; i++) {
            Element eConnection = eConnections[i];
            name = getAttr(eConnection, "name");
            cd = getClassDefinition(eConnection, "", config.getIdentification());
            if (!cd.isBundle()) {
                ClassDefinition _cd = config.getCacheDefinition(cd.getClassName());
                if (_cd != null)
                    cd = _cd;
            }
            try {
                Struct custom = toStruct(getAttr(eConnection, "custom"));
                // Workaround for old EHCache class defintions
                if (cd.getClassName() != null && cd.getClassName().endsWith(".EHCacheLite")) {
                    cd = new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache");
                    if (!custom.containsKey("distributed"))
                        custom.setEL("distributed", "off");
                    if (!custom.containsKey("asynchronousReplicationIntervalMillis"))
                        custom.setEL("asynchronousReplicationIntervalMillis", "1000");
                    if (!custom.containsKey("maximumChunkSizeBytes"))
                        custom.setEL("maximumChunkSizeBytes", "5000000");
                } else // 
                if (cd.getClassName() != null && (cd.getClassName().endsWith(".extension.io.cache.eh.EHCache") || cd.getClassName().endsWith("lucee.runtime.cache.eh.EHCache")))
                    cd = new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache");
                // else cacheClazz = cd.getClazz();
                cc = new CacheConnectionImpl(config, name, cd, custom, Caster.toBooleanValue(getAttr(eConnection, "read-only"), false), Caster.toBooleanValue(getAttr(eConnection, "storage"), false));
                if (!StringUtil.isEmpty(name)) {
                    caches.put(name.toLowerCase(), cc);
                } else
                    SystemOut.print(config.getErrWriter(), "missing cache name");
            } catch (ClassException ce) {
                log.error("Cache", ce);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(ce, true));
            } catch (BundleException be) {
                log.error("Cache", be);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(be, true));
            } catch (IOException e) {
                log.error("Cache", e);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(e, true));
            }
        }
    // }
    // call static init once per driver
    {
        // group by classes
        final Map<ClassDefinition, List<CacheConnection>> _caches = new HashMap<ClassDefinition, List<CacheConnection>>();
        {
            Iterator<Entry<String, CacheConnection>> it = caches.entrySet().iterator();
            Entry<String, CacheConnection> entry;
            List<CacheConnection> list;
            while (it.hasNext()) {
                entry = it.next();
                cc = entry.getValue();
                // Jira 3196 ?!
                if (cc == null)
                    continue;
                list = _caches.get(cc.getClassDefinition());
                if (list == null) {
                    list = new ArrayList<CacheConnection>();
                    _caches.put(cc.getClassDefinition(), list);
                }
                list.add(cc);
            }
        }
        // call
        Iterator<Entry<ClassDefinition, List<CacheConnection>>> it = _caches.entrySet().iterator();
        Entry<ClassDefinition, List<CacheConnection>> entry;
        List<CacheConnection> list;
        ClassDefinition _cd;
        while (it.hasNext()) {
            entry = it.next();
            list = entry.getValue();
            _cd = entry.getKey();
            try {
                Method m = _cd.getClazz().getMethod("init", new Class[] { Config.class, String[].class, Struct[].class });
                if (Modifier.isStatic(m.getModifiers()))
                    m.invoke(null, new Object[] { config, _toCacheNames(list), _toArguments(list) });
                else
                    SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] is not static");
            } catch (InvocationTargetException e) {
                log.error("Cache", e.getTargetException());
            } catch (RuntimeException e) {
                log.error("Cache", e);
            } catch (NoSuchMethodException e) {
                log.error("Cache", "missing method [public static init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] ");
            // SystemOut.print(config.getErrWriter(), "missing method [public static init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] ");
            } catch (Throwable e) {
                ExceptionUtil.rethrowIfNecessary(e);
                log.error("Cache", e);
            }
        }
    }
    // Copy Parent caches as readOnly
    if (hasCS) {
        Map<String, CacheConnection> ds = configServer.getCacheConnections();
        Iterator<Entry<String, CacheConnection>> it = ds.entrySet().iterator();
        Entry<String, CacheConnection> entry;
        while (it.hasNext()) {
            entry = it.next();
            cc = entry.getValue();
            if (!caches.containsKey(entry.getKey()))
                caches.put(entry.getKey(), new ServerCacheConnection(configServer, cc));
        }
    }
    config.setCaches(caches);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServletConfig(javax.servlet.ServletConfig) ThreadLocalConfig(lucee.runtime.engine.ThreadLocalConfig) Element(org.w3c.dom.Element) ClassException(lucee.commons.lang.ClassException) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Method(java.lang.reflect.Method) lucee.aprint(lucee.aprint) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) CacheConnectionImpl(lucee.runtime.cache.CacheConnectionImpl) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) ServerCacheConnection(lucee.runtime.cache.ServerCacheConnection) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServerCacheConnection(lucee.runtime.cache.ServerCacheConnection) CacheConnection(lucee.runtime.cache.CacheConnection)

Example 17 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class XMLConfigWebFactory method loadMonitors.

private static void loadMonitors(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws IOException {
    // only load in server context
    if (configServer != null)
        return;
    configServer = (ConfigServerImpl) config;
    Element parent = getChildByName(doc.getDocumentElement(), "monitoring");
    boolean enabled = Caster.toBooleanValue(getAttr(parent, "enabled"), false);
    configServer.setMonitoringEnabled(enabled);
    SystemOut.printDate(config.getOutWriter(), "monitoring is " + (enabled ? "enabled" : "disabled"));
    Element[] children = getChildren(parent, "monitor");
    java.util.List<IntervallMonitor> intervalls = new ArrayList<IntervallMonitor>();
    java.util.List<RequestMonitor> requests = new ArrayList<RequestMonitor>();
    java.util.List<MonitorTemp> actions = new ArrayList<MonitorTemp>();
    String strType, name;
    ClassDefinition cd;
    boolean log, async;
    short type;
    for (int i = 0; i < children.length; i++) {
        Element el = children[i];
        cd = getClassDefinition(el, "", config.getIdentification());
        strType = getAttr(el, "type");
        name = getAttr(el, "name");
        async = Caster.toBooleanValue(getAttr(el, "async"), false);
        log = Caster.toBooleanValue(getAttr(el, "log"), true);
        if ("request".equalsIgnoreCase(strType))
            type = IntervallMonitor.TYPE_REQUEST;
        else if ("action".equalsIgnoreCase(strType))
            type = Monitor.TYPE_ACTION;
        else
            type = IntervallMonitor.TYPE_INTERVAL;
        if (cd.hasClass() && !StringUtil.isEmpty(name)) {
            name = name.trim();
            try {
                Class clazz = cd.getClazz();
                Object obj;
                ConstructorInstance constr = Reflector.getConstructorInstance(clazz, new Object[] { configServer }, null);
                if (constr != null)
                    obj = constr.invoke();
                else
                    obj = clazz.newInstance();
                SystemOut.printDate(config.getOutWriter(), "loaded " + (strType) + " monitor [" + clazz.getName() + "]");
                if (type == IntervallMonitor.TYPE_INTERVAL) {
                    IntervallMonitor m = obj instanceof IntervallMonitor ? (IntervallMonitor) obj : new IntervallMonitorWrap(obj);
                    m.init(configServer, name, log);
                    intervalls.add(m);
                } else if (type == Monitor.TYPE_ACTION) {
                    ActionMonitor am = obj instanceof ActionMonitor ? (ActionMonitor) obj : new ActionMonitorWrap(obj);
                    actions.add(new MonitorTemp(am, name, log));
                } else {
                    RequestMonitorPro m = new RequestMonitorProImpl(obj instanceof RequestMonitor ? (RequestMonitor) obj : new RequestMonitorWrap(obj));
                    if (async)
                        m = new AsyncRequestMonitor(m);
                    m.init(configServer, name, log);
                    SystemOut.printDate(config.getOutWriter(), "initialize " + (strType) + " monitor [" + clazz.getName() + "]");
                    requests.add(m);
                }
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                SystemOut.printDate(config.getErrWriter(), ExceptionUtil.getStacktrace(t, true));
            }
        }
    }
    configServer.setRequestMonitors(requests.toArray(new RequestMonitor[requests.size()]));
    configServer.setIntervallMonitors(intervalls.toArray(new IntervallMonitor[intervalls.size()]));
    ActionMonitorCollector actionMonitorCollector = ActionMonitorFatory.getActionMonitorCollector(configServer, actions.toArray(new MonitorTemp[actions.size()]));
    configServer.setActionMonitorCollector(actionMonitorCollector);
    ((CFMLEngineImpl) configServer.getCFMLEngine()).touchMonitor(configServer);
}
Also used : RequestMonitorPro(lucee.runtime.monitor.RequestMonitorPro) IntervallMonitor(lucee.runtime.monitor.IntervallMonitor) RequestMonitorWrap(lucee.runtime.monitor.RequestMonitorWrap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ConstructorInstance(lucee.runtime.reflection.pairs.ConstructorInstance) ClassDefinition(lucee.runtime.db.ClassDefinition) RequestMonitorProImpl(lucee.runtime.monitor.RequestMonitorProImpl) ActionMonitor(lucee.runtime.monitor.ActionMonitor) ActionMonitorWrap(lucee.runtime.monitor.ActionMonitorWrap) lucee.aprint(lucee.aprint) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) AsyncRequestMonitor(lucee.runtime.monitor.AsyncRequestMonitor) ActionMonitorCollector(lucee.runtime.monitor.ActionMonitorCollector) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) IntervallMonitorWrap(lucee.runtime.monitor.IntervallMonitorWrap) RequestMonitor(lucee.runtime.monitor.RequestMonitor) AsyncRequestMonitor(lucee.runtime.monitor.AsyncRequestMonitor)

Example 18 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class XMLConfigWebFactory method loadORM.

private static void loadORM(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_ORM);
    Element orm = hasAccess ? getChildByName(doc.getDocumentElement(), "orm") : null;
    boolean hasCS = configServer != null;
    // engine
    ClassDefinition cdDefault = new ClassDefinitionImpl(DummyORMEngine.class);
    ClassDefinition cd = null;
    if (orm != null) {
        cd = getClassDefinition(orm, "engine-", config.getIdentification());
        if (cd == null || cd.isClassNameEqualTo(DummyORMEngine.class.getName()) || cd.isClassNameEqualTo("lucee.runtime.orm.hibernate.HibernateORMEngine"))
            cd = getClassDefinition(orm, "", config.getIdentification());
        if (cd != null && (cd.isClassNameEqualTo(DummyORMEngine.class.getName()) || cd.isClassNameEqualTo("lucee.runtime.orm.hibernate.HibernateORMEngine")))
            cd = null;
    }
    if (cd == null || !cd.hasClass()) {
        if (configServer != null)
            cd = configServer.getORMEngineClass();
        else
            cd = cdDefault;
    }
    // load class
    try {
        cd.getClazz();
    // TODO check interface as well
    } catch (Exception e) {
        log.error("ORM", e);
        cd = cdDefault;
    }
    config.setORMEngineClass(cd);
    // config
    if (orm == null)
        // this is just a dummy
        orm = doc.createElement("orm");
    ORMConfiguration def = hasCS ? configServer.getORMConfig() : null;
    ORMConfiguration ormConfig = ORMConfigurationImpl.load(config, null, orm, config.getRootDirectory(), def);
    config.setORMConfig(ormConfig);
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) DummyORMEngine(lucee.runtime.orm.DummyORMEngine) Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) ORMConfiguration(lucee.runtime.orm.ORMConfiguration)

Example 19 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class XMLConfigWebFactory method loadCacheHandler.

private static void loadCacheHandler(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) throws ClassException, BundleException {
    boolean hasCS = configServer != null;
    // first of all we make sure we have a request and timespan cachehandler
    if (!hasCS) {
        config.addCacheHandler("request", new ClassDefinitionImpl(RequestCacheHandler.class));
        config.addCacheHandler("timespan", new ClassDefinitionImpl(TimespanCacheHandler.class));
    }
    // add CacheHandlers from server context to web context
    if (hasCS) {
        Iterator<Entry<String, Class<CacheHandler>>> it = configServer.getCacheHandlers();
        Entry<String, Class<CacheHandler>> entry;
        while (it.hasNext()) {
            entry = it.next();
            config.addCacheHandler(entry.getKey(), entry.getValue());
        }
    }
    Element root = getChildByName(doc.getDocumentElement(), "cache-handlers");
    Element[] handlers = getChildren(root, "cache-handler");
    if (!ArrayUtil.isEmpty(handlers)) {
        ClassDefinition cd;
        String strId;
        for (int i = 0; i < handlers.length; i++) {
            cd = getClassDefinition(handlers[i], "", config.getIdentification());
            strId = getAttr(handlers[i], "id");
            if (cd.hasClass() && !StringUtil.isEmpty(strId)) {
                strId = strId.trim().toLowerCase();
                try {
                    config.addCacheHandler(strId, cd);
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    log.error("Cache-Handler", t);
                }
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) lucee.aprint(lucee.aprint) TimespanCacheHandler(lucee.runtime.cache.tag.timespan.TimespanCacheHandler) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) RequestCacheHandler(lucee.runtime.cache.tag.request.RequestCacheHandler) CacheHandler(lucee.runtime.cache.tag.CacheHandler) TimespanCacheHandler(lucee.runtime.cache.tag.timespan.TimespanCacheHandler) RequestCacheHandler(lucee.runtime.cache.tag.request.RequestCacheHandler)

Example 20 with ClassDefinition

use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.

the class XMLConfigWebFactory method loadDataSources.

/**
 * loads datasource settings from XMl DOM
 *
 * @param configServer
 * @param config
 * @param doc
 * @throws BundleException
 * @throws ClassNotFoundException
 */
private static void loadDataSources(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    // load JDBC Driver defintion
    {
        Element jdbc = getChildByName(doc.getDocumentElement(), "jdbc");
        Element[] drivers = getChildren(jdbc, "driver");
        Map<String, JDBCDriver> map = new HashMap<String, JDBCDriver>();
        // first add the server drivers, so they can be overwritten
        if (configServer != null) {
            JDBCDriver[] sds = configServer.getJDBCDrivers();
            for (JDBCDriver sd : sds) {
                map.put(sd.cd.toString(), sd);
            }
        }
        ClassDefinition cd;
        String label;
        for (Element driver : drivers) {
            cd = getClassDefinition(driver, "", config.getIdentification());
            label = getAttr(driver, "label");
            // check if label exists
            if (StringUtil.isEmpty(label)) {
                log.error("Datasource", "missing label for jdbc driver [" + cd.getClassName() + "]");
                continue;
            }
            // check if it is a bundle
            if (!cd.isBundle()) {
                log.error("Datasource", "jdbc driver [" + label + "] does not describe a bundle");
                continue;
            }
            map.put(cd.toString(), new JDBCDriver(label, cd));
        }
        config.setJDBCDrivers(map.values().toArray(new JDBCDriver[map.size()]));
    }
    // When set to true, makes JDBC use a representation for DATE data that
    // is compatible with the Oracle8i database.
    System.setProperty("oracle.jdbc.V8Compatible", "true");
    boolean hasCS = configServer != null;
    Map<String, DataSource> datasources = new HashMap<String, DataSource>();
    // Copy Parent datasources as readOnly
    if (hasCS) {
        Map<String, DataSource> ds = configServer.getDataSourcesAsMap();
        Iterator<Entry<String, DataSource>> it = ds.entrySet().iterator();
        Entry<String, DataSource> entry;
        while (it.hasNext()) {
            entry = it.next();
            if (!entry.getKey().equals(QOQ_DATASOURCE_NAME))
                datasources.put(entry.getKey(), entry.getValue().cloneReadOnly());
        }
    }
    // Default query of query DB
    try {
        setDatasource(config, datasources, QOQ_DATASOURCE_NAME, new ClassDefinitionImpl("org.hsqldb.jdbcDriver", "hsqldb", "1.8.0", config.getIdentification()), "hypersonic-hsqldb", "", -1, "jdbc:hsqldb:.", "sa", "", DEFAULT_MAX_CONNECTION, -1, 60000, true, true, DataSource.ALLOW_ALL, false, false, null, new StructImpl(), "", ParamSyntax.DEFAULT, false, false);
    } catch (Exception e) {
        log.error("Datasource", e);
    }
    SecurityManager sm = config.getSecurityManager();
    short access = sm.getAccess(SecurityManager.TYPE_DATASOURCE);
    int accessCount = -1;
    if (access == SecurityManager.VALUE_YES)
        accessCount = -1;
    else if (access == SecurityManager.VALUE_NO)
        accessCount = 0;
    else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10) {
        accessCount = access - SecurityManager.NUMBER_OFFSET;
    }
    // Databases
    Element databases = getChildByName(doc.getDocumentElement(), "data-sources");
    // if(databases==null)databases=doc.createElement("data-sources");
    // PSQ
    String strPSQ = getAttr(databases, "psq");
    if (StringUtil.isEmpty(strPSQ)) {
        // prior version was buggy, was the opposite
        strPSQ = getAttr(databases, "preserve-single-quote");
        if (!StringUtil.isEmpty(strPSQ)) {
            Boolean b = Caster.toBoolean(strPSQ, null);
            if (b != null)
                strPSQ = b.booleanValue() ? "false" : "true";
        }
    }
    if (access != SecurityManager.VALUE_NO && !StringUtil.isEmpty(strPSQ)) {
        config.setPSQL(toBoolean(strPSQ, true));
    } else if (hasCS)
        config.setPSQL(configServer.getPSQL());
    // Data Sources
    Element[] dataSources = getChildren(databases, "data-source");
    if (accessCount == -1)
        accessCount = dataSources.length;
    if (dataSources.length < accessCount)
        accessCount = dataSources.length;
    // if(hasAccess) {
    ClassDefinition cd;
    for (int i = 0; i < accessCount; i++) {
        Element dataSource = dataSources[i];
        if (dataSource.hasAttribute("database")) {
            try {
                cd = getClassDefinition(dataSource, "", config.getIdentification());
                if (!cd.isBundle()) {
                    JDBCDriver jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null);
                    if (jdbc != null)
                        cd = jdbc.cd;
                }
                setDatasource(config, datasources, getAttr(dataSource, "name"), cd, getAttr(dataSource, "host"), getAttr(dataSource, "database"), Caster.toIntValue(getAttr(dataSource, "port"), -1), getAttr(dataSource, "dsn"), getAttr(dataSource, "username"), ConfigWebUtil.decrypt(getAttr(dataSource, "password")), Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), Caster.toIntValue(getAttr(dataSource, "connectionTimeout"), -1), Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true), toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL), toBoolean(getAttr(dataSource, "validate"), false), toBoolean(getAttr(dataSource, "storage"), false), getAttr(dataSource, "timezone"), toStruct(getAttr(dataSource, "custom")), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT), toBoolean(getAttr(dataSource, "literal-timestamp-with-tsoffset"), false), toBoolean(getAttr(dataSource, "always-set-timeout"), false));
            } catch (Exception e) {
                log.error("Datasource", e);
            }
        }
    }
    // }
    config.setDataSources(datasources);
}
Also used : SecurityManager(lucee.runtime.security.SecurityManager) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) lucee.aprint(lucee.aprint) DataSource(lucee.runtime.db.DataSource) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) StructImpl(lucee.runtime.type.StructImpl) JDBCDriver(lucee.runtime.db.JDBCDriver) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

ClassDefinition (lucee.runtime.db.ClassDefinition)41 ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)24 Element (org.w3c.dom.Element)15 ApplicationException (lucee.runtime.exp.ApplicationException)12 lucee.aprint (lucee.aprint)11 Struct (lucee.runtime.type.Struct)10 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)9 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)9 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)9 PageException (lucee.runtime.exp.PageException)9 BundleException (org.osgi.framework.BundleException)9 IOException (java.io.IOException)8 Map (java.util.Map)8 ClassException (lucee.commons.lang.ClassException)8 SecurityException (lucee.runtime.exp.SecurityException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 MalformedURLException (java.net.MalformedURLException)7 HashMap (java.util.HashMap)7 Entry (java.util.Map.Entry)7 StructImpl (lucee.runtime.type.StructImpl)7