Guest User

Untitled

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