Package org.salamanca.commands.persona

Source Code of org.salamanca.commands.persona.InsertarPersona

package org.salamanca.commands.persona;

import java.util.Date;
import javax.jdo.PersistenceManager;
import org.salamanca.broker.BrokerServer;
import org.salamanca.domain.*;
import org.salamanca.commands.ICommand;
import java.util.Vector;
import org.salamanca.commands.MessageException;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class InsertarPersona implements ICommand {
    Persona persona;

    /**
     * InsertarPersona
     *
     * @param persona Persona
     */
    public InsertarPersona(Persona persona) {
        this.persona = persona;
    }

    /**
     * execute
     */
    public void execute() throws MessageException {
        if (persona.getNombre().trim().length() == 0 ||
            persona.getApellido().trim().length() == 0) {
            throw new MessageException(
                    "EL nombre y apellido no pueden estar vacios");
        }

        PersistenceManager pm = BrokerServer.instance().getPMF().
                                getPersistenceManager();
        Vector v = BrokerServer.instance().query(Persona.class,
                                                 "dni==" + persona.getDni());
        if (v.size() > 0) {
            throw new MessageException(
                    "Ya existe una persona con ese DNI");
        }

        pm.currentTransaction().begin();
        pm.makePersistent(persona);

        pm.currentTransaction().commit();

    }

    /**
     * getCommandName
     *
     * @return String
     */
    public String getCommandName() {
        return this.getClass().getName();
    }

    /**
     * getBarDelimitedParameters
     *
     * @return String
     */
    public String getBarDelimitedParameters() {
        return persona.getNombre() + "|" + persona.getApellido() + "|" +
                persona.getCodigoPostal() + "|" +
                persona.getDni() + "|" + persona.getDomicilio() + "|" +
                persona.getFechaNacimiento() + "|" + persona.getLocalidad() +
                "|" + persona.isMasculino() + "|" +
                persona.getTelefono();
    }

}
TOP

Related Classes of org.salamanca.commands.persona.InsertarPersona

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.