Package jsf.util

Source Code of jsf.util.SemanticSearch

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jsf.util;

import java.beans.*;
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import static jsf.util.SemanticSearch.PROP_SAMPLE_PROPERTY;

/**
*
* @author Geymen
*/
public class SemanticSearch implements Serializable {
   
    public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
    private String sampleProperty;
    private ArrayList courseList;
    private PropertyChangeSupport propertySupport;
   
    public SemanticSearch() {
        propertySupport = new PropertyChangeSupport(this);
    }
   
    public String getSampleProperty() {
        return sampleProperty;
    }
   
    public void setSampleProperty(String value) {
        String oldValue = sampleProperty;
        sampleProperty = value;
        propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
    }
   
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("EducationXPU");

    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }
   
    public void getRecommendedCoursesForUserID(Integer userID) {
        try {
            //        Connection con = DriverManager.getConnection("jdbc:default:connection");
                   
                    EntityManager eM = null;
                    eM = getEntityManager();
                    eM.getTransaction().begin();
                   
                    // we are getting the connection string.
                    Connection connection = eM.unwrap(java.sql.Connection.class); // unwraps the Connection class.
                    CallableStatement cs = null;
                   
                    eM.getTransaction().commit();
                   
                   
                    cs = connection.prepareCall("{call GetSemanticCourses(?)}");
                    cs.setInt(1, 1);
                    ResultSet rs = cs.executeQuery();

            while (rs.next()) {
                String courseid = rs.getString("courseid");
                System.out.println("courseID" + ": " + courseid);
            }
        } catch (SQLException ex) {
            Logger.getLogger(RecommendationBean.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }
   
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
   
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
}
TOP

Related Classes of jsf.util.SemanticSearch

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.