public virtual object createId(EntityMetaData metaData, string @string) { Type type = metaData.IdType; // According to JPA-spec all primitive types (and wrappers) are supported, String, util.Date, sql.Date, // BigDecimal and BigInteger if (type == typeof(Long) || type == typeof(long)) { return(long.Parse(@string)); } else if (type == typeof(string)) { return(@string); } else if (type == typeof(Byte) || type == typeof(sbyte)) { return(sbyte.Parse(@string)); } else if (type == typeof(Short) || type == typeof(short)) { return(short.Parse(@string)); } else if (type == typeof(Integer) || type == typeof(int)) { return(int.Parse(@string)); } else if (type == typeof(Float) || type == typeof(float)) { return(float.Parse(@string)); } else if (type == typeof(Double) || type == typeof(double)) { return(double.Parse(@string)); } else if (type == typeof(Character) || type == typeof(char)) { return(new char?(@string[0])); } else if (type == typeof(DateTime)) { return(new DateTime(long.Parse(@string))); } else if (type == typeof(java.sql.Date)) { return(new java.sql.Date(long.Parse(@string))); } else if (type == typeof(decimal)) { return(new decimal(@string)); } else if (type == typeof(BigInteger)) { return(new BigInteger(@string)); } else { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new ProcessEngineException("Unsupported Primary key type for JPA-Entity: " + type.FullName); } }
private object getIdValue(object value, EntityMetaData metaData) { try { if (metaData.IdMethod != null) { return(metaData.IdMethod.invoke(value)); } else if (metaData.IdField != null) { return(metaData.IdField.get(value)); } } catch (System.ArgumentException iae) { throw new ProcessEngineException("Illegal argument exception when getting value from id method/field on JPAEntity", iae); } catch (IllegalAccessException iae) { throw new ProcessEngineException("Cannot access id method/field for JPA Entity", iae); } catch (InvocationTargetException ite) { throw new ProcessEngineException("Exception occured while getting value from id field/method on JPAEntity: " + ite.InnerException.Message, ite.InnerException); } // Fall trough when no method and field is set throw new ProcessEngineException("Cannot get id from JPA Entity, no id method/field set"); }
public virtual string getJPAIdString(object value) { EntityMetaData metaData = getEntityMetaData(value.GetType()); if (!metaData.JPAEntity) { throw new ProcessEngineException("Object is not a JPA Entity: class='" + value.GetType() + "', " + value); } object idValue = getIdValue(value, metaData); return(getIdString(idValue)); }
private EntityMetaData getEntityMetaData(Type clazz) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: EntityMetaData metaData = classMetaDatamap[clazz.FullName]; if (metaData == null) { // Class not present in meta-data map, create metaData for it and add metaData = scanClass(clazz); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: classMetaDatamap[clazz.FullName] = metaData; } return(metaData); }
public virtual string getJPAClassString(object value) { ensureNotNull("null value cannot be saved", "value", value); EntityMetaData metaData = getEntityMetaData(value.GetType()); if (!metaData.JPAEntity) { throw new ProcessEngineException("Object is not a JPA Entity: class='" + value.GetType() + "', " + value); } // Extract the ID from the Entity instance using the metaData //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: return(metaData.EntityClass.FullName); }
public virtual object getJPAEntity(string className, string idString) { Type entityClass = null; entityClass = ReflectUtil.loadClass(className); EntityMetaData metaData = getEntityMetaData(entityClass); ensureNotNull("Class is not a JPA-entity: " + className, "metaData", metaData); // Create primary key of right type object primaryKey = createId(metaData, idString); return(findEntity(entityClass, primaryKey)); }
public virtual EntityMetaData scanClass(Type clazz) { EntityMetaData metaData = new EntityMetaData(); metaData.EntityClass = clazz; // Class should have @Entity annotation bool isEntity = isEntityAnnotationPresent(clazz); metaData.JPAEntity = isEntity; if (isEntity) { // Try to find a field annotated with @Id System.Reflection.FieldInfo idField = getIdField(clazz); if (idField != null) { metaData.IdField = idField; } else { // Try to find a method annotated with @Id System.Reflection.MethodInfo idMethod = getIdMethod(clazz); if (idMethod != null) { metaData.IdMethod = idMethod; } else { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new ProcessEngineException("Cannot find field or method with annotation @Id on class '" + clazz.FullName + "', only single-valued primary keys are supported on JPA-enities"); } } } return(metaData); }