Search in sources :

Example 1 with Memo

use of com.dexels.navajo.document.types.Memo in project navajo by Dexels.

the class TestTMLJson method testMemo.

@Test
public void testMemo() throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
    JSONTML json = JSONTMLFactory.getInstance();
    Property prop = NavajoFactory.getInstance().createProperty(n, "memoProp", "", "", "");
    prop.setAnyValue(new Memo("This is a memo value"));
    n.getMessage("SimpleMessage").addProperty(prop);
    Writer sw = new StringWriter();
    json.format(n, sw, true);
    String result = sw.toString();
    logger.info(result);
    Assert.assertEquals("{\n  \"memoProp\" : \"This is a memo value\"\n}", result);
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Memo(com.dexels.navajo.document.types.Memo) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 2 with Memo

use of com.dexels.navajo.document.types.Memo 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)

Aggregations

Memo (com.dexels.navajo.document.types.Memo)2 Navajo (com.dexels.navajo.document.Navajo)1 Property (com.dexels.navajo.document.Property)1 JSONTML (com.dexels.navajo.document.json.JSONTML)1 Binary (com.dexels.navajo.document.types.Binary)1 ClockTime (com.dexels.navajo.document.types.ClockTime)1 Money (com.dexels.navajo.document.types.Money)1 NavajoType (com.dexels.navajo.document.types.NavajoType)1 Percentage (com.dexels.navajo.document.types.Percentage)1 Access (com.dexels.navajo.script.api.Access)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 Test (org.junit.Test)1