/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.storage.jdbc;

import static io.spine.server.storage.jdbc.Type.BOOLEAN;
import static io.spine.server.storage.jdbc.Type.BYTE_ARRAY;
import static io.spine.server.storage.jdbc.Type.INT;
import static io.spine.server.storage.jdbc.Type.LONG;
import static io.spine.server.storage.jdbc.Type.STRING;
import static io.spine.server.storage.jdbc.Type.STRING_255;

/**
 * Default {@link TypeMapping type mappings} for different databases.
 *
 * @author Dmytro Grankin
 */
@SuppressWarnings("DuplicateStringLiteralInspection") // Use literals for a better readability.
public class TypeMappings {

    private static final TypeMapping MY_SQL = TypeMapping.newBuilder()
                                                         .add(BYTE_ARRAY, "BLOB")
                                                         .add(INT, "INT")
                                                         .add(LONG, "BIGINT")
                                                         .add(STRING_255, "VARCHAR(255)")
                                                         .add(STRING, "TEXT")
                                                         .add(BOOLEAN, "BOOLEAN")
                                                         .build();

    private static final TypeMapping POSTGRES = TypeMapping.newBuilder()
                                                           .add(BYTE_ARRAY, "BYTEA")
                                                           .add(INT, "INT")
                                                           .add(LONG, "BIGINT")
                                                           .add(STRING_255, "VARCHAR(255)")
                                                           .add(STRING, "TEXT")
                                                           .add(BOOLEAN, "BOOLEAN")
                                                           .build();

    private TypeMappings() {
        // Prevent instantiation of this utility class.
    }

    /**
     * Obtains the default type mapping for MySQL database.
     */
    public static TypeMapping mySql() {
        return MY_SQL;
    }

    /**
     * Obtains the default type mapping for PostreSQL database.
     */
    public static TypeMapping postgreSql() {
        return POSTGRES;
    }
}

@@ -1049,16 +1049,74 @@
 .jdbc;%0A%0A
+import io.spine.server.storage.jdbc.TypeMapping.Builder;%0A%0A
 import s
@@ -1559,104 +1559,8 @@
  */%0A
-@SuppressWarnings(%22DuplicateStringLiteralInspection%22) // Use literals for a better readability.%0A
 publ
@@ -1630,27 +1630,27 @@
 Y_SQL = 
-Typ
+bas
 eMapping
 .newBuil
@@ -1645,79 +1645,10 @@
 ping
-.newBuilder()%0A                                                         
+()
 .add
@@ -1729,591 +1729,690 @@
     
+ 
-.add(INT, %22INT%22)%0A                                                         .add(LONG, %22BIGINT%22)%0A                                                         .add(STRING_255, %22VARCHAR(255)%22)%0A                                                         .add(STRING, %22TEXT%22)%0A                         
+ .build();%0A    private static final TypeMapping POSTGRES = baseMapping().add(BYTE_ARRAY, %22BYTEA%22)%0A                                                             .build();%0A%0A    private TypeMappings() %7B%0A        // Prevent instantiation of this utility class.%0A
     
+%7D%0A%0A
     
+/**%0A
      
-        
+* Obtains the default type mapping for MySQL database.%0A
      
+*/%0A
     
-  .add(BOOLEAN, %22BOOLEAN%22)%0A         
+public static TypeMapping mySql() %7B%0A        return MY_SQL;%0A
     
+%7D%0A%0A
     
+/**%0A
      
-        
+* Obtains the default type mapping for PostreSQL database.%0A
      
+*/%0A
     
-                  .build();%0A%0A    private static final TypeMapping POSTGRES = TypeMapping.newBuilder()%0A                                                           .add(BYTE_ARRAY, %22BYTEA%22)%0A            
+public static TypeMapping postgreSql() %7B%0A        return POSTGRES;%0A    %7D%0A%0A    private static TypeMapping.Builder baseMapping() %7B%0A        final Builder baseMapping = TypeMapping.newBuilder()%0A
     
@@ -2514,36 +2514,24 @@
             
-     
-       
 .add(LONG, %22
@@ -2535,36 +2535,24 @@
 , %22BIGINT%22)%0A
-            
             
@@ -2662,36 +2662,24 @@
             
-            
 .add(STRING,
@@ -2683,36 +2683,24 @@
 NG, %22TEXT%22)%0A
-            
             
@@ -2762,465 +2762,36 @@
 AN%22)
-%0A                                                           .build()
 ;%0A
-%0A
     
-private TypeMappings() %7B%0A        // Prevent instantiation of this utility class.%0A    %7D%0A%0A    /**%0A     * Obtains the default type mapping for MySQL database.%0A     */%0A    public static TypeMapping mySql() %7B%0A        return MY_SQL;%0A    %7D%0A%0A    /**%0A     * Obtains the default type mapping for PostreSQL database.%0A     */%0A    public static TypeMapping postgreSql() %7B%0A        return POSTGRES
+    return baseMapping
 ;%0A  

Add base mapping in `TypeMappings` to avoid literal duplications