Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
adapt
ace
Commits
896d4cc0
Commit
896d4cc0
authored
Mar 30, 2017
by
Michael Ritter
Browse files
Introduce CollectionState enum
parent
9d4f1ead
Changes
4
Hide whitespace changes
Inline
Side-by-side
ace-am/src/main/java/edu/umiacs/ace/monitor/core/Collection.java
View file @
896d4cc0
...
...
@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument;
import
javax.persistence.CascadeType
;
import
javax.persistence.CollectionTable
;
import
javax.persistence.Column
;
import
javax.persistence.Convert
;
import
javax.persistence.ElementCollection
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
...
...
@@ -59,6 +60,7 @@ import java.util.Map;
/**
* Collection states
* - A active
* - I interrupted
* - N - never completely scanned (default for new collections)
* - E -
* @author toaster
...
...
@@ -101,7 +103,8 @@ public class Collection implements Serializable {
private
String
storage
;
private
char
state
;
@Convert
(
converter
=
CollectionStateConverter
.
class
)
private
CollectionState
state
;
@Column
(
name
=
"COLGROUP"
)
private
String
group
;
...
...
@@ -193,11 +196,11 @@ public class Collection implements Serializable {
}
public
char
getState
()
{
return
state
;
return
state
.
asChar
()
;
}
public
void
setState
(
char
state
)
{
this
.
state
=
state
;
this
.
state
=
CollectionState
.
fromChar
(
state
)
;
}
public
String
getStorage
()
{
...
...
ace-am/src/main/java/edu/umiacs/ace/monitor/core/CollectionState.java
0 → 100644
View file @
896d4cc0
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
);
}
}
ace-am/src/main/java/edu/umiacs/ace/monitor/core/CollectionStateConverter.java
0 → 100644
View file @
896d4cc0
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
);
}
}
}
ace-am/src/main/resources/META-INF/orm.xml
View file @
896d4cc0
...
...
@@ -15,5 +15,7 @@
</constructor-result>
</sql-result-set-mapping>
<converter
class=
"edu.umiacs.ace.monitor.core.CollectionStateConverter"
/>
</entity-mappings>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment