Last active
July 12, 2021 13:21
-
-
Save brunogasparetto/d6bffef42fb89de56788323cc6771be7 to your computer and use it in GitHub Desktop.
Fluig: Configurar o PostgreSQL no Fluig.
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
<!-- | |
Criar a pasta <instalação do fluig>\appserver\modules\system\layers\base\org\postgresql\main | |
Colocar o .jar do jdbc nessa pasta. | |
Utilizei o postgresql-42.2.20.jar, então deve-se indicar a versão correta no path de resource-root. | |
Criar o arquivo "module.xml" nesta pasta com o seguinte conteúdo: | |
--> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<module xmlns="urn:jboss:module:1.1" name="org.postgresql"> | |
<resources> | |
<resource-root path="postgresql-42.2.20.jar"/> | |
</resources> | |
<dependencies> | |
<module name="javax.api"/> | |
<module name="javax.transaction.api"/> | |
<module name="javax.servlet.api" optional="true"/> | |
</dependencies> | |
</module> | |
<!-- | |
As alterações a seguir serão feitas no arquivo "domain.xml" que está na pasta <instalação do fluig>\appserver\domain\configuration | |
--> | |
<!-- | |
Criar um novo datasource dentro de <datasources> em <subsystem xmlns="urn:jboss:domain:datasources:5.0"> | |
As propriedades jndi-name (esse será o dataSource na consulta) e pool-name, do <datasources>, são importantes para | |
nomear a conexão que será feita no Dataset. | |
--> | |
<datasource enabled="true" jta="false" jndi-name="java:/jdbc/PostgreSqlDS" pool-name="PostgreSqlDS" use-java-context="false" use-ccm="false"> | |
<connection-url>jdbc:postgresql://host-do-banco:porta/NOME-DA-BASE</connection-url> | |
<driver>postgresqlDriver</driver> | |
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> | |
<pool> | |
<min-pool-size>10</min-pool-size> | |
<max-pool-size>100</max-pool-size> | |
<prefill>true</prefill> | |
</pool> | |
<security> | |
<user-name>usuário do banco</user-name> | |
<password>senha do usuário do banco</password> | |
</security> | |
<statement> | |
<prepared-statement-cache-size>32</prepared-statement-cache-size> | |
<share-prepared-statements>false</share-prepared-statements> | |
</statement> | |
<validation> | |
<validate-on-match>false</validate-on-match> | |
<background-validation>false</background-validation> | |
</validation> | |
</datasource> | |
<!-- | |
Criar um novo driver dentro de <drivers> (ainda dentro de datasources): | |
--> | |
<driver name="postgresqlDriver" module="org.postgresql"> | |
<driver-class>org.postgresql.Driver</driver-class> | |
</driver> | |
<!-- | |
Em <subsystem xmlns="urn:jboss:domain:ee:4.0"> deve-se criar um global-modules: | |
--> | |
<global-modules> | |
<module name="org.postgresql" slot="main"/> | |
</global-modules> | |
<!-- Reiniciar o Fluig. --> | |
<!-- | |
Exemplo de utilização no DataSet: | |
try { | |
var dataSource = "/jdbc/PostgreSqlDS"; | |
var ic = new javax.naming.InitialContext(); | |
var ds = ic.lookup(dataSource); | |
var conn = ds.getConnection(); | |
var stmt = conn.createStatement(); | |
var rs = stmt.executeQuery(myQuery); | |
var rsMeta = rs.getMetaData(); | |
var columnCount = rsMeta.getColumnCount(); | |
var i = 0; | |
// Preenchendo automaticamente o nome das colunas do dataset | |
for (i = 1; i <= columnCount; ++i) { | |
dataset.addColumn(rsMeta.getColumnName(i)); | |
} | |
while (rs.next()) { | |
var row = []; | |
for (i = 1; i <= columnCount; ++i) { | |
row.push(rs.getString(i)); | |
} | |
dataset.addRow(row); | |
} | |
} | |
} catch (e) { | |
log.error("ERRO==============> " + e.message); | |
} finally { | |
if (rs != null) { | |
rs.close(); | |
} | |
if (stmt != null) { | |
stmt.close(); | |
} | |
if (conn != null) { | |
conn.close(); | |
} | |
} | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment