<commit_before>package ua.com.fielden.platform.swing.model;

import ua.com.fielden.platform.entity.AbstractEntity;
import ua.com.fielden.platform.equery.fetch;
import ua.com.fielden.platform.swing.ei.editors.ILightweightPropertyBinder;

/**
 * This is convenient UI model based on {@link UModel} simplifying model creation of a single stand alone (or simply master) entity. In this model the entity and managed entity is
 * the same thing.
 * <p>
 * For example, most of so called table codes represent stand alone entities.
 *
 * @author TG Team
 *
 * @param <T>
 *            -- entity type.
 * @param <C>
 *            -- controller type.
 */
public abstract class UmMaster<T extends AbstractEntity, C> extends UModel<T, T, C> {
    /** Represents an entity model used for entity fetching and initialisation. */
    private final fetch<T> fm;

    protected UmMaster(final T entity, final C controller, final ILightweightPropertyBinder<T> propertyBinder, final fetch<T> fm, final boolean lazy) {
	super(entity, controller, propertyBinder, lazy);
	this.fm = fm;
	if (shouldEnforceEntityLoadingDuringInstantiation()) {
	    setEntity(findById(entity.getId(), true));
	}
    }

    /**
     * A method used inside the constructor to determine whether entity retrieval should be enforced during model instantiation. By default it return true, which is correct in most
     * cases. If the default is not suitable the derived model should override it return false.
     *
     * @return
     */
    protected boolean shouldEnforceEntityLoadingDuringInstantiation() {
	return true;
    }

    /**
     * Should be implemented to correctly retrieve managed entity according the master model requirement as supposed to whatever was passed into the constructor.
     *
     * @param id
     * @param forceRetrieval
     * @return
     */
    protected abstract T findById(final Long id, final boolean forceRetrieval);

    @Override
    protected final T getManagedEntity() {
	return getEntity();
    }

    protected fetch<T> getFetchModel() {<commit_msg>Ensured that master model uses fetchAll strategy when no strategy was provided.<commit_after>package ua.com.fielden.platform.swing.model;

import ua.com.fielden.platform.entity.AbstractEntity;
import ua.com.fielden.platform.equery.fetch;
import ua.com.fielden.platform.equery.fetchAll;
import ua.com.fielden.platform.swing.ei.editors.ILightweightPropertyBinder;

/**
 * This is convenient UI model based on {@link UModel} simplifying model creation of a single stand alone (or simply master) entity. In this model the entity and managed entity is
 * the same thing.
 * <p>
 * For example, most of so called table codes represent stand alone entities.
 *
 * @author <NAME>
 *
 * @param <T>
 *            -- entity type.
 * @param <C>
 *            -- controller type.
 */
public abstract class UmMaster<T extends AbstractEntity, C> extends UModel<T, T, C> {
    /** Represents an entity model used for entity fetching and initialisation. */
    private final fetch<T> fm;

    protected UmMaster(final T entity, final C controller, final ILightweightPropertyBinder<T> propertyBinder, final fetch<T> fm, final boolean lazy) {
	super(entity, controller, propertyBinder, lazy);
	this.fm = fm != null ? fm : new fetchAll<T>(entity.getType());
	if (shouldEnforceEntityLoadingDuringInstantiation()) {
	    setEntity(findById(entity.getId(), true));
	}
    }

    /**
     * A method used inside the constructor to determine whether entity retrieval should be enforced during model instantiation. By default it return true, which is correct in most
     * cases. If the default is not suitable the derived model should override it to return false.
     *
     * @return
     */
    protected boolean shouldEnforceEntityLoadingDuringInstantiation() {
	return true;
    }

    /**
     * Should be implemented to correctly retrieve managed entity according the master model requirement as supposed to whatever was passed into the constructor.
     *
     * @param id
     * @param forceRetrieval
     * @return
     */
    protected abstract T findById(final Long id, final boolean forceRetrieval);

    @Override
    protected final T getManagedEntity() {
	return getEntity();
    }

    protected fetch<T> getFetchModel() {
{'fraction_non_alphanumeric': 0.08534583821805393, 'fraction_numerical': 0.0, 'mean_word_length': 3.5479744136460556, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19220', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1139, 'n_words': 437}