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 StringasCSVLine()Returns current state of the cursor in form of CSV string with comma delimiters.booleancanDelete()Whether the session has rights to delete data from current table.booleancanInsert()Whether the session has rights to insert data into current table.booleancanModify()Whether the session has rights to modify data of current table.voidclear()Resets filters, sorting and fully cleans the buffer.voidclearBuffer(boolean withKeys)Clears current cursor buffer (sets all fields to null).abstract voidcopyFieldsFrom(BasicCursor from)Copy field values from a cursor of the same type.voidcopyFiltersFrom(BasicCursor c)Gets a copy of filters along with values of limit (offset and rowcount) from a cursor of the same type.voidcopyOrderFrom(BasicCursor c)Gets a copy of orderings from a cursor of the same type.intcount()Returns number of records in the filtered data set.boolean[]descOrders()Returns mask of DESC orders.voidfindSet()Moves to the first record in the filtered data set causing an error in the case if the transition was not successful.voidfirst()The same as tryFirst() but causes an error if no record is found.BasicCursorgetBufferCopy(CallContext context, Collection<? extends ColumnMeta<?>> fetchedFields)Clones the current cursor.StringgetComplexFilter()Returns (reformatted) expression of the complex filter in CelestaSQL dialect.Object[]getCurrentValues()Returns an array of field values.StringgetOrderBy()Returns "order by" clause for the cursor.ObjectgetValue(String name)Returns a value of a field by its name.booleanisEquivalent(BasicCursor c)Checks if filters and sorting are equivalent for this and other cursor.voidlast()The same as tryLast() but causes an error if no record is found.voidlimit(long offset, long rowCount)Sets filter to a range of records returned by the cursor.abstract DataGrainElementmeta()Metadata object (table, view or sequence) on the basis of which current data object was created.booleannavigate(String command)Navigation method (step-by-step transition in the filtered and sorted data set).booleannavigate(String command, long offset)Navigate forwards or backwards for the given offset.booleannext()The same as navigate(">").booleannextInSet()Moves to the next record in the sorted data set.voidorderBy()Clears sorting.voidorderBy(String... names)Deprecated.voidorderBy(ColumnMeta<?>... columns)Sets sorting.String[]orderByColumnNames()Returns column names that are in sorting.intposition()Method that returns total count of rows that precede the current one in the set.booleanprevious()The same as navigate("<").voidreset()Resets filters and sorting.voidsetComplexFilter(String condition)Sets complex condition to the data set.voidsetFilter(String name, String value)Deprecated.voidsetFilter(ColumnMeta<?> column, String value)Sets filter to the field.voidsetRange(String name)Deprecated.voidsetRange(String name, Object value)Deprecated.voidsetRange(String name, Object valueFrom, Object valueTo)Deprecated.voidsetRange(ColumnMeta<?> column)Resets any filter on a field.<T> voidsetRange(ColumnMeta<? super T> column, T value)Sets range from a single value on the field.<T> voidsetRange(ColumnMeta<? super T> column, T valueFrom, T valueTo)Sets range from..to on the field.voidsetValue(String name, Object value)Sets value of a field by its name.booleantryFindSet()Moves to the first record in the filtered data set and returns information about the success of transition.booleantryFirst()The same as navigate("-").booleantryLast()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:CsqlBasicDataAccessorMetadata object (table, view or sequence) on the basis of which current data object was created.- Specified by:
metain 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:
trueif the transition was successful,falseif 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. Returnsfalseif 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:
trueif 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:
clearin 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
-
-