mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-19 21:00:53 +08:00
Merge pull request #791 from querydsl/i704
Use total/decimal digits instead of size/digits
This commit is contained in:
commit
f09ea9268f
@ -276,8 +276,8 @@
|
||||
<colspec colname='Descriptions' colwidth="1*" />
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Size</entry>
|
||||
<entry>Digits</entry>
|
||||
<entry>Total digits</entry>
|
||||
<entry>Decimal digits</entry>
|
||||
<entry>Type</entry>
|
||||
</row>
|
||||
</thead>
|
||||
@ -321,18 +321,18 @@
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
<para>They can be customized for specific size/digits combinations like this:</para>
|
||||
<para>They can be customized for specific total/decimal digits combinations like this:</para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<numericMappings>
|
||||
<numericMapping>
|
||||
<size>1</size>
|
||||
<digits>0</digits>
|
||||
<total>1</total>
|
||||
<decimal>0</decimal>
|
||||
<javaType>java.lang.Byte</javaType>
|
||||
</numericMapping>
|
||||
</numericMappings>
|
||||
]]></programlisting>
|
||||
|
||||
]]></programlisting>
|
||||
|
||||
<para>Imports can be used to add cross-schema foreign keys support.</para>
|
||||
|
||||
<para>Compared to APT based code generation certain functionality is not available such as QueryDelegate annotation handling.</para>
|
||||
|
||||
@ -388,7 +388,9 @@ public class AbstractMetaDataExportMojo extends AbstractMojo{
|
||||
}
|
||||
if (numericMappings != null) {
|
||||
for (NumericMapping mapping : numericMappings) {
|
||||
configuration.registerNumeric(mapping.size, mapping.digits, Class.forName(mapping.javaType));
|
||||
int total = Math.max(mapping.size, mapping.total);
|
||||
int decimal = Math.max(mapping.digits, mapping.decimal);
|
||||
configuration.registerNumeric(total, decimal, Class.forName(mapping.javaType));
|
||||
}
|
||||
}
|
||||
if (columnComparatorClass != null) {
|
||||
|
||||
@ -19,9 +19,10 @@ package com.mysema.query.maven;
|
||||
*/
|
||||
public class NumericMapping {
|
||||
|
||||
public int size;
|
||||
@Deprecated
|
||||
public int size, digits;
|
||||
|
||||
public int digits;
|
||||
public int total, decimal;
|
||||
|
||||
public String javaType;
|
||||
|
||||
|
||||
@ -319,12 +319,12 @@ public final class Configuration {
|
||||
/**
|
||||
* Override the binding for the given NUMERIC type
|
||||
*
|
||||
* @param size
|
||||
* @param digits
|
||||
* @param total total amount of digits
|
||||
* @param decimal amount of fractional digits
|
||||
* @param javaType
|
||||
*/
|
||||
public void registerNumeric(int size, int digits, Class<?> javaType) {
|
||||
jdbcTypeMapping.registerNumeric(size, digits, javaType);
|
||||
public void registerNumeric(int total, int decimal, Class<?> javaType) {
|
||||
jdbcTypeMapping.registerNumeric(total, decimal, javaType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Blob;
|
||||
@ -20,8 +21,6 @@ import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
import com.mysema.query.sql.types.Null;
|
||||
|
||||
@ -108,30 +107,30 @@ public final class JDBCTypeMapping {
|
||||
sqlTypes.put(javaType, sqlType);
|
||||
}
|
||||
|
||||
public void registerNumeric(int size, int digits, Class<?> javaType) {
|
||||
numericTypes.put(Pair.of(size, digits), javaType);
|
||||
public void registerNumeric(int total, int decimal, Class<?> javaType) {
|
||||
numericTypes.put(Pair.of(total, decimal), javaType);
|
||||
}
|
||||
|
||||
private Class<?> getNumericClass(int size, int digits) {
|
||||
Pair<Integer,Integer> key = Pair.of(size, digits);
|
||||
private Class<?> getNumericClass(int total, int decimal) {
|
||||
Pair<Integer,Integer> key = Pair.of(total, decimal);
|
||||
if (numericTypes.containsKey(key)) {
|
||||
return numericTypes.get(key);
|
||||
} else if (digits <= 0) {
|
||||
if (size > 18 || size == 0) {
|
||||
} else if (decimal <= 0) {
|
||||
if (total > 18 || total == 0) {
|
||||
return BigInteger.class;
|
||||
} else if (size > 9 || size == 0) {
|
||||
} else if (total > 9 || total == 0) {
|
||||
return Long.class;
|
||||
} else if (size > 4) {
|
||||
} else if (total > 4) {
|
||||
return Integer.class;
|
||||
} else if (size > 2) {
|
||||
} else if (total > 2) {
|
||||
return Short.class;
|
||||
} else if (size > 0) {
|
||||
} else if (total > 0) {
|
||||
return Byte.class;
|
||||
} else {
|
||||
return Boolean.class;
|
||||
}
|
||||
} else {
|
||||
if (size > 16) {
|
||||
if (total > 16) {
|
||||
return BigDecimal.class;
|
||||
} else {
|
||||
return Double.class;
|
||||
@ -140,9 +139,9 @@ public final class JDBCTypeMapping {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> get(int sqlType, int size, int digits) {
|
||||
public Class<?> get(int sqlType, int total, int decimal) {
|
||||
if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL) {
|
||||
return getNumericClass(size, digits);
|
||||
return getNumericClass(total, decimal);
|
||||
} else if (types.containsKey(sqlType)) {
|
||||
return types.get(sqlType);
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user