Package org.apache.beehive.controls.api

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


                    if (_returnTypeClass.isAssignableFrom(val.getClass())) {
                        return val;
                    }
                }
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        if (_fields == null) {
            try {
                getFieldMappings();
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        try {
            resultObject = _returnTypeClass.newInstance();
        } catch (InstantiationException e) {
            throw new ControlException("InstantiationException when trying to create instance of : "
                                       + _returnTypeClass.getName(), e);
        } catch (IllegalAccessException e) {
            throw new ControlException("IllegalAccessException when trying to create instance of : "
                                       + _returnTypeClass.getName(), e);
        }

        for (int i = 1; i < _fields.length; i++) {
            AccessibleObject f = _fields[i];
            Object resultValue = null;

            try {
                resultValue = extractColumnValue(i, _fieldTypes[i]);
                if (f instanceof Field) {
                    ((Field) f).set(resultObject, resultValue);
                } else {
                    _args[0] = resultValue;
                    ((Method) f).invoke(resultObject, _args);
                }
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            } catch (IllegalArgumentException iae) {

                try {
                    ResultSetMetaData md = _resultSet.getMetaData();
                    if (f instanceof Field) {
                        throw new ControlException("The declared Java type for field " + ((Field) f).getName()
                                                   + ((Field) f).getType().toString()
                                                   + " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
                                                   + md.getColumnTypeName(i).toString()
                                                   + " which returns objects of type " + resultValue.getClass().getName());
                    } else {
                        throw new ControlException("The declared Java type for method " + ((Method) f).getName()
                                                   + ((Method) f).getParameterTypes()[0].toString()
                                                   + " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
                                                   + md.getColumnTypeName(i).toString()
                                                   + " which returns objects of type " + resultValue.getClass().getName());
                    }
                } catch (SQLException e) {
                    throw new ControlException(e.getMessage(), e);
                }

            } catch (IllegalAccessException e) {
                if (f instanceof Field) {
                    throw new ControlException("IllegalAccessException when trying to access field " + ((Field) f).getName(), e);
                } else {
                    throw new ControlException("IllegalAccessException when trying to access method " + ((Method) f).getName(), e);
                }
            } catch (InvocationTargetException e) {
                if (f instanceof Field) {
                    throw new ControlException("InvocationTargetException when trying to access field " + ((Field) f).getName(), e);
                } else {
                    throw new ControlException("InvocationTargetException when trying to access method " + ((Method) f).getName(), e);
                }
            }
        }
        return resultObject;
    }
View Full Code Here


                    // check for overloads
                    Object field = mapFields.get(fieldName);
                    if (field == null) {
                        mapFields.put(fieldName, m);
                    } else {
                        throw new ControlException("Unable to choose between overloaded methods " + m.getName()
                                                   + " on the " + _returnTypeClass.getName() + " class. Mapping is done using "
                                                   + "a case insensitive comparision of SQL ResultSet columns to field "
                                                   + "names and public setter methods on the return class.");
                    }
                }
            }
        }

        // fix for 8813: include inherited and non-public fields
        for (Class clazz = _returnTypeClass; clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) {
            Field[] classFields = clazz.getDeclaredFields();
            for (Field f : classFields) {
                if (Modifier.isStatic(f.getModifiers())) continue;
                if (!Modifier.isPublic(f.getModifiers())) continue;
                String fieldName = f.getName().toUpperCase();
                if (!mapFields.containsKey(fieldName)) continue;

                Object field = mapFields.get(fieldName);
                if (field == null) {
                    mapFields.put(fieldName, f);
                }
            }
        }

        // finally actually init the fields array
        _fields = new AccessibleObject[_columnCount + 1];
        _fieldTypes = new int[_columnCount + 1];

        for (int i = 1; i < _fields.length; i++) {
            AccessibleObject f = mapFields.get(keys[i]);
            if (f == null) {
                throw new ControlException("Unable to map the SQL column " + keys[i]
                                           + " to a field on the " + _returnTypeClass.getName() +
                                           " class. Mapping is done using a case insensitive comparision of SQL ResultSet "
                                           + "columns to field names and public setter methods on the return class.");
            }
View Full Code Here

                return _resultSet.getClob(index);
            case TypeMappingsFactory.TYPE_ARRAY:
                return _resultSet.getArray(index);
            case TypeMappingsFactory.TYPE_READER:
            case TypeMappingsFactory.TYPE_STREAM:
                throw new ControlException("streaming return types are not supported by the JdbcControl; use ResultSet instead");
            case TypeMappingsFactory.TYPE_STRUCT:
            case TypeMappingsFactory.TYPE_UNKNOWN:
                // JAVA_TYPE (could be any), or REF
                return _resultSet.getObject(index);
            default:
                throw new ControlException("internal error: unknown type ID: " + Integer.toString(resultType));
        }
    }
View Full Code Here

                }

                return RowMapperFactory.getRowMapper(resultSet, returnType, cal).mapRowToReturnType();
            }
        } catch (SQLException e) {
            throw new ControlException(e.getMessage(), e);
        }
    }
View Full Code Here

                    return _tmf.fixNull(m.getReturnType());
                }
                return RowMapperFactory.getRowMapper(resultSet, returnType, cal).mapRowToReturnType();
            }
        } catch (SQLException e) {
            throw new ControlException(e.getMessage(), e);
        }
    }
View Full Code Here

            }
        } catch (IllegalArgumentException iae) {
            ResultSetMetaData md = rs.getMetaData();
            // assuming no errors in resultSetObject() this can only happen
            // for single column result sets.
            throw new ControlException("The declared Java type for array " + componentType.getName()
                                       + "is incompatible with the SQL format of column " + md.getColumnName(1)
                                       + md.getColumnTypeName(1) + "which returns objects of type + "
                                       + list.get(0).getClass().getName());
        }
        return array;
View Full Code Here

    private Object getParameterValue(ControlBeanContext context, Method method, Object[] args) {
        Object value;
        try {
            value = context.getParameterValue(method, _nameQualifiers[0], args);
        } catch (IllegalArgumentException iae) {
            throw new ControlException("Invalid argument name in SQL statement: " + _nameQualifiers[0], iae);
        }

        for (int i = 1; i < _nameQualifiers.length; i++) {
            // handle maps, properties, and fields...
            value = extractValue(value, _nameQualifiers[i - 1], _nameQualifiers[i]);
View Full Code Here

                } catch (NoSuchMethodException e) {
                    getMethodFound = false;
                }

                if (getMethodFound) {
                    throw new ControlException("Colliding field accsessors in user defined class '"
                                               + aClass.getName() + "' for field '" + bName
                                               + "'. Please use is<FieldName> for boolean fields and get<FieldName> name for other datatypes.");
                }
            }
        } catch (NoSuchMethodException e) {
            // ignore
        }

        //
        // try a.getB() if a.isB() was not found.
        //
        if (getMethod == null) {
            try {
                getMethod = aClass.getMethod("get" + bNameCapped, (Class[])null);
            } catch (NoSuchMethodException e) {
                // ignore
            }
        }

        if (getMethod != null) {
            // OK- a.getB()
            try {
                value = getMethod.invoke(aValue, (Object[]) null);
            } catch (IllegalAccessException e) {
                throw new ControlException("Unable to access public method: " + e.toString());
            } catch (java.lang.reflect.InvocationTargetException e) {
                throw new ControlException("Exception thrown when executing : " + getMethod.getName() + "() to use as parameter");
            }
            return value;
        }

        //
        // try a.b
        //

        try {
            value = aClass.getField(bName).get(aValue);
            return value;
        } catch (NoSuchFieldException e) {
            // ignore
        } catch (IllegalAccessException e) {
            // ignore
        }

        //
        // try a.get(b)
        //

        if (aValue instanceof Map) {
            try {
                value = TypeMappingsFactory.getInstance().lookupType(aValue, new Object[]{bName});
                return value;
            } catch (Exception mapex) {
                throw new ControlException("Exception thrown when executing Map.get() to resolve parameter" + mapex.toString());
            }
        }

        // no other options...
        throw new ControlException("Illegal argument in SQL statement: " + _parameterName
                                    + "; unable to find suitable method of retrieving property " + bName
                                    + " out of object " + aName + ".");
    }
View Full Code Here

            // is this a request for generatedKeys ?
            //
            if (_getGeneratedKeys) {

                if (_callableStatement) {
                    throw new ControlException("getGeneratedKeys not supported for CallableStatements");
                }

                if (_genKeyColumnNames.length > 0) {
                    preparedStatement = connection.prepareStatement(sql, _genKeyColumnNames);
                } else if (_genKeyColumnIndexes.length > 0) {
                    preparedStatement = connection.prepareStatement(sql, _genKeyColumnIndexes);
                } else {
                    preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                }

            } else {

                if (_holdability == JdbcControl.HoldabilityType.DRIVER_DEFAULT) {
                    if (_scrollType == JdbcControl.ScrollType.DRIVER_DEFAULT) {
                        preparedStatement = (_callableStatement) ? connection.prepareCall(sql) : connection.prepareStatement(sql);
                    } else {
                        preparedStatement = (_callableStatement)
                                ? connection.prepareCall(sql, _scrollType.getType(), _scrollType.getConcurrencyType())
                                : connection.prepareStatement(sql, _scrollType.getType(), _scrollType.getConcurrencyType());
                    }
                } else {
                    preparedStatement = (_callableStatement)
                            ? connection.prepareCall(sql, _scrollType.getType(), _scrollType.getConcurrencyType(), _holdability.getHoldability())
                            : connection.prepareStatement(sql, _scrollType.getType(), _scrollType.getConcurrencyType(), _holdability.getHoldability());
                }
            }

            //
            // If the method argument is of type SQLParameter, treat this statement as a CallableStatement,
            //
            if (_callableStatement) {
                for (SqlFragment sf : _children) {
                    if (sf.hasParamValue()) {
                        throw new ControlException("Cannot use parameter substution and SQLParameter array in the same method.");
                    }
                }
                JdbcControl.SQLParameter[] params = (JdbcControl.SQLParameter[]) arguments[0];
                if (params == null) {
                    return preparedStatement;
View Full Code Here

     * @throws SQLException
     */
    private void checkJdbcSupport(DatabaseMetaData metaData) throws SQLException {

        if (_getGeneratedKeys && !metaData.supportsGetGeneratedKeys()) {
            throw new ControlException("The database does not support getGeneratedKeys.");
        }

        if (_batchUpdate && !metaData.supportsBatchUpdates()) {
            throw new ControlException("The database does not support batchUpdates.");
        }

        if (_scrollType != JdbcControl.ScrollType.DRIVER_DEFAULT
                && !metaData.supportsResultSetConcurrency(_scrollType.getType(), _scrollType.getConcurrencyType())) {
            throw new ControlException("The database does not support the ResultSet concurrecy type: " + _scrollType.toString());
        }

        if (_holdability != JdbcControl.HoldabilityType.DRIVER_DEFAULT
                && !metaData.supportsResultSetHoldability(_holdability.getHoldability())) {
            throw new ControlException("The database does not support the ResultSet holdability type: " + _holdability.toString());
        }
    }
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.