Package ru.curs.celesta.dbutils
Class BasicCursor
- java.lang.Object
-
- ru.curs.celesta.dbutils.CsqlBasicDataAccessor<CallContext>
-
- ru.curs.celesta.dbutils.BasicDataAccessor
-
- ru.curs.celesta.dbutils.BasicCursor
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
Cursor
,MaterializedViewCursor
,ParameterizedViewCursor
,ReadOnlyTableCursor
,ViewCursor
public abstract class BasicCursor extends BasicDataAccessor
Base cursor class for reading data from views.
-
-
Constructor Summary
Constructors Constructor Description BasicCursor(CallContext context)
BasicCursor(CallContext context, Set<String> fields)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
asCSVLine()
Returns current state of the cursor in form of CSV string with comma delimiters.boolean
canDelete()
Whether the session has rights to delete data from current table.boolean
canInsert()
Whether the session has rights to insert data into current table.boolean
canModify()
Whether the session has rights to modify data of current table.void
clear()
Resets filters, sorting and fully cleans the buffer.void
clearBuffer(boolean withKeys)
Clears current cursor buffer (sets all fields to null).abstract void
copyFieldsFrom(BasicCursor from)
Copy field values from a cursor of the same type.void
copyFiltersFrom(BasicCursor c)
Gets a copy of filters along with values of limit (offset and rowcount) from a cursor of the same type.void
copyOrderFrom(BasicCursor c)
Gets a copy of orderings from a cursor of the same type.int
count()
Returns number of records in the filtered data set.boolean[]
descOrders()
Returns mask of DESC orders.void
findSet()
Moves to the first record in the filtered data set causing an error in the case if the transition was not successful.void
first()
The same as tryFirst() but causes an error if no record is found.BasicCursor
getBufferCopy(CallContext context, Collection<? extends ColumnMeta<?>> fetchedFields)
Clones the current cursor.String
getComplexFilter()
Returns (reformatted) expression of the complex filter in CelestaSQL dialect.Object[]
getCurrentValues()
Returns an array of field values.String
getOrderBy()
Returns "order by" clause for the cursor.Object
getValue(String name)
Returns a value of a field by its name.boolean
isEquivalent(BasicCursor c)
Checks if filters and sorting are equivalent for this and other cursor.void
last()
The same as tryLast() but causes an error if no record is found.void
limit(long offset, long rowCount)
Sets filter to a range of records returned by the cursor.abstract DataGrainElement
meta()
Metadata object (table, view or sequence) on the basis of which current data object was created.boolean
navigate(String command)
Navigation method (step-by-step transition in the filtered and sorted data set).boolean
navigate(String command, long offset)
Navigate forwards or backwards for the given offset.boolean
next()
The same as navigate(">").boolean
nextInSet()
Moves to the next record in the sorted data set.void
orderBy()
Clears sorting.void
orderBy(String... names)
Deprecated.void
orderBy(ColumnMeta<?>... columns)
Sets sorting.String[]
orderByColumnNames()
Returns column names that are in sorting.int
position()
Method that returns total count of rows that precede the current one in the set.boolean
previous()
The same as navigate("<").void
reset()
Resets filters and sorting.void
setComplexFilter(String condition)
Sets complex condition to the data set.void
setFilter(String name, String value)
Deprecated.void
setFilter(ColumnMeta<?> column, String value)
Sets filter to the field.void
setRange(String name)
Deprecated.void
setRange(String name, Object value)
Deprecated.void
setRange(String name, Object valueFrom, Object valueTo)
Deprecated.void
setRange(ColumnMeta<?> column)
Resets any filter on a field.<T> void
setRange(ColumnMeta<? super T> column, T value)
Sets range from a single value on the field.<T> void
setRange(ColumnMeta<? super T> column, T valueFrom, T valueTo)
Sets range from..to on the field.void
setValue(String name, Object value)
Sets value of a field by its name.boolean
tryFindSet()
Moves to the first record in the filtered data set and returns information about the success of transition.boolean
tryFirst()
The same as navigate("-").boolean
tryLast()
The same as navigate("+").-
Methods inherited from class ru.curs.celesta.dbutils.BasicDataAccessor
canRead
-
Methods inherited from class ru.curs.celesta.dbutils.CsqlBasicDataAccessor
callContext, close, isClosed
-
-
-
-
Constructor Detail
-
BasicCursor
public BasicCursor(CallContext context)
-
BasicCursor
public BasicCursor(CallContext context, Set<String> fields)
-
-
Method Detail
-
meta
public abstract DataGrainElement meta()
Description copied from class:CsqlBasicDataAccessor
Metadata object (table, view or sequence) on the basis of which current data object was created.- Specified by:
meta
in classCsqlBasicDataAccessor<CallContext>
-
canInsert
public boolean canInsert()
Whether the session has rights to insert data into current table.- Returns:
- true, if current record can be inserted
-
canModify
public boolean canModify()
Whether the session has rights to modify data of current table.- Returns:
- true, if current record can be updated
-
canDelete
public boolean canDelete()
Whether the session has rights to delete data from current table.- Returns:
- true, if current record can be deleted
-
getOrderBy
public final String getOrderBy()
Returns "order by" clause for the cursor.- Returns:
-
orderByColumnNames
public String[] orderByColumnNames()
Returns column names that are in sorting.- Returns:
-
descOrders
public boolean[] descOrders()
Returns mask of DESC orders.- Returns:
-
tryFindSet
public final boolean tryFindSet()
Moves to the first record in the filtered data set and returns information about the success of transition.- Returns:
true
if the transition was successful,false
if there are no records in the data set.
-
tryFirst
public final boolean tryFirst()
The same as navigate("-").- Returns:
-
first
public final void first()
The same as tryFirst() but causes an error if no record is found.
-
tryLast
public final boolean tryLast()
The same as navigate("+").- Returns:
-
last
public final void last()
The same as tryLast() but causes an error if no record is found.
-
next
public final boolean next()
The same as navigate(">").- Returns:
-
previous
public final boolean previous()
The same as navigate("<").- Returns:
-
findSet
public final void findSet()
Moves to the first record in the filtered data set causing an error in the case if the transition was not successful.
-
asCSVLine
public final String asCSVLine()
Returns current state of the cursor in form of CSV string with comma delimiters.- Returns:
-
nextInSet
public final boolean nextInSet()
Moves to the next record in the sorted data set. Returnsfalse
if the end of the set is reached.- Returns:
-
navigate
public boolean navigate(String command)
Navigation method (step-by-step transition in the filtered and sorted data set).- Parameters:
command
- Command consisting of a sequence of symbols:- = update current record (if it exists in the filtered data set)
- > move to the next record in the filtered data set
- < move to the previous record in the filtered data set
- - move to the first record in the filtered data set
- + move to the last record in the filtered data set
- Returns:
true
if the record was found and the transition completedfalse
- otherwise.
-
navigate
public boolean navigate(String command, long offset)
Navigate forwards or backwards for the given offset.- Parameters:
command
- Can be either '>' or '<' for forwards or backwards navigation.offset
- Offset.
-
setRange
@Deprecated public final void setRange(String name)
Deprecated.Resets any filter on a field.- Parameters:
name
- field name
-
setRange
public final void setRange(ColumnMeta<?> column)
Resets any filter on a field.- Parameters:
column
- field column
-
setRange
@Deprecated public final void setRange(String name, Object value)
Deprecated.Sets range from a single value on the field.- Parameters:
name
- field namevalue
- value along which filtering is performed
-
setRange
public final <T> void setRange(ColumnMeta<? super T> column, T value)
Sets range from a single value on the field.- Type Parameters:
T
- Java type of value- Parameters:
column
- field columnvalue
- value along which filtering is performed
-
setRange
@Deprecated public final void setRange(String name, Object valueFrom, Object valueTo)
Deprecated.Sets range from..to on the field.- Parameters:
name
- field namevalueFrom
- value fromvalueTo
- value to
-
setRange
public final <T> void setRange(ColumnMeta<? super T> column, T valueFrom, T valueTo)
Sets range from..to on the field.- Type Parameters:
T
- Java type of value- Parameters:
column
- field columnvalueFrom
- value fromvalueTo
- value to
-
setFilter
@Deprecated public final void setFilter(String name, String value)
Deprecated.Sets filter to the field.- Parameters:
name
- field namevalue
- filter
-
setFilter
public final void setFilter(ColumnMeta<?> column, String value)
Sets filter to the field.- Parameters:
column
- field columnvalue
- filter
-
setComplexFilter
public final void setComplexFilter(String condition)
Sets complex condition to the data set.- Parameters:
condition
- condition that corresponds to WHERE clause.
-
getComplexFilter
public final String getComplexFilter()
Returns (reformatted) expression of the complex filter in CelestaSQL dialect.
-
limit
public final void limit(long offset, long rowCount)
Sets filter to a range of records returned by the cursor.- Parameters:
offset
- number of records that has to be skipped (0 - start from the beginning).rowCount
- maximal number of records that has to be returned (0 - return all records).
-
reset
public final void reset()
Resets filters and sorting.
-
orderBy
@Deprecated public final void orderBy(String... names)
Deprecated.Sets sorting.- Parameters:
names
- array of fields for sorting
-
orderBy
public final void orderBy(ColumnMeta<?>... columns)
Sets sorting.- Parameters:
columns
- columns array for sorting
-
orderBy
public final void orderBy()
Clears sorting.
-
clear
public void clear()
Resets filters, sorting and fully cleans the buffer.- Specified by:
clear
in classCsqlBasicDataAccessor<CallContext>
-
count
public final int count()
Returns number of records in the filtered data set.- Returns:
-
position
public final int position()
Method that returns total count of rows that precede the current one in the set. This method is intended for internal use by GridDriver. Since rows counting is a resource-consuming operation, usage of this method should be avoided.- Returns:
-
copyFiltersFrom
public final void copyFiltersFrom(BasicCursor c)
Gets a copy of filters along with values of limit (offset and rowcount) from a cursor of the same type.- Parameters:
c
- cursor the filters of which have to be copied
-
copyOrderFrom
public final void copyOrderFrom(BasicCursor c)
Gets a copy of orderings from a cursor of the same type.- Parameters:
c
- cursor the sortings of which have to be copied
-
isEquivalent
public boolean isEquivalent(BasicCursor c)
Checks if filters and sorting are equivalent for this and other cursor.- Parameters:
c
- Other cursor.- Returns:
-
setValue
public final void setValue(String name, Object value)
Sets value of a field by its name. This is needed for an indirect filling of the cursor with data from Java (in Python, naturally, there issetattr(...)
procedure for this goal).- Parameters:
name
- field namevalue
- field value
-
getValue
public final Object getValue(String name)
Returns a value of a field by its name. This is needed for accessing data when using generic cursors, such asCursor
.- Parameters:
name
- field name- Returns:
-
copyFieldsFrom
public abstract void copyFieldsFrom(BasicCursor from)
Copy field values from a cursor of the same type.- Parameters:
from
- cursor that field values have to be copied from
-
getCurrentValues
public final Object[] getCurrentValues()
Returns an array of field values.- Returns:
-
clearBuffer
public final void clearBuffer(boolean withKeys)
Clears current cursor buffer (sets all fields to null).- Parameters:
withKeys
- if true, all fields will be cleared, otherwise, primary key fields will remain unchanged.
-
getBufferCopy
public final BasicCursor getBufferCopy(CallContext context, Collection<? extends ColumnMeta<?>> fetchedFields)
Clones the current cursor.- Parameters:
context
- call contextfetchedFields
- list of fields to be fetched
-
-