Example usage for org.apache.commons.collections15 ClosureUtils nopClosure

List of usage examples for org.apache.commons.collections15 ClosureUtils nopClosure

Introduction

In this page you can find the example usage for org.apache.commons.collections15 ClosureUtils nopClosure.

Prototype

public static Closure nopClosure() 

Source Link

Document

Gets a Closure that will do nothing.

Usage

From source file:com.diversityarrays.dal.db.bms.BmsConnectionInfo.java

@SuppressWarnings("unchecked")
BmsConnectionInfo(JdbcConnectionParameters local, JdbcConnectionParameters central, Closure<String> progress)
        throws DalDbException {

    if (progress == null) {
        progress = ClosureUtils.nopClosure();
    }//  w ww. j a  v  a 2s .co m

    this.localParams = local;
    this.centralParams = central;

    List<SQLException> errors = new ArrayList<SQLException>();
    try {
        if (localParams != null) {
            progress.execute("Connecting to " + localParams.connectionUrl);
            localConnection = createLocalConnection();
        }

        progress.execute("Connecting to " + centralParams.connectionUrl);
        centralConnection = createCentralConnection();

        int totalGids = 0;
        for (Connection c : Arrays.asList(centralConnection, localConnection)) {
            if (c != null) {
                Integer count = SqlUtil.getSingleInteger(c, "SELECT COUNT(*) FROM GERMPLSM");
                if (count != null) {
                    totalGids += count;
                }
            }
        }
        progress.execute("Total of " + totalGids + " GERMPLSM records in database");

        collectUserTypes(progress);

        collectFldnoForGenus(progress);

        if (fldNoForGenus == null) {
            StringBuilder sb = new StringBuilder("Missing FLDNO values for:");
            sb.append("\n").append(genusFromSpecies ? SPECIES_NAME_CONSTRAINT : TAXONOMY_CONSTRAINT);
            throw new DalDbException(sb.toString());
        }

        genusStore = new GenusStore(centralConnection, fldNoForGenus, progress);
        // TODO Determine if need to populate from local database as well

    } catch (SQLException e) {
        errors.add(e);
    } finally {
        if (!errors.isEmpty()) {
            closeConnections();
        }
    }

    if (!errors.isEmpty()) {
        // Just the first one!
        throw new DalDbException(errors.get(0));
    }
}

From source file:com.diversityarrays.dal.db.TestDalDatabase.java

private static DalDatabase createBMS_DalDatabase() throws UnknownHostException, DalDbException {

    USERNAME = "GUEST";
    PASSWORD = "GUEST";

    String where = null;/*from   w  ww  .j  a  v a2s  . c o  m*/
    String hostname = InetAddress.getLocalHost().getCanonicalHostName();
    String h2 = InetAddress.getLocalHost().getHostName();

    if (hostname.startsWith("192.168.9.")) {
        where = "DART";
    } else {
        hostname = InetAddress.getLocalHost().getCanonicalHostName();
        if (hostname.startsWith("pyrus")) {
            where = "HOME";
        } else if ("localhost".equals(hostname) || hostname.startsWith("bmac") || h2.startsWith("beepsmac")) {
            where = "BMAC";
        } else {
            where = "DART";
        }
    }

    String[] centralLocal = CENTRAL_LOCAL_URL_PAIRS.get(where);

    System.out.println(TestDalDatabase.class.getName() + " for BMS using:");
    System.out.println("central: " + centralLocal[0]);
    System.out.println("  local: " + centralLocal[1]);

    JdbcConnectionParameters centralParams = new JdbcConnectionParameters(centralLocal[0], null, null);
    JdbcConnectionParameters localParams = null;
    if (centralLocal[1] != null && !centralLocal[1].isEmpty()) {
        localParams = new JdbcConnectionParameters(centralLocal[1], null, null);
    }

    @SuppressWarnings("unchecked")
    DalDatabase result = new BMS_DalDatabase(ClosureUtils.nopClosure(), false, localParams, centralParams);

    System.out.println(TestDalDatabase.class.getName() + " for KDDart: " + result.getDatabaseName());
    return result;
}

From source file:com.diversityarrays.dal.db.TestDalDatabase.java

@SuppressWarnings({ "rawtypes", "unchecked" })
static private DalDatabase createKddartDalDatabase() throws DalDbException {

    Preferences preferences = Preferences.userNodeForPackage(DalServer.class);
    DalDbProviderService service = new KddartDalDbProviderService();

    Map<Parameter<?>, ParameterValue<?>> parameterValues = new HashMap<Parameter<?>, ParameterValue<?>>();
    Preferences serviceNode = preferences.node("service/" + service.getClass().getName());

    for (Parameter<?> param : service.getParametersRequired()) {
        String s = serviceNode.get(param.name, null);
        try {// www. j a  va 2  s .co m
            Object value = param.stringToValue(s);
            parameterValues.put(param, new ParameterValue(param, value));

            if (KddartDalDatabase.PARAM_USERNAME.equals(param.name)) {
                USERNAME = s;
            } else if (KddartDalDatabase.PARAM_PASSWORD.equals(param.name)) {
                PASSWORD = s;
            }
        } catch (ParameterException e) {
            Throwable t = e.getCause();
            if (t == null) {
                t = e;
            }
            if (t instanceof RuntimeException) {
                throw ((RuntimeException) t);
            }
            throw new RuntimeException(t);
        }
    }

    KddartDalDatabase result = (KddartDalDatabase) service.createDatabase(parameterValues.values(),
            ClosureUtils.nopClosure(), false);

    System.out.println(TestDalDatabase.class.getName() + " for KDDart: " + result.getDatabaseName());

    result.setAutoSwitchGroupOnLogin(true);
    return result;
}

From source file:com.diversityarrays.dal.db.bms.BMS_DalDatabase.java

@SuppressWarnings("unchecked")
public void setDefaultProgress(Closure<String> p) {
    this.defaultProgress = p != null ? p : ClosureUtils.nopClosure();
}