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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,10 @@
package com.jdbernard.wdiwtlt.db.models; package com.jdbernard.wdiwtlt.db.models;
@Model import java.util.Date;
import javax.persistence.Entity;
@Entity
public class MediaFile { public class MediaFile {
public static final String TAG_INFO = "tag info"; public static final String TAG_INFO = "tag info";
public static final String FILE_LOCATION = "file location"; public static final String FILE_LOCATION = "file location";
@ -12,6 +16,7 @@ public class MediaFile {
public String filePath; public String filePath;
public String fileHash; public String fileHash;
public String metaInfoSource = TAG_INFO; public String metaInfoSource = TAG_INFO;
public Date dateAdded;
public String comment; public String comment;
public String toString() { return name; } 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; package com.jdbernard.wdiwtlt.db.models;
@Model import java.util.Date;
import javax.persistence.Entity;
@Entity
public class Playlist { public class Playlist {
public int id; public int id;
public boolean userCreated;
public Date lastUsed;
public String name; public String name;
public int modCount; public int modCount;
public int mediaFileCount;
public String toString() { return name; } public String toString() { return name; }
} }

View File

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

View File

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