1 // Copyright 2011 Leo Przybylski. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without modification, are
4 // permitted provided that the following conditions are met:
5 //
6 // 1. Redistributions of source code must retain the above copyright notice, this list of
7 // conditions and the following disclaimer.
8 //
9 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
10 // of conditions and the following disclaimer in the documentation and/or other materials
11 // provided with the distribution.
12 //
13 // THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
14 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 //
23 // The views and conclusions contained in the software and documentation are those of the
24 // authors and should not be interpreted as representing official policies, either expressed
25 // or implied, of Leo Przybylski.
26 package liquibase.database.typeconversion.ext;
27
28 import liquibase.database.structure.Column;
29 import liquibase.database.structure.type.*;
30 import liquibase.database.Database;
31 import liquibase.database.core.H2Database;
32 import liquibase.database.core.HsqlDatabase;
33 import liquibase.exception.UnexpectedLiquibaseException;
34 import liquibase.util.StringUtils;
35
36 import java.lang.reflect.Field;
37 import java.sql.Types;
38 import java.text.ParseException;
39 import java.util.Arrays;
40 import java.util.List;
41
42 import static liquibase.ext.Constants.EXTENSION_PRIORITY;
43
44
45 /**
46 * Converts to and from generic SQL Types (types located in {@link Types}). Conversion happens at
47 * update and generate phases. All databases are supported because the idea is a generic type
48 * that is a median type and can be used to convert between other types. For example, when exporting
49 * from an Oracle database, can be converted to a MySQL database quickly.
50 *
51 * @author Leo Przybylski
52 * @Deprecated
53 */
54 public class GenericTypeConverter extends liquibase.database.typeconversion.core.AbstractTypeConverter {
55
56 public int getPriority() {
57 return -1 * EXTENSION_PRIORITY;
58 }
59
60 protected static final List<Integer> oneParam = Arrays.asList(
61 Types.CHAR,
62 -15, // Types.NCHAR in java 1.6,
63 Types.VARCHAR,
64 -9, //Types.NVARCHAR in java 1.6,
65 Types.VARBINARY,
66 Types.DOUBLE,
67 Types.FLOAT
68 );
69
70 protected static final List<Integer> twoParams = Arrays.asList(
71 Types.DECIMAL,
72 Types.NUMERIC,
73 Types.REAL
74 );
75
76
77 @Override
78 public NumberType getNumberType() {
79 return new NumberType("NUMERIC");
80 }
81
82
83 /**
84 * Supports all databases, so this always returns true
85 *
86 * @param database (doesn't matter)
87 * @return true always
88 */
89 @Override
90 public boolean supports(final Database database) {
91 return !(database instanceof liquibase.database.core.MySQLDatabase);
92 }
93
94
95 @Override
96 public BooleanType getBooleanType() {
97 return new BooleanType.NumericBooleanType(getNumberType().getDataTypeName());
98 }
99 }