multimedia database using emmo model · tory pattern’. both the examples give results from the...

26
Multimedia Database Using EMMO Model (Enhanced Multimedia Meta Object) Report 08 By Insiya A. Fatehi 29 September 2012

Upload: others

Post on 01-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Multimedia Database Using EMMO Model(Enhanced Multimedia Meta Object)

Report 08

ByInsiya A. Fatehi

29 September 2012

Page 2: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Contents

1 Code Examples for Java Design Patterns 21.1 Facade Factory Pattern Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Abstract Factory Pattern Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2 Understanding Interns Code 202.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.1.1 javax.persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.1.2 javax.validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.1.3 javax.xml.bind.annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.1.4 java.util . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222.1.5 javax.ejb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.2 Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1

Page 3: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Chapter 1

Code Examples for Java Design Patterns

The first example shown below is that of an ’Facade Pattern’ and the next is an ’Abstract Fac-tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO MultimediaDatabase (EMMO MM DB) created before.

1.1 Facade Factory Pattern Example

In this example, we have 6 Java classes : FacadeTest.java, Facade.java, LmpSearch.java,OntoSearch.java, AssoSearch.java, EmmoSearch.java.

The FacadeTest.java is the class where the main resides. The Facade.java is the Facade class.The main in FacadeTest.java makes a call to this class. The remaining four classes are responsiblefor connecting to database, retrieving and printing the corresponding data from the Entity tablein EMMO MM DB. Their code is as shown below :

LmpSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

import java.sql.*;

/**

*

* @author insiya

*/

public class LmpSearch

