Search in sources :

Example 1 with UpdateExecutor

use of net.idea.modbcum.p.UpdateExecutor in project ambit-mirror by ideaconsult.

the class SubstanceWriterTest method delete.

public int delete(SubstanceEndpointsBundle bundle, IRawReader<IStructureRecord> reader, Connection connection) throws Exception {
    /*
		 * DBSubstanceWriter writer; if (bundle != null) writer = new
		 * DBBundleStudyWriter(bundle, DBSubstanceWriter.datasetMeta(), new
		 * SubstanceRecord()); else writer = new
		 * DBSubstanceWriter(DBSubstanceWriter.datasetMeta(), new
		 * SubstanceRecord(), clearMeasurements, clearComposition);
		 * writer.setSplitRecord(splitRecord); writer.setConnection(connection);
		 * writer.open();
		 */
    UpdateExecutor<IQueryUpdate> writer = new UpdateExecutor<IQueryUpdate>();
    writer.setConnection(connection);
    DeleteMatrixValue q = new DeleteMatrixValue();
    q.setGroup(bundle);
    int records = 0;
    while (reader.hasNext()) {
        Object record = reader.next();
        if (record == null)
            continue;
        Assert.assertTrue(record instanceof SubstanceRecord);
        Assert.assertEquals("IUC4-efdb21bb-e79f-3286-a988-b6f6944d3734", ((SubstanceRecord) record).getSubstanceUUID());
        for (ProtocolApplication pa : ((SubstanceRecord) record).getMeasurements()) {
            Assert.assertTrue(pa instanceof ProtocolApplicationAnnotated);
            // System.out.println(((ProtocolApplicationAnnotated) pa)getRecords_to_delete());
            ProtocolApplicationAnnotated paa = (ProtocolApplicationAnnotated) pa;
            List<ValueAnnotated> vaa = paa.getRecords_to_delete();
            for (ValueAnnotated va : vaa) {
                q.setObject(va);
                writer.process(q);
            }
        }
        // writer.setImportedRecord((SubstanceRecord) record);
        // writer.process((IStructureRecord) record);
        records++;
    }
    writer.close();
    return records;
}
Also used : DeleteMatrixValue(ambit2.db.update.bundle.matrix.DeleteMatrixValue) ProtocolApplication(ambit2.base.data.study.ProtocolApplication) UpdateExecutor(net.idea.modbcum.p.UpdateExecutor) ValueAnnotated(ambit2.base.data.study.ValueAnnotated) SubstanceRecord(ambit2.base.data.SubstanceRecord) IQueryUpdate(net.idea.modbcum.i.query.IQueryUpdate) ProtocolApplicationAnnotated(ambit2.base.data.study.ProtocolApplicationAnnotated)

Example 2 with UpdateExecutor

use of net.idea.modbcum.p.UpdateExecutor in project ambit-mirror by ideaconsult.

the class AmbitDBQueryResource method execUpdate.

protected void execUpdate(Object object, IQueryUpdate query) throws ResourceException {
    Connection conn = null;
    UpdateExecutor x = null;
    try {
        DBConnection dbc = new DBConnection(getApplication().getContext(), getConfigFile());
        conn = dbc.getConnection(30, true, 8);
        x = new UpdateExecutor();
        x.setConnection(conn);
        x.process(query);
    } catch (Exception e) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception xx) {
        }
        try {
            if (x != null)
                x.close();
        } catch (Exception xx) {
        }
    }
}
Also used : DBConnection(net.idea.restnet.db.DBConnection) UpdateExecutor(net.idea.modbcum.p.UpdateExecutor) Connection(java.sql.Connection) DBConnection(net.idea.restnet.db.DBConnection) ResourceException(org.restlet.resource.ResourceException) ResourceException(org.restlet.resource.ResourceException)

Example 3 with UpdateExecutor

use of net.idea.modbcum.p.UpdateExecutor in project ambit-mirror by ideaconsult.

the class RegistrationConfirmResource method getRepresentation.

@Override
protected Representation getRepresentation(Variant variant) throws ResourceException {
    if (MediaType.APPLICATION_JSON.equals(variant.getMediaType())) {
        Connection conn = null;
        UpdateExecutor exec = null;
        Object code = getRequest().getResourceRef().getQueryAsForm().getFirstValue(confirmationCode);
        if (code != null)
            try {
                String usersdbname = getContext().getParameters().getFirstValue(AMBITConfig.users_dbname.name());
                if (usersdbname == null)
                    usersdbname = getDefaultUsersDB();
                UserURIReporter reporter = new UserURIReporter(getRequest(), "");
                DBConnection dbc = new DBConnection(getApplication().getContext(), getConfigFile());
                conn = dbc.getConnection();
                UserRegistration reg = new UserRegistration(code.toString());
                reg.setTitle("Confirm reset");
                ConfirmRegistration q = new ConfirmRegistration(reg);
                q.setDatabaseName(usersdbname);
                exec = new UpdateExecutor();
                exec.setConnection(conn);
                exec.process(q);
            } catch (Exception x) {
                try {
                    if (conn != null) {
                        conn.close();
                        conn = null;
                    }
                } catch (Exception xx) {
                }
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
            } finally {
                try {
                    exec.close();
                } catch (Exception x) {
                }
                try {
                    if (conn != null)
                        conn.close();
                } catch (Exception x) {
                }
            }
    }
    return super.getRepresentation(variant);
}
Also used : DBConnection(net.idea.restnet.db.DBConnection) UpdateExecutor(net.idea.modbcum.p.UpdateExecutor) ConfirmRegistration(net.idea.restnet.u.db.ConfirmRegistration) Connection(java.sql.Connection) DBConnection(net.idea.restnet.db.DBConnection) UserURIReporter(net.idea.restnet.user.resource.UserURIReporter) ResourceException(org.restlet.resource.ResourceException) UserRegistration(net.idea.restnet.u.UserRegistration) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 4 with UpdateExecutor

use of net.idea.modbcum.p.UpdateExecutor in project ambit-mirror by ideaconsult.

the class RoleDBResource method execUpdate.

protected void execUpdate(IQueryUpdate query) throws ResourceException {
    Connection conn = null;
    UpdateExecutor x = null;
    try {
        DBConnection dbc = new DBConnection(getApplication().getContext(), getConfigFile());
        conn = dbc.getConnection();
        x = new UpdateExecutor();
        x.setConnection(conn);
        x.process(query);
    } catch (Exception e) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception xx) {
        }
        try {
            if (x != null)
                x.close();
        } catch (Exception xx) {
        }
    }
}
Also used : DBConnection(net.idea.restnet.db.DBConnection) UpdateExecutor(net.idea.modbcum.p.UpdateExecutor) Connection(java.sql.Connection) DBConnection(net.idea.restnet.db.DBConnection) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

UpdateExecutor (net.idea.modbcum.p.UpdateExecutor)4 Connection (java.sql.Connection)3 DBConnection (net.idea.restnet.db.DBConnection)3 ResourceException (org.restlet.resource.ResourceException)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 ProtocolApplication (ambit2.base.data.study.ProtocolApplication)1 ProtocolApplicationAnnotated (ambit2.base.data.study.ProtocolApplicationAnnotated)1 ValueAnnotated (ambit2.base.data.study.ValueAnnotated)1 DeleteMatrixValue (ambit2.db.update.bundle.matrix.DeleteMatrixValue)1 NotFoundException (net.idea.modbcum.i.exceptions.NotFoundException)1 IQueryUpdate (net.idea.modbcum.i.query.IQueryUpdate)1 UserRegistration (net.idea.restnet.u.UserRegistration)1 ConfirmRegistration (net.idea.restnet.u.db.ConfirmRegistration)1 UserURIReporter (net.idea.restnet.user.resource.UserURIReporter)1