All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jwebmp.entityassist.querybuilder.QueryBuilderCore Maven / Gradle / Ivy

There is a newer version: 0.68.0.1
Show newest version
package com.jwebmp.entityassist.querybuilder;

import com.jwebmp.entityassist.CoreEntity;
import com.jwebmp.entityassist.enumerations.ActiveFlag;

import javax.persistence.metamodel.Attribute;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

import static com.jwebmp.entityassist.CoreEntity.*;
import static com.jwebmp.entityassist.enumerations.Operand.*;

/**
 * @param 
 * 		This Class
 * @param 
 * 		Entity Class
 *
 * @author GedMarc
 */
public abstract class QueryBuilderCore, E extends CoreEntity, I extends Serializable>
		extends QueryBuilderSCD
{
	/**
	 * The active flag column name
	 */
	@SuppressWarnings("WeakerAccess")
	public static final String ACTIVE_FLAG_DATE_COLUMN_NAME = "activeFlag";

	/**
	 * Filters from the Active Flag suite where it is in the active range
	 *
	 * @return This
	 */
	@NotNull
	@SuppressWarnings("unchecked")
	public J inActiveRange()
	{
		where((Attribute) getAttribute(ACTIVE_FLAG_DATE_COLUMN_NAME), InList, ActiveFlag.getActiveRangeAndUp());
		return (J) this;
	}

	/**
	 * Selects all records in the visible range
	 *
	 * @return This
	 */
	@NotNull
	@SuppressWarnings("unchecked")
	public J inVisibleRange()
	{
		where((Attribute) getAttribute(ACTIVE_FLAG_DATE_COLUMN_NAME), InList, ActiveFlag.getVisibleRangeAndUp());
		return (J) this;
	}

	/**
	 * Updates the current record with the given active flag type
	 * uses the merge
	 *
	 * @param newActiveFlagType
	 * 		The new flag type to apply
	 * @param entity
	 * 		The entity to operate on
	 *
	 * @return The entity
	 */
	public E delete(ActiveFlag newActiveFlagType, E entity)
	{
		entity.setWarehouseLastUpdatedTimestamp(LocalDateTime.now());
		entity.setEffectiveToDate(LocalDateTime.now());
		entity.setActiveFlag(newActiveFlagType);
		getEntityManager().merge(entity);
		return entity;
	}

	/**
	 * Updates the current record with the given active flag type
	 *
	 * @param entity
	 * 		The entity to delete
	 *
	 * @return the entity
	 */
	@Override
	public E delete(E entity)
	{
		entity.setWarehouseLastUpdatedTimestamp(LocalDateTime.now());
		entity.setEffectiveToDate(LocalDateTime.now());
		entity.setActiveFlag(ActiveFlag.Deleted);
		getEntityManager().merge(entity);
		return entity;
	}

	/**
	 * Marks the record as archived updating the warehouse and effective to date timestamps
	 *
	 * @param entity
	 * 		The entity
	 *
	 * @return The Entity
	 */
	public E archive(E entity)
	{
		entity.setWarehouseLastUpdatedTimestamp(LocalDateTime.now());
		entity.setEffectiveToDate(LocalDateTime.now());
		entity.setActiveFlag(ActiveFlag.Archived);

		getEntityManager().merge(entity);
		return entity;
	}

	/**
	 * Marks the given entity as the given status, with the effective to date and warehouse last updated as now
	 * Merges the entity, then detaches,
	 * 

* Persists the new record down with the end of time used * * @param entity * The entity * @param status * The new status * * @return The updated entity */ @SuppressWarnings("unused") public E closeAndReturnNewlyUpdate(E entity, ActiveFlag status) { entity.setWarehouseLastUpdatedTimestamp(LocalDateTime.now()); entity.setEffectiveToDate(LocalDateTime.now()); entity.setActiveFlag(status); getEntityManager().merge(entity); getEntityManager().detach(entity); entity.setId(null); entity.setWarehouseCreatedTimestamp(LocalDateTime.now()); entity.setWarehouseLastUpdatedTimestamp(LocalDateTime.now()); entity.setEffectiveFromDate(LocalDateTime.now()); entity.setEffectiveToDate(EndOfTime); entity.setActiveFlag(ActiveFlag.Active); persistNow(entity, true); return entity; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy