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;
}
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);
}
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;
}
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;
}
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());
}
}
Aggregations