/** * <p>Create entity.</p> * @param <T> entity type * @param pEntityClass entity class * @return entity instance * @throws Exception - an exception **/ @Override public final <T> T createEntity( final Class<T> pEntityClass) throws Exception { Constructor<T> constructor = pEntityClass.getDeclaredConstructor(); T entity = constructor.newInstance(); if (APersistableBase.class.isAssignableFrom(pEntityClass)) { initPersistableBase(entity); } return entity; }
/** * <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; }
T entity = constructor.newInstance(); if (APersistableBase.class.isAssignableFrom(pEntityClass)) { initPersistableBase(entity); // always for current DB!!! "can_not_change_foreign_src"); initPersistableBase(entity); // always for current DB!!!