martes, 22 de junio de 2010

SOLUCIÓN: Problema de conexión 3G con iOS4



Si te has actualizado al iOs4 y tienes problemas con tu conexión 3G sólo tienes que conectarte desde el Safari de tu iPhone a la web iPhone APN Changer http://www.unlockit.co.nz y seguir las intrucciones que te aparecerán en la pantalla.

domingo, 20 de junio de 2010

Ejemplo de ICEFaces + Hibernate

Un pequeño ejemplo con ICEFaces en el que se crean, editan, borran y buscan empleados por nombre. Muy muy sencillo, pero quizá pueda ayudar a alguien:


EntityManagerSingleton: 

1  
/*
2   * To change this template, choose Tools | Templates
3   * and open the template in the editor.
4   */
5  
6  package com.laura.persistence;
7  
8  import javax.persistence.EntityManager;
9  import javax.persistence.Persistence;
10  
11  
12  /**
13   *
14   * @author laura.gonzalez
15   */
16  public class EntityManagerSingleton
17  {
18      private static EntityManager instance = null;
19  
20      // Private constructor suppresses
21      private EntityManagerSingleton() {}
22  
23      // creador sincronizado para protegerse de posibles problemas  multi-hilo
24      // otra prueba para evitar instantiación múltiple
25      private synchronized static void createInstance() {
26          if (instance == null)
27  
28          {
29              instance = Persistence.createEntityManagerFactory("Hibernate2PU")
30                         .createEntityManager();
31          }
32      }
33  
34      public static EntityManager getInstance() {
35          if (instance == null) createInstance();
36          return instance;
37      }
38  
39  }
40  



Entidad:

1  
/*
2   * To change this template, choose Tools | Templates
3   * and open the template in the editor.
4   */
5  package persistencia;
6  
7  import java.io.Serializable;
8  import javax.persistence.Entity;
9  import javax.persistence.GeneratedValue;
10  import javax.persistence.GenerationType;
11  import javax.persistence.Id;
12  import javax.persistence.NamedQueries;
13  import javax.persistence.NamedQuery;
14  import javax.persistence.SequenceGenerator;
15  import javax.persistence.Table;
16  
17  /**
18   *
19   * @author laura.gonzalez
20   */
21  @Entity
22  @Table(name = "empleados")
23  @NamedQueries(
24  {
25      @NamedQuery(name = "findEmpleadoPorNombre",
26      query = "SELECT e FROM Empleado e " +
27      "WHERE e.nombre LIKE ?1"),
28      @NamedQuery(name = "findEmpleadoPorId",
29      query = "SELECT e FROM Empleado e " +
30      "WHERE e.id=?1")
31  })
32  public class Empleado implements Serializable
33  {
34  
35      private static final long serialVersionUID = 1L;
36      @Id
37      @GeneratedValue(strategy = GenerationType.AUTO)
38      private Long id;
39      private String nombre;
40  
41      public Long getId()
42      {
43          return id;
44      }
45  
46      public void setId(Long id)
47      {
48          this.id = id;
49      }
50  
51      @Override
52      public int hashCode()
53      {
54          int hash = 0;
55          hash += (id != null ? id.hashCode() : 0);
56          return hash;
57      }
58  
59      @Override
60      public boolean equals(Object object)
61      {
62          // TODO: Warning - this method won't work in the case the id fields are not set
63          if (!(object instanceof Empleado))
64          {
65              return false;
66          }
67          Empleado other = (Empleado) object;
68          if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
69          {
70              return false;
71          }
72          return true;
73      }
74  
75      @Override
76      public String toString()
77      {
78          return "persistencia.Empleado[id=" + id + "]";
79      }
80  
81      public String getNombre()
82      {
83          return nombre;
84      }
85  
86      public void setNombre(String nombre)
87      {
88          this.nombre = nombre;
89      }
90  }
91  



Controlador:

