use of com.dexels.navajo.script.api.Access 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.script.api.Access in project navajo by Dexels.
the class MessageMapTest method test3.
@Test
public void test3() throws Exception {
// message1 array and message2 simple message test but with one access obj
/* building message 1 array*/
Navajo n = NavajoFactory.getInstance().createNavajo();
Message array = NavajoFactory.getInstance().createMessage(n, "Array");
n.addMessage(array);
array.setType(Message.MSG_TYPE_ARRAY);
for (int i = 0; i < 4; i++) {
Message c = NavajoFactory.getInstance().createMessage(n, "Array");
c.setIndex(i);
c.setType(Message.MSG_TYPE_ARRAY_ELEMENT);
array.addElement(c);
if (i % 2 == 0) {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 10) + "", 0, "", "out");
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
} else {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 20) + "", 0, "", "out");
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
}
}
n.write(System.err);
/* building message 2 simple message */
Navajo n2 = NavajoFactory.getInstance().createNavajo();
Message simpleMsg = NavajoFactory.getInstance().createMessage(n, "Simple");
simpleMsg.setType(Message.MSG_TYPE_SIMPLE);
Property p1 = NavajoFactory.getInstance().createProperty(n, "Prop", Property.STRING_PROPERTY, "Test1", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "SubProp", Property.STRING_PROPERTY, "Test2", 0, "", "out");
simpleMsg.addProperty(p1);
simpleMsg.addProperty(p1a);
n2.addMessage(simpleMsg);
/*end building messages*/
n2.write(System.err);
Access a = new Access();
a.setOutputDoc(n);
MessageMap mm = new MessageMap();
mm.load(a);
mm.setJoinMessage1("Array");
/*for the 2nd message*/
a.setOutputDoc(n2);
mm.load(a);
mm.setJoinMessage2("Simple");
mm.setJoinType("outer");
Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
resultMessage.setType("array");
n.addMessage(resultMessage);
a.setCurrentOutMessage(resultMessage);
ResultMessage[] result = mm.getResultMessage();
a.setCurrentOutMessage(null);
mm.store();
for (int l = 0; l < result.length; l++) {
assertEquals("PC", result[l].getProperty("Product"));
assertEquals("Test1", result[l].getProperty("Prop"));
assertEquals("Test2", result[l].getProperty("SubProp"));
}
}
use of com.dexels.navajo.script.api.Access in project navajo by Dexels.
the class TestAdapters method testMessageMap.
// TODO Add asserts
@Test
public void testMessageMap() throws UserException, MappableException {
Navajo out = NavajoFactory.getInstance().createNavajo();
Message msg1 = NavajoFactory.getInstance().createMessage(out, "message1");
msg1.setType("array");
Message msg2 = NavajoFactory.getInstance().createMessage(out, "message2");
msg2.setType("array");
out.addMessage(msg1);
out.addMessage(msg2);
for (int i = 0; i < 4; i++) {
Message m1 = NavajoFactory.getInstance().createMessage(out, "message1");
Message m2 = NavajoFactory.getInstance().createMessage(out, "message2");
msg1.addMessage(m1);
msg2.addMessage(m2);
Property p;
p = NavajoFactory.getInstance().createProperty(out, "propje1", Property.STRING_PROPERTY, "" + 3 * i, 0, "", "");
m1.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "propje2", Property.STRING_PROPERTY, "" + 8 * i, 0, "", "");
m1.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "propje3", Property.STRING_PROPERTY, "propjes" + 23 * i, 0, "", "");
m1.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "blieblab", Property.STRING_PROPERTY, "" + 3 * i, 0, "", "");
m2.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "apenoot2", Property.STRING_PROPERTY, "apenoot" + 8 * i, 0, "", "");
m2.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "apfelkorn", Property.STRING_PROPERTY, "apfelkorn" + 23 * i, 0, "", "");
m2.addProperty(p);
}
Property p;
Message m1 = NavajoFactory.getInstance().createMessage(out, "message1");
msg1.addMessage(m1);
p = NavajoFactory.getInstance().createProperty(out, "propje1", Property.STRING_PROPERTY, "343", 0, "", "");
m1.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "propje2", Property.STRING_PROPERTY, "12321", 0, "", "");
m1.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "propje3", Property.STRING_PROPERTY, "propjes2321", 0, "", "");
m1.addProperty(p);
// Additional m2.
Message m2 = NavajoFactory.getInstance().createMessage(out, "message2");
msg2.addMessage(m2);
p = NavajoFactory.getInstance().createProperty(out, "blieblab", Property.STRING_PROPERTY, "0", 0, "", "");
m2.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "apenoot2", Property.STRING_PROPERTY, "12321", 0, "", "");
m2.addProperty(p);
p = NavajoFactory.getInstance().createProperty(out, "apfelkorn", Property.STRING_PROPERTY, "propjes2321", 0, "", "");
m2.addProperty(p);
Access a = new Access();
a.setOutputDoc(out);
MessageMap mm = new MessageMap();
mm.load(a);
mm.setSuppressProperties("propje3");
mm.setJoinMessage1("message1");
mm.setJoinMessage2("message2");
mm.setJoinCondition("propje1=blieblab");
mm.setJoinType("inner");
Message resultMessage = NavajoFactory.getInstance().createMessage(out, "ResultingMessage");
resultMessage.setType("array");
out.addMessage(resultMessage);
a.setCurrentOutMessage(resultMessage);
ResultMessage[] result = mm.getResultMessage();
for (int i = 0; i < result.length; i++) {
Message resultElementMessage = NavajoFactory.getInstance().createMessage(out, "ResultingMessage");
resultElementMessage.setType("array_element");
resultMessage.addElement(resultElementMessage);
a.setCurrentOutMessage(resultElementMessage);
result[i].load(a);
result[i].store();
}
a.setCurrentOutMessage(null);
mm.store();
}
use of com.dexels.navajo.script.api.Access in project navajo by Dexels.
the class TestNavajoMap method testCopyInputMessage.
@Test
public void testCopyInputMessage() throws MappableException, UserException {
final String TEST_INTEGER_1 = "6";
final String TEST_INTEGER_2 = "3";
// Create a message on the in doc with a test value.
Navajo inDoc = NavajoFactory.getInstance().createNavajo();
Property property = NavajoFactory.getInstance().createProperty(outDoc, "newProperty", INTEGER_PROPERTY, TEST_INTEGER_1, 0, "", "out");
Message message = NavajoFactory.getInstance().createMessage(outDoc, "SimpleMessage");
message.addProperty(property);
inDoc.addMessage(message);
// Initialize the navajomap.
DispatcherFactory.createDispatcher(new Dispatcher());
Access access = new Access();
access.setInDoc(inDoc);
access.setOutputDoc(outDoc);
map.load(access);
// Create a property on the navajomap with a different value that could be overwritten with the test value.
map.setPropertyName("/SimpleMessage/newProperty");
map.setPropertyType(INTEGER_PROPERTY);
map.setProperty(TEST_INTEGER_2);
// Test the method while copying the input message.
map.setCopyInputMessages("SimpleMessage");
map.prepareOutDoc();
// Ensure that the property created on the navajomap is not overwritten.
assertEquals(TEST_INTEGER_2, map.outDoc.getMessage("SimpleMessage").getProperty("newProperty").getValue());
}
use of com.dexels.navajo.script.api.Access in project navajo by Dexels.
the class TestNavajoMap method testSendThroughNotSet.
@Test
public void testSendThroughNotSet() throws MappableException, UserException {
Navajo inDoc = NavajoFactory.getInstance().createNavajo();
Property property = NavajoFactory.getInstance().createProperty(inDoc, "Meaning", INTEGER_PROPERTY, "42", 0, "", "out");
Message message = NavajoFactory.getInstance().createMessage(inDoc, "SendThrough");
message.addProperty(property);
inDoc.addMessage(message);
Message global = NavajoFactory.getInstance().createMessage(inDoc, "Global");
global.setScope(Message.MSG_SCOPE_GLOBAL);
inDoc.addMessage(global);
Message local = NavajoFactory.getInstance().createMessage(inDoc, "Local");
local.setScope(Message.MSG_SCOPE_LOCAL);
inDoc.addMessage(local);
// Initialize the navajomap.
DispatcherFactory.createDispatcher(new Dispatcher());
Access access = new Access();
access.setInDoc(inDoc);
access.setOutputDoc(outDoc);
map.load(access);
map.prepareOutDoc();
assertFalse(map.getSendThrough());
assertNull(map.outDoc.getMessage("SendThrough"));
assertEquals(Message.MSG_SCOPE_GLOBAL, map.outDoc.getMessage("Global").getScope());
assertNull(map.outDoc.getMessage("Local"));
}
Aggregations