{

public void search()

{

try

2

Page 4: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

{

System.out.println("The results for LMP search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=100;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

OntoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

import java.sql.*;

/**

*

* @author insiya

*/

public class OntoSearch

{

public void search()

25 August 2012 Week 05 Report 05 3

Page 5: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

{

try

{

System.out.println("The results for ONTO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=200;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

AssoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

import java.sql.*;

/**

*

* @author insiya

25 August 2012 Week 05 Report 05 4

Page 6: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

*/

public class AssoSearch

{

public void search()

{

try

{

System.out.println("The results for ASSO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=300;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

EmmoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

25 August 2012 Week 05 Report 05 5

Page 7: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

import java.sql.*;

/**

*

* @author insiya

*/

public class EmmoSearch

{

public void search()

{

try

{

System.out.println("The results for EMMO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=400;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

25 August 2012 Week 05 Report 05 6

Page 8: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

The Facade.java is the Facade class. A Facade pattern hides the complexities of the system andprovides an interface to the client from where the client can access the system. Here, this classcreates an object of the other classes and calls their search methods.

Facade.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

import java.sql.*;

/**

*

* @author insiya

*/

public class Facade

{

public void choose()

{

LmpSearch l=new LmpSearch();

OntoSearch o=new OntoSearch();

AssoSearch a=new AssoSearch();

EmmoSearch e=new EmmoSearch();

l.search();

o.search();

a.search();

e.search();

}

}

The FacadeTest.java is where the main method is and makes a call to the Facade.java class.

FacadeTest.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package facadetest;

import java.sql.*;

25 August 2012 Week 05 Report 05 7

Page 9: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

import java.util.*;

import java.io.*;

/**

*

* @author insiya

*/

public class FacadeTest

{

public static void main(String[] args) throws IOException

{

Facade f=new Facade();

f.choose();

}

}

Output :run:The results for LMP search are :Row 1EMMO VideoRow 2Basic EMMO SlidesRow 3Titanic SongRow 4The Cabinet Of CaligariRow 5Salem’s LotRow 6Titanic Song LyricsRow 7NosferatuThe results for ONTO search are :Row 1paymentRow 2InstructsRow 3ResearcherRow 4Elizabeth MillerRow 5VideoRow 6DirectorRow 7

25 August 2012 Week 05 Report 05 8

Page 10: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

TopicRow 8SingerRow 9PPT PresentationRow 10RenderingRow 11UploadRow 12DownloadRow 13LoginRow 14TextRow 15SpeakerRow 16LyricistRow 17ComposesRow 18inspireRow 19LanguageRow 20MovieThe results for ASSO search are :Row 1ca→noRow 2dr→ moV1Row 3ly→soRow 4ev→ esRow 5mi→ (va→ dr)Row 6no→ saRow 7dr→ noRow 8va→ drThe results for EMMO search are :Row 1Song Lyrics

25 August 2012 Week 05 Report 05 9

Page 11: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

Row 2Dracula ResearchRow 3Dracula Movies V3Row 4Dracula Movies V2Row 5Dracula StudiesRow 6Dracula Movies V1Row 7Dracula MoviesRow 8Lecture presentationBUILD SUCCESSFUL (total time: 0 seconds)

25 August 2012 Week 05 Report 05 10

Page 12: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

1.2 Abstract Factory Pattern Example

In this example, we first create an abstract class named Search.java. It contains an abstract methodsearch().Then we create four specific search classes that extends this abstract class in their class. Theclasses are LmpSearch.java, OntoSearch.java, AssoSearch.java, EmmoSearch.java.After this, we create the AbstractTest.java class which contains the main class.

The abstract class code is as follows :

Search.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

/**

*

* @author insiya

*/

public abstract class Search

{

public abstract void search();

}

25 August 2012 Week 05 Report 05 11

Page 13: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

The four specific search classes code is as below :

LmpSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

import java.sql.*;

import java.io.*;

/**

*

* @author insiya

*/

public class LmpSearch extends Search

{

@Override

public void search()

{

try

{

System.out.println("The results for LMP search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=100;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

System.out.println("connected to db-lmp");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

25 August 2012 Week 05 Report 05 12

Page 14: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

{

e.printStackTrace();

}

}

}

OntoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

import java.sql.*;

/**

*

* @author insiya

*/

public class OntoSearch extends Search

{

@Override

public void search()

{

try

{

System.out.println("The results for ONTO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=200;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

25 August 2012 Week 05 Report 05 13

Page 15: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

AssoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

import java.sql.*;

/**

*

* @author insiya

*/

public class AssoSearch extends Search

{

@Override

public void search()

{

try

{

System.out.println("The results for ASSO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=300;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

} //end while

con.close();

25 August 2012 Week 05 Report 05 14

Page 16: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

EmmoSearch.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

import java.sql.*;

/**

*

* @author insiya

*/

public class EmmoSearch extends Search

{

@Override

public void search()

{

try

{

System.out.println("The results for EMMO search are : ");

String db1;

int db3;

String dbUrl = "jdbc:mysql://127.0.0.1/EMMO_MM_DB";

String query = "Select name FROM Entity where kind_id=400;";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(dbUrl,"root","root");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next())

{

db1 = rs.getString(1);//gets 1st column data.

db3=rs.getRow();//gets the row no.

System.out.println("Row "+db3);

System.out.println(db1);

25 August 2012 Week 05 Report 05 15

Page 17: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

} //end while

con.close();

}

catch(ClassNotFoundException e)

{

e.printStackTrace();

}

catch(SQLException e)

{

e.printStackTrace();

}

}

}

The AbstractTest.java contains the main and according to the user’s choice it creates an object ofthe particular class. With this object the methods of these subclasses can be accessed.

AbstractTest.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package abstracttest;

import java.io.*;

/**

*

* @author insiya

*/

public class AbstractTest

{

private Search s;

public static void main(String args[]) throws IOException

{

DataInputStream in=new DataInputStream(System.in);

int n;

System.out.println("Enter your choice");

System.out.println("1-LMP\n2-ONTO\n3-ASSO\n4-EMMO");

n=Integer.parseInt(in.readLine());

AbstractTest at=new AbstractTest();

Search s1=at.getSearchCategory(n);

s1.search();

}

public Search getSearchCategory(int n)

{

25 August 2012 Week 05 Report 05 16

Page 18: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

if(n==1)

{

s=new LmpSearch();

}

else

{

if(n==2)

{

s=new OntoSearch();

}

else

{

if(n==3)

{

s=new AssoSearch();

}

else

{

if(n==4)

{

s=new EmmoSearch();

}

}

}

}

return s;

}

}

Output :run:Enter your choice1-LMP2-ONTO3-ASSO4-EMMO1The results for LMP search are :connected to db-lmpRow 1EMMO VideoRow 2Basic EMMO SlidesRow 3Titanic SongRow 4

25 August 2012 Week 05 Report 05 17

Page 19: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

The Cabinet Of CaligariRow 5Salem’s LotRow 6Titanic Song LyricsRow 7NosferatuBUILD SUCCESSFUL (total time: 3 seconds)

run:Enter your choice1-LMP2-ONTO3-ASSO4-EMMO2The results for ONTO search are :Row 1paymentRow 2InstructsRow 3ResearcherRow 4Elizabeth MillerRow 5VideoRow 6DirectorRow 7TopicRow 8SingerRow 9PPT PresentationRow 10RenderingRow 11UploadRow 12DownloadRow 13LoginRow 14TextRow 15Speaker

25 August 2012 Week 05 Report 05 18

Page 20: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 1. CODE EXAMPLES FOR JAVA DESIGN PATTERNS

Row 16LyricistRow 17ComposesRow 18inspireRow 19LanguageRow 20MovieBUILD SUCCESSFUL (total time: 2 seconds)

25 August 2012 Week 05 Report 05 19

Page 21: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Chapter 2

Understanding Interns Code

2.1 Packages

Java consists of an extension called javax. The packages used in the code are as follows :

2.1.1 javax.persistence

javax.Persistence – The javax.persistence package contains the classes and interfaces that definethe contracts between a persistence provider and the managed classes and the clients of the JavaPersistence API.

javax.persistence.Basic – The Basic annotation is the simplest type of mapping to a databasecolumn.

javax.persistence.Column – Is used to specify a mapped column for a persistent property or field.

javax.persistence.Entity – Specifies that the class is an entity.

javax.persistence.Id - Specifies the primary key property or field of an entity.

javax.persistence.JoinColumn – Is used to specify a mapped column for joining an entity asso-ciation.

javax.persistence.JoinTable – This annotation is used in the mapping of associations.

javax.persistence.ManyToOne – This annotation defines a single-valued association to anotherentity class that has many-to-one multiplicity.

javax.persistence.NamedQueries – Specifies an array of named Java Persistence query languagequeries.

javax.persistence.NamedQuery – Is used to specify a named query in the Java Persistence querylanguage, which is a static query expressed in metadata.

javax.persistence.OneToOne – This annotation defines a single-valued association to another entity

20

Page 22: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 2. UNDERSTANDING INTERNS CODE

that has one-to-one multiplicity.

javax.persistence.ManyToMany – Defines a many-valued association with many-to-many multi-plicity.

javax.persistence.Table – This annotation specifies the primary table for the annotated entity.

javax.persistence.GeneratedValue – Provides for the specification of generation strategies for thevalues of primary keys.

javax.persistence.GenerationType – Defines the types of primary key generation.

javax.persistence.CascadeType – Defines the set of cascadable operations that are propagatedto the associated entity.

javax.persistence.Embeddable – Defines a class whose instances are stored as an intrinsic partof an owning entity and share the identity of the entity.

javax.persistence.EmbeddedId – Is applied to a persistent field or property of an entity class ormapped superclass to denote a composite primary key that is an embeddable class.

Javax.persistence.EntityManager – Interface used to interact with the persistence context.

Javax.persistence.EntityManagerFactory – The EntityManagerFactory interface is used by the ap-plication to obtain an application-managed entity manager.

javax.persistence.criteria.CriteriaQuery – The CriteriaQuery interface defines functionality thatis specific to top-level queries.

javax.persistence.Query – Interface used to control query execution.

javax.persistence.PersistenceContext – Expresses a dependency on an EntityManager persistencecontext.

2.1.2 javax.validation

javax.validation.constraints.Size – The annotated element size must be between the specifiedboundaries (included).

javax.validation.constraints.NotNull – The annotated element must not be null.

javax.validation.ConstraintViolationException – Reports the result of constraint violations. ‘

2.1.3 javax.xml.bind.annotation

javax.xml.bind.annotation.XmlRootElement - Maps a class or an enum type to an XML element.

25 August 2012 Week 05 Report 05 21

Page 23: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 2. UNDERSTANDING INTERNS CODE

javax.xml.bind.annotation.XmlTransient – Prevents the mapping of a JavaBean property to XMLrepresentation.

2.1.4 java.util

java.util.List - An ordered collection (also known as a sequence).

javax.util.ArrayList – Resizable-array implementation of the List interface.

java.util.HashMap – Hash table based implementation of the Map interface.

Java.util.Map – An object that maps keys to values.

2.1.5 javax.ejb

javax.ejb.Stateless – Component-defining annotation for a stateless session bean.

javax.ejb.EJB – Indicates a dependency on the local, no-interface, or remote view of an Enter-prise JavaBean.

javax.ejb.LocalBean – Designates that a session bean exposes a no-interface view

2.2 Annotations

Annotations provide data about a program that is not part of the program itself. They have nodirect effect on the operation of the code they annotate.

The use of Annotation is Information for the compiler — They can be used by the compilerto detect errors or suppress warnings.

@Entity : Annotates the class as an entity bean. The attributes are name.

@Table : Specifies the database table for an entity bean. The default table name is the classname. The attributes are name, catalog, schema and uniqueConstraints(Unique constraints thatare to be placed on the table).

@XmlRootElement : The @XmlRootElement annotation can be used with the following pro-gram elements :–a top level class–an enum typeThe complex property @XMLRootElement provides naming and data-type details about the rootXML element, which is the topmost, most inclusive element in the XML string. The attributesare name(local name of the XML element.) ,namespace(namespace name of the XML element).

@NamedQueries : Specifies an array of named Java Persistence query language queries. Query

25 August 2012 Week 05 Report 05 22

Page 24: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 2. UNDERSTANDING INTERNS CODE

names are scoped to the persistence unit. The attributes are value(An array of named Java Per-sistence query language queries).

@NamedQuery : the required attributes are name(Refers to the query when using the Enti-tyManager methods that create query objects) and query(The query string in the Java Persistencequery language). The optional attribute is hints(Vendor-specific query hints) and lockMode.

Every @NamedQuery annotation is attached to exactly one entity class or mapped superclass- usually to the most relevant entity class. But since the scope of named queries is the entirepersistence unit, names should be selected carefully to avoid collision (e.g. by using the uniqueentity name as a prefix).

Example : Attaching multiple named queries to the same entity class requires wrapping themin a @NamedQueriesannotation, as follows:

@Entity

@NamedQueries({

@NamedQuery(name="Country.findAll",

query="SELECT c FROM Country c"),

@NamedQuery(name="Country.findByName",

query="SELECT c FROM Country c WHERE c.name = :name"),

})

public class Country {

...

}

@Id : Specifies the primary key of an entity. The field or property to which the Id annotation isapplied should be one of the following types: any Java primitive type; any primitive wrapper type;String; java.util.Date;java.sql.Date; java.math.BigDecimal; java.math.BigInteger.

@Basic : The Basic annotation is the simplest type of mapping to a database column. TheBasic annotation can be applied to a persistent property or instance variable of any of the fol-lowing types: Java primitive types, wrappers of the primitive types, String, java.math.BigInteger,java.math.BigDecimal,java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time, java.sql. Times-tamp, byte[], Byte[], char[], Character[], enums, and any other type that implements Serializable.The attributes are fetch(Defines whether the value of the field or property should be lazily loadedor must be eagerly fetched) and optional(Defines whether the value of the field or property maybe null. Default is ’true’).

@NotNull : The annotated element must not be null. Accepts any type. The attributes aregroups, message, payload.

@Column : Is used to specify a mapped column for a persistent property or field. If no Columnannotation is specified, the default values are applied. The attributes are name, Unique, Nullable,insertable, Updatable, columnDefinition, Table, Length, presentation, Scale.

25 August 2012 Week 05 Report 05 23

Page 25: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 2. UNDERSTANDING INTERNS CODE

@JoinColumn : Is used to specify a mapped column for joining an entity association. Theattributes are name, ReferencedColumName, Unique, Nullable, insertable, Updatable, column-Definition, Table.

name : The name of the foreign key column. The table in which it is found depends uponthe context. If the join is for a OneToOne or Many- ToOne mapping, the foreign key column is inthe table of the source entity. If the join is for a ManyToMany, the foreign key is in a join table.

ReferencedColumName : The name of the column referenced by this foreign key column. Whenused with relationship mappings, the referenced column is in the table of the target entity. Whenused inside a JoinTable annotation, the referenced key column is in the entity table of the owningentity, or inverse entity if the join is part of the inverse join definition. Default (only applies ifsingle join column is being used): The same name as the primary key column of the referenced table.

@OneToOne : This annotation defines a single-valued association to another entity that hasone-to-one multiplicity. It is not normally necessary to specify the associated target entity explic-itly since it can usually be inferred from the type of the object being referenced. The attributesare : targetEntity, cascade, fetch, optional, mappedBy.

cascade : The operations that must be cascaded to the target of the association.By default nooperations are cascaded.

mappedBy : The field that owns the relationship. This element is only specified on the inverse(non-owning) side of the association.

@ManyToOne : This annotation defines a single-valued association to another entity class thathas many-to-one multiplicity. It is not normally necessary to specify the target entity explicitlysince it can usually be inferred from the type of the object being referenced. The attributes aresame as @OneToOne except the absence of mappedBy.

@JoinTable : This annotation is used in the mapping of associations. It is specified on theowning side of a many-to-many association, or in a unidirectional one-to-many association.If the JoinTable annotation is missing, the default values of the annotation elements apply. Thename of the join table is assumed to be the table names of the associated primary tables concate-nated together (owning side first) using an underscore.

The attributes are name, catalog, schema, JoinColumns(The foreign key columns of the join tablewhich reference the primary table of the entity owning the association (i.e. the owning side ofthe association)), inverseJoinColumns(The foreign key columns of the join table which referencethe primary table of the entity that does not own the association (i.e. the inverse side of theassociation)), uniqueConstraints.

@Embeddable : Defines a class whose instances are stored as an intrinsic part of an owningentity and share the identity of the entity. Each of the persistent properties or fields of the em-bedded object is mapped to the database table for the entity.

@EmbeddedId : Is applied to a persistent field or property of an entity class or mapped su-

25 August 2012 Week 05 Report 05 24

Page 26: Multimedia Database Using EMMO Model · tory Pattern’. Both the examples give results from the ’Entity’ table of the EMMO Multimedia Database (EMMO MM DB) created before. 1.1

Insiya A. Fatehi CHAPTER 2. UNDERSTANDING INTERNS CODE

perclass to denote a composite primary key that is an embeddable class. The embeddable classmust be annotated as Embeddable.

EntityManager : Interface used to interact with the persistence context. A persistence context isa set of entity instances in which for any persistent entity identity there is a unique entity instance.Within the persistence context, the entity instances and their lifecycle are managed. This interfacedefines the methods that are used to interact with the persistence context. The EntityManagerAPI is used to create and remove persistent entity instances, to find entities by their primary key,and to query over entities. The methods are :-

1) persist : Make an entity instance managed and persistent.2)merge : Merge the state of the given entity into the current persistence context.3)remove : Remove the entity instance.4)find : Find by primary key.5)createQuery : Create an instance of Query for executing a Java Persistence query languagestatement.

EntityManagerFactory : Interface used to interact with the entity manager factory for thepersistence unit. The method getCriteriaBuilder is used toreturn an instance of CriteriaBuilderfor the creation of CriteriaQuery objects.

CriteriaQuery : One of its methods is select which is used to specify the item that is to bereturned in the query result.

Query : The methods are :1)setMaxResults() : Set the maximum number of results to retrieve.2)setFirstResult() : Set the position of the first result to retrieve.3)getResultList() : Execute a SELECT query and return the query results as a List.4)getSingleResult() : Execute a SELECT query that returns a single result.

@Stateless : the attributes are description(A string describing the stateless session bean), mapped-Name(A product specific name), name(The ejb-name for this bean)

@PersistenceContext : the attributes are name, properties, type, unitName.name : The name by which the entity manager is to be accessed in the environment referencingcontextproperties : Used to specify properties for the container or persistence provider.unitName : The name of the persistence unit.

25 August 2012 Week 05 Report 05 25