JBoss-IDE 1.2.2 Introduction (Hibernate) 3: Next, it is compute method:
/ **
* @Param Number
* @Return
*
* @ ejb.interface-method view-type = "remote"
* /
Public Double [] compute (int number) {
IF (Number <0) {
Throw New EjBexception ("argument shouth be posacy");
}
Double [] suite = new double [number 1];
Suite [0] = 0;
IF (Number == 0) {
Return suite;
}
// Hibernate Section
Try {
Session session = hibernateutil.currents;
Transaction tx = session.begintransaction ();
// Compare the Input and DB IS
Sam
e fruitt
INT MAX = ("" "" "Select Count (Num.Value) from tutorial.hibernate.num num"). Next ()) .intValue ();
IF (MAX == Number) {// Results Already in DB
Query Query = session.createQuery ("Select Num from Tutorial.Hibernate.Num Num ORDER BY NUM.VALUE ASC");
INT i = 1;
Iteerator it = query.Itemate (); it.hasnext ();) {
Num num = (num) IT.NEXT ();
Suite [I] = Num.getValue ();
i ;
}
}
Else {// Need to Calc Again
// Clear the Table First
Int r = session.delete ("from tutorial.hibernate.num");
Num n = new Num ();
Suite
[1]
= 1;
N.SetValue
Suite
[1]
);
Session.save (n);
For (int i = 2; i <= number; i ) {
N = new Num ();
Suite [i] = suite [i - 1] suite [i - 2];
N.SetValue (Suite [i]);
Session.save (n);
}
}
TX.comMit ();
Hibernateutil.closesis ();
}
Catch (HibernateException HE) {
HE.PrintStackTrace ();
}
Return suite;
}
After the completion, you should see this figure in Package Explorer.
Last Compile Project, right click Tutorial Project -> 'Build Project'