py.pol.una.ii.pw.service.MyControladorClientes.java Source code

Java tutorial

Introduction

Here is the source code for py.pol.una.ii.pw.service.MyControladorClientes.java

Source

/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the
 * distribution for a full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package py.pol.una.ii.pw.service;

import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.inject.Inject;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

import py.pol.una.ii.pw.data.SessionesMyBatis;
import py.pol.una.ii.pw.model.Clientes;

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyControladorClientes {

    @Inject
    SessionesMyBatis sesiones;

    public void eliminar(Clientes cliente) throws IOException {
        /*String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = 
         new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();*/
        SqlSession session = sesiones.getSession();
        try {
            session.delete("mybatis.ClienteMapper.removeCliente", cliente.getId());
        } finally {
            session.close();
        }

    }

    public void register(Clientes cliente) throws IOException {
        /*String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = 
         new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();*/
        SqlSession session = sesiones.getSession();
        try {
            session.insert("mybatis.ClienteMapper.createCliente", cliente);
        } finally {
            session.close();
        }
    }

    public void actualizar(Clientes cliente) throws IOException {
        /*String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = 
         new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();*/
        SqlSession session = sesiones.getSession();
        try {
            session.update("mybatis.ClienteMapper.updateCliente", cliente);
        } finally {
            session.close();
        }
    }

}