Java Code Examples for io.realm.Realm#createObject()

The following examples show how to use io.realm.Realm#createObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PumpHistoryBasal.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
public static void suspend(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        byte reason) {

    PumpHistoryBasal suspendRecord = realm.where(PumpHistoryBasal.class)
            .equalTo("pumpMAC", pumpMAC)
            .equalTo("recordtype", RECORDTYPE.SUSPEND.value())
            .equalTo("eventRTC", eventRTC)
            .findFirst();
    if (suspendRecord == null) {
        Log.d(TAG, "*new* suspend basal");
        suspendRecord = realm.createObject(PumpHistoryBasal.class);
        suspendRecord.pumpMAC = pumpMAC;
        suspendRecord.recordtype = RECORDTYPE.SUSPEND.value();
        suspendRecord.eventDate = eventDate;
        suspendRecord.eventRTC = eventRTC;
        suspendRecord.eventOFFSET = eventOFFSET;
        suspendRecord.suspendReason = reason;
        suspendRecord.programmedDuration = 24 * 60;
        suspendRecord.completed = false;
        suspendRecord.key = HistoryUtils.key("SUSPEND", eventRTC);
        pumpHistorySender.setSenderREQ(suspendRecord);
    }
}
 
Example 2
Source File: RealmNotificationSetting.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static RealmNotificationSetting put(Realm realm, final RealmChatRoom realmChatRoom, final RealmGroupRoom realmGroupRoom, final RealmChannelRoom realmChannelRoom) {
    RealmNotificationSetting realmNotificationSetting = realm.createObject(RealmNotificationSetting.class);
    realmNotificationSetting.setNotification(0);
    realmNotificationSetting.setVibrate(-1);
    realmNotificationSetting.sound(G.fragmentActivity.getResources().getString(R.string.array_Default_Notification_tone));
    realmNotificationSetting.setIdRadioButtonSound(-1);
    realmNotificationSetting.setSmartNotification(G.fragmentActivity.getResources().getString(R.string.array_Default));
    realmNotificationSetting.setTimes(-1);
    realmNotificationSetting.setMinutes(-1);
    realmNotificationSetting.setLedColor(-1);

    if (realmChatRoom != null) {
        realmChatRoom.setRealmNotificationSetting(realmNotificationSetting);
    } else if (realmGroupRoom != null) {
        realmGroupRoom.setRealmNotificationSetting(realmNotificationSetting);
    } else if (realmChannelRoom != null) {
        realmChannelRoom.setRealmNotificationSetting(realmNotificationSetting);
    }
    return realmNotificationSetting;
}
 
Example 3
Source File: InvitationRealm.java    From talk-android with MIT License 6 votes vote down vote up
public void addOrUpdateWithCurrentThread(final Invitation invitation) {
    Realm realm = RealmProvider.getInstance();
    try {
        realm.beginTransaction();
        Invitation realmInvitation = realm.where(Invitation.class)
                .equalTo(Invitation.TEAM_ID, BizLogic.getTeamId())
                .equalTo(Invitation.KEY, invitation.getKey())
                .findFirst();
        if (realmInvitation == null) {
            realmInvitation = realm.createObject(Invitation.class);
        }
        copy(realmInvitation, invitation);
        realm.commitTransaction();
    } catch (Exception e) {
        e.printStackTrace();
        realm.cancelTransaction();
    } finally {
        realm.close();
    }
}
 
Example 4
Source File: TeamRealm.java    From talk-android with MIT License 6 votes vote down vote up
public void addAndUpdateWithCurrentThread(final Team team) {
    Realm realm = RealmProvider.getInstance();
    try {
        realm.beginTransaction();
        Team realmTeam = realm.where(Team.class).equalTo(Team.ID, team.get_id()).findFirst();
        if (realmTeam == null) {
            realmTeam = realm.createObject(Team.class);
        }
        copy(realmTeam, team);
        realm.commitTransaction();
    } catch (Exception e) {
        e.printStackTrace();
        realm.cancelTransaction();
    } finally {
        realm.close();
    }
}
 
