use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator in project ACS by ACS-Community.
the class HibernateWDAOImpl method set_double.
/* (non-Javadoc)
* @see com.cosylab.CDB.WDAOOperations#set_double(java.lang.String, double)
*/
@SuppressWarnings("unchecked")
public void set_double(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))
toSet = String.valueOf(value);
else if (parameterClass.isAssignableFrom(Integer.class) || parameterClass.isAssignableFrom(int.class))
toSet = Integer.valueOf((int) value);
else if (parameterClass.isAssignableFrom(Long.class) || parameterClass.isAssignableFrom(long.class))
toSet = Long.valueOf((long) value);
else if (parameterClass.isAssignableFrom(Byte.class) || parameterClass.isAssignableFrom(byte.class))
toSet = Byte.valueOf((byte) value);
else if (parameterClass.isAssignableFrom(Short.class) || parameterClass.isAssignableFrom(short.class))
toSet = Short.valueOf((short) value);
else if (parameterClass.isAssignableFrom(Double.class) || parameterClass.isAssignableFrom(double.class))
toSet = Double.valueOf(value);
else if (parameterClass.isAssignableFrom(Float.class) || parameterClass.isAssignableFrom(float.class))
toSet = Float.valueOf((float) value);
else if (parameterClass.isAssignableFrom(Boolean.class) || parameterClass.isAssignableFrom(boolean.class))
toSet = (value != 0);
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 '" + value + "' to : " + (this.m_name + "/" + propertyName), th);
throw new NO_RESOURCES(th.getMessage());
}
}
use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator in project ACS by ACS-Community.
the class HibernateWDAOImpl method set_string.
/*
* (non-Javadoc)
*
* @see com.cosylab.CDB.WDAOOperations#set_string(java.lang.String,
* java.lang.String)
*/
@SuppressWarnings("unchecked")
public void set_string(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))
toSet = String.valueOf(value);
else if (parameterClass.isAssignableFrom(Integer.class) || parameterClass.isAssignableFrom(int.class))
toSet = Integer.valueOf(value);
else if (parameterClass.isAssignableFrom(Long.class) || parameterClass.isAssignableFrom(long.class))
toSet = Long.valueOf(value);
else if (parameterClass.isAssignableFrom(Byte.class) || parameterClass.isAssignableFrom(byte.class))
toSet = Byte.valueOf(value);
else if (parameterClass.isAssignableFrom(Short.class) || parameterClass.isAssignableFrom(short.class))
toSet = Short.valueOf(value);
else if (parameterClass.isAssignableFrom(Double.class) || parameterClass.isAssignableFrom(double.class))
toSet = Double.valueOf(value);
else if (parameterClass.isAssignableFrom(Float.class) || parameterClass.isAssignableFrom(float.class))
toSet = Float.valueOf(value);
else if (parameterClass.isAssignableFrom(Boolean.class) || parameterClass.isAssignableFrom(boolean.class))
toSet = Boolean.valueOf(value);
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 '" + value + "' to : " + (this.m_name + "/" + propertyName), th);
throw new NO_RESOURCES(th.getMessage());
}
}
use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator in project ACS by ACS-Community.
the class HibernateWDAOImpl method set_long.
/* (non-Javadoc)
* @see com.cosylab.CDB.WDAOOperations#set_long(java.lang.String, int)
*/
@SuppressWarnings("unchecked")
public void set_long(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))
toSet = String.valueOf(value);
else if (parameterClass.isAssignableFrom(Integer.class) || parameterClass.isAssignableFrom(int.class))
toSet = Integer.valueOf(value);
else if (parameterClass.isAssignableFrom(Long.class) || parameterClass.isAssignableFrom(long.class))
toSet = Long.valueOf(value);
else if (parameterClass.isAssignableFrom(Byte.class) || parameterClass.isAssignableFrom(byte.class))
toSet = Byte.valueOf((byte) value);
else if (parameterClass.isAssignableFrom(Short.class) || parameterClass.isAssignableFrom(short.class))
toSet = Short.valueOf((short) value);
else if (parameterClass.isAssignableFrom(Double.class) || parameterClass.isAssignableFrom(double.class))
toSet = Double.valueOf(value);
else if (parameterClass.isAssignableFrom(Float.class) || parameterClass.isAssignableFrom(float.class))
toSet = Float.valueOf(value);
else if (parameterClass.isAssignableFrom(Boolean.class) || parameterClass.isAssignableFrom(boolean.class))
toSet = (value != 0);
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 '" + value + "' to : " + (this.m_name + "/" + propertyName), th);
throw new NO_RESOURCES(th.getMessage());
}
}
use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator 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());
}
}
use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.NodeAndMutator 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());
}
}
Aggregations