Ir al contenido principal

Spring Boot - Migration / Data Source

Implement H2


In this case first will be use H2
  • Add H2 to pom.xml, in the dependencies section.
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

        <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

  • Modify application.properties file adding the following properties:

The files is in scr/main/resources
  • spring.h2.console.enabled=true
  • spring.h2.console.path=/h2

The value in path property is the URL to see H2 database console.
Ex. http://localhost:8080/h2/

Migration

Use Flyway

Add in pom.xaml the dependency

<dependency>
                 <groupId>org.flywaydb</groupId>
                 <artifactId>flyway-core</artifactId>

</dependency>
  • Create the folder in scr/resources
    • db -> 
      • migration

  • Add to the application.properties
    • flyway.baseline-description=true
  • spring.jpa.hibernate.ddl-auto=false;

  • Create file
    • V2_create_db.sql
Always start the file as V2__

Ex.

CREATE TABLE SHIPWRECK(
   ID INT AUTO_INCREMENT,
   NAME VARCHAR(255),
   DESCRIPTION VARCHAR(2000),
   CONDITION VARCHAR(255),
   DEPTH INT,
   LATITUDE DOUBLE,
   LONGITUDE DOUBLE,
   YEAR_DISCOVERED INT

);

Datasource Configuration


Add in application properties:


spring.datasource.url=jdbc:h2:file:~/dasboot
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

In this case the url is specifying that the db will be stored in a file


Other configurations:

spring.datasource.max-active=10
spring.datasource.max-idle=8
spring.datasource.max-wait=10000
spring.datasource.min-evictable-idle-time-millis=1000
spring.datasource.min-idle=8

spring.datasource.time-between-eviction-runs-millis=1


Datasource for Spring

  • Create a folder for the configuration in
    • scr/main/java
      • <project>
        • config

  • Create a class as <Name>Configuration
  • Add above the class the annotation
    • @Configuration
  • Create a DataSource Bean 
    • @Bean
      @ConfigurationProperties(prefix="spring.datasource")
      @Primary
      public DataSource dataSource(){
      return DataSourceBuilder.create().build();
      }
  • Second Datasource
    • @Bean
      @ConfigurationProperties(prefix="datasource.flyway")
      @Primary
      public DataSource flyWayDataSource(){
      return DataSourceBuilder.create().build();
      }

  • The @Primary annotation is to avoid problems when many datasources are configured
  • The prefix is how is defined in the application.properties






Comentarios

Entradas populares de este blog

Android - Basic Steps (Service)

Service Run in the main thread of the hosting application Android can kill the Service if need the resources Purpose Supporting inter-application method execution Performing background processing Start a Service Call Context.startService(Intent intent)\ To call from a Fragment use getActivity().getApplicationContext().startService( intentService); Executing the service After call startService(...)  In the Service is executed the method onStartCommand(...) If the method returns the constant START_NOT_STICKY then Android will not restart the service automatically if the the process is killedp Foreground To execute the service foreground call the method startForeground() Use this if the user is aware of the process Bind to a Service Call the method Context.bindService( Intent service ServiceConnection con int flags ) Send Toast from the Service On the method onStartCommand receive the message   ...

BI - SSIS ( Basics I )

SSIS - Basic Concepts Tasks Bulk Insert Task—Loads data into a table by using the BULK INSERT SQL command. Data Flow Task—This is the most important task that loads and transforms data into an OLE DB Destination. Execute Package Task—Enables you to execute a package from within a package, making your SSIS packages modular. Execute Process Task—Executes a program external to your package, like one to split your extract file into many files before processing the individual files. Execute SQL Task—Executes a SQL statement or stored procedure. File System Task—This task can handle directory operations like creating, renaming, or deleting a directory. It can also manage file operations like moving, copying, or deleting files. FTP Task—Sends or receives files from an FTP site. Script Task—Runs a set of VB.NET or C# coding inside a Visual Studio environment. Send Mail Task—Sends a mail message through SMTP. Analysis Services Processing Task—This task processes a SQL Server A...

TOGAF9

Kinds of Architectures Business Architecture / Business Process Architecture    Define the business strategy, governance, organization and key business processes Data Architecture    Describe the structure of an organization logical and physical data assets and data resources Application Architecture    Describe a blueprint for the individual application systems to be deploy, interactions and  their relationships to the core business processes of the organization Technology Architecture    Describe the logical software and hardware capabilities that are required to support the deployment of business data and application services. This includes middle-ware infrastructure, networks, communications, processing standards  Architecture Governance Increase transparency of accountability, and informed delegation of authority Controlled risk management Protection of the existing asset base through maximizing  re-us...