Changed to use standard JPA annotations.

This commit is contained in:
Jonathan Bernard 2016-02-12 14:17:48 -06:00
parent f51c57c7e2
commit 069972bfd5
10 changed files with 37 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import java.sql.PreparedStatement
import java.sql.ResultSet
import java.text.SimpleDateFormat
import java.util.regex.Pattern
import javax.persistence.Entity
import javax.sql.DataSource
import groovy.sql.Sql
@ -118,7 +119,7 @@ public class ORM {
getInstanceFields(model.class)
.findAll { it.name != 'id' }
.each { field ->
//if (field.class.getAnnotation(Model)) // check to see if we
//if (field.class.getAnnotation(Entity)) // check to see if we
// have nested models
columns << '"' + nameFromModel(field.name) + '"'
params << field.get(model) }

View File

@ -1,6 +1,8 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import javax.persistence.Entity;
@Entity
public class Album {
public int id;
public String name;

View File

@ -1,6 +1,8 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import javax.persistence.Entity;
@Entity
public class Artist {
public int id;
public String name;

View File

@ -1,12 +1,15 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import javax.persistence.Entity;
@Entity
public class Bookmark {
public int id;
public String name;
public int playlistId;
public int mediaFileId;
public int playIndex;
public boolean user_created;
public String toString() { return name; }
}

View File

@ -1,6 +1,8 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import javax.persistence.Entity;
@Entity
public class Image {
public int id;
public String url;

View File

@ -1,6 +1,10 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import java.util.Date;
import javax.persistence.Entity;
@Entity
public class MediaFile {
public static final String TAG_INFO = "tag info";
public static final String FILE_LOCATION = "file location";
@ -12,6 +16,7 @@ public class MediaFile {
public String filePath;
public String fileHash;
public String metaInfoSource = TAG_INFO;
public Date dateAdded;
public String comment;
public String toString() { return name; }

View File

@ -1,7 +0,0 @@
package com.jdbernard.wdiwtlt.db.models;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface Model { }

View File

@ -1,10 +1,16 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import java.util.Date;
import javax.persistence.Entity;
@Entity
public class Playlist {
public int id;
public boolean userCreated;
public Date lastUsed;
public String name;
public int modCount;
public int mediaFileCount;
public String toString() { return name; }
}

View File

@ -1,6 +1,8 @@
package com.jdbernard.wdiwtlt.db.models;
@Model
import javax.persistence.Entity;
@Entity
public class Tag {
public int id;
public String name;

View File

@ -22,6 +22,7 @@ CREATE TABLE media_files (
file_path VARCHAR NOT NULL,
file_hash VARCHAR NOT NULL,
meta_info_source VARCHAR NOT NULL, -- 'tag' or 'filesystem'
date_added TIMESTAMP NOT NULL DEFAULT NOW(),
comment VARCHAR DEFAULT ''
);
@ -46,8 +47,11 @@ CREATE TABLE tags (
CREATE TABLE playlists (
id SERIAL PRIMARY KEY,
user_created BOOLEAN NOT NULL DEFAULT FALSE,
last_used TIMESTAMP NOT NULL DEFAULT NOW(),
name VARCHAR NOT NULL,
mod_count INTEGER NOT NULL DEFAULT 0
mod_count INTEGER NOT NULL DEFAULT 0,
media_file_count INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE playlists_media_files (
@ -60,6 +64,7 @@ CREATE TABLE playlists_media_files (
CREATE TABLE bookmarks (
id SERIAL PRIMARY KEY,
name VARCHAR,
user_created BOOLEAN NOT NULL DEFAULT FALSE,
playlist_id INTEGER NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
media_file_id INTEGER NOT NULL REFERENCES media_files(id) ON DELETE CASCADE,
play_index INTEGER NOT NULL