Open to all forms of art. Or even something that is just creative. 
Starting today August 7th, 2024, in order to post in the Married Couples, Courting Couples, or Singles forums, you will not be allowed to post if you have your Marital status designated as private. Announcements will be made in the respective forums as well but please note that if yours is currently listed as Private, you will need to submit a ticket in the Support Area to have yours changed.
package org.enterprise.model;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Cacheable;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlTransient;
import org.enterprise.interceptor.annotation.Auditable;
import org.enterprise.stereotype.Domain;
import org.enterprise.util.Entities;
/**
* Base JPA entity representation
*
* @author r035198x
*
*/
@SuppressWarnings("serial")
@Domain
@MappedSuperclass
@Auditable
@Cacheable
public abstract class BaseEntity implements SearchableEntity {
@XmlTransient
@Transient
private List<SearchProperty> searchProperties = new ArrayList<>();
private String lastModifiedBy;
@Temporal(TemporalType.TIMESTAMP)
private Date lastModified;
public BaseEntity() {
updateSearchExclusions();
}
public void updateSearchExclusions() {
Class<?> current = getClass();
while (current != null) {
Field[] declaredFields = current.getDeclaredFields();
for (Field field : declaredFields) {
String fieldName = field.getName();
if (!getSearchExclusions().contains(fieldName) && !(Entities.isMappedByField(field))) {
searchProperties.add(new SearchProperty(fieldName, fieldName, field.getType().getName()));
}
}
current = current.getSuperclass();
}
}
@Override
public List<String> getSearchExclusions() {
List<String> exclusions = new ArrayList<>();
exclusions.add("id");
exclusions.add("lastModifiedBy");
exclusions.add("lastModified");
exclusions.add("searchProperties");
return exclusions;
}
@Override
public void excludeFromSearch(String field) {
Iterator<SearchProperty> iterator = searchProperties.iterator();
while (iterator.hasNext()) {
SearchProperty searchProperty = iterator.next();
if (searchProperty.getName().equalsIgnoreCase(field)) {
iterator.remove();
}
}
}
public List<SearchProperty> getSearchProperties() {
return searchProperties;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseEntity other = (BaseEntity) obj;
if (getId() == null) {
if (other.getId() != null)
return false;
} else if (!getId().equals(other.getId()))
return false;
return true;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
ok.
Well, art comes in different shapes and sizes
Code:package org.enterprise.model; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.persistence.Cacheable; import javax.persistence.MappedSuperclass; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlTransient; import org.enterprise.interceptor.annotation.Auditable; import org.enterprise.stereotype.Domain; import org.enterprise.util.Entities; /** * Base JPA entity representation * * @author r035198x * */ @SuppressWarnings("serial") @Domain @MappedSuperclass @Auditable @Cacheable public abstract class BaseEntity implements SearchableEntity { @XmlTransient @Transient private List<SearchProperty> searchProperties = new ArrayList<>(); private String lastModifiedBy; @Temporal(TemporalType.TIMESTAMP) private Date lastModified; public BaseEntity() { updateSearchExclusions(); } public void updateSearchExclusions() { Class<?> current = getClass(); while (current != null) { Field[] declaredFields = current.getDeclaredFields(); for (Field field : declaredFields) { String fieldName = field.getName(); if (!getSearchExclusions().contains(fieldName) && !(Entities.isMappedByField(field))) { searchProperties.add(new SearchProperty(fieldName, fieldName, field.getType().getName())); } } current = current.getSuperclass(); } } @Override public List<String> getSearchExclusions() { List<String> exclusions = new ArrayList<>(); exclusions.add("id"); exclusions.add("lastModifiedBy"); exclusions.add("lastModified"); exclusions.add("searchProperties"); return exclusions; } @Override public void excludeFromSearch(String field) { Iterator<SearchProperty> iterator = searchProperties.iterator(); while (iterator.hasNext()) { SearchProperty searchProperty = iterator.next(); if (searchProperty.getName().equalsIgnoreCase(field)) { iterator.remove(); } } } public List<SearchProperty> getSearchProperties() { return searchProperties; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BaseEntity other = (BaseEntity) obj; if (getId() == null) { if (other.getId() != null) return false; } else if (!getId().equals(other.getId())) return false; return true; } public String getLastModifiedBy() { return lastModifiedBy; } public void setLastModifiedBy(String lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } public Date getLastModified() { return lastModified; } public void setLastModified(Date lastModified) { this.lastModified = lastModified; } }