use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class TimestampRDBMSMapping method getTimestamp.
/**
* Method to access a Timestamp from the ResultSet.
* @param rs The ResultSet
* @param param The parameter position in the ResultSet row.
* @return The Timestamp object
*/
protected Timestamp getTimestamp(ResultSet rs, int param) {
Timestamp value;
Calendar cal = storeMgr.getCalendarForDateTimezone();
try {
// TODO pass the calendar to Oracle or HSQLDB makes it loses milliseconds
if (cal != null) {
value = rs.getTimestamp(param, cal);
} else {
value = rs.getTimestamp(param);
}
} catch (SQLException e) {
try {
String s = rs.getString(param);
if (rs.wasNull()) {
value = null;
} else {
// JDBC driver has returned something other than a java.sql.Timestamp so we convert it to a Timestamp using its string form.
value = s == null ? null : TypeConversionHelper.stringToTimestamp(s, cal);
}
} catch (SQLException nestedEx) {
throw new NucleusDataStoreException(Localiser.msg("055002", "Timestamp", "" + param, column, e.getMessage()), nestedEx);
}
}
return value;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class CharRDBMSMapping method getChar.
/**
* Method to extract a character from the ResultSet at the specified position
* @param rs The Result Set
* @param param The parameter position
* @return the character
*/
public char getChar(ResultSet rs, int param) {
char value;
try {
String str = rs.getString(param);
if (str == null) {
return 0;
}
value = str.charAt(0);
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("055002", "char", "" + param, column, e.getMessage()), e);
}
return value;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class ClobRDBMSMapping method getObject.
public Object getObject(ResultSet rs, int param) {
if (getDatastoreAdapter().supportsOption(DatastoreAdapter.CLOB_SET_USING_SETSTRING)) {
return super.getObject(rs, param);
}
Object value;
try {
Clob clob = rs.getClob(param);
if (!rs.wasNull()) {
BufferedReader br = new BufferedReader(clob.getCharacterStream());
try {
int c;
StringBuilder sb = new StringBuilder();
while ((c = br.read()) != -1) {
sb.append((char) c);
}
value = sb.toString();
} finally {
br.close();
}
} else {
value = null;
}
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("055002", "Object", "" + param, column, e.getMessage()), e);
} catch (IOException e) {
throw new NucleusDataStoreException(Localiser.msg("055002", "Object", "" + param, column, e.getMessage()), e);
}
return value;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class DecimalRDBMSMapping method getObject.
public Object getObject(ResultSet rs, int param) {
Object value;
try {
if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_LANG_INTEGER)) {
value = rs.getBigDecimal(param);
value = value == null ? null : Integer.valueOf(((BigDecimal) value).toBigInteger().intValue());
} else if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_LANG_LONG)) {
value = rs.getBigDecimal(param);
value = value == null ? null : Long.valueOf(((BigDecimal) value).toBigInteger().longValue());
} else if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_MATH_BIGINTEGER)) {
value = rs.getBigDecimal(param);
value = value == null ? null : ((BigDecimal) value).toBigInteger();
} else if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_MATH_BIGDECIMAL)) {
value = rs.getBigDecimal(param);
} else if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_LANG_FLOAT)) {
double d = rs.getDouble(param);
value = rs.wasNull() ? null : (float) d;
} else if (getJavaTypeMapping().getJavaType().getName().equals(ClassNameConstants.JAVA_LANG_DOUBLE)) {
double d = rs.getDouble(param);
value = rs.wasNull() ? null : d;
} else {
int i = rs.getInt(param);
value = rs.wasNull() ? null : Integer.valueOf(i);
}
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("055002", "Object", "" + param, column, e.getMessage()), e);
}
return value;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class LongVarcharRDBMSMapping method getObject.
public Object getObject(ResultSet rs, int param) {
Object value;
try {
String s = rs.getString(param);
value = rs.wasNull() ? null : s;
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("055002", "Object", "" + param, column, e.getMessage()), e);
}
return value;
}
Aggregations