1  
/*
2   * To change this template, choose Tools | Templates
3   * and open the template in the editor.
4   */
5  package hibernate2;
6  
7  import com.laura.persistence.EntityManagerSingleton;
8  import hibernate2.exceptions.NonexistentEntityException;
9  import java.util.List;
10  import javax.persistence.EntityManager;
11  import javax.persistence.Query;
12  import javax.persistence.NoResultException;
13  import persistencia.Empleado;
14  
15  /**
16   *
17   * @author laura.gonzalez
18   */
19  public class EmpleadoJpaController
20  {
21  
22      public EntityManager getEntityManager()
23      {
24          return EntityManagerSingleton.getInstance();
25      }
26  
27      public EmpleadoJpaController()
28      {
29      }
30  
31      public void create(Empleado empleado) throws Exception
32      {
33          EntityManager em = null;
34          try
35          {
36              em = getEntityManager();
37              em.getTransaction().begin();
38              em.persist(empleado);
39              em.getTransaction().commit();
40          } catch (Exception ex)
41          {
42              throw ex;
43          }
44      }
45  
46      public void edit(Empleado empleado) throws NonexistentEntityException, Exception
47      {
48          EntityManager em = null;
49          try
50          {
51              em = getEntityManager();
52              em.getTransaction().begin();
53              em.merge(empleado);
54              em.getTransaction().commit();
55          } catch (Exception ex)
56          {
57              throw ex;
58          }
59      }
60  
61      public void destroy(Empleado empleado) throws NonexistentEntityException, Exception
62      {
63          EntityManager em = null;
64          try
65          {
66          em = getEntityManager();
67          em.getTransaction().begin();
68          em.remove(empleado);
69          em.getTransaction().commit();
70          }catch(Exception ex)
71          {
72              throw ex;
73          }
74      }
75  
76      public Empleado findEmpleadoPorNombre(
77              String nombre) throws NonexistentEntityException
78      {
79          EntityManager em = getEntityManager();
80          Empleado empleado = null;
81  
82          try
83          {
84              Query query = em.createNamedQuery("findEmpleadoPorNombre");
85              query.setParameter(1, nombre);
86              empleado =
87                      (Empleado) query.getSingleResult();
88              return empleado;
89  
90          } catch (NoResultException ex)
91          {
92              throw new NonexistentEntityException(ex.getMessage());
93          }
94  
95      }
96  
97       public Empleado findEmpleadoPorId(
98              Long id) throws NonexistentEntityException
99      {
100          EntityManager em = getEntityManager();
101          Empleado empleado = null;
102  
103          try
104          {
105              Query query = em.createNamedQuery("findEmpleadoPorId");
106              query.setParameter(1, id);
107              empleado =
108                      (Empleado) query.getSingleResult();
109              return empleado;
110  
111          } catch (NoResultException ex)
112          {
113              throw new NonexistentEntityException(ex.getMessage());
114          }
115  
116      }
117  
118      public List<Empleado> findEmpleadoEntities()
119      {
120          return findEmpleadoEntities(true, -1, -1);
121      }
122  
123      public List<Empleado> findEmpleadoEntities(int maxResults, int firstResult)
124      {
125          return findEmpleadoEntities(false, maxResults, firstResult);
126      }
127  
128      private List<Empleado> findEmpleadoEntities(boolean all, int maxResults, int firstResult)
129      {
130          EntityManager em = getEntityManager();
131          try
132          {
133              Query q = em.createQuery("select object(o) from Empleado as o");
134              if (!all)
135              {
136                  q.setMaxResults(maxResults);
137                  q.setFirstResult(firstResult);
138              }
139  
140              return q.getResultList();
141          } finally
142          {
143              em.close();
144          }
145  
146      }
147  
148      public Empleado findEmpleado(
149              Long id)
150      {
151          EntityManager em = getEntityManager();
152          try
153          {
154  
155  
156              return em.find(Empleado.class, id);
157          } finally
158          {
159              em.close();
160          }
161  
162      }
163  
164      public int getEmpleadoCount()
165      {
166          EntityManager em = getEntityManager();
167          try
168          {
169              return ((Long) em.createQuery("select count(o) from Empleado as o").getSingleResult()).intValue();
170          } finally
171          {
172              em.close();
173          }
174      }
175  }
176  




JSP:

