Search in sources :

Example 1 with IDBProcessor

use of net.idea.modbcum.i.IDBProcessor in project ambit-mirror by ideaconsult.

the class QueryResource method getRepresentation.

protected Representation getRepresentation(Variant variant) throws ResourceException {
    try {
        if (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
            if ((queryObject != null) && (queryObject instanceof Serializable))
                return new ObjectRepresentation((Serializable) returnQueryObject(), MediaType.APPLICATION_JAVA_OBJECT);
            else
                throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
        }
        if (MediaType.APPLICATION_JAVASCRIPT.equals(variant.getMediaType())) {
            if (!isJSONPEnabled())
                throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
        }
        if (queryObject != null) {
            IProcessor<Q, Representation> convertor = null;
            Connection connection = null;
            int retry = 0;
            while (retry < maxRetry) {
                try {
                    DBConnection dbc = new DBConnection(getContext());
                    configureRDFWriterOption(((AmbitApplication) getApplication()).getProperties().getRDFwriter());
                    configureSDFLineSeparators(((AmbitApplication) getApplication()).getProperties().getConfigChangeLineSeparator());
                    configureDatasetMembersPrefixOption(((AmbitApplication) getApplication()).getProperties().isDatasetMembersPrefix());
                    convertor = createConvertor(variant);
                    if (convertor instanceof RepresentationConvertor)
                        ((RepresentationConvertor) convertor).setLicenseURI(getLicenseURI());
                    connection = dbc.getConnection();
                    Reporter reporter = ((RepresentationConvertor) convertor).getReporter();
                    if (reporter instanceof IDBProcessor)
                        ((IDBProcessor) reporter).setConnection(connection);
                    Representation r = convertor.process(queryObject);
                    r.setCharacterSet(CharacterSet.UTF_8);
                    return r;
                } catch (ResourceException x) {
                    throw x;
                } catch (NotFoundException x) {
                    Representation r = processNotFound(x, retry);
                    retry++;
                    if (r != null)
                        return r;
                } catch (BatchProcessingException x) {
                    if (x.getCause() instanceof NotFoundException) {
                        Representation r = processNotFound((NotFoundException) x.getCause(), retry);
                        retry++;
                        if (r != null)
                            return r;
                    } else {
                        Context.getCurrentLogger().severe(x.getMessage());
                        throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
                    }
                } catch (SQLException x) {
                    Representation r = processSQLError(x, retry, variant);
                    retry++;
                    if (r == null)
                        continue;
                    else
                        return r;
                } catch (Exception x) {
                    Context.getCurrentLogger().severe(x.getMessage());
                    throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
                } finally {
                // try { if (connection !=null) connection.close(); }
                // catch (Exception x) {};
                // try { if ((convertor !=null) &&
                // (convertor.getReporter() !=null))
                // convertor.getReporter().close(); } catch (Exception
                // x) {}
                }
            }
            return null;
        } else {
            if (variant.getMediaType().equals(MediaType.TEXT_HTML))
                try {
                    IProcessor<Q, Representation> convertor = createConvertor(variant);
                    Representation r = convertor.process(null);
                    return r;
                } catch (Exception x) {
                    throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x, variant);
                }
            else {
                throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, error, variant);
            }
        }
    } catch (RResourceException x) {
        throw x;
    } catch (ResourceException x) {
        throw new RResourceException(x.getStatus(), x, variant);
    } catch (Exception x) {
        throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) Serializable(java.io.Serializable) IDBProcessor(net.idea.modbcum.i.IDBProcessor) SQLException(java.sql.SQLException) Reporter(net.idea.modbcum.i.reporter.Reporter) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) AmbitApplication(ambit2.rest.AmbitApplication) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) ObjectRepresentation(org.restlet.representation.ObjectRepresentation) Representation(org.restlet.representation.Representation) IProcessor(net.idea.modbcum.i.processors.IProcessor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) RepresentationConvertor(net.idea.restnet.c.RepresentationConvertor) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) RResourceException(ambit2.rest.exception.RResourceException) ObjectRepresentation(org.restlet.representation.ObjectRepresentation)

Example 2 with IDBProcessor

use of net.idea.modbcum.i.IDBProcessor in project ambit-mirror by ideaconsult.

the class DictionaryRowsTest method demo.

protected void demo() {
    DictionarySubjectQuery query = new DictionarySubjectQuery();
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        initDatasource();
        Connection c = datasource.getConnection();
        IAmbitEditor editor = EditorPreferences.getEditor(query);
        if (editor instanceof IDBProcessor) {
            ((IDBProcessor) editor).setConnection(c);
            ((IDBProcessor) editor).open();
        }
        JOptionPane.showMessageDialog(null, editor.getJComponent());
        c.close();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
Also used : IDBProcessor(net.idea.modbcum.i.IDBProcessor) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) Connection(java.sql.Connection) DictionarySubjectQuery(ambit2.db.search.DictionarySubjectQuery)

