Package org.apache.beehive.controls.api

Examples of org.apache.beehive.controls.api.ControlException


    protected Object execPreparedStatement(Method method, Object[] args)
            throws Throwable {

        final SQL methodSQL = (SQL) _context.getMethodPropertySet(method, SQL.class);
        if (methodSQL == null || methodSQL.statement() == null) {
            throw new ControlException("Method " + method.getName() + " is missing @SQL annotation");
        }

        setTypeMappers(methodSQL.typeMappersOverride());

        //
        // build the statement and execute it
        //

        PreparedStatement ps = null;
        try {
            Class returnType = method.getReturnType();

            SqlStatement sqlStatement = _sqlParser.parse(methodSQL.statement());
            ps = sqlStatement.createPreparedStatement(_context, _connection, _cal, method, args);

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("PreparedStatement: "
                            + sqlStatement.createPreparedStatementString(_context, _connection,  method, args));
            }

            //
            // special processing for batch updates
            //
            if (sqlStatement.isBatchUpdate()) {
                return ps.executeBatch();
            }

            //
            // execute the statement
            //
            boolean hasResults = ps.execute();


            //
            // callable statement processing
            //
            if (sqlStatement.isCallableStatement()) {
                SQLParameter[] params = (SQLParameter[]) args[0];
                for (int i = 0; i < params.length; i++) {
                    if (params[i].dir != SQLParameter.IN) {
                        params[i].value = ((CallableStatement) ps).getObject(i + 1);
                    }
                }
                return null;
            }


            //
            // process returned data
            //
            ResultSet rs = null;
            int updateCount = ps.getUpdateCount();

            if (hasResults) {
                rs = ps.getResultSet();
            }

            if (sqlStatement.getsGeneratedKeys()) {
                rs = ps.getGeneratedKeys();
                hasResults = true;
            }

            if (!hasResults && updateCount > -1) {
                boolean moreResults = ps.getMoreResults();
                int tempUpdateCount = ps.getUpdateCount();

                while ((moreResults && rs == null) || tempUpdateCount > -1) {
                    if (moreResults) {
                        rs = ps.getResultSet();
                        hasResults = true;
                        moreResults = false;
                        tempUpdateCount = -1;
                    } else {
                        moreResults = ps.getMoreResults();
                        tempUpdateCount = ps.getUpdateCount();
                    }
                }
            }

            Object returnObject = null;
            if (hasResults) {

                //
                // if a result set mapper was specified in the methods annotation, use it
                // otherwise find the mapper for the return type in the hashmap
                //
                final Class resultSetMapperClass = methodSQL.resultSetMapper();
                final ResultSetMapper rsm;
                if (!UndefinedResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) {
                    if (ResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) {
                        rsm = (ResultSetMapper) resultSetMapperClass.newInstance();
                    } else {
                        throw new ControlException("Result set mappers must be subclasses of ResultSetMapper.class!");
                    }
                } else {
                    if (_resultMappers.containsKey(returnType)) {
                        rsm = _resultMappers.get(returnType);
                    } else {
                        if (_xmlObjectClass != null && _xmlObjectClass.isAssignableFrom(returnType)) {
                            rsm = _resultMappers.get(_xmlObjectClass);
                        } else {
                            rsm = DEFAULT_MAPPER;
                        }
                    }
                }

                returnObject = rsm.mapToResultType(_context, method, rs, _cal);
                if (rsm.canCloseResultSet() == false) {
                    getResources().add(ps);
                }

                //
                // empty ResultSet
                //
            } else {
                if (returnType.equals(Void.TYPE)) {
                    returnObject = null;
                } else if (returnType.equals(Integer.TYPE)) {
                    returnObject = new Integer(updateCount);
                } else if (!sqlStatement.isCallableStatement()) {
                    throw new ControlException("Method " + method.getName() + "is DML but does not return void or int");
                }
            }
            return returnObject;

        } finally {
View Full Code Here


            JndiContextFactory jf = (JndiContextFactory) jndiFactory.newInstance();
            Context jndiContext = jf.getContext();
            _dataSource = (DataSource) jndiContext.lookup(jndiName);
            con = _dataSource.getConnection();
        } catch (IllegalAccessException iae) {
            throw new ControlException("IllegalAccessException:", iae);
        } catch (InstantiationException ie) {
            throw new ControlException("InstantiationException:", ie);
        } catch (NamingException ne) {
            throw new ControlException("NamingException:", ne);
        }
        return con;
    }
View Full Code Here

            if (!EMPTY_STRING.equals(userName)) {
                con = DriverManager.getConnection(dbUrlStr, userName, password);
            } else if (!EMPTY_STRING.equals(propertiesString)) {
                Properties props = parseProperties(propertiesString);
                if (props == null) {
                    throw new ControlException("Invalid properties annotation value: " + propertiesString);
                }
                con = DriverManager.getConnection(dbUrlStr, props);
            } else {
                con = DriverManager.getConnection(dbUrlStr);
            }
        } catch (ClassNotFoundException e) {
            throw new ControlException("Database driver class not found!", e);
        }
        return con;
    }
View Full Code Here

        // cache the Map.get method for efficiency
        try {
            _methodMapGet = java.util.Map.class.getMethod("get", new Class[]{Object.class});
        } catch (NoSuchMethodException e) {
            throw new ControlException("Can not find java.util.Map.get(Object) method");
        }
    }
View Full Code Here

            ControlFactory factory = (ControlFactory)factoryClass.newInstance();
            return factory.instantiate( beanClass, props, context, id );
        }
        catch ( Exception e )
        {
            throw new ControlException( "Exception creating ControlBean", e );
        }
    }
View Full Code Here

                {
                    e = e.getCause();
                }
            }
               
            throw new ControlException( "Exception trying to run client initializer: " + e.getClass().getName() + ", " +
                                        e.getMessage(), e );
        }
    }
View Full Code Here

            ret = ctor.newInstance(context, id, props);
        }
        catch (InvocationTargetException ite)
        {
            Throwable t = ite.getCause();
            throw new ControlException("ControlBean constructor exception", t);
        }
        catch (Exception e)
        {
            throw new ControlException("Exception creating ControlBean", e);
        }

        return ret;
    }
View Full Code Here

        JdbcControl.SQL methodSQL = (JdbcControl.SQL) context.getMethodPropertySet(method, JdbcControl.SQL.class);
        _returnClass = methodSQL.iteratorElementType();

        if (_returnClass == null) {
            throw new ControlException("Invalid return class declared for Iterator:" + _returnClass.getName());
        }

        _rowMapper = RowMapperFactory.getRowMapper(rs, _returnClass, cal);
    }
View Full Code Here

            }

            rows.populate(resultSet);
            return rows;
        } catch (SQLException e) {
            throw new ControlException(e.getMessage(), e);
        }
    }
View Full Code Here

        _fields = null;

        try {
            _columnCount = resultSet.getMetaData().getColumnCount();
        } catch (SQLException e) {
            throw new ControlException("RowToObjectMapper: SQLException: " + e.getMessage(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.beehive.controls.api.ControlException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.