/** * This file is part of JukeIt * * Copyright (C) 2011-2013 Chris Churchwell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.chrischurchwell.jukeit.database; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import com.avaje.ebean.validation.NotEmpty; import com.chrischurchwell.jukeit.JukeIt; @Entity() @Table(name="jb_url_data") public class URLData { public static URLData getEntry(int id) { URLData entry = JukeIt.getInstance().getDatabase().find(URLData.class) .where() .eq("id", id) .findUnique(); return entry; } public static URLData getEntry(String url) { URLData entry = JukeIt.getInstance().getDatabase().find(URLData.class) .where() .eq("url", url) .findUnique(); return entry; } public static URLData saveEntry(String url) { URLData entry = getEntry(url); if (entry != null) { return entry; } entry = new URLData(); entry.setUrl(url); JukeIt.getInstance().getDatabase().save(entry); return entry; } @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; @NotEmpty private String url; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }