Guest User

Untitled

a guest
Jan 3rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. <session-factory>
  2. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  3. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  4. <property name="hibernate.connection.url">jdbc:mysql://****/****?zeroDateTimeBehavior=convertToNull</property>
  5. <property name="hibernate.connection.username">*****</property>
  6. <property name="hibernate.connection.password">*****</property>
  7.  
  8. <property name="connection.pool_size">1</property>
  9. <property name="hbm2ddl.auto">update</property>
  10. <property name="show_sql">true</property>
  11. <property name="connection.autocommit">false</property>
  12.  
  13. <property name="hibernate.c3p0.max_size">1</property>
  14. <property name="hibernate.c3p0.min_size">0</property>
  15. <property name="hibernate.c3p0.timeout">5000</property>
  16. <property name="hibernate.c3p0.max_statements">1000</property>
  17. <property name="hibernate.c3p0.idle_test_period">300</property>
  18. <property name="hibernate.c3p0.acquire_increment">1</property>
  19. <property name="hibernate.current_session_context_class">thread</property>
  20. <mapping class="entity.InformationAboutTheDriver"/>
  21.  
  22. <property name="hibernate.current_session_context_class">thread</property>
  23. <mapping class="entity.InformationAboutTheDriver"/>
  24.  
  25. package controller;
  26.  
  27. import entity.*;
  28. import java.util.*;
  29. import javax.faces.bean.ManagedBean;
  30. import javax.faces.bean.SessionScoped;
  31. import model.*;
  32.  
  33.  
  34. /**
  35. *
  36. * @author Elvir
  37. */
  38. @ManagedBean(name="iatdContrl")
  39. @SessionScoped
  40. public class IatdController {
  41. private List<InformationAboutTheDriver> lst = new ArrayList<InformationAboutTheDriver>();
  42.  
  43. public List<InformationAboutTheDriver> getLst() {
  44. Employee_dao dao=new Employee_dao();
  45. return dao.getAll();
  46. }
  47.  
  48. public void setLst(List<InformationAboutTheDriver> lst) {
  49. this.lst = lst;
  50. }
  51.  
  52. private InformationAboutTheDriver informationAboutTheDriver= new InformationAboutTheDriver();
  53.  
  54. public InformationAboutTheDriver getInformationAboutTheDriver() {
  55. return informationAboutTheDriver;
  56. }
  57.  
  58. public void setInformationAboutTheDriver(InformationAboutTheDriver informationAboutTheDriver) {
  59. this.informationAboutTheDriver = informationAboutTheDriver;
  60. }
  61.  
  62. public void remove (InformationAboutTheDriver aboutTheDriver){
  63. Employee_dao dao = new Employee_dao();
  64. dao.remove(aboutTheDriver);
  65.  
  66. }
  67. public String insert (){
  68. Employee_dao dao=new Employee_dao();
  69. dao.create(informationAboutTheDriver);
  70. return "index";
  71. }
  72. public String edit(InformationAboutTheDriver aboutTheDriver){
  73. this.informationAboutTheDriver=aboutTheDriver;
  74. return "edit";
  75. }
  76. public String save(){
  77. Employee_dao dao=new Employee_dao();
  78. dao.edit(informationAboutTheDriver);
  79. return "index";
  80. }
  81. }
  82.  
  83. @Entity
  84. @Table(name="information_about_the_driver"
  85. ,catalog="***"
  86. )
  87. public class InformationAboutTheDriver implements java.io.Serializable {
  88. private Integer id;
  89. private String name;
  90. private String latitude;
  91. private String longitude;
  92. private String number;
  93.  
  94. public InformationAboutTheDriver() {
  95. }
  96.  
  97. public InformationAboutTheDriver(String name, String latitude, String longitude, String number) {
  98. this.name = name;
  99. this.latitude = latitude;
  100. this.longitude = longitude;
  101. this.number = number;
  102. }
  103.  
  104. @Id @GeneratedValue(strategy=IDENTITY)
  105.  
  106.  
  107. @Column(name="id", unique=true, nullable=false)
  108. public Integer getId() {
  109. return this.id;
  110. }
  111.  
  112. public void setId(Integer id) {
  113. this.id = id;
  114. }
  115.  
  116.  
  117. @Column(name="Name", nullable=false)
  118. public String getName() {
  119. return this.name;
  120. }
  121.  
  122. public void setName(String name) {
  123. this.name = name;
  124. }
  125.  
  126.  
  127. @Column(name="Latitude", nullable=false)
  128. public String getLatitude() {
  129. return this.latitude;
  130. }
  131.  
  132. public void setLatitude(String latitude) {
  133. this.latitude = latitude;
  134. }
  135.  
  136.  
  137. @Column(name="Longitude", nullable=false)
  138. public String getLongitude() {
  139. return this.longitude;
  140. }
  141.  
  142. public void setLongitude(String longitude) {
  143. this.longitude = longitude;
  144. }
  145.  
  146.  
  147. @Column(name="Number", nullable=false)
  148. public String getNumber() {
  149. return this.number;
  150. }
  151.  
  152. public void setNumber(String number) {
  153. this.number = number;
  154. }
  155. }
  156.  
  157. package model;
  158.  
  159. import java.util.*;
  160. import entity.*;
  161. import org.hibernate.*;
  162.  
  163. public class Employee_dao {
  164.  
  165. public List<InformationAboutTheDriver> getAll(){
  166. Session s=HibernateUtil.getSessionFactory()
  167. .getCurrentSession();
  168. List<InformationAboutTheDriver> lst = new ArrayList<>();
  169. try {
  170. s.beginTransaction();
  171. lst=s.createCriteria(InformationAboutTheDriver.class).list();
  172. s.getTransaction().commit();
  173.  
  174. } catch (Exception e) {
  175. e.printStackTrace();
  176. s.getTransaction().rollback();
  177. }
  178. return lst;
  179. }
  180.  
  181. public void create(InformationAboutTheDriver aboutTheDriver){
  182. Session s = HibernateUtil.getSessionFactory()
  183. .getCurrentSession();
  184. try {
  185. s.beginTransaction();
  186. s.save(aboutTheDriver);
  187. s.getTransaction().commit();
  188.  
  189.  
  190. } catch (Exception e) {
  191. e.printStackTrace();
  192. s.getTransaction().rollback();
  193. }
  194.  
  195. }
  196.  
  197. public void edit(InformationAboutTheDriver aboutTheDriver){
  198. Session s = HibernateUtil.getSessionFactory()
  199. .getCurrentSession();
  200. try {
  201. s.beginTransaction();
  202. s.update(aboutTheDriver);
  203. s.getTransaction().commit();
  204.  
  205.  
  206. } catch (Exception e) {
  207. e.printStackTrace();
  208. s.getTransaction().rollback();
  209. }
  210.  
  211. }
  212.  
  213. public void remove (InformationAboutTheDriver aboutTheDriver){
  214. Session s = HibernateUtil.getSessionFactory()
  215. .getCurrentSession();
  216. try {
  217. s.beginTransaction();
  218. s.delete(aboutTheDriver);
  219. s.getTransaction().commit();
  220.  
  221.  
  222. } catch (Exception e) {
  223. e.printStackTrace();
  224. s.getTransaction().rollback();
  225. }
  226.  
  227. }
  228. }
  229.  
  230. import org.hibernate.cfg.AnnotationConfiguration;
  231. import org.hibernate.SessionFactory;
  232.  
  233. /**
  234. * Hibernate Utility class with a convenient method to get Session Factory
  235. * object.
  236. *
  237. * @author Elvir
  238. */
  239. public class HibernateUtil {
  240.  
  241. private static final SessionFactory sessionFactory;
  242.  
  243. static {
  244. try {
  245. // Create the SessionFactory from standard (hibernate.cfg.xml)
  246. // config file.
  247. sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
  248. } catch (Throwable ex) {
  249. // Log the exception.
  250. System.err.println("Initial SessionFactory creation failed." + ex);
  251. throw new ExceptionInInitializerError(ex);
  252. }
  253. }
  254.  
  255. public static SessionFactory getSessionFactory() {
  256. return sessionFactory;
  257. }
  258. }
Add Comment
Please, Sign In to add comment