-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4095a77
Showing
37 changed files
with
4,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# ignore files | ||
|
||
*.class | ||
|
||
.classpath | ||
.project | ||
.settings/ | ||
|
||
target/ | ||
test_Db/ | ||
|
||
derby.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ejemplo de variabilidad en JPA | ||
|
||
Proyectos Maven con ejemplo de implementación de variabilidad usando JPA. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.uniandes.spl</groupId> | ||
<artifactId>ejemplo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>datos.usuario.core</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
<version>7.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${artifactId}</finalName> | ||
</build> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</properties> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
datos.usuario.core/src/main/java/datos/dao/DaoUsuario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package datos.dao; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
import static datos.utils.FluentMap.Map; | ||
import static datos.utils.FluentMap.entry; | ||
import datos.utils.GenericJpaDAO; | ||
import datos.modelo.AbstractUsuario; | ||
|
||
public class DaoUsuario extends GenericJpaDAO<AbstractUsuario, String>{ | ||
|
||
// == constructores | ||
|
||
public DaoUsuario() { } | ||
|
||
public DaoUsuario(EntityManager em) { | ||
super(em); | ||
} | ||
|
||
// == consultas | ||
|
||
@SuppressWarnings("unchecked") | ||
public AbstractUsuario buscarPorNumDocumento(String numDocumento) { | ||
return executeSingleResultNamedQuery("usuario.buscarPorNumDocumento", | ||
Map( entry("numDocumento", numDocumento) )); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
datos.usuario.core/src/main/java/datos/modelo/AbstractUsuario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package datos.modelo; | ||
|
||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
import javax.persistence.NamedQueries; | ||
import javax.persistence.NamedQuery; | ||
|
||
|
||
@MappedSuperclass | ||
@NamedQueries({ | ||
@NamedQuery( name="usuario.buscarPorNumDocumento", | ||
query="select u from Usuario u where u.numDocumento = :numDocumento" ) | ||
}) | ||
public class AbstractUsuario { | ||
|
||
@Id | ||
private String codigo; | ||
|
||
private String numDocumento; | ||
|
||
private String nombre; | ||
|
||
private String direccion; | ||
|
||
public AbstractUsuario() { | ||
super(); | ||
} | ||
|
||
public void setCodigo(String value) { | ||
this.codigo = value; | ||
} | ||
|
||
public String getCodigo() { | ||
return this.codigo; | ||
} | ||
|
||
public void setNumDocumento(String value) { | ||
this.numDocumento = value; | ||
} | ||
|
||
public String getNumDocumento() { | ||
return this.numDocumento; | ||
} | ||
|
||
public void setNombre(String value) { | ||
this.nombre = value; | ||
} | ||
|
||
public String getNombre() { | ||
return this.nombre; | ||
} | ||
|
||
public void setDireccion(String value) { | ||
this.direccion = value; | ||
} | ||
|
||
public String getDireccion() { | ||
return this.direccion; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
datos.usuario.core/src/main/java/datos/utils/FluentMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package datos.utils; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class FluentMap { | ||
|
||
public static <K, V> Map<K, V> Map(Tuple<K, V>... entries) { | ||
Map<K, V> map = new HashMap<K, V>(); | ||
|
||
for (Tuple<K, V> entry : entries) { | ||
map.put(entry.t1, entry.t2); | ||
} | ||
return map; | ||
} | ||
|
||
public static <T1, T2> Tuple<T1, T2> entry(T1 o1, T2 o2) { | ||
return new Tuple<T1, T2>(o1, o2); | ||
} | ||
|
||
public static class Tuple<T1, T2> { | ||
private T1 t1; | ||
private T2 t2; | ||
|
||
public Tuple(T1 t1, T2 t2) { | ||
this.t1 = t1; | ||
this.t2 = t2; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
datos.usuario.core/src/main/java/datos/utils/GenericDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package datos.utils; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
public interface GenericDAO<T, ID extends Serializable> { | ||
|
||
// == busquedas | ||
|
||
T findById(ID id); | ||
T findById(ID id, boolean lock); | ||
List<T> findAll(); | ||
|
||
// == CRUD | ||
|
||
T create(T entity); | ||
T update(T entity); | ||
void delete(T entity); | ||
|
||
// == Transacciones | ||
|
||
public void beginTransaction(); | ||
public void commit(); | ||
public void rollback(); | ||
|
||
} |
Oops, something went wrong.