Check-in [c77a94e144]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:persintencia reserva
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c77a94e1446159ea180c96f44ade55acb8d629cc
User & Date: malcon 2015-01-11 11:46:42
Context
2015-01-11
15:48
registro cliente web listo, falta validaciones, check-in: ec3074ddc2 user: malcon tags: trunk
11:46
persintencia reserva check-in: c77a94e144 user: malcon tags: trunk
11:12
registro cliente, sale error check-in: 4b8eccaca6 user: malcon tags: trunk
Changes

Changes to src/model/Reserva.java.

     1      1   package model;
     2      2   
     3         -public class Reserva {
            3  +import java.io.Serializable;
            4  +import java.util.Date;
            5  +
            6  +public class Reserva implements Serializable{
     4      7   
            8  +  private static final long serialVersionUID = 1L;
            9  +  private  Integer id;
           10  +  private String num_reserva;
           11  +  private Date fe_reserva;
           12  +  private Date fe_expiracion;
           13  +  private Paquete paquete;
           14  +  //private Precio_Paquete precio_paquete;
           15  +  private Date fe_salida;
           16  +  private Integer nro_personas;
           17  +  private String estado;
           18  +  
           19  +public Integer getId() {
           20  +	return id;
           21  +}
           22  +public void setId(Integer id) {
           23  +	this.id = id;
           24  +}
           25  +public String getNum_reserva() {
           26  +	return num_reserva;
           27  +}
           28  +public void setNum_reserva(String num_reserva) {
           29  +	this.num_reserva = num_reserva;
           30  +}
           31  +public Date getFe_reserva() {
           32  +	return fe_reserva;
           33  +}
           34  +public void setFe_reserva(Date fe_reserva) {
           35  +	this.fe_reserva = fe_reserva;
           36  +}
           37  +public Date getFe_expiracion() {
           38  +	return fe_expiracion;
           39  +}
           40  +public void setFe_expiracion(Date fe_expiracion) {
           41  +	this.fe_expiracion = fe_expiracion;
           42  +}
           43  +public Paquete getPaquete() {
           44  +	return paquete;
           45  +}
           46  +public void setPaquete(Paquete paquete) {
           47  +	this.paquete = paquete;
           48  +}
           49  +public Date getFe_salida() {
           50  +	return fe_salida;
           51  +}
           52  +public void setFe_salida(Date fe_salida) {
           53  +	this.fe_salida = fe_salida;
           54  +}
           55  +public Integer getNro_personas() {
           56  +	return nro_personas;
           57  +}
           58  +public void setNro_personas(Integer nro_personas) {
           59  +	this.nro_personas = nro_personas;
           60  +}
           61  +public String getEstado() {
           62  +	return estado;
           63  +}
           64  +public void setEstado(String estado) {
           65  +	this.estado = estado;
           66  +}
           67  +  
           68  +  
           69  +  
           70  +  
     5     71   }

Added src/negocio/ReservaService.java.

            1  +package negocio;
            2  +
            3  +import java.util.List;
            4  +
            5  +
            6  +import model.Reserva;
            7  +
            8  +public interface ReservaService {
            9  +
           10  +	public Reserva obtener(Integer codigo) throws Exception;
           11  +	public void actualizar(Reserva reserva) throws Exception ;
           12  +	public void registrar(Reserva reserva) throws Exception;
           13  +	public List<Reserva> buscar(Reserva reserva) throws Exception;
           14  +}

Added src/negocio/ReservaServiceDAO.java.

            1  +package negocio;
            2  +
            3  +import java.util.List;
            4  +
            5  +import org.apache.ibatis.session.SqlSession;
            6  +
            7  +
            8  +import persistencia.mybatis.mapper.ReservaMapper;
            9  +import util.MyBatisUtil;
           10  +
           11  +import model.Reserva;
           12  +
           13  +public class ReservaServiceDAO  implements ReservaService{
           14  +
           15  +	@Override
           16  +	public Reserva obtener(Integer codigo) throws Exception {
           17  +		
           18  +		SqlSession session=MyBatisUtil.getSqlSessionFactory().openSession();
           19  +		ReservaMapper ReservaMapper=session.getMapper(ReservaMapper.class);
           20  +		Reserva reserva=ReservaMapper.obtener(codigo);
           21  +		session.close();
           22  +		return reserva;
           23  +	}
           24  +
           25  +	
           26  +	@Override
           27  +	public void registrar(Reserva reserva) throws Exception {
           28  +		System.out.println("registrar reserva" + reserva.getId());
           29  +		SqlSession  session=MyBatisUtil.getSqlSessionFactory().openSession();
           30  +		ReservaMapper reservaMapper = session.getMapper(ReservaMapper.class);
           31  +		reservaMapper.insertar(reserva);
           32  +		session.commit();
           33  +		session.close();
           34  +		
           35  +	}
           36  +
           37  +	@Override
           38  +	public List<Reserva> buscar(Reserva reserva) throws Exception {
           39  +		SqlSession session=MyBatisUtil.getSqlSessionFactory().openSession();
           40  +		ReservaMapper reservaMapper = session.getMapper(ReservaMapper.class);
           41  +		List<Reserva> reservas = reservaMapper.buscar(reserva);
           42  +		session.close();
           43  +		return reservas;
           44  +	}
           45  +
           46  +
           47  +	@Override
           48  +	public void actualizar(Reserva reserva) throws Exception {
           49  +		// TODO Auto-generated method stub
           50  +		
           51  +	}
           52  +
           53  +}

Changes to src/persistencia/mybatis/config/mybatis-config.xml.

    10     10   	<settings>
    11     11   		<setting name="defaultStatementTimeout" value="2"/>
    12     12   	</settings>
    13     13   	
    14     14   	<typeAliases>
    15     15   		<typeAlias type="model.Cliente" alias="cliente"/>
    16     16   		<typeAlias type="model.Usuario" alias="usuario"/>
           17  +		<typeAlias type="model.Reserva" alias="reserva"/>
           18  +		<typeAlias type="model.Reserva" alias="paquete"/>
    17     19   	</typeAliases>
    18     20   	
    19     21       <environments default="clase">
    20     22       
    21     23           <environment id="clase">
    22     24               <transactionManager type="JDBC"/>
    23     25               <dataSource type="JNDI">

Added src/persistencia/mybatis/mapper/ReservaMapper.java.

            1  +package persistencia.mybatis.mapper;
            2  +
            3  +import java.util.List;
            4  +
            5  +import model.Reserva;
            6  +
            7  +public interface ReservaMapper {
            8  +
            9  +		List<Reserva> buscar(Reserva reserva);
           10  +		Reserva obtener(Integer codigo);
           11  +		void insertar(Reserva reserva);
           12  +		void actualizar(Reserva reserva);
           13  +}

Added src/persistencia/mybatis/mapper/ReservaMapper.xml.

            1  +<?xml version="1.0" encoding="UTF-8"?>
            2  +
            3  +<!DOCTYPE mapper 
            4  +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            5  + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
            6  +
            7  + <mapper namespace="persistencia.mybatis.mapper.ReservaMapper">
            8  + 
            9  +     <resultMap type="reserva" id="rmReservaBusqueda">
           10  +        <id column="id" property="codigo"/>
           11  +<result column="num_reserva" property="num_reserva"/>
           12  +        <result column="fe_reserva" property="fe_reserva"/>
           13  +        <result column="fe_salida" property="fe_salida"/>
           14  +        <result column="fe_expiracion" property="fe_expiracion"/>
           15  +        <result column="nro_personas" property="nro_personas"/>
           16  +        <result column="estado" property="estado"/>
           17  +        <association property="paquete" javaType="paquete">
           18  +            	<result column = "paquete_id" property="codigo"/>
           19  +        </association>
           20  +     </resultMap>
           21  +     
           22  +    <select id="buscar" resultMap="rmReservaBusqueda" parameterType="reserva">
           23  +    	SELECT num_reserva, fe_reserva, fe_salida, fe_expiracion, paquete_id , nro_personas, estado
           24  +    	FROM reserva
           25  +    	WHERE num_reserva LIKE #{num_reserva}
           26  +    </select>
           27  +    
           28  +    <resultMap type="reserva" id="rmReservaByPK">
           29  +        <id column="id" property="codigo"/>
           30  +        <result column="num_reserva" property="num_reserva"/>
           31  +        <result column="fe_reserva" property="fe_reserva"/>
           32  +        <result column="fe_salida" property="fe_salida"/>
           33  +        <result column="fe_expiracion" property="fe_expiracion"/>
           34  +        <result column="nro_personas" property="nro_personas"/>
           35  +        <result column="estado" property="estado"/>
           36  +      
           37  +    
           38  +        <association property="paquete" javaType="paquete">
           39  +            	<result column = "paquete_id" property="codigo"/>
           40  +        </association>
           41  +    </resultMap>
           42  +    
           43  + 	<select id="obtener" resultMap="rmReservaByPK" parameterType="integer">
           44  + 		SELECT num_reserva, fe_reserva, fe_salida, fe_expiracion, paquete_id , nro_personas, estado
           45  + 			FROM reserva
           46  + 			WHERE id = #{codigo}
           47  + 		
           48  + 	</select>
           49  + 	
           50  + 	<insert id="insertar" parameterType="reserva">
           51  + 		INSERT INTO reserva(num_reserva, fe_reserva, fe_salida, fe_expiracion, paquete_id , nro_personas, estado)
           52  + 		values (#{num_reserva},#{fe_reserva},#{fe_salida},#{fe_expiracion},#{paquete.codigo},#{nro_personas},#{estado})
           53  + 	</insert>
           54  + 	
           55  + 	<update id="actualizar" parameterType="reserva">
           56  + 		UPDATE reserva
           57  + 		SET estado=#{estado}
           58  + 			WHERE id=#{codigo}
           59  + 	</update>
           60  + 
           61  + 
           62  + </mapper>