Search in sources :

Example 1 with DataSourceDefintion

use of lucee.runtime.db.DBUtil.DataSourceDefintion in project Lucee by lucee.

the class AppListenerUtil method toDataSource.

public static DataSource toDataSource(Config config, String name, Struct data, Log log) throws PageException {
    String user = Caster.toString(data.get(KeyConstants._username, null), null);
    String pass = Caster.toString(data.get(KeyConstants._password, ""), "");
    if (StringUtil.isEmpty(user)) {
        user = null;
        pass = null;
    } else {
        user = user.trim();
        pass = pass.trim();
    }
    // first check for {class:... , connectionString:...}
    Object oConnStr = data.get(CONNECTION_STRING, null);
    if (oConnStr != null) {
        String className = Caster.toString(data.get(KeyConstants._class));
        if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(className)) {
            className = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        }
        ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), ThreadLocalPageContext.getConfig().getIdentification());
        try {
            return ApplicationDataSource.getInstance(config, name, cd, Caster.toString(oConnStr), user, pass, Caster.toBooleanValue(data.get(BLOB, null), false), Caster.toBooleanValue(data.get(CLOB, null), false), Caster.toIntValue(data.get(CONNECTION_LIMIT, null), -1), Caster.toIntValue(data.get(CONNECTION_TIMEOUT, null), 1), Caster.toLongValue(data.get(META_CACHE_TIMEOUT, null), 60000L), Caster.toTimeZone(data.get(TIMEZONE, null), null), Caster.toIntValue(data.get(ALLOW, null), DataSource.ALLOW_ALL), Caster.toBooleanValue(data.get(STORAGE, null), false), Caster.toBooleanValue(data.get(READ_ONLY, null), false), log);
        } catch (Exception cnfe) {
            throw Caster.toPageException(cnfe);
        }
    }
    // then for {type:... , host:... , ...}
    String type = Caster.toString(data.get(KeyConstants._type));
    DataSourceDefintion dbt = DBUtil.getDataSourceDefintionForType(type, null);
    if (dbt == null)
        throw new ApplicationException("no datasource type [" + type + "] found");
    try {
        return new DataSourceImpl(config, null, name, dbt.classDefinition, Caster.toString(data.get(KeyConstants._host)), dbt.connectionString, Caster.toString(data.get(DATABASE)), Caster.toIntValue(data.get(KeyConstants._port, null), -1), user, pass, Caster.toIntValue(data.get(CONNECTION_LIMIT, null), -1), Caster.toIntValue(data.get(CONNECTION_TIMEOUT, null), 1), Caster.toLongValue(data.get(META_CACHE_TIMEOUT, null), 60000L), Caster.toBooleanValue(data.get(BLOB, null), false), Caster.toBooleanValue(data.get(CLOB, null), false), DataSource.ALLOW_ALL, Caster.toStruct(data.get(KeyConstants._custom, null), null, false), Caster.toBooleanValue(data.get(READ_ONLY, null), false), true, Caster.toBooleanValue(data.get(STORAGE, null), false), Caster.toTimeZone(data.get(TIMEZONE, null), null), "", ParamSyntax.toParamSyntax(data, ParamSyntax.DEFAULT), Caster.toBooleanValue(data.get("literalTimestampWithTSOffset", null), false), Caster.toBooleanValue(data.get("alwaysSetTimeout", null), false), log);
    } catch (Exception cnfe) {
        throw Caster.toPageException(cnfe);
    }
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ApplicationException(lucee.runtime.exp.ApplicationException) DataSourceDefintion(lucee.runtime.db.DBUtil.DataSourceDefintion) DataSourceImpl(lucee.runtime.db.DataSourceImpl) ClassDefinition(lucee.runtime.db.ClassDefinition) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

ClassDefinition (lucee.runtime.db.ClassDefinition)1 DataSourceDefintion (lucee.runtime.db.DBUtil.DataSourceDefintion)1 DataSourceImpl (lucee.runtime.db.DataSourceImpl)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 PageException (lucee.runtime.exp.PageException)1 ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)1