Example 3 with IDBProcessor

use of net.idea.modbcum.i.IDBProcessor in project ambit-mirror by ideaconsult.

the class QueryFieldEditorTest method demo.

protected void demo() {
    QueryField query = new QueryField();
    try {
        initDatasource();
        Connection c = datasource.getConnection();
        IAmbitEditor editor = EditorPreferences.getEditor(query);
        if (editor instanceof IDBProcessor) {
            ((IDBProcessor) editor).setConnection(c);
            ((IDBProcessor) editor).open();
        }
        JOptionPane.showMessageDialog(null, editor.getJComponent());
        System.out.println(query.toString());
        System.out.println(query.getSQL());
        System.out.println(query.getParameters());
        c.close();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
Also used : IDBProcessor(net.idea.modbcum.i.IDBProcessor) QueryField(ambit2.db.search.structure.QueryField) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) Connection(java.sql.Connection)

Example 4 with IDBProcessor

use of net.idea.modbcum.i.IDBProcessor in project ambit-mirror by ideaconsult.

the class QueryFunctionalGroupsEditorTest method demo.

protected void demo() {
    ProcessorCreateProfileQuery p = new ProcessorCreateProfileQuery();
    Template t = new Template();
    t.setName("ambit2.descriptors.FunctionalGroupDescriptor");
    try {
        initDatasource();
        Connection c = datasource.getConnection();
        p.setConnection(c);
        IQueryRetrieval<IStructureRecord> query = p.process(t);
        IAmbitEditor editor = EditorPreferences.getEditor(query);
        if (editor instanceof IDBProcessor) {
            ((IDBProcessor) editor).setConnection(c);
            ((IDBProcessor) editor).open();
        }
        JOptionPane.showMessageDialog(null, editor.getJComponent());
        System.out.println(query.toString());
        System.out.println(query.getSQL());
        System.out.println(query.getParameters());
        c.close();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) IDBProcessor(net.idea.modbcum.i.IDBProcessor) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) ProcessorCreateProfileQuery(ambit2.db.processors.ProcessorCreateProfileQuery) Connection(java.sql.Connection) Template(ambit2.base.data.Template)

Example 5 with IDBProcessor

use of net.idea.modbcum.i.IDBProcessor in project ambit-mirror by ideaconsult.

the class QueryStoredResultsEditorTest method demo.

protected void demo() {
    QueryStoredResults query = new QueryStoredResults();
    try {
        initDatasource();
        Connection c = datasource.getConnection();
        IAmbitEditor editor = EditorPreferences.getEditor(query);
        if (editor instanceof IDBProcessor) {
            ((IDBProcessor) editor).setConnection(c);
            ((IDBProcessor) editor).open();
        }
        JOptionPane.showMessageDialog(null, editor.getJComponent());
        System.out.println(query.toString());
        System.out.println(query.getSQL());
        System.out.println(query.getParameters());
        c.close();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
Also used : IDBProcessor(net.idea.modbcum.i.IDBProcessor) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) Connection(java.sql.Connection) QueryStoredResults(ambit2.db.search.structure.QueryStoredResults)

Aggregations

Connection (java.sql.Connection)7 IDBProcessor (net.idea.modbcum.i.IDBProcessor)7 IAmbitEditor (ambit2.base.interfaces.IAmbitEditor)6 Template (ambit2.base.data.Template)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 ProcessorException (ambit2.base.processors.ProcessorException)1 ProcessorCreateProfileQuery (ambit2.db.processors.ProcessorCreateProfileQuery)1 DictionarySubjectQuery (ambit2.db.search.DictionarySubjectQuery)1 QueryDataset (ambit2.db.search.structure.QueryDataset)1 QueryField (ambit2.db.search.structure.QueryField)1 QueryStoredResults (ambit2.db.search.structure.QueryStoredResults)1 ScopeQuery (ambit2.db.search.structure.ScopeQuery)1 AmbitApplication (ambit2.rest.AmbitApplication)1 DBConnection (ambit2.rest.DBConnection)1 RResourceException (ambit2.rest.exception.RResourceException)1 Serializable (java.io.Serializable)1 SQLException (java.sql.SQLException)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 BatchProcessingException (net.idea.modbcum.i.exceptions.BatchProcessingException)1 NotFoundException (net.idea.modbcum.i.exceptions.NotFoundException)1