Example 5
Source File: RealmRoomMessage.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void makeForwardMessage(Realm realm, long roomId, long messageId, long forwardedMessageId) {
    RealmRoomMessage roomMessage = realm.where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.MESSAGE_ID, forwardedMessageId).findFirst();
    if (roomMessage != null) {
        RealmRoomMessage forwardedMessage = realm.createObject(RealmRoomMessage.class, messageId);
        if (roomMessage.getForwardMessage() != null) {
            forwardedMessage.setForwardMessage(roomMessage.getForwardMessage());
            forwardedMessage.setHasMessageLink(roomMessage.getForwardMessage().getHasMessageLink());
        } else {
            forwardedMessage.setForwardMessage(roomMessage);
            forwardedMessage.setHasMessageLink(roomMessage.getHasMessageLink());
        }

        forwardedMessage.setCreateTime(TimeUtils.currentLocalTime());
        forwardedMessage.setMessageType(ProtoGlobal.RoomMessageType.TEXT);
        forwardedMessage.setRoomId(roomId);
        forwardedMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
        forwardedMessage.setUserId(G.userId);
        forwardedMessage.setShowMessage(true);
    }
}
 
Example 6
Source File: RealmOfflineSeen.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static RealmOfflineSeen put(Realm realm, long messageId) {
    RealmOfflineSeen realmOfflineSeen = realm.createObject(RealmOfflineSeen.class, SUID.id().get());
    realmOfflineSeen.setOfflineSeen(messageId);
    realm.copyToRealmOrUpdate(realmOfflineSeen);

    return realmOfflineSeen;
}
 
Example 7
Source File: RealmRoomMessageContact.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static RealmRoomMessageContact put(Realm realm, StructMessageInfo structMessageInfo) {
    RealmRoomMessageContact realmRoomMessageContact = realm.createObject(RealmRoomMessageContact.class, AppUtils.makeRandomId());
    realmRoomMessageContact.setFirstName(structMessageInfo.userInfo.firstName);
    realmRoomMessageContact.setLastName(structMessageInfo.userInfo.lastName);
    realmRoomMessageContact.addPhone(structMessageInfo.userInfo.phone);
    return realmRoomMessageContact;
}
 
Example 8
Source File: RealmCallConfig.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setIceServer(Realm realm, List<ProtoSignalingGetConfiguration.SignalingGetConfigurationResponse.IceServer> iceServer) {

        for (ProtoSignalingGetConfiguration.SignalingGetConfigurationResponse.IceServer mIceService : iceServer) {
            RealmIceServer iceProto = realm.createObject(RealmIceServer.class);
            iceProto.setUrl(mIceService.getUrl());
            iceProto.setUsername(mIceService.getUsername());
            iceProto.setCredential(mIceService.getCredential());
            realmIceServer.add(iceProto);
        }


    }
 
Example 9
Source File: RealmCallLog.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void addLog(ProtoSignalingGetLog.SignalingGetLogResponse.SignalingLog callLog, Realm realm) {
    RealmCallLog realmCallLog = realm.where(RealmCallLog.class).equalTo(RealmCallLogFields.ID, callLog.getId()).findFirst();
    if (realmCallLog == null) {
        realmCallLog = realm.createObject(RealmCallLog.class, callLog.getId());
    }

    realmCallLog.setLogProto(callLog);
    realmCallLog.setName(callLog.getPeer().getDisplayName());
    realmCallLog.setTime(callLog.getOfferTime());
}
 
Example 10
Source File: RealmMember.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static RealmMember put(Realm realm, ProtoGroupGetMemberList.GroupGetMemberListResponse.Member member) {
    RealmMember realmMember = realm.createObject(RealmMember.class, SUID.id().get());
    realmMember.setRole(member.getRole().toString());
    realmMember.setPeerId(member.getUserId());
    realmMember = realm.copyToRealm(realmMember);
    return realmMember;
}
 
Example 11
Source File: RealmOfflineEdited.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static RealmOfflineEdited put(Realm realm, long messageId, String message) {
    RealmOfflineEdited realmOfflineEdited = realm.createObject(RealmOfflineEdited.class, SUID.id().get());
    realmOfflineEdited.setMessageId(messageId);
    realmOfflineEdited.setMessage(message);
    realmOfflineEdited = realm.copyToRealm(realmOfflineEdited);

    return realmOfflineEdited;
}
 
Example 12
Source File: StepTransaction.java    From healthgo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Realm realm) {
    Log.d("realm", "now insert [" + date + " ," + num + "]");

    StepModel stepModel =realm.where(StepModel.class).equalTo("date",date).findFirst();

    if (stepModel == null)
        stepModel = realm.createObject(StepModel.class);
    stepModel.setDate(date);
    stepModel.setNumSteps(num);
}
 
Example 13
Source File: TeamRealm.java    From talk-android with MIT License 5 votes vote down vote up
public void addWithCurrentThread(final Team team) {
    Realm realm = RealmProvider.getInstance();
    try {
        realm.beginTransaction();
        Team teamInfo = realm.createObject(Team.class);
        copy(teamInfo, team);
        realm.commitTransaction();
    } catch (Exception e) {
        e.printStackTrace();
        realm.cancelTransaction();
    } finally {
        realm.close();
    }
}
 
Example 14
Source File: PumpHistoryMarker.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
public static void marker(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        RECORDTYPE recordtype,
        int duration,
        byte carbUnits,
        double carbInput,
        double insulin) {

    PumpHistoryMarker record = realm.where(PumpHistoryMarker.class)
            .equalTo("pumpMAC", pumpMAC)
            .equalTo("eventRTC", eventRTC)
            .equalTo("recordtype", recordtype.value())
            .findFirst();

    if (record == null) {
        Log.d(TAG, "*new* recordtype: " + recordtype.name());
        record = realm.createObject(PumpHistoryMarker.class);
        record.pumpMAC = pumpMAC;
        record.recordtype = recordtype.value();
        record.eventDate = eventDate;
        record.eventRTC = eventRTC;
        record.eventOFFSET = eventOFFSET;
        record.duration = duration;
        record.carbUnits = carbUnits;
        record.carbInput = carbInput;
        record.insulin = insulin;
        record.key = HistoryUtils.key("MARK", eventRTC);
        pumpHistorySender.setSenderREQ(record);
    }
}
 
Example 15
Source File: TaskRepository.java    From citrus with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param realm
 * @param name
 * @param groupName
 * @return
 */
public static Task create(@NonNull Realm realm, @NonNull String name, String groupName) {
    realm.beginTransaction();
    Task task = realm.createObject(Task.class);
    task.setName(name);
    if (groupName != null) {
        task.setGroupName(groupName);
    }
    realm.commitTransaction();
    return task;
}
 
