Skip to content

Instantly share code, notes, and snippets.

@jonasurbano
Last active December 28, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasurbano/7512908 to your computer and use it in GitHub Desktop.
Save jonasurbano/7512908 to your computer and use it in GitHub Desktop.
Servicio.java
package org.pfc.domain;
import javax.persistence.Column;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.pfc.utils.JsonMap;
public class Servicio {
private static final String CLAVE_VISITAS = "visitas";
// Otras propiedades
@Column
private String misc;
// Otros métodos
/**
* Obtiene {@code clave} del misc
* convirtiendo a Map el String
*/
private String getMisc(String clave) {
return JsonMap.toMap(misc).get(clave);
}
/**
* Añade o actualiza {@code "clave"} en el JSON
* convirtiendo a Map la propiedad misc
*/
private void setMisc(String clave,String valor) {
misc = JsonMap.toJson(clave, valor, misc);
}
public int getVisitas() {
String visitas = getMisc(CLAVE_VISITAS);
if (visitas == null) return 0;
try {
return Integer.parseInt(visitas);
} catch (Exception e) {
return 0;
}
}
public void incrementarVisitas() {
int visitas = getVisitas();
if (visitas == 0) setMisc(CLAVE_VISITAS, Integer.toString(1));
else setMisc(CLAVE_VISITAS,Integer.toString(++visitas));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment