Weaved methods (only valid to version 1.0.1)

When you execute the Floggy they weave 2 fields and 5 methods into the entity class. These class members are used to store and retrieved the entities from the RMS system. Below is the entity and its members weaved by Floggy.

The sample entity:

package net.sourceforge.floggy.persistence.model;

import java.util.Date;
import net.sourceforge.floggy.persistence.Persistable;

public class Frog implements Persistable {
        
        private String name;
        private Date bornDate;
        private char sex;

        ...
}

Now we present the members generated by the Floggy weaver:

  1. This field identifies uniquely the data represented by this entity on the RMS system. It is like a primary key on RDBMS systems.
    private int __id = -1;
  2. This field represents the metadata of this entity.
    private final static net.sourceforge.floggy.persistence.PersistableMetadata __persistableMetadata = 
            new net.sourceforge.floggy.persistence.PersistableMetadata("Frog-1820871197");
  3. This methods is used to retrieve the metadata field.
    public net.sourceforge.floggy.persistence.PersistableMetadata __getPersistableMetadata() {
        return __persistableMetadata;
    }
  4. This method is responsible to initialize the entity with the values retrieved from the byte array. It know the order and type of the fields serialized in the byte array.
    public void __load(byte[] buffer) throws java.lang.Exception {
        java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(buffer);
        java.io.DataInputStream dis = new java.io.DataInputStream(bais);
        if(dis.readByte() == 0) {
            this.name = dis.readUTF();
        }
        else {
            this.name = null;
        }
        if(dis.readByte() == 0) {
            this.bornDate = new java.util.Date(dis.readLong());
        }
        else {
            this.bornDate = null;
        }
        this.sex = dis.readChar();
        dis.close();
    }
  5. This method is responsible to initialize the entity. First the byte array are retrieved from the RMS system using the id parameter and than the entity are initialized using the __load method above.
    public void __load(int id) throws java.lang.Exception {
        javax.microedition.rms.RecordStore rs = 
            net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
        byte[] buffer = rs.getRecord(id);
        rs.closeRecordStore();
        this.__load(buffer);
        this.__id = id;
    }
  6. This method is responsible to store the entity in the RMS sytem. The order and type of the fields are the same used in the __load(byte[]) method..
    public int __save() throws java.lang.Exception {
        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
        java.io.DataOutputStream dos = new java.io.DataOutputStream(baos);
        javax.microedition.rms.RecordStore rs = 
            net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
        if(this.name == null) {
            dos.writeByte(1);
        }
        else {
            dos.writeByte(0);
            dos.writeUTF(this.name);
        }
        if(this.bornDate == null) {
            dos.writeByte(1);
        }
        else {
            dos.writeByte(0);
            dos.writeLong(this.bornDate.getTime());
        }
        dos.writeChar(this.sex);
        if(this.__id == -1) {
            this.__id = rs.addRecord(baos.toByteArray(), 0, baos.size());
        }
        else {
            rs.setRecord(this.__id, baos.toByteArray(), 0, baos.size());
        }
        rs.closeRecordStore();
        dos.close();
        return this.__id;
    }
  7. This method is responsible to delete the entity from the RMS system.
    public void __delete() throws java.lang.Exception {
        if (this.__id != -1) {
            javax.microedition.rms.RecordStore rs = 
                    net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
            rs.deleteRecord(this.__id);
            rs.closeRecordStore();
        }
    }