jboss-user
[Arriba] [Todas las Listas]

[jboss-Usuario] [Datasource Configuración] - Re: Cómo tú programmati

To: User development <jboss-user@xxxxxxxxxxxxxxx>
Subject: [jboss-Usuario] [Datasource Configuración] - Re: Cómo tú programmatically crear datasources en JBoss5
From: Tom Coupland <do-not-reply@xxxxxxxxx>
Date: Thu, 01 Sep 2011 07:43:57 -0400
Auto-submitted: yes
Delivery-date: Thu, 01 Sep 2011 08:44:47 -0400
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <2-615235-3-88228-1310657350622-2-615404-3-70091-1310720365764.jivesbs.jivemailuser@http://community.jboss.org>
List-archive: <http://lists.jboss.org/pipermail/jboss-user>
List-help: <mailto:jboss-user-request@lists.jboss.org?subject=help>
List-id: The JBoss User main mailing list <jboss-user.lists.jboss.org>
List-post: <mailto:jboss-user@lists.jboss.org>
List-subscribe: <https://lists.jboss.org/mailman/listinfo/jboss-user>, <mailto:jboss-user-request@lists.jboss.org?subject=subscribe>
List-unsubscribe: <https://lists.jboss.org/mailman/listinfo/jboss-user>, <mailto:jboss-user-request@lists.jboss.org?subject=unsubscribe>
References: <2-615235-3-88228-1310657350622.jivesbs.jivemailuser@http://community.jboss.org> <2-615235-3-88228-1310657350622-2-615404-3-70091-1310720365764.jivesbs.jivemailuser@http://community.jboss.org>
Reply-to: The JBoss User main mailing list <jboss-user@xxxxxxxxxxxxxxx>
Sender: jboss-user-bounces@xxxxxxxxxxxxxxx
Tom *Coupland [*http://comunidad.*jboss.*org/Personas/*tcoup] creó la discusión

"*Re: Cómo  tú *programmatically crear *datasources en *JBoss5"

para ver la discusión, visita: *http://comunidad.*jboss.*org/Mensaje/624249#624249

--------------------------------------------------------------
Siguiendo 'seguidores *xnet *excellant aconsejar *i creó una fábrica. Yo incluso (finalmente) salió qué para poner en él!

Para complexión un EMF necesitas hacer a algo le gusta:

{#nom_de_nom}
   *EntityManagerFactory *buildEntityManagerFactory(*DataSource *datasource) 
        #unknown{^*Ejb3Configuración *ejbconf = nuevo *Ejb3Configuración();

        *ejbconf.*setDataSource(*datasource);
        *ejbconf.*setProperty("*hibernate.Dialecto", "*org.*hibernate.Dialecto.*MySQL5*InnoDBDialect");
        *ejbconf.*setProperty("*hibernate.Espectáculo_*sql", "falso");

        //Marca *transactionally consciente
        *ejbconf.*setProperty("*hibernate.Transacción.Director_*lookup_clase", "*org.*hibernate.Transacción.*JBossTransactionManagerLookup");
        *ejbconf.*setProperty("*jta.*UserTransaction", "*java:*comp/*UserTransaction");
        *ejbconf.*setProperty("*hibernate.Clase_de contexto_de sesión_actual", "*jta");
        *ejbconf.*setProperty(*HibernatePersistence.TIPO_de TRANSACCIÓN, *PersistenceUnitTransactionType.JTA.Nombre());

        //Añade *caching
        *ejbconf.*setProperty("*hibernate.*cache.Clase_de proveedor", "*HibernateEhCacheProviderClass");
        *ejbconf.*setProperty("*hibernate.*cache.Uso_segundo_nivel_*cache", "cierto");
        *ejbconf.*setProperty("Red.*sf.*ehcache.*configurationResourceName", "*META-*INF/*ehcache.*xml");

        //Añadirte alubias de entidad aquí
        *ejbconf.*addAnnotatedClass(*SomeEntityBean.Clase);

        regreso  *ejbconf.*buildEntityManagerFactory();#Nom}

Golpeando arriba de un *datasource con *DBCP parece:

{#nom_de_nom} 
      *DataSource *buildDatasource(Cadena *connectionUrl)
        // #verbcj fábrica de conexión de la base que produce crudo *db conexiones.
        *ConnectionFactory *connectionFactory = Nuevo *DriverManagerConnectionFactory(*connectionUrl, *libraryUser,
                *libraryPassword);

        // piscina de Objeto para *pooling conexiones crudas
        *GenericObjectPool *connPool = nuevo *GenericObjectPool();
        *connPool.*setMaxActive(*maxShardConns);
        *connPool.*setMinIdle(*minShardConns);
        *connPool.*setMaxIdle(*maxIdleConns);
        *connPool.*setMinEvictableIdleTimeMillis(*shardConnTimeOutMins * 60 * 1000);
        *connPool.*setTestOnBorrow(Cierto);

        *connPool = nuevo *InstrumentedObjectPool(*extractServerName(*connectionUrl), *connPool);

        Cadena *connectionValidationSql = "SELECCIONAR 1;";
        *KeyedObjectPoolFactory *preparedStatementPool = *null;
        *Boolean *defaultConnectionsToReadOnly = falso;
        *Boolean *defaultConnectionsToAutoCommit = falso;

        *TransactionManager *transactionManager;
        prueba
            #unknown{^*transactionManager = (*TransactionManager) *InitialContext.*doLookup("*java:/*TransactionManager");
        } Coge (*NamingException *e)
            #verbcj nuevo *RuntimeException("Incapaz a *lookup director de transacción", *e);
        }

        *LocalXAConnectionFactory *transactionFactory = nuevo *LocalXAConnectionFactory(*transactionManager,
                *connectionFactory);

        // Crea fábrica para dirigir el *connectionPool
        *PoolableManagedConnectionFactory *poolableConnectionFactory = nuevo *PoolableManagedConnectionFactory(
                *transactionFactory, *connPool, *preparedStatementPool, *connectionValidationSql,
                *defaultConnectionsToReadOnly, *defaultConnectionsToAutoCommit);

        *ManagedDataSource *dataSource = nuevo *ManagedDataSource(*connPool, *transactionFactory.*getTransactionRegistry());

        Regreso *dataSource;#nom}

Utilizando estos en combinación te darán un *transactionally EMF consciente con conexión *pooling.
--------------------------------------------------------------

Respuesta a este mensaje por ir a Comunidad
[*http://comunidad.*jboss.*org/Mensaje/624249#624249]

Empieza una discusión nueva en *Datasource Configuración en Comunidad
[*http://comunidad.*jboss.*org/Escoge-contenedor!Entrada.*jspa?*contentType=1&*containerType=14&contenedor=2077]

Tom Coupland [http://community.jboss.org/people/tcoup] created the discussion

"Re: How do you programmatically create datasources in JBoss5"

To view the discussion, visit: http://community.jboss.org/message/624249#624249

--------------------------------------------------------------
Following 'fans xnet's excellant advise i did create a factory. I even (eventually) worked out what to put in it!

In order to build an EMF you need to do something like:

{code}
 public EntityManagerFactory buildEntityManagerFactory(DataSource datasource) { 
        Ejb3Configuration ejbconf = new Ejb3Configuration();

        ejbconf.setDataSource(datasource);
        ejbconf.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
        ejbconf.setProperty("hibernate.show_sql", "false");

        //Make transactionally aware
        ejbconf.setProperty("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");
        ejbconf.setProperty("jta.UserTransaction", "java:comp/UserTransaction");
        ejbconf.setProperty("hibernate.current_session_context_class", "jta");
        ejbconf.setProperty(HibernatePersistence.TRANSACTION_TYPE, PersistenceUnitTransactionType.JTA.name());

        //Add caching
        ejbconf.setProperty("hibernate.cache.provider_class", "HibernateEhCacheProviderClass");
        ejbconf.setProperty("hibernate.cache.use_second_level_cache", "true");
        ejbconf.setProperty("net.sf.ehcache.configurationResourceName", "META-INF/ehcache.xml");

        //Add you entity beans here
        ejbconf.addAnnotatedClass(SomeEntityBean.class);

        return  ejbconf.buildEntityManagerFactory();
{code}

Knocking up a datasource with DBCP looks like:

{code} 
    public DataSource buildDatasource(String connectionUrl) {
        // Create base connection factory that produces raw db connections.
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionUrl, libraryUser,
                libraryPassword);

        // Object pool for pooling raw connections
        GenericObjectPool connPool = new GenericObjectPool();
        connPool.setMaxActive(maxShardConns);
        connPool.setMinIdle(minShardConns);
        connPool.setMaxIdle(maxIdleConns);
        connPool.setMinEvictableIdleTimeMillis(shardConnTimeOutMins * 60 * 1000);
        connPool.setTestOnBorrow(true);

        connPool = new InstrumentedObjectPool(extractServerName(connectionUrl), connPool);

        String connectionValidationSql = "SELECT 1;";
        KeyedObjectPoolFactory preparedStatementPool = null;
        Boolean defaultConnectionsToReadOnly = false;
        Boolean defaultConnectionsToAutoCommit = false;

        TransactionManager transactionManager;
        try {
            transactionManager = (TransactionManager) InitialContext.doLookup("java:/TransactionManager");
        } catch (NamingException e) {
            throw new RuntimeException("Unable to lookup transaction manager", e);
        }

        LocalXAConnectionFactory transactionFactory = new LocalXAConnectionFactory(transactionManager,
                connectionFactory);

        // Create factory to manage the connectionPool
        PoolableManagedConnectionFactory poolableConnectionFactory = new PoolableManagedConnectionFactory(
                transactionFactory, connPool, preparedStatementPool, connectionValidationSql,
                defaultConnectionsToReadOnly, defaultConnectionsToAutoCommit);

        ManagedDataSource dataSource = new ManagedDataSource(connPool, transactionFactory.getTransactionRegistry());

        return dataSource;
{code}

Using these in combination will give you a transactionally aware EMF with connection pooling.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/624249#624249]

Start a new discussion in Datasource Configuration at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]

_______________________________________________
*jboss-Usuario *mailing lista
*jboss-user@xxxxxxxxxxxxxxx
*https://listas.*jboss.*org/*mailman/*listinfo/*jboss-Usuario
_______________________________________________
jboss-user mailing list
jboss-user@xxxxxxxxxxxxxxx
https://lists.jboss.org/mailman/listinfo/jboss-user
<Anterior por Tema] Tema Actual [Siguiente por Tema>
  • [jboss-Usuario] [Datasource Configuración] - Re: Cómo tú programmatically crear datasources en JBoss5, Tom Coupland <=