Search in sources :

Example 11 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ErrorMsg method fatal.

/**
 * Indicates a fatal situation (implementation error).
 * @param msg error message
 */
public void fatal(String msg) throws JDOFatalInternalException {
    JDOFatalInternalException ex = new JDOFatalInternalException(msg);
    logger.throwing("jqlc.ErrorMsg", "fatal", ex);
    throw ex;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 12 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ParameterTable method defineValueByIndex.

/**
 */
private void defineValueByIndex(int index, Object value) {
    // index < 0 => implementation error
    if (index < 0)
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "jqlc.parametertable.definevaluebyindex.wrongindex", String.valueOf(index)));
    // index > type.size => too many actual parameters
    if (index >= types.size())
        throw new JDOQueryException(// NOI18N
        I18NHelper.getMessage(messages, "jqlc.parametertable.definevaluebyindex.wrongnumberofargs"));
    // check type compatibility of actual and formal parameter
    Class formalType = ((Type) types.get(index)).getJavaClass();
    if (!isCompatibleValue(formalType, value)) {
        String actualTypeName = ((value == null) ? "<type of null>" : value.getClass().getName());
        throw new JDOQueryException(// NOI18N
        I18NHelper.getMessage(// NOI18N
        messages, // NOI18N
        "jqlc.parametertable.definevaluebyindex.typemismatch", actualTypeName, formalType.getName()));
    }
    // everything is ok => set the actual parameters's value
    values.set(index, value);
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) Type(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.Type) WrapperClassType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.WrapperClassType) DateType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType) StringType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.StringType) MathType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.MathType) PrimitiveType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.PrimitiveType) JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Example 13 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class VariableTable method markConstraint.

/**
 * Mark the specified variable as constaint with the specified expr.
 * The method sets the constraint field of the VarInfo object to true.
 */
public void markConstraint(JQLAST variable, JQLAST expr) {
    String name = variable.getText();
    VarInfo entry = (VarInfo) varInfos.get(name);
    if (entry == null)
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "jqlc.variabletable.markconstraint.varnotfound", name));
    String old = (entry.constraint == null ? null : entry.constraint.getText());
    if ((old != null) && !old.equals(expr.getText())) {
        errorMsg.unsupported(variable.getLine(), variable.getColumn(), // NOI18N
        I18NHelper.getMessage(// NOI18N
        messages, // NOI18N
        "jqlc.variabletable.markconstraint.multiple", name));
    }
    entry.constraint = expr;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 14 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ResultDesc method getValueFromResultSet.

/**
 * Gets value at index from resultData. resultData is queried for passed resultType.
 * @param resultData The resultset object.
 * @param index Index at which result needs to be obtained.
 * @param resultType Type of expected result.
 * @param columnType Types of column at index <code>index</code> as represented by
 *                      java.sql.Types.
 * @return value from <code>resultData</code> at <code>index</code>.
 */