Example 16
Source File: PumpHistoryBasal.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
public static void completed(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        byte preset,
        byte type,
        double rate,
        int percentageOfRate,
        int duration,
        boolean canceled) {

    PumpHistoryBasal completedRecord = realm.where(PumpHistoryBasal.class)
            .equalTo("pumpMAC", pumpMAC)
            .equalTo("recordtype", RECORDTYPE.COMPLETED.value())
            .equalTo("eventRTC", eventRTC)
            .findFirst();
    if (completedRecord == null) {
        Log.d(TAG, "*new* temp basal completed");
        completedRecord = realm.createObject(PumpHistoryBasal.class);
        completedRecord.pumpMAC = pumpMAC;
        completedRecord.recordtype = RECORDTYPE.COMPLETED.value();
        completedRecord.eventDate = eventDate;
        completedRecord.eventRTC = eventRTC;
        completedRecord.eventOFFSET = eventOFFSET;
        completedRecord.programmedDuration = duration;
        completedRecord.preset = preset;
        completedRecord.type = type;
        completedRecord.rate = rate;
        completedRecord.percentageOfRate = percentageOfRate;
        completedRecord.completed = false;
        completedRecord.canceled = canceled;
        completedRecord.key = HistoryUtils.key("BASAL", eventRTC);

        // look for a corresponding programmed temp basal
        PumpHistoryBasal programmedRecord = realm.where(PumpHistoryBasal.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("recordtype", RECORDTYPE.PROGRAMMED.value())
                .equalTo("completed", false)
                .greaterThan("eventRTC", HistoryUtils.offsetRTC(eventRTC, - (duration + 1) * 60))
                .lessThan("eventRTC", eventRTC)
                .findFirst();
        if (programmedRecord != null) {
            int completedDuration = canceled ? (int) Math.round((double) (eventRTC - programmedRecord.eventRTC) / 60) : duration;
            Log.d(TAG, "*update* temp basal programed (from completed) canceled=" + canceled + " completedDuration=" + completedDuration);

            programmedRecord.completedDuration = completedDuration;
            programmedRecord.canceled = canceled;
            programmedRecord.completed = true;

            completedRecord.completedDuration = completedDuration;
            completedRecord.completed = true;
            // only run completed senders when a temp basal is canceled
            if (canceled) pumpHistorySender.setSenderREQ(completedRecord);
        }
    }
}
 
Example 17
Source File: PumpHistoryBasal.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
public static void resume(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        byte reason) {

    PumpHistoryBasal resumeRecord = realm.where(PumpHistoryBasal.class)
            .equalTo("pumpMAC", pumpMAC)
            .equalTo("recordtype", RECORDTYPE.RESUME.value())
            .equalTo("eventRTC", eventRTC)
            .findFirst();
    if (resumeRecord == null) {
        Log.d(TAG, "*new* resume basal");
        resumeRecord = realm.createObject(PumpHistoryBasal.class);
        resumeRecord.pumpMAC = pumpMAC;
        resumeRecord.recordtype = RECORDTYPE.RESUME.value();
        resumeRecord.eventDate = eventDate;
        resumeRecord.eventRTC = eventRTC;
        resumeRecord.eventOFFSET = eventOFFSET;
        resumeRecord.resumeReason = reason;
        resumeRecord.programmedDuration = 0;
        resumeRecord.key = HistoryUtils.key("RESUME", eventRTC);
        pumpHistorySender.setSenderREQ(resumeRecord);

        // look for corresponding suspend and update it's duration
        RealmResults<PumpHistoryBasal> suspendRecords = realm.where(PumpHistoryBasal.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("recordtype", RECORDTYPE.SUSPEND.value())
                .equalTo("completed", false)
                .greaterThan("eventRTC", HistoryUtils.offsetRTC(eventRTC, - 24 * 60 * 60))
                .lessThan("eventRTC", eventRTC)
                .sort("eventDate", Sort.DESCENDING)
                .findAll();
        if (suspendRecords.size() > 0) {
            PumpHistoryBasal suspendRecord = suspendRecords.first();
            suspendRecord.completed = true;
            suspendRecord.completedDuration = (int) Math.round(((double) (eventRTC - suspendRecord.getEventRTC())) / 60);
            suspendRecord.resumeReason = reason;
            resumeRecord.suspendReason = suspendRecord.suspendReason;
        }

        // look for a temp that was in progress and resume temp with recalculated duration (for nightscout)
        RealmResults<PumpHistoryBasal> realmResults = realm.where(PumpHistoryBasal.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("recordtype", RECORDTYPE.PROGRAMMED.value())
                .equalTo("completed", false)
                .greaterThan("eventRTC", HistoryUtils.offsetRTC(eventRTC, - 24 * 60 * 60))
                .lessThan("eventRTC", eventRTC)
                .sort("eventDate", Sort.DESCENDING)
                .findAll();
        if (realmResults.size() == 1) {
            PumpHistoryBasal programedRecord = realmResults.first();
            int remaining = (int) Math.round(((double) programedRecord.programmedDuration - ((double) (eventRTC - programedRecord.eventRTC) / 60)));
            if (remaining > 0) {
                Log.d(TAG, "temp still in progress after resumed basal");
                resumeRecord.programmedDuration = remaining;
                resumeRecord.type = programedRecord.type;
                resumeRecord.rate = programedRecord.rate;
                resumeRecord.percentageOfRate = programedRecord.percentageOfRate;
            }
        }

    }
}
 
Example 18
Source File: PumpHistoryAlarm.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
public static void cleared(
            PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
            Date eventDate, int eventRTC, int eventOFFSET,
            int faultNumber) {
/*
        // debug for 670 faults
        PumpAlert pumpAlert = new PumpAlert().faultNumber(faultNumber).build();
        //if (!pumpAlert.isAlertKnown() || (faultNumber >= 818 && faultNumber <= 840)) {
        if (!pumpAlert.isAlertKnown()) {
            Date pumpdate = MessageUtils.decodeDateTime(eventRTC & 0xFFFFFFFFL, eventOFFSET);
            PumpHistorySystem.event(pumpHistorySender, realm,
                    eventDate, eventDate,
                    String.format("%08X:%04X:DEBUGALERT", eventRTC, faultNumber),
                    PumpHistorySystem.STATUS.DEBUG_NIGHTSCOUT,
                    new RealmList<>(
                            String.format("[ClearedAlert]<br>pumpDate: %s<br>faultNumber: #%s",
                                    FormatKit.getInstance().formatAsYMDHMS(pumpdate.getTime()),
                                    faultNumber))
            );
        }
*/
        if (faultNumber == 110) return; // ignore cleared silenced alerts

        PumpHistoryAlarm record = realm.where(PumpHistoryAlarm.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("cleared", true)
                .equalTo("clearedRTC", eventRTC)
                .equalTo("faultNumber", faultNumber)
                .findFirst();

        if (record == null) {
            // look for a alarm
            RealmResults<PumpHistoryAlarm> results = realm.where(PumpHistoryAlarm.class)
                    .equalTo("pumpMAC", pumpMAC)
                    .equalTo("alarmed", true)
                    .equalTo("cleared", false)
                    .equalTo("silenced", false)
                    .equalTo("faultNumber", faultNumber)
                    .lessThanOrEqualTo("alarmedRTC", eventRTC)
                    .greaterThan("alarmedRTC", HistoryUtils.offsetRTC(eventRTC, -12 * 60 * 60))
                    .sort("alarmedDate", Sort.DESCENDING)
                    .findAll();

            if (results.size() == 0) {
                Log.d(TAG, String.format("*new* alarm (cleared) #%s", faultNumber));
                record = realm.createObject(PumpHistoryAlarm.class);
                record.pumpMAC = pumpMAC;
                record.eventDate = eventDate;
                record.faultNumber = faultNumber;
                record.clearedDate = eventDate;
                record.clearedRTC = eventRTC;
                record.clearedOFFSET = eventOFFSET;
                record.cleared = true;

            } else {
                Log.d(TAG, String.format("*update* alarm (cleared) #%s records=%s", faultNumber, results.size()));
                for (PumpHistoryAlarm item : results) {
                    item.clearedDate = eventDate;
                    item.clearedRTC = eventRTC;
                    item.clearedOFFSET = eventOFFSET;
                    item.cleared = true;
                    pumpHistorySender.setSenderREQ(item);
                    // is this the original alert?
                    if (!item.repeated) break;
                }
            }

        }
    }
 
Example 19
Source File: PumpHistoryAlarm.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
public static void alarm(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        int faultNumber,
        byte notificationMode,
        boolean alarmHistory,
        boolean extraData,
        byte[] alarmData) throws IntegrityException {

    PumpHistoryAlarm record;

    // check if a silenced alarm notification
    if (faultNumber == 110) {

        record = realm.where(PumpHistoryAlarm.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("alarmedRTC", eventRTC)
                .equalTo("alarmed", true)
                .equalTo("silenced", false)
                .findFirst();

        if (record != null) {
            Log.d(TAG, String.format("*update* alarm (silenced) #%s", record.faultNumber));
            pumpHistorySender.setSenderREQ(record);
        } else {
            Log.d(TAG, String.format("*new* alarm (silenced) #%s", faultNumber));
            record = realm.createObject(PumpHistoryAlarm.class);
            record.pumpMAC = pumpMAC;
            record.eventDate = eventDate;
            record.alarmedDate = eventDate;
            record.alarmedRTC = eventRTC;
            record.alarmedOFFSET = eventOFFSET;
            record.faultNumber = faultNumber;
        }

        record.silenced = true;
    }

    else {

        record = realm.where(PumpHistoryAlarm.class)
                .equalTo("pumpMAC", pumpMAC)
                .equalTo("alarmedRTC", eventRTC)
                .equalTo("alarmed", true)
                .equalTo("faultNumber", faultNumber)
                .findFirst();

        if (record == null) {
            // look for a cleared alarm
            RealmResults<PumpHistoryAlarm> results = realm.where(PumpHistoryAlarm.class)
                    .equalTo("pumpMAC", pumpMAC)
                    .equalTo("alarmed", false)
                    .equalTo("cleared", true)
                    .equalTo("faultNumber", faultNumber)
                    .greaterThanOrEqualTo("clearedRTC", eventRTC)
                    .lessThan("clearedRTC", HistoryUtils.offsetRTC(eventRTC, 12 * 60 * 60))
                    .sort("clearedDate", Sort.ASCENDING)
                    .findAll();
            if (results.size() == 0) {
                Log.d(TAG, String.format("*new* alarm #%s", faultNumber));
                record = realm.createObject(PumpHistoryAlarm.class);
                record.pumpMAC = pumpMAC;
            } else {
                Log.d(TAG, String.format("*update* alarm #%s", faultNumber));
                record = results.first();
            }

            record.eventDate = eventDate;

            record.alarmedDate = eventDate;
            record.alarmedRTC = eventRTC;
            record.alarmedOFFSET = eventOFFSET;
            record.alarmed = true;

            record.faultNumber = faultNumber;
            record.notificationMode = notificationMode;
            record.alarmHistory = alarmHistory;

            record.extraData = extraData;
            if (extraData && alarmData != null) record.alarmData = alarmData;

            // check if pump re-raised/escalated an alarm that is already recorded in the history
            if (!alarmHistory && notificationMode == 3) record.repeated = true;

            // key composed of 2 byte faultNumber and 4 byte eventRTC due to multiple alerts at the same time
            record.key = HistoryUtils.key("ALARM", (short) faultNumber, eventRTC);

            pumpHistorySender.setSenderREQ(record);
        }

        else HistoryUtils.integrity(record, eventDate);
    }
}
 
Example 20
Source File: PumpHistoryLoop.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
public static void transition(
        PumpHistorySender pumpHistorySender, Realm realm, long pumpMAC,
        Date eventDate, int eventRTC, int eventOFFSET,
        byte transitionValue,
        byte transitionReason) {

    PumpHistoryLoop record;

    switch (PumpHistoryParser.CL_TRANSITION_VALUE.convert(transitionValue)) {

        case CL_INTO_ACTIVE:
            record = realm.where(PumpHistoryLoop.class)
                    .equalTo("pumpMAC", pumpMAC)
                    .equalTo("eventRTC", eventRTC)
                    .equalTo("recordtype", RECORDTYPE.TRANSITION_IN.value())
                    .findFirst();
            if (record == null) {
                Log.d(TAG, "*new* loop transition in event");
                record = realm.createObject(PumpHistoryLoop.class);
                record.pumpMAC = pumpMAC;
                record.recordtype = RECORDTYPE.TRANSITION_IN.value();
                record.eventDate = eventDate;
                record.eventRTC = eventRTC;
                record.eventOFFSET = eventOFFSET;
                record.transitionValue = transitionValue;
                record.transitionReason = transitionReason;
                record.key = HistoryUtils.key("LOOP", eventRTC);
                pumpHistorySender.setSenderREQ(record);
            }
            break;

        case CL_OUT_OF_ACTIVE:
            record = realm.where(PumpHistoryLoop.class)
                    .equalTo("eventRTC", eventRTC)
                    .equalTo("pumpMAC", pumpMAC)
                    .equalTo("recordtype", RECORDTYPE.TRANSITION_OUT.value())
                    .findFirst();
            if (record == null) {
                Log.d(TAG, "*new* loop transition out event");
                record = realm.createObject(PumpHistoryLoop.class);
                record.pumpMAC = pumpMAC;
                record.recordtype = RECORDTYPE.TRANSITION_OUT.value();
                record.eventDate = eventDate;
                record.eventRTC = eventRTC;
                record.eventOFFSET = eventOFFSET;
                record.transitionValue = transitionValue;
                record.transitionReason = transitionReason;
                record.key = HistoryUtils.key("LOOP", eventRTC);
            }

    }
}