-
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.
- Loading branch information
Showing
6 changed files
with
171 additions
and
34 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/edu/eci/cvds/services/ServiciosBancoFactory.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,59 @@ | ||
package edu.eci.cvds.services; | ||
|
||
import com.google.inject.Injector; | ||
import edu.eci.cvds.persistence.*; | ||
import edu.eci.cvds.persistence.mybatisimpl.*; | ||
import edu.eci.cvds.services.impl.ServiciosBancoDeProyectosImpl; | ||
import org.mybatis.guice.XMLMyBatisModule; | ||
import org.mybatis.guice.datasource.helper.JdbcHelper; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.google.inject.Guice.createInjector; | ||
|
||
public class ServiciosBancoFactory { | ||
|
||
private static ServiciosBancoFactory instance = new ServiciosBancoFactory(); | ||
|
||
private static Optional<Injector> optInjector; | ||
|
||
private Injector myBatisInjector(String env, String pathResource) { | ||
return createInjector(new XMLMyBatisModule() { | ||
@Override | ||
protected void initialize() { | ||
setEnvironmentId(env); | ||
install(JdbcHelper.PostgreSQL); | ||
setClassPathResource(pathResource); | ||
bind(UsuarioDAO.class).to(MyBatisUsuarioDAO.class); | ||
bind(ServiciosBancoDeProyectos.class).to(ServiciosBancoDeProyectosImpl.class); | ||
} | ||
}); | ||
} | ||
|
||
private ServiciosBancoFactory(){ | ||
optInjector = Optional.empty(); | ||
} | ||
|
||
public ServiciosBancoDeProyectos getServiciosBanco(){ | ||
if (!optInjector.isPresent()) { | ||
optInjector = Optional.of(myBatisInjector("development","mybatis-config.xml")); | ||
} | ||
|
||
return optInjector.get().getInstance(ServiciosBancoDeProyectos.class); | ||
} | ||
|
||
|
||
public ServiciosBancoDeProyectos getServiciosBancoTesting(){ | ||
if (!optInjector.isPresent()) { | ||
optInjector = Optional.of(myBatisInjector("development","mybatis-config.xml")); | ||
} | ||
|
||
return optInjector.get().getInstance(ServiciosBancoDeProyectos.class); | ||
} | ||
|
||
|
||
public static ServiciosBancoFactory getInstance(){ | ||
return instance; | ||
} | ||
|
||
} |
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,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.eci.cvds.view; | ||
|
||
/** | ||
* | ||
* @author juaco | ||
*/ | ||
public class ManejoIniciativaBean { | ||
|
||
} |
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
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
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
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