tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
0
ZUGRIFFE
747
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    flashray flashray ist offline Mitglied Rubin
    Registriert seit
    Sep 2005
    Ort
    Mannheim
    Beiträge
    1.325
    Hallo,

    ich habe für ein kleines GAE-GWT Projekt ein einfaches Datenmodell entworfen und dies versucht mit JPA umzusetzen. Ist das so im großen und ganzen ok?

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    
    import java.util.Date;
    import java.util.List;
     
    import javax.persistence.*;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class Context {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
     
        private String label;
     
        private String description;
     
        private Date dateAdded;
     
        @OneToMany(cascade = CascadeType.ALL)
        private List<Category> categories;
     
        public Context() {
        }
     
        public Key getKey() {
            return key;
        }
     
        public String getLabel() {
            return label;
        }
     
        public void setLabel(String label) {
            this.label = label;
        }
     
        public Date getDateAdded() {
            return dateAdded;
        }
     
        public void setDateAdded(Date dateAdded) {
            this.dateAdded = dateAdded;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setCategories(List<Category> categories) {
            this.categories = categories;
        }
     
        public List<Category> getCategories() {
            return categories;
        }
    }

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    
    import java.util.List;
     
    import javax.persistence.*;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class Category {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
     
        private String label;
     
        private String description;
        
        private Context context;
     
        @OneToMany(cascade=CascadeType.ALL)
        private List<SubCategory> subcategories;
        
        public Category() {
        }
     
        public Key getKey() {
            return key;
        }
     
        public String getLabel() {
            return label;
        }
     
        public void setLabel(String label) {
            this.label = label;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setSubcategories(List<SubCategory> subcategories) {
            this.subcategories = subcategories;
        }
     
        public List<SubCategory> getSubcategories() {
            return subcategories;
        }
     
        public void setContext(Context context) {
            this.context = context;
        }
     
        public Context getContext() {
            return context;
        }
    }

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    
    import javax.persistence.*;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class SubCategory {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
     
        private String label;
     
        private String description;
        
        private Category category;
        
        public SubCategory() {
        }
     
        public Key getKey() {
            return key;
        }
     
        public String getLabel() {
            return label;
        }
     
        public void setLabel(String label) {
            this.label = label;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public String getDescription() {
            return description;
        }
     
        public Category getCategory() {
            return category;
        }
     
        public void setCategory(Category category) {
            this.category = category;
        }
    }

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    
    import java.util.Date;
     
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class Link {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
     
        private String label;
     
        private String url;
        
        private String description;
     
        private Date dateAdded;
     
        public Link() {
        }
        
        public Key getKey() {
            return key;
        }
     
        public String getLabel() {
            return label;
        }
     
        public void setLabel(String label) {
            this.label = label;
        }
     
        public String getUrl() {
            return url;
        }
     
        public void setUrl(String url) {
            this.url = url;
        }
     
        public Date getDateAdded() {
            return dateAdded;
        }
     
        public void setDateAdded(Date dateAdded) {
            this.dateAdded = dateAdded;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public String getDescription() {
            return description;
        } 
    }

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class MetaData {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
     
        private long hits;
     
        private double rating;
     
        private long ratingCount;
     
        private Link link;
        
        private Context context;
        
        public MetaData() {
        }
     
        public Key getKey() {
            return key;
        }
     
        public long getHits() {
            return hits;
        }
     
        public void setHits(long hits) {
            this.hits = hits;
        }
     
        public double getRating() {
            return rating;
        }
     
        public void setRating(double rating) {
            this.rating = rating;
        }
     
        public long getRatingCount() {
            return ratingCount;
        }
     
        public void setRatingCount(long ratingCount) {
            this.ratingCount = ratingCount;
        }
     
        public void setLink(Link link) {
            this.link = link;
        }
     
        public Link getLink() {
            return link;
        }
     
        public void setContext(Context context) {
            this.context = context;
        }
     
        public Context getContext() {
            return context;
        }
     
    }

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
     
    import com.google.appengine.api.datastore.Key;
     
    @Entity
    public class Mapping {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Key key;
        
        private Link link;
        
        private SubCategory subcategory;
     
        public Mapping() {
        }
        
        public Key getKey() {
            return key;
        }
     
        public Link getLink() {
            return link;
        }
     
        public void setLink(Link link) {
            this.link = link;
        }
     
        public SubCategory getSubcategory() {
            return subcategory;
        }
     
        public void setSubcategory(SubCategory subcategory) {
            this.subcategory = subcategory;
        }
    }
    Miniaturansicht angehängter Grafiken Miniaturansicht angehängter Grafiken JPA-datenmodell.png