/**
* This file is part of eCommerce.
*
* Foobar is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* 2007 Matej Hausenblas matej.hausenblas@gmail.com
*
*/
package metier.clients;
import factories.FClients;
import factories.exceptions.FactoriesException;
import interfaces.clients.IMetierClients;
import interfaces.exceptions.MetierException;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import base.Client;
import database.GestionConnection;
/**
*
*/
public class MetierClients /*extends UnicastRemoteObject*/ implements IMetierClients, Serializable{
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -1484115746927458950L;
/**
* Fabrique de Clients, a la creation de cette classe,
* on souhaite pouvoir utiliser la fabrique eventuellement a plusieurs
* endroits, on la retrouve alors et initialise sa connexion.
*/
private FClients fc;
/**
* Constructeur initialise la Fabrique et lui renseigne une connexion.
*/
public MetierClients() throws MetierException/*, RemoteException*/{
/*super();*/
this.fc = FClients.getInstance();
// s'assurer que la fabrique a bien une connexion a la base de donnees.
try{
if(! fc.hasConnection()){
System.out.println("Setting connection");
fc.setConnection(GestionConnection.getInstance().getConnection());
System.out.println("Connection set");
}
// Mise a jour de la base de donnees:
}catch(SQLException se){
throw new MetierException(MetierException.CONNEXION_IMPOSSIBLE);
}
}
/* (non-Javadoc)
* @see interfaces.clients.IMetierClients#creerClient(base.Client)
*/
public Client creerClient(Client client) throws RemoteException,
MetierException {
try {
fc.creerClient(client);
} catch (SQLException e) {
throw new MetierException(MetierException.CONNEXION_IMPOSSIBLE);
} catch (FactoriesException e) {
// l'erreur recue veut dire qu'un client de tel identifiant existe deja.
throw new MetierException(e.getMessage());
}
return client;
}
/* (non-Javadoc)
* @see interfaces.clients.IMetierClients#modifierAdresse(base.Client)
*/
public void modifierAdresse(Client clt) throws RemoteException,
MetierException {
try {
this.fc.updateAdresse(clt);
} catch (SQLException e) {
throw new MetierException(MetierException.CONNEXION_IMPOSSIBLE);
} catch (FactoriesException e) {
/* l'erreur vient du fait que le client n'existe pas dans la base
* de donnees
*/
throw new MetierException(e.getMessage());
}
}
/* (non-Javadoc)
* @see interfaces.clients.IMetierClients#rechercherClient(java.lang.String)
*/
public Client rechercherClient(String idClient) throws RemoteException,
MetierException {
try {
return this.fc.rechercherClient(idClient);
} catch (SQLException e) {
throw new MetierException(MetierException.CONNEXION_IMPOSSIBLE);
} catch (FactoriesException e) {
// client n'existe pas.
throw new MetierException(e.getMessage());
}
}
}