use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.
the class HomeRoutingManagement method store.
/**
* Persist
*/
public void store() {
try {
XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream(persistFile.toString()));
writer.setBinding(binding);
writer.setIndentation(TAB_INDENT);
writer.write(ccMccmncCollection, CC_MCCMNS_COLLECTION, CcMccmncCollection.class);
writer.close();
} catch (Exception e) {
logger.error("Error while persisting the ccMccmncCollection in file", e);
}
}
use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.
the class NN_DBOper method createRecord.
// SCHEMA 1 ************************
public void createRecord(long dueSlot, Sms sms) throws PersistenceException {
PreparedStatementCollection2 psc = getStatementCollection(sms.getSubmitDate());
try {
PreparedStatement ps = psc.createRecordData;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.setString(Schema.COLUMN_ADDR_DST_DIGITS, sms.getSmsSet().getDestAddr());
boundStatement.setInt(Schema.COLUMN_ADDR_DST_TON, sms.getSmsSet().getDestAddrTon());
boundStatement.setInt(Schema.COLUMN_ADDR_DST_NPI, sms.getSmsSet().getDestAddrNpi());
boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
if (sms.getSourceAddr() != null) {
boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr());
}
boundStatement.setInt(Schema.COLUMN_ADDR_SRC_TON, sms.getSourceAddrTon());
boundStatement.setInt(Schema.COLUMN_ADDR_SRC_NPI, sms.getSourceAddrNpi());
boundStatement.setInt(Schema.COLUMN_DUE_DELAY, sms.getSmsSet().getDueDelay());
if (sms.getSmsSet().getStatus() != null)
boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode());
boundStatement.setBool(Schema.COLUMN_ALERTING_SUPPORTED, sms.getSmsSet().isAlertingSupported());
boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
boundStatement.setInt(Schema.COLUMN_MO_MESSAGE_REF, sms.getMoMessageRef());
if (sms.getOrigEsmeName() != null) {
boundStatement.setString(Schema.COLUMN_ORIG_ESME_NAME, sms.getOrigEsmeName());
}
if (sms.getOrigSystemId() != null) {
boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId());
}
if (sms.getSubmitDate() != null) {
DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate());
}
if (sms.getServiceType() != null) {
boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType());
}
boundStatement.setInt(Schema.COLUMN_ESM_CLASS, sms.getEsmClass());
boundStatement.setInt(Schema.COLUMN_PROTOCOL_ID, sms.getProtocolId());
boundStatement.setInt(Schema.COLUMN_PRIORITY, sms.getPriority());
boundStatement.setInt(Schema.COLUMN_REGISTERED_DELIVERY, sms.getRegisteredDelivery());
boundStatement.setInt(Schema.COLUMN_REPLACE, sms.getReplaceIfPresent());
boundStatement.setInt(Schema.COLUMN_DATA_CODING, sms.getDataCoding());
boundStatement.setInt(Schema.COLUMN_DEFAULT_MSG_ID, sms.getDefaultMsgId());
if (sms.getShortMessage() != null) {
boundStatement.setBytes(Schema.COLUMN_MESSAGE, ByteBuffer.wrap(sms.getShortMessage()));
}
if (sms.getScheduleDeliveryTime() != null) {
DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, sms.getScheduleDeliveryTime());
}
if (sms.getValidityPeriod() != null) {
DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_VALIDITY_PERIOD, sms.getValidityPeriod());
}
boundStatement.setInt(Schema.COLUMN_DELIVERY_COUNT, sms.getDeliveryCount());
if (sms.getTlvSet().getOptionalParameterCount() > 0) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
writer.setIndentation("\t");
writer.write(sms.getTlvSet(), TLV_SET, TlvSet.class);
writer.close();
byte[] rawData = baos.toByteArray();
String serializedEvent = new String(rawData);
boundStatement.setString(Schema.COLUMN_OPTIONAL_PARAMETERS, serializedEvent);
} catch (XMLStreamException e) {
String msg = "XMLStreamException when serializing optional parameters for '" + sms.getDbId() + "'!";
throw new PersistenceException(msg, e);
}
}
ResultSet res = session.execute(boundStatement);
ps = psc.createRecordSlots;
boundStatement = new BoundStatement(ps);
boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
res = session.execute(boundStatement);
ps = psc.createRecordDests;
boundStatement = new BoundStatement(ps);
boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
boundStatement.setBool(Schema.COLUMN_SENT, false);
res = session.execute(boundStatement);
} catch (Exception e1) {
String msg = "Failed createRecord !";
throw new PersistenceException(msg, e1);
}
}
Aggregations