use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class DateAppendClockTime method testInvalidNumArguements.
@Test(expected = com.dexels.navajo.expression.api.TMLExpressionException.class)
public void testInvalidNumArguements() throws Exception {
Date date = new Date();
ClockTime cTime = new ClockTime("11:28");
System.out.println(" ------ Running Valid Parameters case ------ ");
System.out.println("Sending Date :: " + date);
System.out.println("Sending ClockTime :: " + cTime);
da.reset();
System.out.println(da.evaluate());
da.evaluate();
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class StandardFunctionsTest method testToMilliseconds.
@Test
public void testToMilliseconds() {
FunctionInterface fi = fff.getInstance(cl, "ToMilliseconds");
fi.reset();
fi.insertStopwatchOperand(new StopwatchTime(20));
Object o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Integer.class, o.getClass());
fi.reset();
fi.insertClockTimeOperand(new ClockTime(new Date()));
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Long.class, o.getClass());
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class SQLMapHelper method setParameter.
/**
* Set the parameters for the statement
* @param statement
* @param param
* @param idx
* @param binaryStreamList
* @param dbIdentifier
* @param isLegacyMode
* @param debug
* @param myAccess
* @return PreparedStatement
* @throws java.sql.SQLException
*/
public static PreparedStatement setParameter(PreparedStatement statement, final Object param, final int idx, StreamClosable callback, String dbIdentifier, boolean isLegacyMode, boolean debug, Access myAccess) throws java.sql.SQLException {
Access access = myAccess;
if (access == null) {
access = new Access();
if (debug) {
Access.writeToConsole(access, "Created a new Access object to write to the console");
}
}
if ((param == null) || (param instanceof NavajoType && !(param instanceof Binary) && ((NavajoType) param).isEmpty())) {
if (SQLMapConstants.POSTGRESDB.equals(dbIdentifier) || SQLMapConstants.ENTERPRISEDB.equals(dbIdentifier) || SQLMapConstants.ORACLEDB.equals(dbIdentifier)) {
if (debug) {
Access.writeToConsole(access, "Had to do something in order to not get the cast error from a null value, because it concerns " + dbIdentifier + "\n");
}
if (param == null) {
statement.setNull(idx + 1, Types.NULL);
} else {
statement.setNull(idx + 1, Types.VARCHAR);
}
} else {
statement.setNull(idx + 1, Types.VARCHAR);
}
} else if (param instanceof String) {
statement.setString(idx + 1, (String) param);
} else if (param instanceof Integer) {
statement.setInt(idx + 1, ((Integer) param).intValue());
} else if (param instanceof Long) {
statement.setLong(idx + 1, ((Long) param).longValue());
} else if (param instanceof Double) {
statement.setDouble(idx + 1, ((Double) param).doubleValue());
} else if (param instanceof Percentage) {
statement.setDouble(idx + 1, ((Percentage) param).doubleValue());
} else if (param instanceof java.util.Date) {
long time = ((java.util.Date) param).getTime();
if (isLegacyMode) {
java.sql.Date sqlDate = new java.sql.Date(time);
statement.setDate(idx + 1, sqlDate);
} else {
Timestamp sqlDate = new java.sql.Timestamp(time);
statement.setTimestamp(idx + 1, sqlDate);
}
} else if (param instanceof Boolean) {
// So prevent the error by using setInt instead
if (SQLMapConstants.POSTGRESDB.equals(dbIdentifier) || SQLMapConstants.ENTERPRISEDB.equals(dbIdentifier)) {
if (debug) {
Access.writeToConsole(access, "Used setInt instead of setBoolean, because it concerns " + dbIdentifier + "\n");
}
statement.setInt(idx + 1, ((Boolean) param).booleanValue() == Boolean.TRUE ? 1 : 0);
} else {
statement.setBoolean(idx + 1, ((Boolean) param).booleanValue());
}
} else if (param instanceof ClockTime) {
java.sql.Timestamp sqlDate = new java.sql.Timestamp(((ClockTime) param).dateValue().getTime());
statement.setTimestamp(idx + 1, sqlDate);
} else if (param instanceof Money) {
statement.setDouble(idx + 1, ((Money) param).doubleValue());
} else if (param instanceof Memo) {
String memoString = ((Memo) param).toString();
statement.setCharacterStream(idx + 1, new StringReader(memoString), memoString.length());
} else if (param instanceof Binary) {
Binary b = (Binary) param;
setBlob(statement, idx, b, callback);
if (debug) {
Access.writeToConsole(access, "ADDED BLOB\n");
}
} else {
throw new SQLException("Unknown type encountered in SQLMap.setStatementParameters(): " + param);
}
return statement;
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class SQLMapHelper method getColumnValue.
/**
* Gets the columnvalue from the resultset while checking the correct datatype
* @param rs
* @param type
* @param columnIndex
* @return Object
* @throws SQLException
* @throws UserException
*/
public static Object getColumnValue(ResultSet rs, int type, int columnIndex) throws SQLException, UserException {
Object value = null;
ResultSetMetaData meta = rs.getMetaData();
switch(type) {
case Types.SQLXML:
case Types.CLOB:
case Types.NCLOB:
case Types.BINARY:
case Types.BLOB:
case Types.VARBINARY:
case Types.LONGVARBINARY:
InputStream is = rs.getBinaryStream(columnIndex);
if (is != null) {
value = new Binary(is);
}
break;
case Types.INTEGER:
case Types.BIGINT:
case Types.SMALLINT:
case Types.TINYINT:
int tmpValue = rs.getInt(columnIndex);
if (rs.wasNull()) {
} else {
value = Integer.valueOf(tmpValue);
}
break;
case Types.LONGNVARCHAR:
case Types.LONGVARCHAR:
case Types.NCHAR:
case Types.NVARCHAR:
case Types.CHAR:
case Types.VARCHAR:
if (rs.getString(columnIndex) != null) {
value = new String(rs.getString(columnIndex));
}
break;
case Types.NUMERIC:
int scale = meta.getScale(columnIndex);
if (scale <= 0) {
if (// java max int takes 19 digits
meta.getPrecision(columnIndex) >= 19) {
// Note that if we want to support such high precision, also getSimplefiedType (see below) needs to change
logger.warn("getColumnValue: Retrieving value with great precision ( " + meta.getPrecision(columnIndex) + " ), possible truncation taking place");
}
int tmpValueNumeric = rs.getInt(columnIndex);
if (!rs.wasNull()) {
value = Integer.valueOf(tmpValueNumeric);
}
} else {
double tmpValueDouble = rs.getDouble(columnIndex);
if (!rs.wasNull()) {
value = Double.valueOf(tmpValueDouble);
}
}
break;
case Types.DECIMAL:
case Types.FLOAT:
case Types.DOUBLE:
double tmpValueDouble = rs.getDouble(columnIndex);
if (!rs.wasNull()) {
value = Double.valueOf(tmpValueDouble);
}
break;
case Types.DATE:
if (rs.getDate(columnIndex) != null) {
long l = -1;
try {
Date d = rs.getDate(columnIndex);
l = d.getTime();
} catch (Exception e) {
Date d = rs.getDate(columnIndex);
l = d.getTime();
}
value = new java.util.Date(l);
}
break;
case // For Oracle; timestamp with
-101:
// clocktime.
if (rs.getTimestamp(columnIndex) != null) {
long l = -1;
try {
Timestamp ts = rs.getTimestamp(columnIndex);
l = ts.getTime();
} catch (Exception e) {
Date d = rs.getDate(columnIndex);
l = d.getTime();
}
value = new ClockTime(new java.util.Date(l));
}
break;
case Types.TIMESTAMP:
if (rs.getTimestamp(columnIndex) != null) {
long l = -1;
try {
Timestamp ts = rs.getTimestamp(columnIndex);
l = ts.getTime();
} catch (Exception e) {
Date d = rs.getDate(columnIndex);
l = d.getTime();
}
value = new java.util.Date(l);
}
break;
case Types.TIME:
value = new Time(rs.getTime(columnIndex).getTime());
break;
case Types.BOOLEAN:
case Types.BIT:
boolean tmpValueBoolean = rs.getBoolean(columnIndex);
if (!rs.wasNull()) {
value = Boolean.valueOf(tmpValueBoolean);
}
break;
case Types.ARRAY:
value = rs.getArray(columnIndex);
break;
case Types.REF:
value = rs.getRef(columnIndex);
break;
case Types.ROWID:
value = rs.getRowId(columnIndex);
break;
case Types.NULL:
break;
// TODO: No idea what to do with these types
case Types.DATALINK:
case Types.DISTINCT:
case Types.JAVA_OBJECT:
case Types.OTHER:
case Types.REAL:
case Types.STRUCT:
value = rs.getObject(columnIndex);
break;
default:
// If it concerns an unknown type, then throw exception
throw new UserException(-1, "Unknown SQL type : " + type);
}
return value;
}
Aggregations