blob: c9d3365edf9253545994d7f2d42ec570f865cca4 [file] [log] [blame]
/**
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.authentication.account.entities;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PreRemove;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.eclipse.osbp.authentication.account.entities.UserAccount;
import org.eclipse.osbp.dsl.common.datatypes.IEntity;
import org.eclipse.osbp.runtime.common.annotations.Dispose;
@Entity
@Table(name = "USER_ACCOUNT_FILTER")
@DiscriminatorValue(value = "USER_ACCOUNT_FILTER")
@SuppressWarnings("all")
public class UserAccountFilter implements IEntity {
@Transient
@Dispose
private boolean disposed;
@Id
private String id = java.util.UUID.randomUUID().toString();
@Column(name = "FILTER")
private String filter;
@Column(name = "INVERS")
private boolean invers;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ACCOUNT_ID")
private UserAccount userAccount;
/**
* @return true, if the object is disposed.
* Disposed means, that it is prepared for garbage collection and may not be used anymore.
* Accessing objects that are already disposed will cause runtime exceptions.
*
*/
@Dispose
public boolean isDisposed() {
return this.disposed;
}
/**
* Checks whether the object is disposed.
* @throws RuntimeException if the object is disposed.
*/
private void checkDisposed() {
if (isDisposed()) {
throw new RuntimeException("Object already disposed: " + this);
}
}
/**
* Calling dispose will destroy that instance. The internal state will be
* set to 'disposed' and methods of that object must not be used anymore.
* Each call will result in runtime exceptions.<br>
* If this object keeps composition containments, these will be disposed too.
* So the whole composition containment tree will be disposed on calling this method.
*/
@Dispose
public void dispose() {
if (isDisposed()) {
return;
}
disposed = true;
}
/**
* @return Returns the id property or <code>null</code> if not present.
*/
public String getId() {
checkDisposed();
return this.id;
}
/**
* Sets the id property to this instance.
*/
public void setId(final String id) {
checkDisposed();
this.id = id;
}
/**
* @return Returns the filter property or <code>null</code> if not present.
*/
public String getFilter() {
checkDisposed();
return this.filter;
}
/**
* Sets the filter property to this instance.
*/
public void setFilter(final String filter) {
checkDisposed();
this.filter = filter;
}
/**
* @return Returns the invers property or <code>null</code> if not present.
*/
public boolean getInvers() {
checkDisposed();
return this.invers;
}
/**
* Sets the invers property to this instance.
*/
public void setInvers(final boolean invers) {
checkDisposed();
this.invers = invers;
}
/**
* @return Returns the userAccount property or <code>null</code> if not present.
*/
public UserAccount getUserAccount() {
checkDisposed();
return this.userAccount;
}
/**
* Sets the userAccount property to this instance.
* Since the reference is a container reference, the opposite reference (UserAccount.userAccountFilter)
* of the userAccount will be handled automatically and no further coding is required to keep them in sync.
* See {@link UserAccount#setUserAccountFilter(UserAccount)}.
*/
public void setUserAccount(final UserAccount userAccount) {
checkDisposed();
if (this.userAccount != null) {
this.userAccount.internalRemoveFromUserAccountFilter(this);
}
this.userAccount = userAccount;
if (this.userAccount != null) {
this.userAccount.internalAddToUserAccountFilter(this);
}
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserAccountFilter other = (UserAccountFilter) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
return true;
}
@Override
public int hashCode() {
int prime = 31;
int result = 1;
result = prime * result + ((this.id== null) ? 0 : this.id.hashCode());
return result;
}
/**
* Iterates all cross references and removes them from the parent to avoid ConstraintViolationException
*/
@PreRemove
protected void preRemove() {
}
}