Search in sources :

Example 1 with SQLMapDatasourceMap

use of com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap in project navajo by Dexels.

the class SQLMaintenanceMap method setDatasources.

@SuppressWarnings("deprecation")
public synchronized void setDatasources(SQLMapDatasourceMap[] datasources) throws UserException, NavajoException, MappableException {
    if (noAccess)
        throw new MappableException("Cannot enter maintenance object in write mode, already in use");
    saveConfigFile(true);
    for (int i = 0; i < datasources.length; i++) {
        SQLMapDatasourceMap datasource = datasources[i];
        this.dirty = true;
        Message msg = sqlMapConfigFile.getMessage("datasources").getMessage(datasource.getDatasourceName());
        if (msg == null) {
            msg = NavajoFactory.getInstance().createMessage(sqlMapConfigFile, datasource.getDatasourceName());
            sqlMapConfigFile.getMessage("datasources").addMessage(msg);
            Property prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "url", Property.STRING_PROPERTY, datasource.url, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "logfile", Property.STRING_PROPERTY, datasource.logfile, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "max_connections", Property.INTEGER_PROPERTY, "" + datasource.max_connections, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "min_connections", Property.INTEGER_PROPERTY, "" + datasource.min_connections, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "password", Property.STRING_PROPERTY, datasource.password, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "refresh", Property.STRING_PROPERTY, datasource.refresh + "", 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "username", Property.STRING_PROPERTY, datasource.username, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
            prop = NavajoFactory.getInstance().createProperty(sqlMapConfigFile, "driver", Property.STRING_PROPERTY, datasource.driver, 0, "", Property.DIR_IN);
            msg.addProperty(prop);
        } else {
            msg.getProperty("url").setValue(datasource.getUrl());
            msg.getProperty("logfile").setValue(datasource.getLogfile());
            msg.getProperty("max_connections").setValue(datasource.max_connections + "");
            msg.getProperty("min_connections").setValue(datasource.min_connections + "");
            msg.getProperty("password").setValue(datasource.password);
            msg.getProperty("refresh").setValue(datasource.refresh + "");
            msg.getProperty("username").setValue(datasource.username);
            msg.getProperty("driver").setValue(datasource.driver);
        }
        if (dirty) {
            saveConfigFile(false);
            // reload sqlmap.xml
            SQLMap sqlMap = new SQLMap();
            sqlMap.load(access);
            sqlMap.setReload(datasource.datasourceName);
        }
    }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) Message(com.dexels.navajo.document.Message) SQLMapDatasourceMap(com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap) Property(com.dexels.navajo.document.Property)

Example 2 with SQLMapDatasourceMap

use of com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap in project navajo by Dexels.

the class SQLMaintenanceMap method getDatasources.

public synchronized SQLMapDatasourceMap[] getDatasources() {
    List<SQLMapDatasourceMap> all = new ArrayList<SQLMapDatasourceMap>();
    List<Message> list = sqlMapConfigFile.getMessage("datasources").getAllMessages();
    for (int i = 0; i < list.size(); i++) {
        Message msg = list.get(i);
        SQLMapDatasourceMap dm = new SQLMapDatasourceMap();
        dm.datasourceName = msg.getName();
        dm.url = msg.getProperty("url").getValue();
        dm.logfile = msg.getProperty("logfile").getValue();
        dm.max_connections = Integer.parseInt(msg.getProperty("max_connections").getValue());
        dm.min_connections = Integer.parseInt(msg.getProperty("min_connections").getValue());
        dm.password = msg.getProperty("password").getValue();
        dm.refresh = Float.parseFloat(msg.getProperty("refresh").getValue());
        dm.username = msg.getProperty("username").getValue();
        dm.driver = msg.getProperty("driver").getValue();
        all.add(dm);
    }
    datasources = new SQLMapDatasourceMap[all.size()];
    datasources = all.toArray(datasources);
    return datasources;
}
Also used : Message(com.dexels.navajo.document.Message) ArrayList(java.util.ArrayList) SQLMapDatasourceMap(com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap)

Aggregations

SQLMapDatasourceMap (com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap)2 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)1 MappableException (com.dexels.navajo.script.api.MappableException)1 ArrayList (java.util.ArrayList)1