Introduction
I've tasked myself with learning the new things available to JDK 7 and EJB 3.1 and how they integrate with Netbeans. In order to so do, in my experience, it is most gratifying to pick up a new project using these new technologies.
In this case, as at the time, I was wondering what to do with my old Photographs, I've decided to start up a project called YourPersonalPhotographOrganiser, which is nothing more than a simple Photo Gallery.
You can find the netbeans project on github at https://github.com/maartenl/YourPersonalPhotographOrganiser. Just check it out into your ~/NetBeansProjects/YourPersonalPhotographOrganiser directory, and see how far you get.
It's a work in progress, but it's at the stage where there's something more or less workable. Let me remind you that this software is for use at your own risk. Use it locally, as there is NO security (neither authentication nor authorization) implemented at the moment.
Requirements
- simple database, easy to make changes directly, if so required
- used for home use
- no authentication or authorization required
- helps me to understand the jdk 7, glassfish and jee 3.1, by using all the new stuff in there.
- absolutely NO changing of the photographs, all changes are done in java, in memory, in glassfish.*
- flexible in where these photographs are located (no need to keep them in the webdir, for example)
*) I've had too many instances where:
- changing files from webinterface is a security risk, and requires proper access rights.
- changing files causes the extra data present in the jpegs put there by photocameras to be discarded
- changing files potentially causes deterioration of the quality of the jpegs
- changing files has sometimes caused the file to be damaged in some way
- changing files makes it impossible to determine if the photo is already present in your collection
Technical
Some of the (new) stuff that is being used.- JDK7 (Look for "JDK7" in the sourcecode)
- multiple catch
- try-with-resources
- new switch statement
- diamond-notation
- filevisitor interface
- Path class usage
- EJB 3.1
- no local interfaces on beans
- EJBs inside the WAR, no longer is an EAR required
- Improved Context and Dependency Injection
- Netbeans IDE 7.0.1.
- GlassFish Server Open Source Edition 3.1.1 (build 12).
- JPA (Hibernate)
- REST (Jersey)
- MySQL
- JQuery
- HTML, CSS, JavaScript and AJAX
- JSON
Database Schema
The database schema below shows the used Hibernate Entities. They have the same name as the tables. The database script below should run without errors on your average MySQL database.drop table if exists Log;
drop table if exists Tag;
drop table if exists Comment;
drop table if exists GalleryPhotograph;
drop table if exists Gallery;
drop table if exists Photograph;
drop table if exists Location;
create table Location (
id bigint not null auto_increment primary key,
filepath varchar(512)
);
create table Photograph (
id bigint not null auto_increment primary key,
location_id bigint not null,
filename varchar(255),
relativepath varchar(1024),
taken timestamp,
hashstring varchar(1024),
filesize bigint,
angle int,
foreign key (location_id) references Location (id)
);
create table Gallery (
id bigint not null auto_increment primary key,
name varchar(80),
description text,
creation_date timestamp not null default current_timestamp,
parent_id bigint,
highlight bigint,
sortorder int not null,
foreign key (parent_id) references Gallery (id),
foreign key (highlight) references Photograph (id)
);
create table GalleryPhotograph (
id bigint not null auto_increment primary key,
gallery_id bigint not null,
photograph_id bigint not null,
name varchar(255),
description text,
sortorder bigint,
foreign key (gallery_id) references Gallery (id),
foreign key (photograph_id) references Photograph (id)
);
create table Comment (
id bigint not null auto_increment primary key,
galleryphotograph_id bigint not null,
author varchar(255),
submitted timestamp,
comment text,
foreign key (galleryphotograph_id) references GalleryPhotograph (id)
);
create table Tag (
tagname varchar(80) not null,
photograph_id bigint not null,
primary key (tagname, photograph_id),
foreign key (photograph_id) references Photograph (id)
);
create table Log (
id bigint not null auto_increment primary key,
jobdate timestamp not null default current_timestamp,
joblog blob not null
);
-- only allows a photograph to appear once in a gallery
create unique index unique_per_photograph_per_gallery
on GalleryPhotograph (gallery_id, photograph_id);
drop table if exists Tag;
drop table if exists Comment;
drop table if exists GalleryPhotograph;
drop table if exists Gallery;
drop table if exists Photograph;
drop table if exists Location;
create table Location (
id bigint not null auto_increment primary key,
filepath varchar(512)
);
create table Photograph (
id bigint not null auto_increment primary key,
location_id bigint not null,
filename varchar(255),
relativepath varchar(1024),
taken timestamp,
hashstring varchar(1024),
filesize bigint,
angle int,
foreign key (location_id) references Location (id)
);
create table Gallery (
id bigint not null auto_increment primary key,
name varchar(80),
description text,
creation_date timestamp not null default current_timestamp,
parent_id bigint,
highlight bigint,
sortorder int not null,
foreign key (parent_id) references Gallery (id),
foreign key (highlight) references Photograph (id)
);
create table GalleryPhotograph (
id bigint not null auto_increment primary key,
gallery_id bigint not null,
photograph_id bigint not null,
name varchar(255),
description text,
sortorder bigint,
foreign key (gallery_id) references Gallery (id),
foreign key (photograph_id) references Photograph (id)
);
create table Comment (
id bigint not null auto_increment primary key,
galleryphotograph_id bigint not null,
author varchar(255),
submitted timestamp,
comment text,
foreign key (galleryphotograph_id) references GalleryPhotograph (id)
);
create table Tag (
tagname varchar(80) not null,
photograph_id bigint not null,
primary key (tagname, photograph_id),
foreign key (photograph_id) references Photograph (id)
);
create table Log (
id bigint not null auto_increment primary key,
jobdate timestamp not null default current_timestamp,
joblog blob not null
);
-- only allows a photograph to appear once in a gallery
create unique index unique_per_photograph_per_gallery
on GalleryPhotograph (gallery_id, photograph_id);
Update 1: Moved angle field from GalleryPhotograph over to Photograph
Update 2: It's nice to have a script for creating the database, but an ORM can automatically generate the proper tables for you if you like.
Inside the file.jsp,there is <%@ page import="gallery.beans.PhotographFacadeLocal"%>, but where is the PhotographFacadeLocal? It's not in the folder specified.
ReplyDeleteYou are absolutely right. Deleted the reference to the non-existing file.
DeleteUpdated github. (It's been a while since I got into this project. Time I started it
up again.)