2014-09-10 2 views
0

저는 Ebean을 사용하여 Java로 솔루션을 구현하고 있으며 열거 형을 사용하거나 단순히 테이블을 조회하는 데 문제가 있습니다.열거 형 테이블과 룩업 테이블

나는 "Tooth"테이블을 가지고 있습니다. 치아는 "임시"또는 "영구"일 수 있습니다. 나는 "T"와 "P"를 변환 할 필요가 직접 SQL 쿼리를 수행하려는 경우 그래서 해결책은 조회 테이블을 사용하는 것입니다, 그러나

@EnumMapping(nameValuePairs = "TEMPORARY=T, PERMANENT=P") 
public enum DentitionType { TEMPORARY, PERMANENT; } 

:

나는 간단한 열거를 만들 수 있습니다

@Entity 
public class DentitionType { 

    @Column(length = 15) 
    public String name; 

    private static DentitionType permanent; 

    public boolean isTemporary() { 
     return !this.equals(getPermanent()); 
    } 

    public boolean isPermanent() { 
     return this.equals(getPermanent()); 
    } 

    public static DentitionType getPermanent() { 
     if (permanent == null) { 
      permanent = DentitionType.FIND.byId(2L); 
     } 

     return permanent; 
    } 
} 

이것은 하드 코딩 된 것으로 느껴지고 큰 테이블의 경우 많은 isSomething 함수가 필요합니다.

더 좋은 솔루션이 있습니까? 미리 감사드립니다.

+0

저는 참조/조회 테이블을 지정하는 가장 좋은 방법을 찾는 것과 같은 보트에 있습니다. 내 모든 조회는 데이터베이스에서 수행되므로 참조 무결성을 유지할 수 있습니다. 너 무슨 짓을 한거야? – dotnetster

+0

@dotnetster 조회 테이블을 사용했습니다. 하지만 난 여전히 하드 코드를 발견 ... – KirdApe

답변

0

왜 사용하지 않습니까?

public enum DentitionType { 
    TEMPORARY('T'), PERMANENT('P'); 
    private char value; 
    private Currency(char value) { 
     this.value = value; 
    } 
    public static DentitionType Get(final char value){ 
     for (DentitionType type : DentitionType.values()) 
     if (type.name == name) 
      return type; 
     return null; 
    } 
}; 
+0

좋은 생성자 :) – panagdu