private static Object getValueFromResultSet(ResultSet resultData, int index, int resultType, int columnType) throws SQLException {
    Object retVal = null;
    try {
        switch(resultType) {
            case FieldTypeEnumeration.BOOLEAN_PRIMITIVE:
            case FieldTypeEnumeration.BOOLEAN:
                boolean booleanValue = resultData.getBoolean(index);
                if (!resultData.wasNull())
                    retVal = new Boolean(booleanValue);
                break;
            case FieldTypeEnumeration.CHARACTER_PRIMITIVE:
            case FieldTypeEnumeration.CHARACTER:
                String strValue = resultData.getString(index);
                if (strValue != null)
                    retVal = FieldDesc.getCharFromString(strValue);
                break;
            case FieldTypeEnumeration.BYTE_PRIMITIVE:
            case FieldTypeEnumeration.BYTE:
                byte byteValue = resultData.getByte(index);
                if (!resultData.wasNull())
                    retVal = new Byte(byteValue);
                break;
            case FieldTypeEnumeration.SHORT_PRIMITIVE:
            case FieldTypeEnumeration.SHORT:
                short shortValue = resultData.getShort(index);
                if (!resultData.wasNull())
                    retVal = new Short(shortValue);
                break;
            case FieldTypeEnumeration.INTEGER_PRIMITIVE:
            case FieldTypeEnumeration.INTEGER:
                int intValue = resultData.getInt(index);
                if (!resultData.wasNull())
                    retVal = new Integer(intValue);
                break;
            case FieldTypeEnumeration.LONG_PRIMITIVE:
            case FieldTypeEnumeration.LONG:
                long longValue = resultData.getLong(index);
                if (!resultData.wasNull())
                    retVal = new Long(longValue);
                break;
            case FieldTypeEnumeration.FLOAT_PRIMITIVE:
            case FieldTypeEnumeration.FLOAT:
                float floatValue = resultData.getFloat(index);
                if (!resultData.wasNull())
                    retVal = new Float(floatValue);
                break;
            case FieldTypeEnumeration.DOUBLE_PRIMITIVE:
            case FieldTypeEnumeration.DOUBLE:
                double doubleValue = resultData.getDouble(index);
                if (!resultData.wasNull())
                    retVal = new Double(doubleValue);
                break;
            case FieldTypeEnumeration.BIGDECIMAL:
            case FieldTypeEnumeration.BIGINTEGER:
                retVal = resultData.getBigDecimal(index);
                if ((resultType == FieldTypeEnumeration.BIGINTEGER) && (retVal != null)) {
                    retVal = ((java.math.BigDecimal) retVal).toBigInteger();
                }
                break;
            case FieldTypeEnumeration.STRING:
                if (LocalFieldDesc.isCharLobType(columnType)) {
                    Reader reader = resultData.getCharacterStream(index);
                    retVal = readCharacterStreamToString(reader);
                } else {
                    retVal = resultData.getString(index);
                }
                break;
            case FieldTypeEnumeration.SQL_DATE:
                retVal = resultData.getDate(index);
                break;
            case FieldTypeEnumeration.SQL_TIME:
                retVal = resultData.getTime(index);
                break;
            case FieldTypeEnumeration.UTIL_DATE:
            case FieldTypeEnumeration.SQL_TIMESTAMP:
                // Variable ts is introduced to avoid cast
                Timestamp ts;
                ts = resultData.getTimestamp(index);
                if (resultType == FieldTypeEnumeration.UTIL_DATE && ts != null) {
                    retVal = new Date(ts.getTime());
                } else {
                    retVal = ts;
                }
                break;
            case FieldTypeEnumeration.ARRAY_BYTE_PRIMITIVE:
                InputStream is = resultData.getBinaryStream(index);
                retVal = readInputStreamToByteArray(is);
                break;
            case FieldTypeEnumeration.NOT_ENUMERATED:
                // RESOLVE:
                // We should only get here for getting values for hidden fields.
                // hiddenFields does not have their java type initialized. Its sort of difficult
                // to initialize java type without major re-org of the code in ClassDesc :(.
                // But once it is done, we should throw an exception if we reach here.
                // 
                // For now retrieve value for hidden fields as object as they are any way
                // stored as Object in SQLStatemanager.
                retVal = resultData.getObject(index);
                break;
            default:
                // Please update this method to handle new type.
                throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "sqlstore.resultdesc.unknownfieldtype", resultType));
        }
    // switch
    } catch (SQLException e) {
        if (logger.isLoggable(Logger.WARNING)) {
            Object[] items = { new Integer(index), new Integer(resultType), new Integer(columnType), e };
            logger.log(Logger.WARNING, "sqlstore.resultdesc.errorgettingvalefromresulset", items);
        }
        throw e;
    }
    // to case FieldTypeEnumeration.String
    if (LocalFieldDesc.isFixedCharType(columnType) && // Character. Do not convert them to String.
    resultType != FieldTypeEnumeration.CHARACTER_PRIMITIVE && resultType != FieldTypeEnumeration.CHARACTER && retVal != null) {
        // To support char columns, we rtrim fields mapped to fixedchar.
        retVal = StringHelper.rtrim(retVal.toString());
    }
    return retVal;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) SQLException(java.sql.SQLException) Timestamp(java.sql.Timestamp)

Example 15 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ResultDesc method findOrCreateStateManager.

/**
 * Returns a StateManager which PC instance to be populated with the values.
 * If such instance exists in this PersistenceManager cache,
 * it is returned, otherwise a new instance is created.
 */
private StateManager findOrCreateStateManager(ResultSet resultData, PersistenceManager pm) {
    try {
        Class oidClass = config.getOidClass();
        Object oid = oidClass.newInstance();
        // Copy key field values
        Field[] keyFields = config.getKeyFields();
        String[] keyNames = config.getKeyFieldNames();
        for (int i = 0; i < keyFields.length; i++) {
            Field keyField = keyFields[i];
            String keyName = keyNames[i];
            FieldDesc fd = config.getField(keyName);
            int index = fieldNames.indexOf(keyName);
            ResultFieldDesc rfd = (ResultFieldDesc) fields.get(index);
            Object v = getConvertedObject(resultData, rfd.getColumnRef(), fd, null);
            if (debug) {
                // NOI18N
                logger.finest("sqlstore.resultdesc.marking_key_field", keyName);
            }
            if (v == null) {
                return null;
            }
            keyField.set(oid, v);
        }
        return pm.findOrCreateStateManager(oid, config.getPersistenceCapableClass());
    } catch (Exception e) {
        // RESOLVE...
        throw new JDOFatalInternalException(e.getMessage());
    }
}
Also used : Field(java.lang.reflect.Field) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) SQLException(java.sql.SQLException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ForeignFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc) FieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)

Aggregations

JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)26 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)4 ColumnElement (org.netbeans.modules.dbschema.ColumnElement)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)3 ArrayList (java.util.ArrayList)3 JDODataStoreException (com.sun.jdo.api.persistence.support.JDODataStoreException)2 JDOException (com.sun.jdo.api.persistence.support.JDOException)2 JDOUnsupportedOptionException (com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException)2 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)2 RetrieveDescImpl (com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)2 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 TableElement (org.netbeans.modules.dbschema.TableElement)2 JDOQueryException (com.sun.jdo.api.persistence.support.JDOQueryException)1 ClassDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc)1 FieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)1 ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)1 TableDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc)1 DateType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType)1