use of alma.cdbErrType.wrappers.AcsJCDBExceptionEx in project ACS by ACS-Community.
the class WDALImpl method set_DAO.
/**
* Change content of a node identified by curl so given xml is scanned for
* differences which are applied. This function can be invoked with full
* expanded version of the existing xml with some changes or it can be
* invoked by small xml with only changes to be applied. For example to
* change parameter 'Timeot' in Manager we can pass as xml
* <pre>
* <code>
* <?xml version="1.0" encoding="ISO-8859-1"?>
* <Manager Timeout="50.0"/>
* </code>
* </pre>
* and new value will be saved in the xml file.
*
* @param curl uri for the CDB node
* @param xml
*
* @throws CDBRecordDoesNotExistEx
* @throws CDBFieldDoesNotExistEx
* @throws CDBRecordIsReadOnlyEx
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
*/
public void set_DAO(String curl, String xml) throws CDBRecordDoesNotExistEx, CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBXMLErrorEx, CDBExceptionEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "set_DAO " + curl);
// check if node exists
if (!nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record does not exist: " + curl);
throw new CDBRecordDoesNotExistEx();
}
File xmlFile = getNodeFile(curl);
if (!xmlFile.canWrite()) {
throw new CDBRecordIsReadOnlyEx();
}
// read given xml and iterate through its content and check if something was changed
DAOImpl daoImp = null;
XMLHandler daoXMLSolver = null;
// get content of the given xml string using parser without any shemas and validation
// since given xml string come from a client that have no shemas and it is full expanded version
// of existing xml or it is smal composed xml of few properties
XMLHandler xmlSolver = new XMLHandler(false, logger);
// TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
//xmlSolver.setMarkArrays(2);
parseXML(xml, xmlSolver);
// get original xml that we will use to compare
xml = dalImpl.get_DAO(curl);
daoXMLSolver = new XMLHandler(false, logger);
parseXML(xml, daoXMLSolver);
daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, logger);
// iterater throuth given xml and put changed attributes in map
LinkedHashMap map = new LinkedHashMap();
try {
checkforChanges("", xmlSolver.m_rootNode, map, daoImp);
saveChanges(curl, map);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
} catch (AcsJCDBXMLErrorEx e) {
throw e.toCDBXMLErrorEx();
} catch (AcsJCDBExceptionEx e) {
throw e.toCDBExceptionEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBExceptionEx in project ACS by ACS-Community.
the class HibernateWDALImpl method saveChanges.
/**
* Save changes given by map to the node identified by curl
*
* @param curl
* @param propertyMap
*
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
* @throws CDBFieldDoesNotExistEx
*/
public void saveChanges(String curl, Map propertyMap) throws CDBXMLErrorEx, CDBExceptionEx, CDBFieldDoesNotExistEx, CDBRecordDoesNotExistEx {
Object node = curl.length() == 0 ? rootNode : DOMJavaClassIntrospector.getNode(curl, rootNode);
if (node == null || DOMJavaClassIntrospector.isPrimitive(node.getClass())) {
AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
ex.setCurl(curl);
m_logger.log(AcsLogLevel.NOTICE, "WDAL::saveChanges " + ex.getShortDescription());
throw ex.toCDBRecordDoesNotExistEx();
}
boolean commit = false;
Transaction tr = mainSession.beginTransaction();
try {
HibernateWDAOImpl wdao = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger, false, false);
for (Object key : propertyMap.keySet()) {
String propertyName = key.toString();
wdao.set_field_data(propertyName, propertyMap.get(propertyName).toString());
}
commit = true;
} catch (CDBFieldIsReadOnlyEx fne) {
AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(fne);
throw cdbex.toCDBExceptionEx();
} catch (WrongCDBDataTypeEx fne) {
AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(fne);
throw cdbex.toCDBExceptionEx();
} finally {
if (commit)
tr.commit();
else
tr.rollback();
}
/// TODO revert memory state?!!!
}
use of alma.cdbErrType.wrappers.AcsJCDBExceptionEx in project ACS by ACS-Community.
the class HibernateWDALImpl method set_DAO.
/* (non-Javadoc)
* @see com.cosylab.CDB.WDALOperations#set_DAO(java.lang.String, java.lang.String)
*/
public void set_DAO(String curl, String xml) throws CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBExceptionEx, CDBXMLErrorEx, CDBRecordDoesNotExistEx {
checkAccess();
m_logger.log(AcsLogLevel.INFO, "set_DAO: " + curl);
// read given xml and iterate through its content and check if something was changed
DAOImpl daoImp = null;
XMLHandler daoXMLSolver = null;
// get content of the given xml string using parser without any shemas and validation
// since given xml string come from a client that have no shemas and it is full expanded version
// of existing xml or it is small composed xml of few properties
XMLHandler xmlSolver = new XMLHandler(false, m_logger);
// TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
//xmlSolver.setMarkArrays(2);
parseXML(xml, xmlSolver);
Object node = DOMJavaClassIntrospector.getNode(curl, rootNode);
if (node == null) {
AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
ex.setCurl(curl);
throw ex.toCDBRecordDoesNotExistEx();
}
// node is saved as XML
if (node instanceof XMLSaver) {
XMLSaver saver = (XMLSaver) node;
Transaction tr = null;
try {
tr = mainSession.beginTransaction();
saver.save(xml);
tr.commit();
} catch (Throwable th) {
if (tr != null)
tr.rollback();
m_logger.log(AcsLogLevel.NOTICE, "Failed to set DAO: " + curl, th);
AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(th);
throw cdbex.toCDBExceptionEx();
}
return;
}
// get original xml that we will use to compare
xml = get_DAO(curl);
daoXMLSolver = new XMLHandler(false, m_logger);
parseXML(xml, daoXMLSolver);
daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, m_logger);
// iterater throuth given xml and put changed attributes in map
LinkedHashMap map = new LinkedHashMap();
try {
checkforChanges("", xmlSolver.m_rootNode, map, daoImp);
saveChanges(curl, map);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
} catch (AcsJCDBXMLErrorEx e) {
throw e.toCDBXMLErrorEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBExceptionEx in project ACS by ACS-Community.
the class WDALImpl method add_node.
/**
* Adds a new node specified by curl to the CDB initially filed with
*
* @param curl uri for the CDB node
* @param xml
*
* @throws CDBRecordAlreadyExistsEx
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
*/
public void add_node(String curl, String xml) throws CDBRecordAlreadyExistsEx, CDBXMLErrorEx, CDBExceptionEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "add_node " + curl);
// check if node is already there
if (nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record already exists: " + curl);
AcsJCDBRecordAlreadyExistsEx e2 = new AcsJCDBRecordAlreadyExistsEx();
e2.setCurl(curl);
e2.log(logger);
throw e2.toCDBRecordAlreadyExistsEx();
}
// check that suplied xml is valid
try {
validateXML(xml);
} catch (AcsJCDBXMLErrorEx e) {
e.log(logger);
throw e.toCDBXMLErrorEx();
}
// recreate dir structure and put data content
getNodeFile(curl).getParentFile().mkdirs();
try {
// write content
writeXmlData(curl, xml);
} catch (AcsJCDBExceptionEx e) {
throw e.toCDBExceptionEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBExceptionEx in project ACS by ACS-Community.
the class WDALImpl method writeXmlData.
/**
* Writes given xml to disk overwriting eventualy existing file
*
* @param curl uri for the CDB node
* @param xmlData xml to write
*
* @throws CDBExceptionEx general CDB exception if something goes wrong while
* saving
*/
private synchronized void writeXmlData(String curl, String xmlData) throws AcsJCDBExceptionEx {
File xmlFile = getNodeFile(curl);
try {
xmlFile.createNewFile();
FileWriter fw = new FileWriter(xmlFile);
fw.write(xmlData);
fw.close();
} catch (IOException e) {
e.printStackTrace();
AcsJCDBExceptionEx e2 = new AcsJCDBExceptionEx(e);
//e2.setCurl(curl);
throw e2;
//throw new CDBExceptionEx("Exception while writing node " + curl
// + " : " + e);
}
// let other new about change
clear_cache(curl);
}
Aggregations