Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. package org.modelos;
  2.  
  3. public class ModeloAutor implements java.io.Serializable {
  4. /**
  5. *
  6. */
  7. private static final long serialVersionUID = 1L;
  8. private long id;
  9. private String nombreAutor;
  10. private String apellidoAutor;
  11. private String correoAutor;
  12. private String cveInstitucion;
  13. private String cveOrcid;
  14.  
  15. public ModeloAutor(){}
  16.  
  17.  
  18.  
  19. public ModeloAutor(long id, String nombreAutor, String apellidoAutor,
  20. String correoAutor, String cveInstitucion, String cveOrcid) {
  21. super();
  22. this.id = id;
  23. this.nombreAutor = nombreAutor;
  24. this.apellidoAutor = apellidoAutor;
  25. this.correoAutor = correoAutor;
  26. this.cveInstitucion = cveInstitucion;
  27. this.cveOrcid = cveOrcid;
  28. }
  29.  
  30.  
  31.  
  32. public long getId() {
  33. return id;
  34. }
  35.  
  36. public void setId(long id) {
  37. this.id = id;
  38. }
  39.  
  40. public String getNombreAutor() {
  41. return nombreAutor;
  42. }
  43.  
  44. public void setNombreAutor(String nombreAutor) {
  45. this.nombreAutor = nombreAutor;
  46. }
  47.  
  48. public String getApellidoAutor() {
  49. return apellidoAutor;
  50. }
  51.  
  52. public void setApellidoAutor(String apellidoAutor) {
  53. this.apellidoAutor = apellidoAutor;
  54. }
  55.  
  56. public String getCorreoAutor() {
  57. return correoAutor;
  58. }
  59.  
  60. public void setCorreoAutor(String correoAutor) {
  61. this.correoAutor = correoAutor;
  62. }
  63.  
  64. public String getCveInstitucion() {
  65. return cveInstitucion;
  66. }
  67.  
  68. public void setCveInstitucion(String cveInstitucion) {
  69. this.cveInstitucion = cveInstitucion;
  70. }
  71.  
  72. public String getCveOrcid() {
  73. return cveOrcid;
  74. }
  75.  
  76. public void setCveOrcid(String cveOrcid) {
  77. this.cveOrcid = cveOrcid;
  78. }
  79.  
  80.  
  81. }
  82.  
  83.  
  84. package org.dao;
  85.  
  86. import java.util.List;
  87.  
  88. import org.modelos.ModeloAutor;
  89. //import org.skife.jdbi.v2.StatementContext;
  90. import org.skife.jdbi.v2.sqlobject.Bind;
  91. import org.skife.jdbi.v2.sqlobject.SqlQuery;
  92. import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
  93. //import org.skife.jdbi.v2.tweak.ResultSetMapper;
  94. //import org.skife.jdbi.v2.sqlobject.customizers.*;
  95.  
  96. @RegisterMapper(ModeloAutorMapper.class)
  97. public interface AutorDao {
  98.  
  99.  
  100. @SqlQuery("SELECT CVEAUTNOR, NOMAUTNOR,APEAUTNOR,MAILAUTNOR1,CVEENTINT,CVEORCID FROM TBLAUTNOR WHERE CVEAUTNOR = :id")
  101. ModeloAutor findById(@Bind("id") long id);
  102. @SqlQuery("SELECT CVEAUTNOR, NOMAUTNOR,APEAUTNOR,MAILAUTNOR1,CVEENTINT,CVEORCID FROM TBLAUTNOR")
  103. List<ModeloAutor> verTodo();
  104.  
  105. }
  106.  
  107. package org.dao;
  108.  
  109. import java.sql.ResultSet;
  110. import java.sql.SQLException;
  111.  
  112. import org.modelos.ModeloAutor;
  113. import org.skife.jdbi.v2.StatementContext;
  114. import org.skife.jdbi.v2.tweak.ResultSetMapper;
  115.  
  116. public class ModeloAutorMapper implements ResultSetMapper<ModeloAutor> {
  117.  
  118. public ModeloAutorMapper(){}
  119.  
  120. @Override
  121. public ModeloAutor map(int arg0, ResultSet resultSet, StatementContext arg2)
  122. throws SQLException {
  123. ModeloAutor modeloAutor = new ModeloAutor();
  124. modeloAutor.setId(resultSet.getLong("CVEAUTNOR"));
  125. modeloAutor.setNombreAutor(resultSet.getString("NOMAUTNOR"));
  126. modeloAutor.setApellidoAutor(resultSet.getString("APEAUTNOR"));
  127. modeloAutor.setCorreoAutor(resultSet.getString("MAILAUTNOR1"));
  128. modeloAutor.setCveInstitucion(resultSet.getString("CVEENTINT"));
  129. modeloAutor.setCveOrcid(resultSet.getString("CVEORCID"));
  130. return modeloAutor;
  131. }
  132. }
  133.  
  134.  
  135. package org.tutorial;
  136.  
  137. import static java.lang.System.out;
  138.  
  139. import java.util.List;
  140. import java.util.Map;
  141. import java.util.Scanner;
  142.  
  143. import org.dao.AutorDao;
  144. import org.modelos.ModeloAutor;
  145. import org.skife.jdbi.v2.DBI;
  146. import org.skife.jdbi.v2.Handle;
  147. import org.skife.jdbi.v2.Query;
  148. import org.skife.jdbi.v2.util.StringMapper;
  149.  
  150. public class TestJdbi3 {
  151.  
  152. public static void main(String[] args) {
  153. // Scanner sc = new Scanner(System.in);
  154. // int clave=0;
  155. /*DBI dbi = new DBI("jdbc:oracle:thin:@148.215.1.174:1521:DBSRALYC",
  156. "uredalyc",
  157. "uredalyc174");
  158. */
  159.  
  160. DBI dbi = new DBI("jdbc:oracle:thin:@148.215.1.155:1521:DBSRALYC",
  161. "uautores",
  162. "uautores155");
  163.  
  164.  
  165. Handle h = dbi.open();
  166. if(!dbi.open().isInTransaction()){
  167. out.println("No esta realizando alguna transaccion");
  168. }
  169.  
  170.  
  171. // out.print("Introduzca clave de la revista: ");
  172. // clave = sc.nextInt();
  173. // String revista = h.createQuery("select uredalyc.tblentrev.NOMENTREV from uredalyc.tblentrev where uredalyc.tblentrev.CVEENTREV= :id")
  174. // .bind("id", clave)
  175. // .map(StringMapper.FIRST)
  176. // .first();
  177. // revista= revista == null ? "No hay revista con esa clave" : revista;
  178. // out.println("Revista:"+revista);
  179.  
  180.  
  181. // Query<Map<String, Object>> q =
  182. // h.createQuery("select uredalyc.tblentrev.NOMENTREV from uredalyc.tblentrev order by uredalyc.tblentrev.CVEENTREV ");
  183. // Query<String> q2 = q.map(StringMapper.FIRST);
  184. // List<String> rs = q2.list();
  185. // if(rs.size() > 0){
  186. // for(String n: rs){
  187. // out.println(n);
  188. // }
  189. // }
  190. // out.println("Total revistas:"+rs.size());
  191.  
  192. try{
  193. AutorDao autor= dbi.open(AutorDao.class);
  194. if(autor.verTodo().size()>0){
  195. out.println("Lista Autor llena!!: "+autor.verTodo().size());
  196. for(ModeloAutor aut: autor.verTodo()){
  197. out.println("**Id:"+aut.getId());
  198. out.println("Autor:"+aut.getNombreAutor() + " "+aut.getApellidoAutor());
  199. out.println("Email:"+aut.getCorreoAutor());
  200. out.println("Orcid:"+aut.getCveOrcid()+"**");
  201. }
  202. }
  203. }
  204. catch(Exception ex){
  205. ex.printStackTrace();
  206. }
  207.  
  208.  
  209.  
  210. //sc.close();
  211. h.close();
  212.  
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement