Class SQLiteDataOperator<T extends BaseDataEntity<String>>
- Type Parameters:
T- the entity type
- All Implemented Interfaces:
DataOperator<T>,RowCountingDelete
Extends the abstract relational operator, providing SQLite-specific table creation without engine specification.
- Since:
- 6.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.interfaces.DataOperator
DataOperator.LikeType -
Field Summary
Fields inherited from class com.ultikits.ultitools.interfaces.impl.data.AbstractRelationalDataOperator
dataSource, queryRunner, tableName, transactionManager, type -
Constructor Summary
ConstructorsConstructorDescriptionSQLiteDataOperator(DataSource dataSource, Class<T> type) Creates a new SQLite data operator. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateTableSqlFromClazz(Class<T> type) Creates the SQL statement to create the table.private static booleanprivate static booleanisFiniteNumber(Object value) Whethervalueis a number whosedoublevalue is finite (not infinite, not NaN).private static booleanprivate static booleanisIntegral(Class<?> type) protected StringorderedComparisonOperand(String column, Class<?> fieldType) ComparesGREATERandLESSas numbers of the field's Java type: abyte,short,intorlongfield (or its wrapper) as a 64-bit integer throughCAST(column AS BIGINT), adoublefield (or its wrapper) as a 64-bit floating-point number throughCAST(column AS DOUBLE), and afloatfield (or its wrapper) throughCAST(CAST(CAST(column AS REAL) AS VARCHAR) AS DOUBLE), whichorderedComparisonPlaceholder(Class, Object)applies to the value as well.protected StringorderedComparisonPlaceholder(Class<?> fieldType, Object value) Passes the value of aGREATERorLESScondition on afloatfield (or its wrapper) through the same conversion as the column,CAST(CAST(CAST(? AS REAL) AS VARCHAR) AS DOUBLE), so both sides keep the same 15 significant digits (seeorderedComparisonOperand(String, Class)), when the value is aNumberwhosedoublevalue is finite.private static StringthroughStoredFloatText(String operand) The float conversion both sides share;operandis a column name or?.Methods inherited from class com.ultikits.ultitools.interfaces.impl.data.AbstractRelationalDataOperator
backfillNullIds, buildColumnDefinitions, del, delById, deleteByIdCounted, exist, exist, getAll, getAll, getById, getLike, getListHandler, insert, insertAll, page, setTransactionManager, transaction, transaction, update, update, updateAll, updateCounted, updateIfMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.ultikits.ultitools.interfaces.DataOperator
query
-
Constructor Details
-
SQLiteDataOperator
Creates a new SQLite data operator.- Parameters:
dataSource- the SQLite data sourcetype- the entity class
-
-
Method Details
-
orderedComparisonOperand
ComparesGREATERandLESSas numbers of the field's Java type: abyte,short,intorlongfield (or its wrapper) as a 64-bit integer throughCAST(column AS BIGINT), adoublefield (or its wrapper) as a 64-bit floating-point number throughCAST(column AS DOUBLE), and afloatfield (or its wrapper) throughCAST(CAST(CAST(column AS REAL) AS VARCHAR) AS DOUBLE), whichorderedComparisonPlaceholder(Class, Object)applies to the value as well. Every other type is compared as stored.A field left on the default
@Columntype is aVARCHAR(255)column, which SQLite gives TEXT affinity, so without the cast it compares a number as text and2 > 10is true (#675). The cast follows the field's Java type, not the column's declared type, so tables that already exist need no change. A cast target whose name containsINThas INTEGER affinity (64-bit) in SQLite and one containingDOUBhas REAL affinity (64-bit);BIGINTandDOUBLEare also 64-bit types on the H2 stand-in, whoseINTEGERis 32-bit andREALsingle precision. Integral and floating fields get separate casts because a singleREALcast would lose whole numbers beyond 2^53.A
floatvalue is bound as thedoubleit widens to (0.1fas0.10000000149011612), and a default column keeps SQLite's 15-significant-digit text of that double (0.100000001490116). The text reads back as exactly0.1f, but compared with the bound value it is smaller, soLESS 0.1fwould select the row holding0.1f. Passing both sides through the same conversion to text compares them the way Java compares the values as they read back: two different finite floats differ well before the 15th significant digit, so the conversion keeps their order and never makes them equal. The conversion is applied to the value only when it is a number whosedoublevalue is finite (seeorderedComparisonPlaceholder(Class, Object)): SQLite writes an infinite value as the textInf, which converts back to 0, and converts text that is not a number to 0. Every other value (an infinity, NaN, aBigDecimalorBigIntegerbeyond the range of a double, or any text) is bound as it is and compared with the converted column, as before the conversion existed. A finite number of another type is converted too, so a whole number or an exact decimal equal to a stored float, such as 2^60 as aLong, compares as equal to it. One case stays approximate: a number (not only adouble) that agrees with a stored float to 15 significant digits but differs after them, such as a whole number of 10^15 or more like(1L << 53) + 1or a decimal with 16 or more significant digits, compares as equal to it, in a default column and also in a column declaredREAL, where the stored value is exact but the conversion still rounds it to 15 digits. The innerREALcast changes nothing on SQLite, whoseREALis 64-bit; on the H2 stand-in, whereREALis single precision, it first rounds the stored or bound value to the float it holds. Adoublefield keeps the plain bound value: the value it reads back is the stored text read as adouble, which is whatCAST(column AS DOUBLE)compares.- Overrides:
orderedComparisonOperandin classAbstractRelationalDataOperator<T extends BaseDataEntity<String>>- Parameters:
column- an allow-listed@Columnname of the entityfieldType- the Java type of the field mapped tocolumn- Returns:
- the SQL operand to compare, e.g.
columnor a cast of it - Since:
- 6.3.0
-
orderedComparisonPlaceholder
Passes the value of aGREATERorLESScondition on afloatfield (or its wrapper) through the same conversion as the column,CAST(CAST(CAST(? AS REAL) AS VARCHAR) AS DOUBLE), so both sides keep the same 15 significant digits (seeorderedComparisonOperand(String, Class)), when the value is aNumberwhosedoublevalue is finite. Any other value on afloatfield, and every value on a field of another type, is bound unchanged: the conversion would turn an infinity, a number beyond the range of a double, or text that is not a number into 0.- Overrides:
orderedComparisonPlaceholderin classAbstractRelationalDataOperator<T extends BaseDataEntity<String>>- Parameters:
fieldType- the Java type of the field the condition comparesvalue- the condition's value, which is bound to the placeholder; may benull- Returns:
- the SQL operand holding exactly one
?, e.g.?or a cast of it - Since:
- 6.3.0
-
isFiniteNumber
Whethervalueis a number whosedoublevalue is finite (not infinite, not NaN). -
throughStoredFloatText
The float conversion both sides share;operandis a column name or?. -
isIntegral
-
isFloat
-
isDouble
-
createTableSqlFromClazz
Description copied from class:AbstractRelationalDataOperatorCreates the SQL statement to create the table.Override this method to customize table creation for different databases.
- Specified by:
createTableSqlFromClazzin classAbstractRelationalDataOperator<T extends BaseDataEntity<String>>- Parameters:
type- the entity class- Returns:
- the CREATE TABLE SQL statement
-