244 lines
8.7 KiB
Plaintext
244 lines
8.7 KiB
Plaintext
package com.example.cuida.data.dao;
|
|
|
|
import android.database.Cursor;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.lifecycle.LiveData;
|
|
import androidx.room.EntityInsertionAdapter;
|
|
import androidx.room.RoomDatabase;
|
|
import androidx.room.RoomSQLiteQuery;
|
|
import androidx.room.util.CursorUtil;
|
|
import androidx.room.util.DBUtil;
|
|
import androidx.sqlite.db.SupportSQLiteStatement;
|
|
import com.example.cuida.data.model.Appointment;
|
|
import java.lang.Class;
|
|
import java.lang.Exception;
|
|
import java.lang.Override;
|
|
import java.lang.String;
|
|
import java.lang.SuppressWarnings;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.concurrent.Callable;
|
|
|
|
@SuppressWarnings({"unchecked", "deprecation"})
|
|
public final class AppointmentDao_Impl implements AppointmentDao {
|
|
private final RoomDatabase __db;
|
|
|
|
private final EntityInsertionAdapter<Appointment> __insertionAdapterOfAppointment;
|
|
|
|
public AppointmentDao_Impl(@NonNull final RoomDatabase __db) {
|
|
this.__db = __db;
|
|
this.__insertionAdapterOfAppointment = new EntityInsertionAdapter<Appointment>(__db) {
|
|
@Override
|
|
@NonNull
|
|
protected String createQuery() {
|
|
return "INSERT OR ABORT INTO `appointments` (`id`,`type`,`date`,`time`,`reason`,`isPast`) VALUES (nullif(?, 0),?,?,?,?,?)";
|
|
}
|
|
|
|
@Override
|
|
protected void bind(@NonNull final SupportSQLiteStatement statement,
|
|
final Appointment entity) {
|
|
statement.bindLong(1, entity.id);
|
|
if (entity.type == null) {
|
|
statement.bindNull(2);
|
|
} else {
|
|
statement.bindString(2, entity.type);
|
|
}
|
|
if (entity.date == null) {
|
|
statement.bindNull(3);
|
|
} else {
|
|
statement.bindString(3, entity.date);
|
|
}
|
|
if (entity.time == null) {
|
|
statement.bindNull(4);
|
|
} else {
|
|
statement.bindString(4, entity.time);
|
|
}
|
|
if (entity.reason == null) {
|
|
statement.bindNull(5);
|
|
} else {
|
|
statement.bindString(5, entity.reason);
|
|
}
|
|
final int _tmp = entity.isPast ? 1 : 0;
|
|
statement.bindLong(6, _tmp);
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override
|
|
public void insert(final Appointment appointment) {
|
|
__db.assertNotSuspendingTransaction();
|
|
__db.beginTransaction();
|
|
try {
|
|
__insertionAdapterOfAppointment.insert(appointment);
|
|
__db.setTransactionSuccessful();
|
|
} finally {
|
|
__db.endTransaction();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public LiveData<List<Appointment>> getFutureAppointments() {
|
|
final String _sql = "SELECT * FROM appointments WHERE isPast = 0 ORDER BY date ASC, time ASC";
|
|
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
|
|
return __db.getInvalidationTracker().createLiveData(new String[] {"appointments"}, false, new Callable<List<Appointment>>() {
|
|
@Override
|
|
@Nullable
|
|
public List<Appointment> call() throws Exception {
|
|
final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
|
|
try {
|
|
final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "id");
|
|
final int _cursorIndexOfType = CursorUtil.getColumnIndexOrThrow(_cursor, "type");
|
|
final int _cursorIndexOfDate = CursorUtil.getColumnIndexOrThrow(_cursor, "date");
|
|
final int _cursorIndexOfTime = CursorUtil.getColumnIndexOrThrow(_cursor, "time");
|
|
final int _cursorIndexOfReason = CursorUtil.getColumnIndexOrThrow(_cursor, "reason");
|
|
final int _cursorIndexOfIsPast = CursorUtil.getColumnIndexOrThrow(_cursor, "isPast");
|
|
final List<Appointment> _result = new ArrayList<Appointment>(_cursor.getCount());
|
|
while (_cursor.moveToNext()) {
|
|
final Appointment _item;
|
|
final String _tmpType;
|
|
if (_cursor.isNull(_cursorIndexOfType)) {
|
|
_tmpType = null;
|
|
} else {
|
|
_tmpType = _cursor.getString(_cursorIndexOfType);
|
|
}
|
|
final String _tmpDate;
|
|
if (_cursor.isNull(_cursorIndexOfDate)) {
|
|
_tmpDate = null;
|
|
} else {
|
|
_tmpDate = _cursor.getString(_cursorIndexOfDate);
|
|
}
|
|
final String _tmpTime;
|
|
if (_cursor.isNull(_cursorIndexOfTime)) {
|
|
_tmpTime = null;
|
|
} else {
|
|
_tmpTime = _cursor.getString(_cursorIndexOfTime);
|
|
}
|
|
final String _tmpReason;
|
|
if (_cursor.isNull(_cursorIndexOfReason)) {
|
|
_tmpReason = null;
|
|
} else {
|
|
_tmpReason = _cursor.getString(_cursorIndexOfReason);
|
|
}
|
|
final boolean _tmpIsPast;
|
|
final int _tmp;
|
|
_tmp = _cursor.getInt(_cursorIndexOfIsPast);
|
|
_tmpIsPast = _tmp != 0;
|
|
_item = new Appointment(_tmpType,_tmpDate,_tmpTime,_tmpReason,_tmpIsPast);
|
|
_item.id = _cursor.getInt(_cursorIndexOfId);
|
|
_result.add(_item);
|
|
}
|
|
return _result;
|
|
} finally {
|
|
_cursor.close();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void finalize() {
|
|
_statement.release();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public LiveData<List<Appointment>> getPastAppointments() {
|
|
final String _sql = "SELECT * FROM appointments WHERE isPast = 1 ORDER BY date DESC, time DESC";
|
|
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
|
|
return __db.getInvalidationTracker().createLiveData(new String[] {"appointments"}, false, new Callable<List<Appointment>>() {
|
|
@Override
|
|
@Nullable
|
|
public List<Appointment> call() throws Exception {
|
|
final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
|
|
try {
|
|
final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "id");
|
|
final int _cursorIndexOfType = CursorUtil.getColumnIndexOrThrow(_cursor, "type");
|
|
final int _cursorIndexOfDate = CursorUtil.getColumnIndexOrThrow(_cursor, "date");
|
|
final int _cursorIndexOfTime = CursorUtil.getColumnIndexOrThrow(_cursor, "time");
|
|
final int _cursorIndexOfReason = CursorUtil.getColumnIndexOrThrow(_cursor, "reason");
|
|
final int _cursorIndexOfIsPast = CursorUtil.getColumnIndexOrThrow(_cursor, "isPast");
|
|
final List<Appointment> _result = new ArrayList<Appointment>(_cursor.getCount());
|
|
while (_cursor.moveToNext()) {
|
|
final Appointment _item;
|
|
final String _tmpType;
|
|
if (_cursor.isNull(_cursorIndexOfType)) {
|
|
_tmpType = null;
|
|
} else {
|
|
_tmpType = _cursor.getString(_cursorIndexOfType);
|
|
}
|
|
final String _tmpDate;
|
|
if (_cursor.isNull(_cursorIndexOfDate)) {
|
|
_tmpDate = null;
|
|
} else {
|
|
_tmpDate = _cursor.getString(_cursorIndexOfDate);
|
|
}
|
|
final String _tmpTime;
|
|
if (_cursor.isNull(_cursorIndexOfTime)) {
|
|
_tmpTime = null;
|
|
} else {
|
|
_tmpTime = _cursor.getString(_cursorIndexOfTime);
|
|
}
|
|
final String _tmpReason;
|
|
if (_cursor.isNull(_cursorIndexOfReason)) {
|
|
_tmpReason = null;
|
|
} else {
|
|
_tmpReason = _cursor.getString(_cursorIndexOfReason);
|
|
}
|
|
final boolean _tmpIsPast;
|
|
final int _tmp;
|
|
_tmp = _cursor.getInt(_cursorIndexOfIsPast);
|
|
_tmpIsPast = _tmp != 0;
|
|
_item = new Appointment(_tmpType,_tmpDate,_tmpTime,_tmpReason,_tmpIsPast);
|
|
_item.id = _cursor.getInt(_cursorIndexOfId);
|
|
_result.add(_item);
|
|
}
|
|
return _result;
|
|
} finally {
|
|
_cursor.close();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void finalize() {
|
|
_statement.release();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public List<String> getBookedTimesForDate(final String date) {
|
|
final String _sql = "SELECT time FROM appointments WHERE date = ?";
|
|
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 1);
|
|
int _argIndex = 1;
|
|
if (date == null) {
|
|
_statement.bindNull(_argIndex);
|
|
} else {
|
|
_statement.bindString(_argIndex, date);
|
|
}
|
|
__db.assertNotSuspendingTransaction();
|
|
final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
|
|
try {
|
|
final List<String> _result = new ArrayList<String>(_cursor.getCount());
|
|
while (_cursor.moveToNext()) {
|
|
final String _item;
|
|
if (_cursor.isNull(0)) {
|
|
_item = null;
|
|
} else {
|
|
_item = _cursor.getString(0);
|
|
}
|
|
_result.add(_item);
|
|
}
|
|
return _result;
|
|
} finally {
|
|
_cursor.close();
|
|
_statement.release();
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static List<Class<?>> getRequiredConverters() {
|
|
return Collections.emptyList();
|
|
}
|
|
}
|