edu.internet2.middleware.grouperBox.GrouperBoxDbUser Maven / Gradle / Ivy
package edu.internet2.middleware.grouperBox;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import edu.internet2.middleware.grouperClient.jdbc.GcDbAccess;
import edu.internet2.middleware.grouperClient.jdbc.GcPersist;
import edu.internet2.middleware.grouperClient.jdbc.GcPersistableClass;
import edu.internet2.middleware.grouperClient.jdbc.GcPersistableField;
import edu.internet2.middleware.grouperClient.jdbc.GcSqlAssignPrimaryKey;
import edu.internet2.middleware.grouperClient.util.GrouperClientUtils;
@GcPersistableClass(tableName="penn_box_user", defaultFieldPersist=GcPersist.doPersist)
public class GrouperBoxDbUser implements GcSqlAssignPrimaryKey {
/**
*
*/
@Override
public boolean gcSqlAssignNewPrimaryKeyForInsert() {
if (this.boxId != null) {
return false;
}
this.boxId = this.boxIdForInsert;
return true;
}
public GrouperBoxDbUser() {
}
public List retrieveAllFromDatabase() {
List grouperBoxDbUserList = new GcDbAccess()
.sql("select * from penn_box_user").selectList(GrouperBoxDbUser.class);
return grouperBoxDbUserList;
}
/**
*
*/
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof GrouperBoxDbUser)) {
return false;
}
GrouperBoxDbUser other = (GrouperBoxDbUser) obj;
return new EqualsBuilder()
.append(this.boxId, other.boxId)
// ignore boxIdForInsert
.append(this.createdAt, other.createdAt)
.append(this.login, other.login)
.append(this.modifiedAt, other.modifiedAt)
.append(this.name, other.name)
.append(this.spaceUsed, other.spaceUsed)
.append(this.status, other.status)
.append(this.subjectId, other.subjectId)
.isEquals();
}
/**
* Computes the hash code based on the origin and destination nodes
*
* @return the hash code
*/
@Override
public int hashCode() {
return new HashCodeBuilder()
.append( this.boxId)
// ignore boxIdForInsert
.append( this.createdAt)
.append( this.login)
.append( this.modifiedAt)
.append( this.name)
.append( this.spaceUsed)
.append( this.status)
.append( this.subjectId)
.toHashCode();
}
/**
*
*/
private void storePrepare() {
this.name = GrouperClientUtils.abbreviate(this.name, 100);
}
/**
*
*/
public void store() {
this.storePrepare();
new GcDbAccess().storeToDatabase(this);
}
/**
* delete batch
* @param gcGrouperSyncGroups
* @return rows deleted (groups and logs)
*/
public static int deleteBatch(Collection grouperBoxDbUsers) {
int count = 0;
if (GrouperClientUtils.length(grouperBoxDbUsers) == 0) {
return 0;
}
List> batchBindVars = new ArrayList>();
for (GrouperBoxDbUser grouperBoxDbUser : grouperBoxDbUsers) {
List