SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-16-2010, 11:37 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Database Recommendations?

I need to make use of a database in one of my plugins and I've never used a database before in Java. I see there are various plugins already available that have to do with database manipulation but I have no idea what they do or how to use them (SQLite JDBC, Sage H2).

My needs are simple. I'm currently storing data as serialized objects in a flat file that I read into memory and search as needed. To speed things up I keep the file loaded in memory but this is causing the plugin to use way too much Java Heap. The database can grow to be several hundred MB.

What database systems are available that:
- Are either already being used by other plugins (ideal) or can easily be added to the Sage repository?
- Have a reasonable learning curve.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #2  
Old 10-16-2010, 11:55 AM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
JavaDB (formally known as Apache Derby) used to be popular. But it really seems H2 is more popular these days. There are a couple of plugins already out there that seem to be using H2. I have played with both, albeit in a limited fashion and I prefer H2. I thought someone else was using H2 in sage, but I don't see it in the libraries list -- maybe ortus was using it..

SQLLite is out there as a dependency already - but I have never used that one.

One benefit of H2 (IMO) over JavaDB is that you can have in memory databases - great for unit testing, etc.

However, from a difficulty aspect - the should all pretty much be the same. A few lines of initialization code and then just standard SQL.
Reply With Quote
  #3  
Old 10-16-2010, 11:59 AM
jaminben jaminben is offline
Sage Icon
 
Join Date: Sep 2007
Location: Norwich, UK
Posts: 1,754
Send a message via MSN to jaminben
Ya, Ortus uses a H2 database.....but thats as much help as I can give as I didn't set it up

Cheers

Ben

Edit

Actually I think Phoenix uses H2 as well but I can't be sure.
__________________
Server - Win7 64bit, 2.4Ghz Intel Core 2 Duo, TBS 6284 PCI-E Quad DVB-T2 Tuner, 3 x HD200 & 1 x HD300 extenders

Last edited by jaminben; 10-16-2010 at 12:02 PM.
Reply With Quote
  #4  
Old 10-16-2010, 12:19 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Sounds like H2 is the leading candidate. Time to do some reading, thanks.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #5  
Old 10-16-2010, 12:24 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Is it really necessary to store it seperate now with the new userrecord API additions to metadata you could store them there and would be a better way. I have been giving much that to switching smm over to using it. I am assuming you can store you complete custom objects in there but haven't had time to test it yet. I would stay away from a external db if at all possible especially if you don't have any database knowledge.
Reply With Quote
  #6  
Old 10-16-2010, 01:44 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by PLUCKYHD View Post
Is it really necessary to store it seperate now with the new userrecord API additions to metadata you could store them there and would be a better way. I have been giving much that to switching smm over to using it. I am assuming you can store you complete custom objects in there but haven't had time to test it yet. I would stay away from a external db if at all possible especially if you don't have any database knowledge.
I don't think it's possible for me to use the new metadata API. I'm working with Podcasts that may or may not have a MediaFile and the MediaFile may or may not have been deleted. I am also hesitant to fill up the wiz.bin with many MB of data. Maybe I've misunderstood this API?

As for not having any DB knowledge, that makes it all the more fun and challenging. A year ago I didn't have any Java knowledge and a year before that I didn't have any Studio knowledge.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #7  
Old 10-16-2010, 02:28 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by tmiranda View Post

As for not having any DB knowledge, that makes it all the more fun and challenging. A year ago I didn't have any Java knowledge and a year before that I didn't have any Studio knowledge.
I definately wouldn't worry about filling up the sage db the not having a media file is understandable and the issue I am facing with smm however I have deemed a way worthy of faking that aspect like playon does.

And I know about learning was just trying to steer you away as a database adds allot of maintenance and issues.

That said I understand the need an want for an external database so if you power on good luck.
Reply With Quote
  #8  
Old 10-16-2010, 02:44 PM
Fonceur's Avatar
Fonceur Fonceur is offline
Sage Icon
 
Join Date: Jan 2008
Location: DDO, QC
Posts: 1,915
Quote:
Originally Posted by tmiranda View Post
I am also hesitant to fill up the wiz.bin with many MB of data. Maybe I've misunderstood this API?
You are not putting the whole podcast in there (you might be able as a blob, but...), just links and such, so it shouldn't be that bad...
__________________
SageTCPServer (2.3.5): Open source TCP interface to the SageTV API
MLSageTV (3.1.8)/Sage Media Server (1.13): SageTV plugin for MainLobby/CQC
TaSageTV (2.58)/TaSTVRemote (1.14): Monitor/control SageTV with an Android device
TbSageTV (1.02)/STVRemote (1.11): Monitor/control SageTV with a PlayBook 2
TiSageTV (1.64)/TiSTVRemote (1.09): Monitor/control SageTV with an iPhone/iPod/iPad
Reply With Quote
  #9  
Old 10-16-2010, 02:55 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by Fonceur View Post
You are not putting the whole podcast in there (you might be able as a blob, but...), just links and such, so it shouldn't be that bad...
No, not the whole podcast but there is a lot of other data. There is the "Podcast", which contains general information about the feed and then for each Podcast there are multiple "Episodes" that contain information about that specific Episode. Depending on how the plugin is used there may be dozens or hundreds of Podcasts defined and then each Podcast can have a hundred or more Episodes.

A lot of the data needs to stay around for a long time. For example, when a user downloads an Episode, watches it, and then deletes it. I need to keep track of which Episodes were downloaded and deleted and which were not.

I'm open to suggestions on how to use the existing Sage API, but it seems to me that a real database is the best way to go.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #10  
Old 10-16-2010, 02:57 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Aside from that, there may be other advantages to treating the podcasts as mediafiles (the dummy files Plucky mentioned).
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #11  
Old 10-16-2010, 03:33 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by Fuzzy View Post
Aside from that, there may be other advantages to treating the podcasts as mediafiles (the dummy files Plucky mentioned).
After they are recorded they ARE MediaFiles, that's the easy part. It's before they are recorded and after they are deleted that I need to worry about.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #12  
Old 10-16-2010, 03:42 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by tmiranda View Post
After they are recorded they ARE MediaFiles, that's the easy part. It's before they are recorded and afterthey are deleted that I need to worry about.
That's easy use the series API to keep the history an future about each podcast as a series. That would actually work pretty well since jeff opened up that series for us. That would actually work pretty well treat each podcast series as a series.
Reply With Quote
  #13  
Old 10-16-2010, 05:12 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by PLUCKYHD View Post
That's easy use the series API to keep the history an future about each podcast as a series.
That's interesting, I'll have to take a closer look at that API.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #14  
Old 10-16-2010, 06:49 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Just to clarify... Phoenix does not use an external database. I did look at H2 at one point, and if I were to use a database, then I'd use H2.

But, to be honest, I haven't found a reason to actually use database to store anything.

The new UserRecordAPI was actually something that I had requested as a means to store user defined records in the wiz.bin. Now that it has been added, I don't see any reason to use a database at all.

You can store any fields you want in the UserRecordAPI, and as long as you have a primary key (ie, a unique identifier) for each record, then retrieving the data is fairly fast. Also the data can be retreived from the server or the client transparently, like any other sage api.

UserRecordAPI has the idea of "stores". "stores" are basically like tables. So you add a new record to a store using a key, and then you have a dynamic record on which you can operate.

For example, you might have a feed store, named, "tmiranda.feed", where the primary key is the feed url. You can then store data against that feed url, and retrieve using the feed url. Lkewise you can create a store, "tmiranda.media", where the primary key is the media download url. You can then track watched statuses, fetch date, etc, against the url.

you can use the UserRecordAPI in conjuntion with other APIs, such as the SeriesInfoInfo. ie, if you are storing "series" type information, then using the SeriesInfoAPI make sense.

If you do decide to use the UserRecordAPI, then I strongly suggest that you prefix all your "stores" with your own identifier. Just so you know, "phoenix.", "sagex." and "bmt." is reserved (the honour system)
Reply With Quote
  #15  
Old 10-16-2010, 06:54 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post

If you do decide to use the UserRecordAPI, then I strongly suggest that you prefix all your "stores" with your own identifier. Just so you know, "phoenix.", "sagex." and "bmt." is reserved (the honour system)
Man guess I need to rename

