-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
US-31: Clevcore-Engine migration to GitHub
- Loading branch information
1 parent
60bd04f
commit decc7e1
Showing
8 changed files
with
616 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,4 @@ | ||
/target/ | ||
/.classpath | ||
/.project | ||
/.settings/ |
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,109 @@ | ||
<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> | ||
|
||
<groupId>ar.com.clevcore</groupId> | ||
<artifactId>clevcore-backend</artifactId> | ||
<version>1.1.0</version> | ||
<packaging>jar</packaging> | ||
<name>Clevcore Backend</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<eclipselink.version>2.5.2</eclipselink.version> | ||
<java.version>1.8</java.version> | ||
<javax.persistence.version>2.1.0</javax.persistence.version> | ||
<junit.version>4.11</junit.version> | ||
<mysql.connector.version>5.1.30</mysql.connector.version> | ||
|
||
<clevcore.java.version>1.1.0</clevcore.java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Clevcore --> | ||
<dependency> | ||
<groupId>ar.com.clevcore</groupId> | ||
<artifactId>clevcore-java</artifactId> | ||
<version>${clevcore.java.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Eclipselink --> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>eclipselink</artifactId> | ||
<version>${eclipselink.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>javax.persistence</artifactId> | ||
<version>${javax.persistence.version}</version> | ||
</dependency> | ||
|
||
<!-- MySQL --> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>${mysql.connector.version}</version> | ||
</dependency> | ||
|
||
<!-- JUnit --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>clevcore-backend</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<version>2.9</version> | ||
<configuration> | ||
<additionalBuildcommands> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.wst.validation.validationbuilder</name> | ||
</buildCommand> | ||
</additionalBuildcommands> | ||
<additionalProjectnatures> | ||
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature> | ||
<projectnature>org.eclipse.jdt.core.javanature</projectnature> | ||
<projectnature>org.eclipse.m2e.core.maven2Nature</projectnature> | ||
</additionalProjectnatures> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
src/main/java/ar/com/clevcore/backend/persistance/base/Dao.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,34 @@ | ||
package ar.com.clevcore.backend.persistance.base; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
public interface Dao<E extends Serializable> { | ||
|
||
E selectOne(EntityManager entityManager) throws Exception; | ||
|
||
E selectIdOne(E entity, EntityManager entityManager) throws Exception; | ||
|
||
E selectEqualOne(E entity, EntityManager entityManager) throws Exception; | ||
|
||
E selectLikeOne(E entity, EntityManager entityManager) throws Exception; | ||
|
||
|
||
List<E> selectAll(EntityManager entityManager) throws Exception; | ||
|
||
List<E> selectIdAll(E entity, EntityManager entityManager) throws Exception; | ||
|
||
List<E> selectEqualAll(E entity, EntityManager entityManager) throws Exception; | ||
|
||
List<E> selectLikeAll(E entity, EntityManager entityManager) throws Exception; | ||
|
||
|
||
void insert(E entity, EntityManager entityManager) throws Exception; | ||
|
||
void update(E entity, EntityManager entityManager) throws Exception; | ||
|
||
void delete(E entity, EntityManager entityManager) throws Exception; | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/ar/com/clevcore/backend/persistance/base/DaoImpl.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,100 @@ | ||
package ar.com.clevcore.backend.persistance.base; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.NoResultException; | ||
import javax.persistence.NonUniqueResultException; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
|
||
import ar.com.clevcore.backend.utils.PersistanceUtils; | ||
import ar.com.clevcore.backend.utils.PersistanceUtils.Operator; | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public class DaoImpl<E extends Serializable> implements Dao<E> { | ||
|
||
private Class<?> clazz; | ||
|
||
public DaoImpl() { | ||
clazz = (Class<?>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; | ||
} | ||
|
||
@Override | ||
public E selectOne(EntityManager entityManager) throws Exception { | ||
try { | ||
CriteriaQuery criteriaQuery = entityManager.getCriteriaBuilder().createQuery(clazz); | ||
criteriaQuery.select(criteriaQuery.from(clazz)); | ||
return (E) entityManager.createQuery(criteriaQuery).getSingleResult(); | ||
} catch (NoResultException | NonUniqueResultException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public E selectIdOne(E entity, EntityManager entityManager) throws Exception { | ||
try { | ||
return (E) PersistanceUtils.getSelectQuery(entity, Operator.EQUAL, true, entityManager).getSingleResult(); | ||
} catch (NoResultException | NonUniqueResultException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public E selectLikeOne(E entity, EntityManager entityManager) throws Exception { | ||
try { | ||
return (E) PersistanceUtils.getSelectQuery(entity, Operator.LIKE, false, entityManager).getSingleResult(); | ||
} catch (NoResultException | NonUniqueResultException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public E selectEqualOne(E entity, EntityManager entityManager) throws Exception { | ||
try { | ||
return (E) PersistanceUtils.getSelectQuery(entity, Operator.EQUAL, false, entityManager).getSingleResult(); | ||
} catch (NoResultException | NonUniqueResultException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public List<E> selectAll(EntityManager entityManager) throws Exception { | ||
CriteriaQuery criteriaQuery = entityManager.getCriteriaBuilder().createQuery(clazz); | ||
criteriaQuery.select(criteriaQuery.from(clazz)); | ||
return (List<E>) entityManager.createQuery(criteriaQuery).getResultList(); | ||
} | ||
|
||
@Override | ||
public List<E> selectIdAll(E entity, EntityManager entityManager) throws Exception { | ||
return (List<E>) PersistanceUtils.getSelectQuery(entity, Operator.EQUAL, true, entityManager).getResultList(); | ||
} | ||
|
||
@Override | ||
public List<E> selectEqualAll(E entity, EntityManager entityManager) throws Exception { | ||
return (List<E>) PersistanceUtils.getSelectQuery(entity, Operator.EQUAL, false, entityManager).getResultList(); | ||
} | ||
|
||
@Override | ||
public List<E> selectLikeAll(E entity, EntityManager entityManager) throws Exception { | ||
return (List<E>) PersistanceUtils.getSelectQuery(entity, Operator.LIKE, false, entityManager).getResultList(); | ||
} | ||
|
||
@Override | ||
public void insert(E entity, EntityManager entityManager) throws Exception { | ||
entityManager.persist(entity); | ||
} | ||
|
||
@Override | ||
public void update(E entity, EntityManager entityManager) throws Exception { | ||
entityManager.merge(entity); | ||
} | ||
|
||
@Override | ||
public void delete(E entity, EntityManager entityManager) throws Exception { | ||
entity = entityManager.merge(entity); | ||
entityManager.remove(entity); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/ar/com/clevcore/backend/service/base/Service.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,39 @@ | ||
package ar.com.clevcore.backend.service.base; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
import ar.com.clevcore.exceptions.ClevcoreException; | ||
|
||
public interface Service<E extends Serializable> { | ||
|
||
EntityManager getEntityManager(); | ||
|
||
|
||
E selectOne() throws ClevcoreException; | ||
|
||
E selectIdOne(E entity) throws ClevcoreException; | ||
|
||
E selectEqualOne(E entity) throws ClevcoreException; | ||
|
||
E selectLikeOne(E entity) throws ClevcoreException; | ||
|
||
|
||
List<E> selectAll() throws ClevcoreException; | ||
|
||
List<E> selectIdAll(E entity) throws ClevcoreException; | ||
|
||
List<E> selectEqualAll(E entity) throws ClevcoreException; | ||
|
||
List<E> selectLikeAll(E entity) throws ClevcoreException; | ||
|
||
|
||
void insert(E entity) throws ClevcoreException; | ||
|
||
void update(E entity) throws ClevcoreException; | ||
|
||
void delete(E entity) throws ClevcoreException; | ||
|
||
} |
Oops, something went wrong.