Advertisement
Guest User

Untitled

a guest
Sep 6th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. Je bâtirai
  2.  
  3. <?xml version='1.0' encoding='utf-8'?>
  4. <!DOCTYPE hibernate-configuration PUBLIC
  5. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  6. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  7. <hibernate-configuration>
  8. <session-factory>
  9. <!-- Database connection settings -->
  10. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  11. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  12. <property name="connection.url">jdbc:mysql://localhost:3306/church</property>
  13. <property name="connection.username">root</property>
  14. <property name="connection.password">carthy-2</property>
  15.  
  16. <property name="hibernate.connection.CharSet">utf8</property>
  17. <property name="hibernate.connection.characterEncoding">utf8</property>
  18. <property name="hibernate.connection.useUnicode">true</property>
  19.  
  20. <!-- JDBC connection pool (use the built-in) -->
  21. <property name="connection.pool_size">1</property>
  22. <!-- SQL dialect -->
  23. <!-- Enable Hibernate's automatic session context management -->
  24. <property name="current_session_context_class">thread</property>
  25. <!-- Disable the second-level cache -->
  26. <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  27. <!-- Echo all executed SQL to stdout -->
  28. <property name="show_sql">true</property>
  29.  
  30. <!-- Drop and re-create the database schema on startup -->
  31. <!-- créer la BD -->
  32. <!-- property name="hbm2ddl.auto">create</property -->
  33. <!-- Met la BD existante à jour -->
  34. <!-- property name="hbm2ddl.auto">update</property -->
  35. <property name="hibernate.hbm2ddl.auto">update</property>
  36.  
  37. <!-- Mapping des classes persistantes -->
  38.  
  39. <mapping class="com.church.metier.User" />
  40. <mapping class="com.church.metier.Comment" />
  41. <mapping class="com.church.metier.Text" />
  42. <mapping class="com.church.metier.MessageText" />
  43. <mapping class="com.church.metier.MessageVideo" />
  44. <mapping class="com.church.metier.News" />
  45. <mapping class="com.church.metier.VerseMonth" />
  46. <mapping package="com.church.metier" />
  47.  
  48.  
  49. </session-factory>
  50. </hibernate-configuration>
  51.  
  52. System.out.println( VerseMonthDAO.retreveVersetMonth());
  53.  
  54. package com.church.DAO;
  55.  
  56. import com.church.metier.VerseMonth;
  57.  
  58. import java.util.Locale;
  59.  
  60. import org.hibernate.Session;
  61. import org.springframework.cglib.core.Local;
  62. import org.springframework.context.i18n.LocaleContextHolder;
  63.  
  64. import com.church.util.HibernateUtil;
  65.  
  66. public class VerseMonthDAO {
  67.  
  68.  
  69. public static void savaOrUpdate(VerseMonth verse){
  70. Session hibernateSession = HibernateUtil.getSession();
  71. org.hibernate.Transaction transc = null;
  72.  
  73. try{
  74. transc = hibernateSession.beginTransaction();
  75. hibernateSession.saveOrUpdate(verse);
  76. transc.commit();
  77. }catch(Exception e){
  78. if (transc!=null){
  79. transc.rollback();
  80. }
  81. e.printStackTrace();
  82. }finally {
  83. hibernateSession.close();
  84. }
  85. }
  86.  
  87. public static String retreveVersetMonth(){
  88. Locale locale = LocaleContextHolder.getLocale();
  89. String language = locale.getLanguage();
  90.  
  91. if(language.equals("en")){
  92. language = "textEn";
  93. }else if(language.equals("in")){
  94. language = "textIn";
  95. }else{
  96. language = "textFr";
  97. }
  98.  
  99. Session hibernateSession = HibernateUtil.getSession();
  100. org.hibernate.Transaction transc = null;
  101. String verse = null;
  102. Long count ;
  103.  
  104.  
  105. try{
  106. transc = hibernateSession.beginTransaction();
  107. count = ((Long) hibernateSession.createQuery("select count(*) from VerseMonth").uniqueResult());
  108.  
  109. verse = (String) hibernateSession.createQuery
  110. ("SELECT "+ language +" FROM VerseMonth verse WHERE verse.verseId = '" + count.intValue() + "'")
  111. .uniqueResult();
  112.  
  113. transc.commit();
  114. }catch(Exception e){
  115. if (transc!=null){
  116. transc.rollback();
  117. }
  118. e.printStackTrace();
  119. }finally {
  120. hibernateSession.close();
  121. }
  122.  
  123. return verse;
  124.  
  125. }
  126.  
  127. public static String retreveSourceMonth(){
  128. Locale locale = LocaleContextHolder.getLocale();
  129. String language = locale.getLanguage();
  130.  
  131. if(language.equals("en")){
  132. language = "sourceEn";
  133. }else if(language.equals("in")){
  134. language = "sourceIn";
  135. }else{
  136. language = "sourceFr";
  137. }
  138.  
  139.  
  140. Session hibernateSession = HibernateUtil.getSession();
  141. org.hibernate.Transaction transc = null;
  142. String source = null;
  143. Long count ;
  144.  
  145.  
  146. try{
  147. transc = hibernateSession.beginTransaction();
  148. count = ((Long) hibernateSession.createQuery("select count(*) from VerseMonth").uniqueResult());
  149.  
  150. source = (String) hibernateSession.createQuery
  151. ("SELECT "+ language +" FROM VerseMonth verse WHERE verse.verseId = '" + count.intValue() + "'")
  152. .uniqueResult();
  153.  
  154. transc.commit();
  155. }catch(Exception e){
  156. if (transc!=null){
  157. transc.rollback();
  158. }
  159. e.printStackTrace();
  160. }finally {
  161. hibernateSession.close();
  162. }
  163.  
  164. return source;
  165.  
  166. }
  167. }
  168.  
  169. +---------+----------------+----------------+----------------+-------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
  170. | verseId | SOURCEEN | SOURCEFR | SOURCEIN | TEXTEN | TEXTFR | TEXTIN |
  171. +---------+----------------+----------------+----------------+-------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
  172. | 1 | Je bâtirai | Je bâtirai | Je bâtirai | Je bâtirai | Je bâtirai | Je bâtirai |
  173. +---------+----------------+----------------+----------------+-------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement