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