1  
<?xml version="1.0" encoding="ISO-8859-15"?>
2  
<!-- 
3      Document   : Page1
4      Created on : 22-abr-2010, 9:05:19
5      Author     : laura.gonzalez
6  -->
7  <jsp:root version="2.0" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:jsp="http://java.sun.com/JSP/Page">
8      <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
9      <f:view>
10          <html id="outputHtml1">
11              <head id="outputHead1">
12                  <ice:outputStyle href="./resources/stylesheet.css" id="outputStyle1"/>
13                  <ice:outputStyle href="./xmlhttp/css/xp/xp.css" id="outputStyle2"/>
14              </head>
15              <body id="outputBody1" style="-rave-layout: grid">
16                  <ice:form id="form1">
17                      <ice:commandButton action="#{Page1.buttonCrear_action}" binding="#{Page1.buttonCrear}" id="buttonCrear"
18                          style="left: 48px; top: 144px; position: absolute" value="Crear"/>
19                      <ice:inputText binding="#{Page1.inputTextNombre}" id="inputTextNombre" style="left: 168px; top: 72px; position: absolute"/>
20                      <ice:outputLabel id="outputLabel1" style="left: 48px; top: 72px; position: absolute" value="Nombre"/>
21                      <ice:inputText binding="#{Page1.inputTextId}" disabled="true" id="inputTextId" style="left: 168px; top: 96px; position: absolute"/>
22                      <ice:outputLabel id="outputLabel2" style="left: 72px; top: 96px; position: absolute" value="ID"/>
23                      <ice:commandButton action="#{Page1.buttonBuscar_action}" binding="#{Page1.buttonBuscar}" id="buttonBuscar"
24                          style="left: 144px; top: 144px; position: absolute" value="Buscar"/>
25                      <ice:commandButton action="#{Page1.buttonEditar_action}" binding="#{Page1.buttonEditar}" id="buttonEditar"
26                          style="left: 240px; top: 144px; position: absolute" value="Editar"/>
27                      <ice:commandButton action="#{Page1.buttonBorrar_action}" binding="#{Page1.buttonBorrar}" id="buttonBorrar"
28                          style="left: 336px; top: 144px; position: absolute" value="Borrar"/>
29                      <ice:outputText binding="#{Page1.outputTextMensaje}" id="outputTextMensaje" style="position: absolute; left: 96px; top: 240px"/>
30                  </ice:form>
31              </body>
32          </html>
33      </f:view>
34  </jsp:root>
35  



