~peter-kovac11/play/play-scala-console-improvements

« back to all changes in this revision

Viewing changes to samples-and-tests/yabe-with-scala/app/models/Tag.java

  • Committer: guillaume
  • Date: 2009-11-11 17:19:54 UTC
  • Revision ID: guillaume@macbook-pro-de-guillaume.local-20091111171954-1z761dqr0aw93747
yabe-with-scala

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package models;
2
 
 
3
 
import java.util.*;
4
 
import javax.persistence.*;
5
 
 
6
 
import play.db.jpa.*;
7
 
import play.data.validation.*;
8
 
 
9
 
@Entity
10
 
public class Tag extends Model implements Comparable<Tag> {
11
 
 
12
 
    @Required
13
 
    public String name;
14
 
    
15
 
    private Tag(String name) {
16
 
        this.name = name;
17
 
    }
18
 
    
19
 
    public static Tag findOrCreateByName(String name) {
20
 
        Tag tag = Tag.find("byName", name).one();
21
 
        if(tag == null) {
22
 
            tag = new Tag(name);
23
 
        }
24
 
        return tag;
25
 
    }
26
 
    
27
 
    public static List<Map> getCloud() {
28
 
        List<Map> result = Tag.find(
29
 
            "select new map(t.name as tag, count(p.id) as pound) from Post p join p.tags as t group by t.name"
30
 
        ).fetch();
31
 
        return result;
32
 
    }
33
 
    
34
 
    public String toString() {
35
 
        return name;
36
 
    }
37
 
    
38
 
    public int compareTo(Tag otherTag) {
39
 
        return name.compareTo(otherTag.name);
40
 
    }
41
 
 
42
 
}
 
 
b'\\ No newline at end of file'