Search in sources :

Example 21 with ClockTime

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();
}
Also used : ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date) Test(org.junit.Test)

Example 22 with ClockTime

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());
}
Also used : StopwatchTime(com.dexels.navajo.document.types.StopwatchTime) FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date) Test(org.junit.Test)

Example 23 with ClockTime

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;
}
Also used : Percentage(com.dexels.navajo.document.types.Percentage) SQLException(java.sql.SQLException) NavajoType(com.dexels.navajo.document.types.NavajoType) Timestamp(java.sql.Timestamp) Access(com.dexels.navajo.script.api.Access) ClockTime(com.dexels.navajo.document.types.ClockTime) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Date(java.sql.Date) Money(com.dexels.navajo.document.types.Money) StringReader(java.io.StringReader) Binary(com.dexels.navajo.document.types.Binary) Memo(com.dexels.navajo.document.types.Memo)

Example 24 with ClockTime

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;
}
Also used : InputStream(java.io.InputStream) Time(java.sql.Time) ClockTime(com.dexels.navajo.document.types.ClockTime) ClockTime(com.dexels.navajo.document.types.ClockTime) Timestamp(java.sql.Timestamp) Date(java.sql.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) UserException(com.dexels.navajo.script.api.UserException) SQLException(java.sql.SQLException) ResultSetMetaData(java.sql.ResultSetMetaData) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException)

Aggregations

ClockTime (com.dexels.navajo.document.types.ClockTime)24 Date (java.util.Date)14 Test (org.junit.Test)8 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 Money (com.dexels.navajo.document.types.Money)6 Percentage (com.dexels.navajo.document.types.Percentage)6 StopwatchTime (com.dexels.navajo.document.types.StopwatchTime)5 Calendar (java.util.Calendar)5 Navajo (com.dexels.navajo.document.Navajo)4 Property (com.dexels.navajo.document.Property)4 Binary (com.dexels.navajo.document.types.Binary)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 Message (com.dexels.navajo.document.Message)3 Date (java.sql.Date)3 SQLException (java.sql.SQLException)3 Timestamp (java.sql.Timestamp)3 NavajoException (com.dexels.navajo.document.NavajoException)2 Operand (com.dexels.navajo.document.Operand)2 DatePattern (com.dexels.navajo.document.types.DatePattern)2 NavajoType (com.dexels.navajo.document.types.NavajoType)2