Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

...

Pasos

Descripción 

1. DataBase Creation

Crear únicamente la base de datos sobre el SGBD elegido; el conjunto del esquema (tablas, claves primarias, triggers…) se creará posteriormente de manera automática en un primer despliegue, en el momento que la aplicación reconoce que no existe. El proceso va a variar ligeramente:

Para Oracle: En este caso el acceso y creación del esquema es por usuario. Así que será suficiente con crear un usuario para este fin con los suficientes privilegios. Este usuario será el que se indique en el fichero de configuración server.xml del Tomcat. Por ejemplo, en el caso de que el usuario fuese

Create only the database on the chosen DBMS; The schema set (tables, primary keys, triggers ...) will be created automatically later on a first deployment, at a time when the application recognizes that it does not exist. The process will vary slightly:

  • For Oracle: In this case the access and creation of the schema is per user. So it will be sufficient to create a user for this purpose with sufficient privileges. This user will be indicated in the Tomcat server.xml configuration file. For example, in case the user is DashboardSII:

 

CREATE USER DASHBOARDSII IDENTIFIED BY DASHBOARDSII;

 

  • For SqlServer: A schema with the database name defined in the connection will be created. For example, in the event that the database is called sii:

 

CREATE DATABASE sii […];

 

  • For MySql: Just as in the case of Sql Server will create a scheme with the name DashboardSII:

 

CREATE SCHEMA DashboardSII;

2. Configuration of the SIIDashboard.properties property file

It copies the properties file used by the dashboard in the desired path.

A good choice would be the server's configuration folder; In the case of Apache Tomcat, the '/ conf' folder. Although it could be anywhere else. The path where it is saved will be used later to give value to an environment variable that the application will use to retrieve the identifier of the tenant.

Therefore, this property file will basically have a single property.

 

sii.tenant=001


3. Configuring the connection to the database within the Web container

A couple of items must be configured at the server level. Although the specific way to do this configuration will depend on the chosen server, we will use as a reference example the Apache Tomcat server, because it is the server on which the solution has been developed and tested.


  • Oracle 

JNDI resource name: jdbc / SIIOracle

For Apache Tomcat, in the file 'server.xml', within the <GlobalNamingResources> block, a new <Resource> tag is added with the connection data to the database. 

 

<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver"

factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactor y" maxActive="200" maxIdle="200" maxWait="-1"

name="jdbc/SIIOracle" password="*****" testOnBorrow="true" type="javax.sql.DataSource"

url="jdbc:oracle:thin:@//***.**.*.**:****/****" username="*******" validationQuery="select 1 from dual" validationQueryTimeout="5"/>

 

For Apache Tomcat, in the 'context.xml' file we create a new <ResourceLink> entry inside the <Context> block to reference the connection to the database previously declared in the file 'server.xml'.


<ResourceLink global="jdbc/SIIOracle" name="jdbc/SIIOracle" type="javax.sql.DataSource"/>

 

If we set the value for the attributes "global" and "name" match the name given to the resource we created earlier.

Copy in the '/ lib' directory, if it does not exist, the Java connection library to Oracle: ojdbc7.jar

  • Sql Server 

JNDI resource name: jdbc / SIISqlserver

For Apache Tomcat, in the file 'server.xml', within the <GlobalNamingResources> block, a new <Resource> tag with the connection data to the database is added.

<Resource auth="Container" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDrive r" maxActive="200" maxIdle="200" maxOpenPreparedStatements="100" maxWait="-1" name="jdbc/SIISqlserver" password="u2r_da2hb0ard" poolPreparedStatements="true" type="javax.sql.DataSource" url="jdbc:sqlserver://***.**.**.**:****;databaseName=**;user

=*******;password=*******;" username="*******" validationQuery="select 1"/> 

  

For Apache Tomcat, in the 'context.xml' file we create a new <ResourceLink> entry inside the <Context> block to reference the connection to the database previously declared in the file 'server.xml'.

<ResourceLink global="jdbc/SIISqlserver" name="jdbc/SIISqlserver" type="javax.sql.DataSource"/> 

If we set the value for the attributes "global" and "name" match the name given to the resource we created earlier.

In the '/ lib' directory, copy the Java library to SqlServer: sqljdbc4-6.0.jar

  • MySql

JNDI resource name: jdbc / SIIMySQL

For Apache Tomcat, in the file 'server.xml', within the <GlobalNamingResources> block, a new <Resource> tag with the connection data to the database is added.

 

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="200" maxIdle="200" maxWait="-1" name="jdbc/SIIMySQL" password="*******" poolPreparedStatements="true" type="javax.sql.DataSource"

url="jdbc:mysql://***.***.**.**:***/DashboardSII" username="root"/>

 

For Apache Tomcat, in the 'context.xml' file we create a new <ResourceLink> entry inside the <Context> block to reference the connection to the database previously declared in the file 'server.xml'.

<ResourceLink global="jdbc/SIIMySQL" name="jdbc/SIIMySQL" type="javax.sql.DataSource"/> 

If we set the value for the attributes "global" and "name" match the name given to the resource we created earlier.

Copy to the '/ lib' folder, if it does not exist, the Java library connecting to SqlServer: mysql-connector-java-5.1.42.jar

4. Declaration of the path to the properties file

We create an environment variable with the path where the 'SII-Dashboard.properties' property file we have copied previously.

For Apache Tomcat, the context.xml file defines a new <Environment> entry within the <Context>

 

<Environment name="sii-dashboard-props-file-location" override="true" type="java.lang.String" value="D:/apachetomcat-8.0.36/conf/SII-Dashboard.properties"/>

 

The full path where the property file is specified as value of the attribute "value"

5. BD's profile statement

In the configuration file 'context.xml' of Apache Tomcat, a new variable is defined to indicate the profile used according to the database.

 

  • For Oracle:

<Environment name="spring.profiles.active" value="oracle" type="java.lang.String"/>

 

  • For SqlServer:
<Environment name="spring.profiles.active" value="sqlserver" type="java.lang.String"/>


  • For MySql:
<Environment name="spring.profiles.active" value="mysql" type="java.lang.String"/> 


 6. Set Java configurations at startup of the application server

  • Windows:
set JAVA_OPTS=-“Dfile.encoding=UTF-8 –Xms256m Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=1024m”
  • Unix:
set JAVA_OPTS=-Dfile.encoding=UTF-8 –Xms256m Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=1024m 


...