ManagedBean:
1  
/*
2   * Page1.java
3   *
4   * Created on 22-abr-2010, 9:05:19
5   * Copyright laura.gonzalez
6   */
7  package hibernate2;
8  
9  import com.icesoft.faces.component.ext.HtmlCommandButton;
10  import com.icesoft.faces.component.ext.HtmlInputText;
11  import com.icesoft.faces.component.ext.HtmlOutputText;
12  import com.sun.rave.web.ui.appbase.AbstractPageBean;
13  import hibernate2.exceptions.NonexistentEntityException;
14  import javax.faces.FacesException;
15  import persistencia.Empleado;
16  
17  public class Page1 extends AbstractPageBean
18  {
19      // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
20  
21      private int __placeholder;
22      private HtmlInputText inputTextNombre = new HtmlInputText();
23      private HtmlInputText inputTextId = new HtmlInputText();
24      private HtmlOutputText outputTextMensaje = new HtmlOutputText();
25      private HtmlCommandButton buttonEditar = new HtmlCommandButton();
26      private HtmlCommandButton buttonCrear = new HtmlCommandButton();
27      private HtmlCommandButton buttonBuscar = new HtmlCommandButton();
28      private HtmlCommandButton buttonBorrar = new HtmlCommandButton();
29      private Empleado empleadoBuscado = new Empleado();
30      private String nombreBuscado;
31  
32      private void _init() throws Exception
33      {
34          buttonCrear.setRendered(true);
35          buttonBuscar.setRendered(true);
36          buttonEditar.setRendered(false);
37          buttonBorrar.setRendered(false);
38      }
39  
40      // </editor-fold>
41      /**
42       * <p>Construct a new Page bean instance.</p>
43       */
44      public Page1()
45      {
46      }
47  
48      public void init()
49      {
50          // Perform initializations inherited from our superclass
51          super.init();
52  
53          try
54          {
55              _init();
56          } catch (Exception e)
57          {
58              log("Page1 Initialization Failure", e);
59              throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
60          }
61  
62  
63      }
64  
65      public void preprocess()
66      {
67      }
68  
69      public void prerender()
70      {
71      }
72  
73      public void destroy()
74      {
75      }
76  
77      public void limpiarCampos()
78      {
79          inputTextId.setValue("");
80          inputTextNombre.setValue("");
81          buttonCrear.setRendered(true);
82          buttonBuscar.setRendered(true);
83          buttonEditar.setRendered(false);
84          buttonBorrar.setRendered(false);
85      }
86  
87      public String buttonCrear_action()
88      {
89          Empleado empleado = new Empleado();
90          empleado.setNombre(inputTextNombre.getText());
91          EmpleadoJpaController empleadoJpaController = new EmpleadoJpaController();
92          Boolean error = false;
93          try
94          {
95              empleadoJpaController.create(empleado);
96          } catch (Exception ex)
97          {
98              outputTextMensaje.setValue("Error al crear");
99              error = true;
100          }
101          if (!error)
102          {
103              outputTextMensaje.setValue("Empleado creado");
104          }
105          limpiarCampos();
106          return null;
107      }
108  
109      public String buttonBuscar_action()
110      {
111          Empleado empleado = new Empleado();
112          EmpleadoJpaController empleadoJpaController = new EmpleadoJpaController();
113          if (inputTextNombre.getText().equals(""))
114          {
115              outputTextMensaje.setValue("Introduzca un nombre por favor");
116          } else
117          {
118              Boolean error = false;
119              try
120              {
121                  empleadoBuscado = empleadoJpaController.findEmpleadoPorNombre(inputTextNombre.getText());
122              } catch (NonexistentEntityException ex)
123              {
124                  outputTextMensaje.setValue("Empleado no encontrado");
125                  error = true;
126                  buttonCrear.setRendered(true);
127                  buttonBuscar.setRendered(true);
128                  buttonEditar.setRendered(false);
129                  buttonBorrar.setRendered(false);
130              }
131              if (!error)
132              {
133  //                empleadoBuscado = empleado;
134                  inputTextId.setValue(empleadoBuscado.getId().toString());
135                  nombreBuscado = empleadoBuscado.getNombre().toString();
136                  outputTextMensaje.setValue("Empleado encontrado");
137                  buttonCrear.setRendered(true);
138                  buttonBuscar.setRendered(true);
139                  buttonEditar.setRendered(true);
140                  buttonBorrar.setRendered(true);
141              }
142          }
143  
144          return null;
145      }
146  
147      public String buttonEditar_action()
148      {
149          EmpleadoJpaController empleadoJpaController = new EmpleadoJpaController();
150  //        empleadoBuscado.setNombre(inputTextNombre.getText());
151          Empleado empleado = new Empleado();
152  
153          Boolean error = false;
154          try
155          {
156              empleado = empleadoJpaController.findEmpleadoPorId(Long.valueOf(inputTextId.getText()));
157          } catch (NonexistentEntityException ex)
158          {
159              ex.printStackTrace();
160              outputTextMensaje.setValue("Empleado no encontrado");
161              error = true;
162          }
163          if (!error)
164          {
165              Boolean error2 = false;
166              empleado.setNombre(inputTextNombre.getText());
167              try
168              {
169                  empleadoJpaController.edit(empleado);
170              } catch (Exception ex)
171              {
172                  ex.printStackTrace();
173                  outputTextMensaje.setValue("Se ha producido un error al editar");
174                  error2 = true;
175  
176              }
177              if (!error2)
178              {
179                  outputTextMensaje.setValue("Empleado editado");
180              }
181              limpiarCampos();
182          }
183  
184  
185          return null;
186      }
187  
188      public String buttonBorrar_action()
189      {
190          EmpleadoJpaController empleadoJpaController = new EmpleadoJpaController();
191  //        empleadoBuscado.setNombre(inputTextNombre.getText());
192          Empleado empleado = new Empleado();
193  
194          Boolean error = false;
195          try
196          {
197              empleado = empleadoJpaController.findEmpleadoPorId(Long.valueOf(inputTextId.getText()));
198          } catch (NonexistentEntityException ex)
199          {
200              ex.printStackTrace();
201              outputTextMensaje.setValue("Empleado no encontrado");
202              error = true;
203          }
204          if (!error)
205          {
206              try
207              {
208                  empleadoJpaController.destroy(empleado);
209              } catch (Exception ex)
210              {
211                  outputTextMensaje.setValue("Se ha producido un error al borrar");
212                  error = true;
213              }
214              if (!error)
215              {
216                  outputTextMensaje.setValue("Empleado borrado");
217              }
218              limpiarCampos();
219          }
220          return null;
221      }
222  
223      public HtmlInputText getInputTextNombre()
224      {
225          return inputTextNombre;
226      }
227  
228      public void setInputTextNombre(HtmlInputText hit)
229      {
230          this.inputTextNombre = hit;
231      }
232  
233      public HtmlInputText getInputTextId()
234      {
235          return inputTextId;
236      }
237  
238      public void setInputTextId(HtmlInputText hit)
239      {
240          this.inputTextId = hit;
241      }
242  
243      public HtmlOutputText getOutputTextMensaje()
244      {
245          return outputTextMensaje;
246      }
247  
248      public void setOutputTextMensaje(HtmlOutputText hot)
249      {
250          this.outputTextMensaje = hot;
251      }
252  
253      public HtmlCommandButton getButtonEditar()
254      {
255          return buttonEditar;
256      }
257  
258      public void setButtonEditar(HtmlCommandButton hcb)
259      {
260          this.buttonEditar = hcb;
261      }
262  
263      public HtmlCommandButton getButtonCrear()
264      {
265          return buttonCrear;
266      }
267  
268      public void setButtonCrear(HtmlCommandButton hcb)
269      {
270          this.buttonCrear = hcb;
271      }
272  
273      public HtmlCommandButton getButtonBuscar()
274      {
275          return buttonBuscar;
276      }
277  
278      public void setButtonBuscar(HtmlCommandButton hcb)
279      {
280          this.buttonBuscar = hcb;
281      }
282  
283      public HtmlCommandButton getButtonBorrar()
284      {
285          return buttonBorrar;
286      }
287  
288      public void setButtonBorrar(HtmlCommandButton hcb)
289      {
290          this.buttonBorrar = hcb;
291      }
292  
293      public Empleado getEmpleadoBuscado()
294      {
295          return empleadoBuscado;
296      }
297  
298      public void setEmpleadoBuscado(Empleado empleadoBuscado)
299      {
300          this.empleadoBuscado = empleadoBuscado;
301      }
302  
303      public String getNombreBuscado()
304      {
305          return nombreBuscado;
306      }
307  
308      public void setNombreBuscado(String nombreBuscado)
309      {
310          this.nombreBuscado = nombreBuscado;
311      }
312  }
313  
314  

