jmoordbunit
  • Introduction
  • Overview
    • Creditos
    • Autor
    • Introduccion
    • Porque JmoordbUnit
    • Pasos
  • UnitTest
    • Que es UnitTest
    • Ejemplos
  • UnitView
    • Que es UtilView
    • header
    • DataTable
    • PanelGrid
    • InputText
  • Proyecto EJB
    • Microtestingejb
    • Maven
    • Esquema General
    • Paquetes
    • Provider
    • Entity
    • Repository
    • Converter
    • DataModel
    • Services
    • Construir proyecto
    • BodegaTest
  • Proyecto Web
    • Proyecto
    • Orden de ejecucion
    • Maven pom.xml
    • Test
    • Mock
    • Construir el proyecto
    • Ejecutar el proyecto
    • UberJar
    • Script desde Consola
  • Testing con UnitView
    • Testing con UnitView
    • Formulario
    • SelectOneMenu
    • DataTable
    • RadioButton
    • CheckBox
    • Todos Componentes
    • ColorTest
  • Testing de bases de datos dinĂ¡micas
    • Testing
Powered by GitBook
On this page

Was this helpful?

  1. Proyecto EJB

Provider

Crear el provider

/*
 * 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 com.avbravo.microtestingejb.provider;

/**
 *
 * @author avbravo
 */
import com.avbravo.avbravoutils.JsfUtil;
import com.mongodb.MongoClient;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;

/**
 * * * @author
 */
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class MongoClientProvider {

    private static final Logger LOG = Logger.getLogger(MongoClientProvider.class.getName());
    private MongoClient mongoClient = null;

    @Lock(LockType.READ)
    public MongoClient getMongoClient() {
        if (mongoClient == null) {
            init();
        }
        return mongoClient;
    }

    @PostConstruct
    public void init() {
        try {
            /* String database=""; String username=""; String password=""; String host="localhost"; String port="27017"; char[] charArray = password.toCharArray(); MongoCredential credential = MongoCredential.createCredential(username, database, charArray); mongoClient = new MongoClient(new ServerAddress(host,port), Arrays.asList(credential)); */ mongoClient = new MongoClient();
        } catch (Exception e) {
            JsfUtil.errorMessage("init() " + e.getLocalizedMessage());
            LOG.warning("MongoClientProvider init() " + e.getLocalizedMessage());
        }
    }
}
PreviousPaquetesNextEntity

Last updated 6 years ago

Was this helpful?