/** * <p>Retrieve member from given class.</p> * @param pClazz - class * @param pFieldName - field name * @return Field field. * @throws Exception if field not exist **/ @Override public final Field retrieveField(final Class<?> pClazz, final String pFieldName) throws Exception { for (Field fld : pClazz.getDeclaredFields()) { if (fld.getName().equals(pFieldName)) { return fld; } } final Class<?> superClazz = pClazz.getSuperclass(); Field field = null; if (superClazz != null && superClazz != java.lang.Object.class) { field = retrieveField(superClazz, pFieldName); } if (field == null) { throw new Exception("There is no field " + pFieldName + " in class " + pClazz); //TO-DO class must be original } return field; }
/** * <p>Delete entity with NON-COMPLEX ID from DB.</p> * @param <T> entity type * @param <K> ID type * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void deleteEntity( final T pEntity) throws Exception { TableSql tableSql = this.getTablesMap().get(pEntity.getClass() .getSimpleName()); Field fieldId = this.utlReflection.retrieveField(pEntity.getClass(), tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); deleteEntity(pEntity.getClass(), id); }
/** * <p>Init database birth and ID birth of entity.</p> * @param pEntity entity * @throws Exception an exception **/ public final void initPersistableBase(final Object pEntity) throws Exception { Field fieldIdDbBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_DATABASE_BIRTH_NAME); fieldIdDbBirth.setAccessible(true); if (getSrvDatabase() != null) { //for test purpose, otherwise it must be set fieldIdDbBirth.set(pEntity, getSrvDatabase().getIdDatabase()); } Field fieldIdBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_BIRTH_NAME); fieldIdBirth.setAccessible(true); fieldIdBirth.set(pEntity, null); }
/** * <p>Refresh entity from DB by given entity with ID.</p> * @param <T> entity type * @param pEntity entity * @return entity or null * @throws Exception - an exception **/ @Override public final <T> T retrieveEntity(final T pEntity) throws Exception { @SuppressWarnings("unchecked") Class<T> entityClass = (Class<T>) pEntity.getClass(); TableSql tableSql = getTablesMap().get(entityClass.getSimpleName()); Field fieldId = getUtlReflection().retrieveField(entityClass, tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); return retrieveEntityById(entityClass, id); }
if ("true".equals(entry.getValue().get("isEnabled"))) { Field field = getUtlReflection() .retrieveField(pEntity.getClass(), entry.getKey()); field.setAccessible(true); Object fieldValue = field.get(pEntity);
if ("true".equals(entry.getValue().get("isEnabled"))) { Field field = getUtlReflection() .retrieveField(pEntity.getClass(), entry.getKey()); field.setAccessible(true); Object fieldValue = field.get(pEntity);
final Object pEntity, final String pFieldName, final String pFieldStrValue) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final Object pEntity, final String pFieldName, final String pFieldStrValue) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final String pFieldStrValue, final Map<String, Object> pAddParam) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final Object pEntity, final String pFieldName, final String pFieldStrValue) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final String pFieldStrValue, final Map<String, Object> pAddParam) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final String pFieldStrValue, final Map<String, Object> pAddParam) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
/** * <p>Retrieve copy of entity from DB by given ID.</p> * @param <T> entity type * @param pEntityClass entity class * @param pId ID * @return entity or null * @throws Exception - an exception **/ @Override public final <T> T retrieveCopyEntity( final Class<T> pEntityClass, final Object pId) throws Exception { T entity = retrieveEntityById(pEntityClass, pId); TableSql tableSql = getTablesMap().get(pEntityClass.getSimpleName()); Field fieldId = getUtlReflection().retrieveField(pEntityClass, tableSql.getIdName()); fieldId.setAccessible(true); fieldId.set(entity, null); if (APersistableBase.class.isAssignableFrom(pEntityClass)) { initPersistableBase(entity); } return entity; }
if (idName != null) { // if non-complex PK Field fieldId = getUtlReflection() .retrieveField(pEntity.getClass(), idName); fieldId.setAccessible(true);
TableSql tableSqlEntityOwner = getTablesMap() .get(pEntityOwnerClass.getSimpleName()); Field fieldIdEntityOwner = getUtlReflection().retrieveField( pEntityOwnerClass, tableSqlEntityOwner.getIdName()); fieldIdEntityOwner.setAccessible(true); Field fieldEntityOwner = getUtlReflection().retrieveField(pEntityClass, ownerFieldName); fieldEntityOwner.setAccessible(true);
TableSql tableSqlOwner = getTablesMap().get(pEntityOwner.getClass() .getSimpleName()); Field fieldIdOwner = getUtlReflection().retrieveField(pEntityOwner .getClass(), tableSqlOwner.getIdName()); fieldIdOwner.setAccessible(true);
if (idName != null) { // if non-complex PK Field fieldId = getUtlReflection() .retrieveField(pEntity.getClass(), idName); fieldId.setAccessible(true);
if (idName != null) { // if non-complex PK Field fieldId = getUtlReflection() .retrieveField(pEntity.getClass(), idName); fieldId.setAccessible(true); Object idValue = fieldId.get(pEntity);
if (idName != null) { // if non-complex PK Field fieldId = getUtlReflection() .retrieveField(pEntity.getClass(), idName); fieldId.setAccessible(true);
if (idName != null) { // if non-complex PK Field fieldId = getUtlReflection() .retrieveField(pEntity.getClass(), idName); fieldId.setAccessible(true); Object idValue = fieldId.get(pEntity);