Does the user API allow storing custom objects it doesn't appear to but I haven't honestly looked at it hard yet.
Reply With Quote
  #16  
Old 10-16-2010, 07:39 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
No, there are no typed objects, just Strings, in the UserRecordAPI. This is consistent with the other apis that have been added to mediafile, series, favorites, etc.

So, if you need to retain a value as an int, boolean, etc, then you'll have to manually convert the data from a string to the required type.
Reply With Quote
  #17  
Old 10-16-2010, 08:17 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
No, there are no typed objects, just Strings, in the UserRecordAPI. This is consistent with the other apis that have been added to mediafile, series, favorites, etc.

So, if you need to retain a value as an int, boolean, etc, then you'll have to manually convert the data from a string to the required type.
That is what I thought when I glanced over it thanks.
Reply With Quote
  #18  
Old 10-16-2010, 09:06 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
One potential downside to storing a large volume of plugin-specific data in Wiz.bin is that people who uninstall your plugin then have no easy way to get rid of that leftover data. Storing it in an external database in a plugin-specific subdirectory makes it easier to find and remove later.

If you do decide to go the Wiz.bin route, you should probably provide a cleanup command that people can use to purge your plugin's data before uninstalling it.
__________________
-- Greg
Reply With Quote
  #19  
Old 10-16-2010, 09:07 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Until recently, I've always used SQLite. It works, but when we looked at adding STVi support for SRE it became apparent that SQLite doesn't fit well when you need to access the DB on the server from a PC client. It was either roll my own client/server comm to access the SQLite DB (lol!!) or move to a client/server DB. Once I started looking at H2 closely it was a no brainer.

I obviously won't remove the SQLite JDBC driver from the plugin repository, but any future projects will definitely be H2 and I'll eventually move my current projects that are still using SQLite (SageAlert) over to H2 at some point in the future. The web console for H2 was an added bonus on top of the client/server architecture. Also, referential constraints that are actually enforced is a really nice thing to have as well. Not that I've tried it yet, but Java classes can be used as UDFs, which kind of caught my attention as well. You can even embed Java code as UDFs directly via SQL.

Bottom line, I recommend H2, especially if you need to access the DB on PC clients.

And by the time we're done with SJQv4 you'll be an SQL/H2 expert!
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
Reply With Quote
  #20  
Old 10-17-2010, 06:11 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by GKusnick View Post
One potential downside to storing a large volume of plugin-specific data in Wiz.bin is that people who uninstall your plugin then have no easy way to get rid of that leftover data. Storing it in an external database in a plugin-specific subdirectory makes it easier to find and remove later.

If you do decide to go the Wiz.bin route, you should probably provide a cleanup command that people can use to purge your plugin's data before uninstalling it.
I agree... Too bad there isn't a hook that gets called in the Plugin API to notify a plugin when it gets removed

Because the UserRecordAPI is made of up stores, as long a devs stick to a consistent naming scheme, it should be fairly easy for someone like yourself to get a list of all of the "stores" and then delete the ones that should not be there... you know, in case the developer doesn't remove their data store automatically, which is bound to happen. If I get time, I'll probably add a data browser to the bmt web ui, so that people can browse the stores, data, remove them, etc.

Quote:
Originally Posted by Slugger View Post
Once I started looking at H2 closely it was a no brainer.

Bottom line, I recommend H2, especially if you need to access the DB on PC clients.
I'd have to agree... H2 is a solid and feature rich database. I think that there is a sagex-h2 plugin in the repository. It's not mine, but I do depend on it in phoenix as well... even though I haven't actually needed to use the database yet. I'd recommend using it, since it has the plugin configuration for setting the port, enabling the servers, etc. We probably don't want to have 4-5 different H2 instances all running inside side.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wacky Database noble SageTV HD Theater - Media Player 3 03-13-2009 08:11 AM
Database upgrade may take a while... jzaman SageTV Software 9 01-08-2007 09:14 PM
Database help. stanger89 SageTV Customizations 7 04-16-2006 03:58 PM
Database Compatability wolfpackmars2 SageTV Software 2 11-07-2005 05:19 PM


All times are GMT -6. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.