sábado, 19 de junio de 2010

Cómo quitar el hipo

He estado toda la tarde con hipo, y después de probar muchos "trucos" caseros finalmente me he decidido a buscar por internet. He encontrado este enlace y realmente ha funcionado. Os dejo el truco por si puede ayudar a alguien:

Aspira la mayor cantidad de aire que puedas y aguanta la repiración, coloca las manos en el marco de la puerta y estírate hacia delante. Debes sentir como se arquea la espalda y el abdomen se estira. Todo esto mientras se retiene el aire. Es recomendable mantenerte así de 30 a 60 segundos.


Aquí teneis una foto con la posición que debéis tener:

miércoles, 16 de junio de 2010

Season Finales

























Este año las "season finales"  tienen un elemento común: todas tratan de que te afecte emocionalmente, que llores, suspires, y te quedes la siguiente media hora pensando en el final que acabas de ver. Da la impresión de que si el espectador no sufre, el final no será bueno. Y la verdad es que casi todas aciertan, a no ser que bajo un final emotivo pretendan esconder que no muestran absolutamente nada de su esencia.

Eso sí, quién me iba a decir allá por el año 2004 cuando veía las primeras temporadas que el final de la 6ª me parecería mejor en Anatomía de Grey que en Perdidos.

iPhone 4

Movistar apostando por las nuevas formas de comunicación ha lanzado una campaña llamada por ellos mismos "Gota a gota" desde twitter donde ha ido dejando caer la información de precios para los ya clientes de la operadora que ya poseen un smartphone (supongo que comprado directamente a movistar y no cualquier smartphone libre), y a los que les queden 3 meses o menos del contrato de permanencia. Eso sí, a tus puntos (yo tengo sólo 40.000pts y llevo más de 3 años sin realizar un solo canje) hay que sumarle los 120.000 pts que movistar generosamente  regala a todos los cumplan las condiciones antes descritas:


También han creado una página web donde puedes inscribirte para que se pongan en contacto contigo para darte toda la información que necesites: www.movistar.es/iphone4