Search in sources :

Example 1 with DbAmbitException

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

the class AmbitRows method open.

public synchronized void open() throws DbAmbitException {
    if (query == null)
        throw new DbAmbitException("Query not defined!");
    setReady(false);
    try {
        close();
    // rowset.close();
    } catch (Exception x) {
        logger.log(Level.WARNING, x.getMessage(), x);
    }
    if (getConnection() != null)
        executor.setConnection(connection);
    executor.open();
    try {
        populate(executor.process(query));
    } catch (AmbitException x) {
        throw new DbAmbitException(x);
    } catch (SQLException x) {
        throw new DbAmbitException(x);
    } finally {
        setReady(true);
    }
}
Also used : DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) SQLException(java.sql.SQLException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) SQLException(java.sql.SQLException) SyncProviderException(javax.sql.rowset.spi.SyncProviderException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Example 2 with DbAmbitException

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

the class OntologyEditor method setConnection.

/**
 *						 query[side.ordinal()].setValue(((Dictionary)selected).getTemplate());
 *										 rows[side.ordinal()].setQuery(query[side.ordinal()]);
 */
/*
	 * (non-Javadoc)
	 * @see ambit2.db.AbstractDBProcessor#setConnection(java.sql.Connection)
	 */
@Override
public void setConnection(Connection connection) throws DbAmbitException {
    super.setConnection(connection);
    for (SIDE side : SIDE.values()) {
        rows[side.ordinal()].setConnection(connection);
        try {
            rows[side.ordinal()].setQuery(query[side.ordinal()]);
        } catch (Exception x) {
            x.printStackTrace();
        }
    }
    processor.setConnection(connection);
}
Also used : SIDE(ambit2.db.processors.ProcessorOntology.SIDE) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Example 3 with DbAmbitException

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

the class RepositoryReader method open.

public void open() throws DbAmbitException {
    try {
        prepareStatement(connection);
        ps_structures.clearParameters();
        rs = ps_structures.executeQuery();
    } catch (SQLException x) {
        throw new DbAmbitException(null, x);
    }
}
Also used : DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) SQLException(java.sql.SQLException)

Example 4 with DbAmbitException

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

the class ProcessorCreateQuery method insertScreenedResults.

protected int insertScreenedResults(IStoredQuery result, final IQueryRetrieval<IStructureRecord> query) throws SQLException, AmbitException {
    final PreparedStatement insertGoodResults = connection.prepareStatement(IStoredQuery.SQL_INSERT + " values(?,?,?,1,?,?)");
    QueryStructureReporter<IQueryRetrieval<IStructureRecord>, IStructureRecord> reporter = new QueryStructureReporter<IQueryRetrieval<IStructureRecord>, IStructureRecord>() {

        @Override
        public void close() throws Exception {
            // TODO Auto-generated method stub
            super.close();
        }

        @Override
        public void header(IStructureRecord output, IQueryRetrieval<IStructureRecord> query) {
        // TODO Auto-generated method stub
        }

        @Override
        public Object processItem(IStructureRecord record) throws AmbitException {
            try {
                insertGoodResults.setInt(1, query.getId());
                insertGoodResults.setInt(2, record.getIdchemical());
                insertGoodResults.setInt(3, record.getIdstructure());
                insertGoodResults.setDouble(4, 1);
                insertGoodResults.setNull(5, Types.VARCHAR);
                insertGoodResults.executeUpdate();
            } catch (Exception x) {
                throw new AmbitException(x);
            }
            return null;
        }

        public void open() throws DbAmbitException {
        }

        @Override
        public void footer(IStructureRecord output, IQueryRetrieval<IStructureRecord> query) {
        // TODO Auto-generated method stub
        }
    };
    try {
        long timeout = 8 * 1000;
        try {
            timeout = Long.parseLong(Preferences.getProperty(Preferences.TIMEOUT));
        } catch (Exception x) {
        }
        // 1s
        reporter.setTimeout(timeout);
        reporter.setAutoCommit(true);
        reporter.setConnection(connection);
        reporter.process(query);
    } catch (Exception x) {
        logger.log(Level.WARNING, x.getMessage(), x);
    } finally {
        try {
            insertGoodResults.close();
        } catch (Exception x) {
            logger.log(Level.FINEST, x.getMessage(), x);
        }
        try {
            reporter.close();
        } catch (Exception x) {
            logger.log(Level.FINEST, x.getMessage(), x);
        }
    }
    return 1;
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) QueryStructureReporter(ambit2.db.reporters.QueryStructureReporter) PreparedStatement(java.sql.PreparedStatement) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Aggregations

DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)4 SQLException (java.sql.SQLException)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 ProcessorException (ambit2.base.processors.ProcessorException)1 SIDE (ambit2.db.processors.ProcessorOntology.SIDE)1 QueryStructureReporter (ambit2.db.reporters.QueryStructureReporter)1 PreparedStatement (java.sql.PreparedStatement)1 SyncProviderException (javax.sql.rowset.spi.SyncProviderException)1 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)1