Search in sources :

Example 11 with AcsJCDBFieldDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDAOImpl method set_long_seq.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDAOOperations#set_long_seq(java.lang.String, int[])
	 */
@SuppressWarnings("unchecked")
public void set_long_seq(String propertyName, int[] value) throws CDBFieldIsReadOnlyEx, CDBFieldDoesNotExistEx {
    NodeAndMutator nodeAndMutator = DOMJavaClassIntrospector.getRecursiveMutatorMethod(propertyName, m_rootNode);
    if (nodeAndMutator == null) {
        AcsJCDBFieldDoesNotExistEx ex = new AcsJCDBFieldDoesNotExistEx();
        ex.setFieldName(propertyName);
        throw ex.toCDBFieldDoesNotExistEx();
    }
    Transaction tr = null;
    try {
        if (nodeAndMutator.mutator.getParameterTypes().length != 1) {
            AcsJCDBFieldIsReadOnlyEx acsex = new AcsJCDBFieldIsReadOnlyEx();
            acsex.setFieldName(propertyName);
            throw acsex.toCDBFieldIsReadOnlyEx();
        }
        Object toSet;
        Class parameterClass = nodeAndMutator.mutator.getParameterTypes()[0];
        if (parameterClass.isAssignableFrom(String.class)) {
            StringBuilder strValue = new StringBuilder(64);
            if (value.length > 0) {
                for (int i = 0; i < value.length - 1; i++) {
                    strValue.append(value[i]).append(',');
                }
                strValue.append(value[value.length - 1]);
            }
            toSet = strValue.toString();
        } else if (parameterClass.isAssignableFrom(String[].class)) {
            String[] arr = new String[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = String.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(int[].class)) {
            int[] arr = new int[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (int) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(long[].class)) {
            toSet = value;
        } else if (parameterClass.isAssignableFrom(byte[].class)) {
            byte[] arr = new byte[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (byte) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(short[].class)) {
            short[] arr = new short[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (short) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(double[].class)) {
            double[] arr = new double[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (double) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(float[].class)) {
            float[] arr = new float[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (float) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(boolean[].class)) {
            boolean[] arr = new boolean[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (value[i] != 0);
            toSet = arr;
        } else
            throw new NO_RESOURCES("cannot convert value");
        if (m_autoCommit)
            tr = m_session.beginTransaction();
        nodeAndMutator.mutator.invoke(nodeAndMutator.node, new Object[] { toSet });
        if (tr != null)
            tr.commit();
    } catch (Throwable th) {
        if (tr != null)
            tr.rollback();
        if (!m_silent)
            m_logger.log(AcsLogLevel.NOTICE, "Failed to set '" + Arrays.toString(value) + "' to : " + (this.m_name + "/" + propertyName), th);
        throw new NO_RESOURCES(th.getMessage());
    }
}
Also used : AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) NodeAndMutator(com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator) Transaction(org.hibernate.Transaction) AcsJCDBFieldIsReadOnlyEx(alma.cdbErrType.wrappers.AcsJCDBFieldIsReadOnlyEx) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 12 with AcsJCDBFieldDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDAOImpl method set_double_seq.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDAOOperations#set_double_seq(java.lang.String, double[])
	 */
@SuppressWarnings("unchecked")
public void set_double_seq(String propertyName, double[] value) throws CDBFieldIsReadOnlyEx, CDBFieldDoesNotExistEx {
    NodeAndMutator nodeAndMutator = DOMJavaClassIntrospector.getRecursiveMutatorMethod(propertyName, m_rootNode);
    if (nodeAndMutator == null) {
        AcsJCDBFieldDoesNotExistEx ex = new AcsJCDBFieldDoesNotExistEx();
        ex.setFieldName(propertyName);
        throw ex.toCDBFieldDoesNotExistEx();
    }
    Transaction tr = null;
    try {
        if (nodeAndMutator.mutator.getParameterTypes().length != 1) {
            AcsJCDBFieldIsReadOnlyEx acsex = new AcsJCDBFieldIsReadOnlyEx();
            acsex.setFieldName(propertyName);
            throw acsex.toCDBFieldIsReadOnlyEx();
        }
        Object toSet;
        Class parameterClass = nodeAndMutator.mutator.getParameterTypes()[0];
        if (parameterClass.isAssignableFrom(String.class)) {
            StringBuilder strValue = new StringBuilder(64);
            if (value.length > 0) {
                for (int i = 0; i < value.length - 1; i++) {
                    strValue.append(value[i]).append(',');
                }
                strValue.append(value[value.length - 1]);
            }
            toSet = strValue.toString();
        } else if (parameterClass.isAssignableFrom(String[].class)) {
            String[] arr = new String[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = String.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(int[].class)) {
            int[] arr = new int[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (int) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(long[].class)) {
            long[] arr = new long[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (long) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(byte[].class)) {
            byte[] arr = new byte[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (byte) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(short[].class)) {
            short[] arr = new short[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (short) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(double[].class)) {
            toSet = value;
        } else if (parameterClass.isAssignableFrom(float[].class)) {
            float[] arr = new float[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (float) value[i];
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(boolean[].class)) {
            boolean[] arr = new boolean[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = (value[i] != 0);
            toSet = arr;
        } else
            throw new NO_RESOURCES("cannot convert value");
        if (m_autoCommit)
            tr = m_session.beginTransaction();
        nodeAndMutator.mutator.invoke(nodeAndMutator.node, new Object[] { toSet });
        if (tr != null)
            tr.commit();
    } catch (Throwable th) {
        if (tr != null)
            tr.rollback();
        if (!m_silent)
            m_logger.log(AcsLogLevel.NOTICE, "Failed to set '" + Arrays.toString(value) + "' to : " + (this.m_name + "/" + propertyName), th);
        throw new NO_RESOURCES(th.getMessage());
    }
}
Also used : AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) NodeAndMutator(com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator) Transaction(org.hibernate.Transaction) AcsJCDBFieldIsReadOnlyEx(alma.cdbErrType.wrappers.AcsJCDBFieldIsReadOnlyEx) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 13 with AcsJCDBFieldDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDAOImpl method set_string_seq.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDAOOperations#set_string_seq(java.lang.String, java.lang.String[])
	 */
@SuppressWarnings("unchecked")
public void set_string_seq(String propertyName, String[] value) throws CDBFieldIsReadOnlyEx, CDBFieldDoesNotExistEx {
    NodeAndMutator nodeAndMutator = DOMJavaClassIntrospector.getRecursiveMutatorMethod(propertyName, m_rootNode);
    if (nodeAndMutator == null) {
        AcsJCDBFieldDoesNotExistEx ex = new AcsJCDBFieldDoesNotExistEx();
        ex.setFieldName(propertyName);
        throw ex.toCDBFieldDoesNotExistEx();
    }
    Transaction tr = null;
    try {
        if (nodeAndMutator.mutator.getParameterTypes().length != 1) {
            AcsJCDBFieldIsReadOnlyEx acsex = new AcsJCDBFieldIsReadOnlyEx();
            acsex.setFieldName(propertyName);
            throw acsex.toCDBFieldIsReadOnlyEx();
        }
        Object toSet;
        Class parameterClass = nodeAndMutator.mutator.getParameterTypes()[0];
        if (parameterClass.isAssignableFrom(String.class)) {
            StringBuilder strValue = new StringBuilder(64);
            if (value.length > 0) {
                for (int i = 0; i < value.length - 1; i++) {
                    strValue.append(value[i]).append(',');
                }
                strValue.append(value[value.length - 1]);
            }
            toSet = strValue.toString();
        } else if (parameterClass.isAssignableFrom(String[].class)) {
            toSet = value;
        } else if (parameterClass.isAssignableFrom(int[].class)) {
            int[] arr = new int[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Integer.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(long[].class)) {
            long[] arr = new long[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Long.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(byte[].class)) {
            byte[] arr = new byte[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Byte.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(short[].class)) {
            short[] arr = new short[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Short.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(double[].class)) {
            double[] arr = new double[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Double.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(float[].class)) {
            float[] arr = new float[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Float.valueOf(value[i]);
            toSet = arr;
        } else if (parameterClass.isAssignableFrom(boolean[].class)) {
            boolean[] arr = new boolean[value.length];
            for (int i = 0; i < arr.length; i++) arr[i] = Boolean.valueOf(value[i]);
            toSet = arr;
        } else
            throw new NO_RESOURCES("cannot convert value");
        if (m_autoCommit)
            tr = m_session.beginTransaction();
        nodeAndMutator.mutator.invoke(nodeAndMutator.node, new Object[] { toSet });
        if (tr != null)
            tr.commit();
    } catch (Throwable th) {
        if (tr != null)
            tr.rollback();
        if (!m_silent)
            m_logger.log(AcsLogLevel.NOTICE, "Failed to set '" + Arrays.toString(value) + "' to : " + (this.m_name + "/" + propertyName), th);
        throw new NO_RESOURCES(th.getMessage());
    }
}
Also used : AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) NodeAndMutator(com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator) Transaction(org.hibernate.Transaction) AcsJCDBFieldIsReadOnlyEx(alma.cdbErrType.wrappers.AcsJCDBFieldIsReadOnlyEx) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 14 with AcsJCDBFieldDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx in project ACS by ACS-Community.

the class WDAOImpl method setField.

private void setField(String strFieldName, String value) throws AcsJCDBFieldDoesNotExistEx {
    XMLTreeNode pNode = getRootNode();
    StringTokenizer st = new StringTokenizer(strFieldName, "/");
    String fieldName = st.nextToken();
    while (st.hasMoreTokens()) {
        pNode = (XMLTreeNode) pNode.m_subNodesMap.get(fieldName);
        if (pNode == null) {
            AcsJCDBFieldDoesNotExistEx e = new AcsJCDBFieldDoesNotExistEx();
            e.setFieldName(strFieldName);
            throw e;
        }
        fieldName = st.nextToken();
    }
    String currentValue = (String) pNode.m_fieldMap.get(fieldName);
    if (currentValue == null) {
        m_logger.log(AcsLogLevel.NOTICE, "setField():'" + getName() + "' Unable to find field: '" + strFieldName + "'");
        AcsJCDBFieldDoesNotExistEx e = new AcsJCDBFieldDoesNotExistEx();
        e.setFieldName(strFieldName);
        throw e;
    }
    m_logger.log(AcsLogLevel.INFO, "setField():'" + getName() + "' set '" + strFieldName + "'=" + value);
    // set value in memory
    m_logger.log(AcsLogLevel.DEBUG, "setField(): - Set value in memory");
    pNode.m_fieldMap.put(fieldName, value);
    // and on disk
    m_logger.log(AcsLogLevel.DEBUG, "setField(): - Set value in disk");
    HashMap map = new HashMap();
    map.put(strFieldName, value);
    try {
        m_logger.log(AcsLogLevel.DEBUG, "setField(): - Saving Changes");
        wdal.saveChanges(getName(), map);
    } catch (AcsJCDBFieldDoesNotExistEx e) {
        throw e;
    } catch (Exception e) {
        // TODO do something with this exception
        e.printStackTrace();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) HashMap(java.util.HashMap)

Example 15 with AcsJCDBFieldDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx in project ACS by ACS-Community.

the class DAOImpl method get_long_seq.

public int[] get_long_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
    String stringValue;
    try {
        stringValue = getField(propertyName);
    } catch (AcsJCDBFieldDoesNotExistEx e) {
        throw e.toCDBFieldDoesNotExistEx();
    }
    ArrayList list = new ArrayList();
    String val = null;
    try {
        StringTokenizer st = new StringTokenizer(stringValue, ",");
        while (st.hasMoreTokens()) {
            val = st.nextToken().trim();
            list.add(new Integer(val));
        }
    } catch (NumberFormatException nfe) {
        if (!m_silent)
            m_logger.log(AcsLogLevel.NOTICE, "Failed to cast element #" + list.size() + " of value '" + val + "' to long: " + nfe);
        AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx(nfe);
        e2.setValue(val);
        e2.setDataType("long");
        throw e2.toWrongCDBDataTypeEx();
    }
    int[] seq = new int[list.size()];
    for (int i = 0; i < list.size(); i++) seq[i] = ((Integer) list.get(i)).intValue();
    return seq;
}
Also used : AcsJWrongCDBDataTypeEx(alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx) StringTokenizer(java.util.StringTokenizer) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) ArrayList(java.util.ArrayList)

Aggregations

AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)18 Transaction (org.hibernate.Transaction)7 AcsJCDBFieldIsReadOnlyEx (alma.cdbErrType.wrappers.AcsJCDBFieldIsReadOnlyEx)6 AcsJWrongCDBDataTypeEx (alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx)6 NodeAndMutator (com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator)6 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)6 StringTokenizer (java.util.StringTokenizer)5 ArrayList (java.util.ArrayList)3 AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)2 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 CDBRecordIsReadOnlyEx (alma.cdbErrType.CDBRecordIsReadOnlyEx)1 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 ConvertToPrimitiveFeature (com.cosylab.cdb.jdal.hibernate.ConvertToPrimitiveFeature)1 XMLSaver (com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Element (org.w3c.dom.Element)1