blob: 1e0db9059cb0334486059f9a995bd85e2c22265e [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
2 * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
13 *
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15 */
16
17package com.sun.s1asdev.jdbc.initsql.ejb;
18
Gaurav Guptaed5e7312020-05-01 07:54:26 +053019import jakarta.ejb.*;
Vinay Vishal57171472018-09-18 20:22:00 +053020import javax.naming.*;
21import javax.sql.*;
22import java.rmi.*;
23import java.util.*;
24import java.sql.*;
Gaurav Guptac2a128d2020-05-01 20:56:15 +053025import jakarta.transaction.SystemException;
26import jakarta.transaction.UserTransaction;
Vinay Vishal57171472018-09-18 20:22:00 +053027
28public class SimpleSessionBean implements SessionBean
29{
30
31 private SessionContext context;
32 private InitialContext ic;
33 private DataSource ds1;
34
35 public void setSessionContext(SessionContext ctxt) {
36 this.context = ctxt;
37 try {
38 ic = new InitialContext();
39 ds1 = (com.sun.appserv.jdbc.DataSource)ic.lookup("java:comp/env/DataSource1");
40 } catch( Exception ne ) {
41 ne.printStackTrace();
42 }
43 }
44
45 public void ejbCreate() throws CreateException {
46 }
47
48 /**
49 * Test to select the names from a table.
50 *
51 * The result set would contain different number of rows based on
52 * a session property set during the initialization sql phase.
53 * Based on the property set, the number of rows are compared to
54 * test the feature.
55 */
56 public boolean test1(boolean caseSensitive) {
57 Connection con = null;
58 Statement stmt = null;
59 ResultSet rs = null;
60 String query = "Select name from WORKERS where name='Joy Joy'";
61 boolean result = false;
62 int size = 0;
63 try {
64 con = ds1.getConnection();
65 stmt = con.createStatement();
66 rs = stmt.executeQuery(query);
67 if(rs != null) {
68 while(rs.next()) {
69 size++;
70 }
71 }
72 if(caseSensitive) {
73 result = size == 1;
74 } else {
75 result = size == 3;
76 }
77 } catch (SQLException ex) {
78 result = false;
79 ex.printStackTrace();
80 } finally {
81 if(rs != null) {
82 try {
83 rs.close();
84 } catch(Exception ex) {}
85 }
86 if(stmt != null) {
87 try {
88 stmt.close();
89 } catch(Exception ex) {}
90 }
91 if(con != null) {
92 try {
93 stmt.close();
94 } catch(Exception ex) {}
95 }
96 }
97 return result;
98 }
99
100 public void ejbStore() {}
101 public void ejbRemove() {}
102 public void ejbActivate() {}
103 public void ejbPassivate() {}
104 public void unsetEntityContext() {}
105 public void ejbPostCreate() {}
106}