| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.database; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.os.Build; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public abstract class AbstractWindowedCursor extends AbstractCursor { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
protected CursorWindow mWindow; |
| 44 |
|
| 45 |
@Override |
| 46 |
public byte[] getBlob(int columnIndex) { |
| 47 |
checkPosition(); |
| 48 |
return mWindow.getBlob(mPos, columnIndex); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public String getString(int columnIndex) { |
| 53 |
checkPosition(); |
| 54 |
return mWindow.getString(mPos, columnIndex); |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public void copyStringToBuffer(int columnIndex, CharArrayBuffer buffer) { |
| 59 |
checkPosition(); |
| 60 |
mWindow.copyStringToBuffer(mPos, columnIndex, buffer); |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public short getShort(int columnIndex) { |
| 65 |
checkPosition(); |
| 66 |
return mWindow.getShort(mPos, columnIndex); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public int getInt(int columnIndex) { |
| 71 |
checkPosition(); |
| 72 |
return mWindow.getInt(mPos, columnIndex); |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public long getLong(int columnIndex) { |
| 77 |
checkPosition(); |
| 78 |
return mWindow.getLong(mPos, columnIndex); |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public float getFloat(int columnIndex) { |
| 83 |
checkPosition(); |
| 84 |
return mWindow.getFloat(mPos, columnIndex); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public double getDouble(int columnIndex) { |
| 89 |
checkPosition(); |
| 90 |
return mWindow.getDouble(mPos, columnIndex); |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public boolean isNull(int columnIndex) { |
| 95 |
checkPosition(); |
| 96 |
return mWindow.getType(mPos, columnIndex) == Cursor.FIELD_TYPE_NULL; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Deprecated |
| 103 |
public boolean isBlob(int columnIndex) { |
| 104 |
return getType(columnIndex) == Cursor.FIELD_TYPE_BLOB; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@Deprecated |
| 111 |
public boolean isString(int columnIndex) { |
| 112 |
return getType(columnIndex) == Cursor.FIELD_TYPE_STRING; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
@Deprecated |
| 119 |
public boolean isLong(int columnIndex) { |
| 120 |
return getType(columnIndex) == Cursor.FIELD_TYPE_INTEGER; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
@Deprecated |
| 127 |
public boolean isFloat(int columnIndex) { |
| 128 |
return getType(columnIndex) == Cursor.FIELD_TYPE_FLOAT; |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public int getType(int columnIndex) { |
| 133 |
checkPosition(); |
| 134 |
return mWindow.getType(mPos, columnIndex); |
| 135 |
} |
| 136 |
|
| 137 |
@Override |
| 138 |
protected void checkPosition() { |
| 139 |
super.checkPosition(); |
| 140 |
|
| 141 |
if (mWindow == null) { |
| 142 |
throw new StaleDataException("Attempting to access a closed CursorWindow." + |
| 143 |
"Most probable cause: cursor is deactivated prior to calling this method."); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
@Override |
| 148 |
public CursorWindow getWindow() { |
| 149 |
return mWindow; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public void setWindow(CursorWindow window) { |
| 166 |
if (window != mWindow) { |
| 167 |
closeWindow(); |
| 168 |
mWindow = window; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public boolean hasWindow() { |
| 178 |
return mWindow != null; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 186 |
protected void closeWindow() { |
| 187 |
if (mWindow != null) { |
| 188 |
mWindow.close(); |
| 189 |
mWindow = null; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
@UnsupportedAppUsage |
| 201 |
protected void clearOrCreateWindow(String name) { |
| 202 |
if (mWindow == null) { |
| 203 |
mWindow = new CursorWindow(name); |
| 204 |
} else { |
| 205 |
mWindow.clear(); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
@Override |
| 211 |
@UnsupportedAppUsage |
| 212 |
protected void onDeactivateOrClose() { |
| 213 |
super.onDeactivateOrClose(); |
| 214 |
closeWindow(); |
| 215 |
} |
| 216 |
} |