DBInteger.java

  1. /*
  2.  * Copyright 2013 Gregory Graham.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package nz.co.gregs.dbvolution.datatypes;

  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.util.ArrayList;
  20. import java.util.Collection;
  21. import java.util.Comparator;
  22. import java.util.List;
  23. import nz.co.gregs.dbvolution.columns.IntegerColumn;
  24. import nz.co.gregs.dbvolution.databases.definitions.DBDefinition;
  25. import nz.co.gregs.dbvolution.exceptions.IncorrectRowProviderInstanceSuppliedException;
  26. import nz.co.gregs.dbvolution.expressions.IntegerExpression;
  27. import nz.co.gregs.dbvolution.expressions.NumberExpression;
  28. import nz.co.gregs.dbvolution.expressions.StringExpression;
  29. import nz.co.gregs.dbvolution.results.NumberResult;
  30. import nz.co.gregs.dbvolution.operators.DBPermittedRangeExclusiveOperator;
  31. import nz.co.gregs.dbvolution.operators.DBPermittedRangeInclusiveOperator;
  32. import nz.co.gregs.dbvolution.operators.DBPermittedRangeOperator;
  33. import nz.co.gregs.dbvolution.operators.DBPermittedValuesOperator;
  34. import nz.co.gregs.dbvolution.query.RowDefinition;
  35. import nz.co.gregs.dbvolution.results.IntegerResult;
  36. import nz.co.gregs.dbvolution.utility.StringCheck;
  37. import nz.co.gregs.dbvolution.utility.comparators.ComparableComparator;

  38. /**
  39.  * Encapsulates database values that are Integers.
  40.  *
  41.  * <p>
  42.  * Use DBinteger when the column is a {@code INT} or {@code NUMBER(x)}, that is
  43.  * any numeric datatype without a decimal or fractional part.
  44.  *
  45.  * <p>
  46.  * Use {@link DBNumber} when the numbers do not have a decimal or fractional
  47.  * part.
  48.  *
  49.  * <p>
  50.  * Generally DBInteger is declared inside your DBRow sub-class as:
  51.  * {@code @DBColumn public DBInteger myIntColumn = new DBInteger();}
  52.  *
  53.  * <p style="color: #F90;">Support DBvolution at
  54.  * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  55.  *
  56.  * @author Gregory Graham
  57.  */
  58. public class DBInteger extends QueryableDatatype<Long> implements IntegerResult {

  59.     private static final long serialVersionUID = 1L;

  60.     /**
  61.      * Create a DBInteger with the value set to the value provided..
  62.      *
  63.      * @param value value
  64.      */
  65.     public DBInteger(int value) {
  66.         this(Integer.valueOf(value));
  67.     }

  68.     /**
  69.      * Create a DBInteger with the value set to the value provided..
  70.      *
  71.      * @param value value
  72.      */
  73.     public DBInteger(Integer value) {
  74.         super(Long.valueOf(value));
  75.     }

  76.     /**
  77.      * Create a DBInteger with the value set to the value provided..
  78.      *
  79.      * @param value value
  80.      */
  81.     public DBInteger(long value) {
  82.         this(Long.valueOf(value));
  83.     }

  84.     /**
  85.      * Create a DBInteger with the value set to the value provided..
  86.      *
  87.      * @param value value
  88.      */
  89.     public DBInteger(Long value) {
  90.         super(value);
  91.     }

  92.     /**
  93.      * Create a DBInteger as a column expression.
  94.      *
  95.      * @param value value
  96.      */
  97.     public DBInteger(IntegerExpression value) {
  98.         super(value);
  99.     }

  100.     /**
  101.      * Create a DBInteger as a column expression.
  102.      *
  103.      * <p>
  104.      * Only the integer part of the number will be represented.
  105.      *
  106.      * @param value value
  107.      */
  108.     public DBInteger(NumberExpression value) {
  109.         super(value.integerPart());
  110.     }

  111.     /**
  112.      * The default constructor for DBInteger.
  113.      *
  114.      * <p>
  115.      * Creates an unset undefined DBInteger object.
  116.      *
  117.      */
  118.     public DBInteger() {
  119.         super();
  120.     }

  121.     @Override
  122.     public String getSQLDatatype() {
  123.         return "INTEGER";
  124.     }

  125.     /**
  126.      * Returns a Long of the database value or NULL if the database value is null
  127.      *
  128.      * <p style="color: #F90;">Support DBvolution at
  129.      * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  130.      *
  131.      * @return the long value or null
  132.      */
  133.     @Override
  134.     public Long getValue() {
  135.         return this.getLiteralValue();
  136.     }

  137.     /**
  138.      * Returns an Integer of the database value or NULL if the database value is
  139.      * null
  140.      *
  141.      * <p style="color: #F90;">Support DBvolution at
  142.      * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  143.      *
  144.      * @return the integer value or null
  145.      */
  146.     public Integer intValue() {
  147.         Long value = getValue();
  148.         return value == null ? null : value.intValue();
  149.     }

  150.     /**
  151.      * Returns a Long of the database value or NULL if the database value is null
  152.      *
  153.      * <p style="color: #F90;">Support DBvolution at
  154.      * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  155.      *
  156.      * @return the long value or null
  157.      */
  158.     public Long longValue() {
  159.         return getValue();
  160.     }

  161.     /**
  162.      *
  163.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  164.      *
  165.      * @param permitted permitted
  166.      */
  167.     public void permittedValues(Long... permitted) {
  168.         this.setOperator(new DBPermittedValuesOperator<Long>(permitted));
  169.     }

  170.     /**
  171.      *
  172.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  173.      *
  174.      * @param permitted permitted
  175.      */
  176.     public void permittedValues(IntegerResult... permitted) {
  177.         this.setOperator(new DBPermittedValuesOperator<IntegerResult>(permitted));
  178.     }

  179.     /**
  180.      *
  181.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  182.      *
  183.      * @param permitted permitted
  184.      */
  185.     public void permittedValues(NumberResult... permitted) {
  186.         List<IntegerResult> list = new ArrayList<>();
  187.         for (NumberResult num : permitted) {
  188.             list.add(new NumberExpression(num).integerResult());
  189.         }
  190.         this.setOperator(new DBPermittedValuesOperator<IntegerResult>(list.toArray(new IntegerResult[]{})));
  191.     }

  192.     /**
  193.      *
  194.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  195.      *
  196.      * @param permitted permitted
  197.      */
  198.     public void permittedValues(Number... permitted) {
  199.         List<Long> ints = new ArrayList<>();
  200.         for (Number dbint : permitted) {
  201.             ints.add(dbint.longValue());
  202.         }
  203.         final Long[] longArray = ints.toArray(new Long[]{});
  204.         this.setOperator(new DBPermittedValuesOperator<Long>(longArray));
  205.     }

  206.     /**
  207.      *
  208.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  209.      *
  210.      * @param permitted permitted
  211.      */
  212.     public void permittedValues(DBInteger... permitted) {
  213.         List<Long> ints = new ArrayList<>();
  214.         for (DBInteger dbint : permitted) {
  215.             ints.add(dbint.getValue());
  216.         }
  217.         final Long[] longArray = ints.toArray(new Long[]{});
  218.         this.setOperator(new DBPermittedValuesOperator<Long>(longArray));
  219.     }

  220.     /**
  221.      *
  222.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  223.      *
  224.      * @param permitted permitted
  225.      */
  226.     public void permittedValues(DBNumber... permitted) {
  227.         List<Long> ints = new ArrayList<>();
  228.         for (DBNumber dbint : permitted) {
  229.             ints.add(dbint.getValue().longValue());
  230.         }
  231.         final Long[] longArray = ints.toArray(new Long[]{});
  232.         this.setOperator(new DBPermittedValuesOperator<Long>(longArray));
  233.     }

  234.     /**
  235.      *
  236.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  237.      *
  238.      * @param permitted permitted
  239.      */
  240.     public void permittedValues(Collection<Long> permitted) {
  241.         this.setOperator(new DBPermittedValuesOperator<Long>(permitted));
  242.     }

  243.     /**
  244.      *
  245.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  246.      *
  247.      * @param permitted permitted
  248.      */
  249.     public void permittedValuesInteger(Collection<Integer> permitted) {
  250.         this.setOperator(new DBPermittedValuesOperator<Integer>(permitted));
  251.     }

  252.     /**
  253.      *
  254.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  255.      *
  256.      * @param permitted permitted
  257.      */
  258.     public void permittedValuesLong(Collection<Long> permitted) {
  259.         permittedValues(permitted);
  260.     }

  261.     /**
  262.      *
  263.      * reduces the rows to only the object, Set, List, Array, or vararg of objects
  264.      *
  265.      * @param permitted permitted
  266.      */
  267.     public void permittedValues(Integer... permitted) {
  268.         this.setOperator(new DBPermittedValuesOperator<Integer>(permitted));
  269.     }

  270.     /**
  271.      *
  272.      * excludes the object, Set, List, Array, or vararg of objects
  273.      *
  274.      *
  275.      * @param excluded  excluded
  276.      */
  277.     public void excludedValues(Long... excluded) {
  278.         this.setOperator(new DBPermittedValuesOperator<Long>(excluded));
  279.         negateOperator();
  280.     }

  281.     /**
  282.      *
  283.      * excludes the object, Set, List, Array, or vararg of objects
  284.      *
  285.      *
  286.      * @param excluded  excluded
  287.      */
  288.     public void excludedValues(DBInteger... excluded) {
  289.         this.setOperator(new DBPermittedValuesOperator<DBInteger>(excluded));
  290.         negateOperator();
  291.     }

  292.     /**
  293.      *
  294.      * excludes the object, Set, List, Array, or vararg of objects
  295.      *
  296.      *
  297.      * @param excluded  excluded
  298.      */
  299.     public void excludedValues(Integer... excluded) {
  300.         this.setOperator(new DBPermittedValuesOperator<Integer>(excluded));
  301.         negateOperator();
  302.     }

  303.     /**
  304.      *
  305.      * excludes the object, Set, List, Array, or vararg of objects
  306.      *
  307.      *
  308.      * @param excluded  excluded
  309.      */
  310.     public void excludedValuesLong(List<Long> excluded) {
  311.         this.setOperator(new DBPermittedValuesOperator<Long>(excluded));
  312.         negateOperator();
  313.     }

  314.     /**
  315.      *
  316.      * excludes the object, Set, List, Array, or vararg of objects
  317.      *
  318.      *
  319.      * @param excluded  excluded
  320.      */
  321.     public void excludedValuesInteger(List<Integer> excluded) {
  322.         this.setOperator(new DBPermittedValuesOperator<Integer>(excluded));
  323.         negateOperator();
  324.     }

  325.     /**
  326.      * Performs searches based on a range.
  327.      *
  328.      * if both ends of the range are specified the lower-bound will be included in
  329.      * the search and the upper-bound excluded. I.e permittedRange(1,3) will
  330.      * return 1 and 2.
  331.      *
  332.      * <p>
  333.      * if the upper-bound is null the range will be open ended and inclusive.
  334.      * <br>
  335.      * I.e permittedRange(1,null) will return 1,2,3,4,5, etc.
  336.      *
  337.      * <p>
  338.      * if the upper-bound is null the range will be open ended and exclusive.
  339.      * <br>
  340.      * I.e permittedRange(null, 5) will return 4,3,2,1, etc.
  341.      *
  342.      * @param lowerBound lowerBound
  343.      * @param upperBound upperBound
  344.      */
  345.     public void permittedRange(Long lowerBound, Long upperBound) {
  346.         setOperator(new DBPermittedRangeOperator<Long>(lowerBound, upperBound));
  347.     }

  348.     /**
  349.      * Performs searches based on a range.
  350.      *
  351.      * if both ends of the range are specified the lower-bound will be included in
  352.      * the search and the upper-bound excluded. I.e permittedRange(1,3) will
  353.      * return 1 and 2.
  354.      *
  355.      * <p>
  356.      * if the upper-bound is null the range will be open ended and inclusive.
  357.      * <br>
  358.      * I.e permittedRange(1,null) will return 1,2,3,4,5, etc.
  359.      *
  360.      * <p>
  361.      * if the upper-bound is null the range will be open ended and exclusive.
  362.      * <br>
  363.      * I.e permittedRange(null, 5) will return 4,3,2,1, etc.
  364.      *
  365.      * @param lowerBound lowerBound
  366.      * @param upperBound upperBound
  367.      */
  368.     public void permittedRange(Integer lowerBound, Integer upperBound) {
  369.         setOperator(new DBPermittedRangeOperator<Integer>(lowerBound, upperBound));
  370.     }

  371.     /**
  372.      * Performs searches based on a range.
  373.      *
  374.      * if both ends of the range are specified both the lower- and upper-bound
  375.      * will be included in the search. I.e permittedRangeInclusive(1,3) will
  376.      * return 1, 2, and 3.
  377.      *
  378.      * <p>
  379.      * if the upper-bound is null the range will be open ended and inclusive.
  380.      * <br>
  381.      * I.e permittedRangeInclusive(1,null) will return 1,2,3,4,5, etc.
  382.      *
  383.      * <p>
  384.      * if the upper-bound is null the range will be open ended and inclusive.
  385.      * <br>
  386.      * I.e permittedRangeInclusive(null, 5) will return 5,4,3,2,1, etc.
  387.      *
  388.      * @param lowerBound lowerBound
  389.      * @param upperBound upperBound
  390.      */
  391.     public void permittedRangeInclusive(Long lowerBound, Long upperBound) {
  392.         setOperator(new DBPermittedRangeInclusiveOperator(lowerBound, upperBound));
  393.     }

  394.     /**
  395.      * Performs searches based on a range.
  396.      *
  397.      * if both ends of the range are specified both the lower- and upper-bound
  398.      * will be included in the search. I.e permittedRangeInclusive(1,3) will
  399.      * return 1, 2, and 3.
  400.      *
  401.      * <p>
  402.      * if the upper-bound is null the range will be open ended and inclusive.
  403.      * <br>
  404.      * I.e permittedRangeInclusive(1,null) will return 1,2,3,4,5, etc.
  405.      *
  406.      * <p>
  407.      * if the upper-bound is null the range will be open ended and inclusive.
  408.      * <br>
  409.      * I.e permittedRangeInclusive(null, 5) will return 5,4,3,2,1, etc.
  410.      *
  411.      * @param lowerBound lowerBound
  412.      * @param upperBound upperBound
  413.      */
  414.     public void permittedRangeInclusive(Integer lowerBound, Integer upperBound) {
  415.         setOperator(new DBPermittedRangeInclusiveOperator(lowerBound, upperBound));
  416.     }

  417.     /**
  418.      * Performs searches based on a range.
  419.      *
  420.      * if both ends of the range are specified both the lower- and upper-bound
  421.      * will be excluded in the search. I.e permittedRangeExclusive(1,3) will
  422.      * return 2.
  423.      *
  424.      * <p>
  425.      * if the upper-bound is null the range will be open ended and exclusive.
  426.      * <br>
  427.      * I.e permittedRangeExclusive(1,null) will return 2,3,4,5, etc.
  428.      *
  429.      * <p>
  430.      * if the upper-bound is null the range will be open ended and exclusive.
  431.      * <br>
  432.      * I.e permittedRangeExclusive(null, 5) will return 4,3,2,1, etc.
  433.      *
  434.      * @param lowerBound lowerBound
  435.      * @param upperBound upperBound
  436.      */
  437.     public void permittedRangeExclusive(Long lowerBound, Long upperBound) {
  438.         setOperator(new DBPermittedRangeExclusiveOperator(lowerBound, upperBound));
  439.     }

  440.     /**
  441.      * Performs searches based on a range.
  442.      *
  443.      * if both ends of the range are specified both the lower- and upper-bound
  444.      * will be excluded in the search. I.e permittedRangeExclusive(1,3) will
  445.      * return 2.
  446.      *
  447.      * <p>
  448.      * if the upper-bound is null the range will be open ended and exclusive.
  449.      * <br>
  450.      * I.e permittedRangeExclusive(1,null) will return 2,3,4,5, etc.
  451.      *
  452.      * <p>
  453.      * if the upper-bound is null the range will be open ended and exclusive.
  454.      * <br>
  455.      * I.e permittedRangeExclusive(null, 5) will return 4,3,2,1, etc.
  456.      *
  457.      * @param lowerBound lowerBound
  458.      * @param upperBound upperBound
  459.      */
  460.     public void permittedRangeExclusive(Integer lowerBound, Integer upperBound) {
  461.         setOperator(new DBPermittedRangeExclusiveOperator(lowerBound, upperBound));
  462.     }

  463.     /**
  464.      * Performs searches based on a range.
  465.      *
  466.      * if both ends of the range are specified the lower-bound will be included in
  467.      * the search and the upper-bound excluded. I.e excludedRange(1,3) will return
  468.      * -1, 0, 3, 4...
  469.      *
  470.      * <p>
  471.      * if the upper-bound is null the range will be open ended and inclusive.
  472.      * <br>
  473.      * I.e excludedRange(1,null) will return 0, -1, -2, etc.
  474.      *
  475.      * <p>
  476.      * if the upper-bound is null the range will be open ended and exclusive.
  477.      * <br>
  478.      * I.e excludedRange(null, 5) will return 5, 6, 7, 8, etc.
  479.      *
  480.      * @param lowerBound lowerBound
  481.      * @param upperBound upperBound
  482.      */
  483.     public void excludedRange(Long lowerBound, Long upperBound) {
  484.         setOperator(new DBPermittedRangeOperator<Long>(lowerBound, upperBound));
  485.         negateOperator();
  486.     }

  487.     /**
  488.      * Performs searches based on a range.
  489.      *
  490.      * if both ends of the range are specified the lower-bound will be included in
  491.      * the search and the upper-bound excluded. I.e excludedRange(1,3) will return
  492.      * -1, 0, 3, 4...
  493.      *
  494.      * <p>
  495.      * if the upper-bound is null the range will be open ended and inclusive.
  496.      * <br>
  497.      * I.e excludedRange(1,null) will return 0, -1, -2, etc.
  498.      *
  499.      * <p>
  500.      * if the upper-bound is null the range will be open ended and exclusive.
  501.      * <br>
  502.      * I.e excludedRange(null, 5) will return 5, 6, 7, 8, etc.
  503.      *
  504.      * @param lowerBound lowerBound
  505.      * @param upperBound upperBound
  506.      */
  507.     public void excludedRange(Integer lowerBound, Integer upperBound) {
  508.         setOperator(new DBPermittedRangeOperator<Integer>(lowerBound, upperBound));
  509.         negateOperator();
  510.     }

  511.     /**
  512.      * Performs searches based on a range.
  513.      *
  514.      * if both ends of the range are specified both the lower- and upper-bound
  515.      * will be included in the search. I.e excludedRangeInclusive(1,3) will return
  516.      * ..., -1, 0, 4, 5, 6, etc.
  517.      *
  518.      * <p>
  519.      * if the upper-bound is null the range will be open ended and inclusive.
  520.      * <br>
  521.      * I.e excludedRangeInclusive(1,null) will return 0, -1, -2, etc.
  522.      *
  523.      * <p>
  524.      * if the upper-bound is null the range will be open ended and inclusive.
  525.      * <br>
  526.      * I.e excludedRangeInclusive(null, 5) will return 6, 7, 8, 9, etc.
  527.      *
  528.      * @param lowerBound lowerBound
  529.      * @param upperBound upperBound
  530.      */
  531.     public void excludedRangeInclusive(Long lowerBound, Long upperBound) {
  532.         setOperator(new DBPermittedRangeInclusiveOperator(lowerBound, upperBound));
  533.         negateOperator();
  534.     }

  535.     /**
  536.      * Performs searches based on a range.
  537.      *
  538.      * if both ends of the range are specified both the lower- and upper-bound
  539.      * will be included in the search. I.e excludedRangeInclusive(1,3) will return
  540.      * ..., -1, 0, 4, 5, 6, etc.
  541.      *
  542.      * <p>
  543.      * if the upper-bound is null the range will be open ended and inclusive.
  544.      * <br>
  545.      * I.e excludedRangeInclusive(1,null) will return 0, -1, -2, etc.
  546.      *
  547.      * <p>
  548.      * if the upper-bound is null the range will be open ended and inclusive.
  549.      * <br>
  550.      * I.e excludedRangeInclusive(null, 5) will return 6, 7, 8, 9, etc.
  551.      *
  552.      * @param lowerBound lowerBound
  553.      * @param upperBound upperBound
  554.      */
  555.     public void excludedRangeInclusive(Integer lowerBound, Integer upperBound) {
  556.         setOperator(new DBPermittedRangeInclusiveOperator(lowerBound, upperBound));
  557.         negateOperator();
  558.     }

  559.     /**
  560.      * Performs searches based on a range.
  561.      *
  562.      * if both ends of the range are specified both the lower- and upper-bound
  563.      * will be excluded in the search. I.e excludedRangeExclusive(1,3) will return
  564.      * ..., -2-1,0,1,3,4, etc but not 2.
  565.      *
  566.      * <p>
  567.      * if the upper-bound is null the range will be open ended and exclusive.
  568.      * <br>
  569.      * I.e excludedRangeExclusive(1,null) will return 1, 0, -1, etc.
  570.      *
  571.      * <p>
  572.      * if the upper-bound is null the range will be open ended and exclusive.
  573.      * <br>
  574.      * I.e excludedRangeExclusive(null, 5) will return 5, 6, 7, 8, etc.
  575.      *
  576.      * @param lowerBound lowerBound
  577.      * @param upperBound upperBound
  578.      */
  579.     public void excludedRangeExclusive(Long lowerBound, Long upperBound) {
  580.         setOperator(new DBPermittedRangeExclusiveOperator(lowerBound, upperBound));
  581.         negateOperator();
  582.     }

  583.     /**
  584.      * Performs searches based on a range.
  585.      *
  586.      * if both ends of the range are specified both the lower- and upper-bound
  587.      * will be excluded in the search. I.e excludedRangeExclusive(1,3) will return
  588.      * ..., -2-1,0,1,3,4, etc but not 2.
  589.      *
  590.      * <p>
  591.      * if the upper-bound is null the range will be open ended and exclusive.
  592.      * <br>
  593.      * I.e excludedRangeExclusive(1,null) will return 1, 0, -1, etc.
  594.      *
  595.      * <p>
  596.      * if the upper-bound is null the range will be open ended and exclusive.
  597.      * <br>
  598.      * I.e excludedRangeExclusive(null, 5) will return 5, 6, 7, 8, etc.
  599.      *
  600.      * @param lowerBound lowerBound
  601.      * @param upperBound upperBound
  602.      */
  603.     public void excludedRangeExclusive(Integer lowerBound, Integer upperBound) {
  604.         setOperator(new DBPermittedRangeExclusiveOperator(lowerBound, upperBound));
  605.         negateOperator();
  606.     }

  607.     /**
  608.      * Sets the value of this DBInteger to the value provided.
  609.      *
  610.      * @param newLiteralValue   newLiteralValue
  611.      */
  612.     public void setValue(DBNumber newLiteralValue) {
  613.         setValue(newLiteralValue.getValue());
  614.     }

  615.     /**
  616.      * Sets the value of this DBInteger to the value provided.
  617.      *
  618.      * <p>
  619.      * Convenience method that uses {@link  Long#Long(java.lang.String)} to set the
  620.      * value
  621.      *
  622.      * @param newLiteralValue   newLiteralValue
  623.      */
  624.     public void setValue(String newLiteralValue) {
  625.         setValue(Long.valueOf(StringCheck.checkNotNullOrEmpty(newLiteralValue,null,null)));
  626.     }

  627.     /**
  628.      * Sets the value of this DBInteger to the value provided.
  629.      *
  630.      * @param newLiteralValue   newLiteralValue
  631.      */
  632.     public void setValue(DBInteger newLiteralValue) {
  633.         setValue(newLiteralValue.getValue());
  634.     }

  635.     /**
  636.      * Sets the value of this DBInteger to the value provided.
  637.      *
  638.      * @param newLiteralValue   newLiteralValue
  639.      */
  640.     public void setValue(Number newLiteralValue) {
  641.         if (newLiteralValue == null) {
  642.             super.setLiteralValue(null);
  643.         } else {
  644.             super.setLiteralValue(newLiteralValue.longValue());
  645.         }
  646.     }

  647.     /**
  648.      * Sets the value of this DBInteger to the value provided.
  649.      *
  650.      * @param newLiteralValue   newLiteralValue
  651.      */
  652.     @Override
  653.     public void setValue(Long newLiteralValue) {
  654.         if (newLiteralValue == null) {
  655.             super.setLiteralValue(null);
  656.         } else {
  657.             super.setLiteralValue(newLiteralValue);
  658.         }
  659.     }

  660.     /**
  661.      * Sets the value of this DBInteger to the value provided.
  662.      *
  663.      * @param newLiteralValue   newLiteralValue
  664.      */
  665.     public void setValue(Integer newLiteralValue) {
  666.         if (newLiteralValue == null) {
  667.             super.setLiteralValue(null);
  668.         } else {
  669.             super.setLiteralValue(newLiteralValue.longValue());
  670.         }
  671.     }

  672.     /**
  673.      *
  674.      * @param defn
  675.      * <p style="color: #F90;">Support DBvolution at
  676.      * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  677.      * @return the underlying number formatted for a SQL statement
  678.      */
  679.     @Override
  680.     public String formatValueForSQLStatement(DBDefinition defn) {
  681.         if (isNull()) {
  682.             return defn.getNull();
  683.         }
  684.         return defn.beginNumberValue() + getLiteralValue() + defn.endNumberValue();
  685.     }

  686.     @Override
  687.     public boolean isAggregator() {
  688.         return false;
  689.     }

  690.     @Override
  691.     protected Long getFromResultSet(DBDefinition database, ResultSet resultSet, String fullColumnName) throws SQLException {
  692.         return resultSet.getLong(fullColumnName);
  693.     }

  694.     @Override
  695.     public DBInteger copy() {
  696.         return (DBInteger) super.copy();
  697.     }

  698.     @Override
  699.     public boolean getIncludesNull() {
  700.         return false;
  701.     }

  702.     @Override
  703.     public StringExpression stringResult() {
  704.         return IntegerExpression.value(this).stringResult();
  705.     }

  706.     @Override
  707.     protected void setValueFromStandardStringEncoding(String encodedValue) {
  708.         if (encodedValue.isEmpty()) {
  709.             super.setLiteralValue(null);
  710.         } else {
  711.             try {
  712.                 Double parseDouble = Double.valueOf(StringCheck.checkNotNullOrEmpty(encodedValue,null,null));
  713.                 Long literalLong = parseDouble.longValue();
  714.                 setLiteralValue(literalLong);
  715.             } catch (NumberFormatException noFormat) {
  716.                 setLiteralValue(null);
  717.             }
  718.         }
  719.     }

  720.     @Override
  721.     public IntegerColumn getColumn(RowDefinition row) throws IncorrectRowProviderInstanceSuppliedException {
  722.         return new IntegerColumn(row, this);
  723.     }

  724.     public void excludeNotNull() {
  725.         this.permittedValues((Long) null);
  726.     }

  727.     public void excludeNull() {
  728.         this.excludedValues((Long) null);
  729.     }

  730.     public void permitOnlyNull() {
  731.         excludeNotNull();
  732.     }

  733.     public void permitOnlyNotNull() {
  734.         excludeNull();
  735.     }

  736.     /**
  737.      * Set the value to be inserted when no value has been set, using
  738.      * {@link #setValue(java.lang.Object) setValue(...)}, for the QDT.
  739.      *
  740.      * <p>
  741.      * The value is only used during the initial insert and does not effect the
  742.      * definition of the column within the database.</p>
  743.      *
  744.      * <p>
  745.      * Care should be taken when using this as some "obvious" uses are better
  746.      * handled using the
  747.      * {@link #setDefaultInsertValue(nz.co.gregs.dbvolution.results.AnyResult) expression version}.
  748.      * In particular, setDefaultInsertValue(new Date()) is probably NOT what you
  749.      * want, setDefaultInsertValue(DateExpression.currentDate()) will produce a
  750.      * correct creation date value.</p>
  751.      *
  752.      * @param value the value to use during insertion when no particular value has
  753.      * been specified.
  754.      * @return This QDT
  755.      */
  756.     @Override
  757.     public synchronized DBInteger setDefaultInsertValue(Long value) {
  758.         super.setDefaultInsertValue(value);
  759.         return this;
  760.     }

  761.     /**
  762.      * Set the value to be inserted when no value has been set, using
  763.      * {@link #setValue(java.lang.Object) setValue(...)}, for the QDT.
  764.      *
  765.      * <p>
  766.      * The value is only used during the initial insert and does not effect the
  767.      * definition of the column within the database.</p>
  768.      *
  769.      * @param value the value to use during insertion when no particular value has
  770.      * been specified.
  771.      * @return This QDT
  772.      */
  773.     public synchronized DBInteger setDefaultInsertValue(IntegerResult value) {
  774.         super.setDefaultInsertValue(value);
  775.         return this;
  776.     }

  777.     /**
  778.      * Set the value to be used during an update when no value has been set, using
  779.      * {@link #setValue(java.lang.Object) setValue(...)}, for the QDT.
  780.      *
  781.      * <p>
  782.      * The value is only used during updates and does not effect the definition of
  783.      * the column within the database nor the initial value of the column.</p>
  784.      *
  785.      * <p>
  786.      * Care should be taken when using this as some "obvious" uses are better
  787.      * handled using the
  788.      * {@link #setDefaultUpdateValue(nz.co.gregs.dbvolution.results.AnyResult) expression version}.
  789.      * In particular, setDefaultUpdateValue(new Date()) is probably NOT what you
  790.      * want, setDefaultUpdateValue(DateExpression.currentDate()) will produce a
  791.      * correct update time value.</p>
  792.      *
  793.      * @param value the value to use during update when no particular value has
  794.      * been specified.
  795.      * @return This QDT
  796.      */
  797.     @Override
  798.     public synchronized DBInteger setDefaultUpdateValue(Long value) {
  799.         super.setDefaultUpdateValue(value);
  800.         return this;
  801.     }

  802.     /**
  803.      * Set the value to be used during an update when no value has been set, using
  804.      * {@link #setValue(java.lang.Object) setValue(...)}, for the QDT.
  805.      *
  806.      * <p>
  807.      * The value is only used during updates and does not effect the definition of
  808.      * the column within the database nor the initial value of the column.</p>
  809.      *
  810.      * @param value the value to use during update when no particular value has
  811.      * been specified.
  812.      * @return This QDT
  813.      */
  814.     public synchronized DBInteger setDefaultUpdateValue(IntegerResult value) {
  815.         super.setDefaultUpdateValue(value);
  816.         return this;
  817.     }

  818.     @Override
  819.     public Comparator<Long> getComparator() {
  820.         return ComparableComparator.forClass(Long.class);
  821.     }
  822. }