use of lucee.transformer.library.ClassDefinitionImpl 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);
}
}
}
}
}
use of lucee.transformer.library.ClassDefinitionImpl 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);
}
use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.
the class CacheRegionNew method _call.
static String _call(PageContext pc, String cacheName, Struct properties, Boolean throwOnError, String strWebAdminPassword) throws PageException {
Password webAdminPassword = CacheUtil.getPassword(pc, strWebAdminPassword, false);
try {
// TODO why we have here EHCache?
XMLConfigAdmin adminConfig = XMLConfigAdmin.newInstance((ConfigWebImpl) pc.getConfig(), webAdminPassword);
adminConfig.updateCacheConnection(cacheName, new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache", null, null, pc.getConfig().getIdentification()), Config.CACHE_TYPE_NONE, properties, false, false);
adminConfig.storeAndReload();
} catch (Exception e) {
if (throwOnError)
throw Caster.toPageException(e);
}
return null;
}
use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.
the class ModernApplicationContext method toCacheConnection.
public static CacheConnection toCacheConnection(Config config, String name, Struct data) throws ApplicationException, CacheException, ClassException, BundleException {
// class definition
String className = Caster.toString(data.get(KeyConstants._class, null), null);
if (StringUtil.isEmpty(className))
throw new ApplicationException("missing key class in struct the defines a cachec connection");
ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), config.getIdentification());
CacheConnectionImpl cc = new CacheConnectionImpl(config, name, cd, Caster.toStruct(data.get(KeyConstants._custom, null), null), Caster.toBooleanValue(data.get(KeyConstants._readonly, null), false), Caster.toBooleanValue(data.get(KeyConstants._storage, null), false));
String id = cc.id();
CacheConnection icc = initCacheConnections.get(id);
if (icc != null)
return icc;
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, new String[] { cc.getName() }, new Struct[] { cc.getCustom() } });
else
SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + cd.toString() + "] is not static");
initCacheConnections.put(id, cc);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
return cc;
}
use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.
the class Admin method doUpdateAdminSyncClass.
private void doUpdateAdminSyncClass() throws PageException {
ClassDefinition cd = new ClassDefinitionImpl(getString("admin", action, "class"), getString("bundleName", null), getString("bundleVersion", null), config.getIdentification());
admin.updateAdminSyncClass(cd);
store();
}
Aggregations