Commit 896d4cc0 authored by Michael Ritter's avatar Michael Ritter
Browse files

Introduce CollectionState enum

parent 9d4f1ead
...@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument; ...@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
...@@ -59,6 +60,7 @@ import java.util.Map; ...@@ -59,6 +60,7 @@ import java.util.Map;
/** /**
* Collection states * Collection states
* - A active * - A active
* - I interrupted
* - N - never completely scanned (default for new collections) * - N - never completely scanned (default for new collections)
* - E - * - E -
* @author toaster * @author toaster
...@@ -101,7 +103,8 @@ public class Collection implements Serializable { ...@@ -101,7 +103,8 @@ public class Collection implements Serializable {
private String storage; private String storage;
private char state; @Convert(converter = CollectionStateConverter.class)
private CollectionState state;
@Column(name = "COLGROUP") @Column(name = "COLGROUP")
private String group; private String group;
...@@ -193,11 +196,11 @@ public class Collection implements Serializable { ...@@ -193,11 +196,11 @@ public class Collection implements Serializable {
} }
public char getState() { public char getState() {
return state; return state.asChar();
} }
public void setState( char state ) { public void setState( char state ) {
this.state = state; this.state = CollectionState.fromChar(state);
} }
public String getStorage() { public String getStorage() {
......
package edu.umiacs.ace.monitor.core;
/**
* A test to see how we can do this
*
* Created by shake on 3/30/17.
*/
public enum CollectionState {
ACTIVE, INTERRUPTED, NEVER, ERROR;
public static CollectionState fromChar(char state) {
switch (state) {
case 'A':
return ACTIVE;
case 'I':
return INTERRUPTED;
case 'N':
return NEVER;
case 'E':
return ERROR;
default:
throw new IllegalArgumentException("Unknown state " + state);
}
}
public char asChar() {
return this.name().charAt(0);
}
}
package edu.umiacs.ace.monitor.core;
import javax.persistence.AttributeConverter;
/**
* Converter to go from CollectionState enum to a Char
*
* Created by shake on 3/30/17.
*/
public class CollectionStateConverter implements AttributeConverter<CollectionState, String> {
@Override
public String convertToDatabaseColumn(CollectionState collectionState) {
switch (collectionState) {
case ACTIVE:
return "A";
case NEVER:
return "N";
case INTERRUPTED:
return "I";
case ERROR:
return "E";
default:
throw new IllegalArgumentException("Unknown state " + collectionState);
}
}
@Override
public CollectionState convertToEntityAttribute(String s) {
switch (s) {
case "A":
return CollectionState.ACTIVE;
case "N":
return CollectionState.NEVER;
case "I":
return CollectionState.INTERRUPTED;
case "E":
return CollectionState.ERROR;
default:
throw new IllegalArgumentException("Unknown state " + s);
}
}
}
...@@ -15,5 +15,7 @@ ...@@ -15,5 +15,7 @@
</constructor-result> </constructor-result>
</sql-result-set-mapping> </sql-result-set-mapping>
<converter class="edu.umiacs.ace.monitor.core.CollectionStateConverter"/>
</entity-mappings> </entity-mappings>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment