jeudi 13 août 2015

How to resolve huge byte[] issue in OrmLite

I have 2 tables Header and Binary

Header is smth like:

@DatabaseTable(tableName = Header.TABLE_NAME)
public class Header extends Table {
    @DatabaseField(
            generatedId = true,
            columnName = HEADER_ID,
            dataType = DataType.LONG_OBJ
    )
    private Long id;

    @ForeignCollectionField(orderColumnName = Binary.BINARY_ORDER, orderAscending = true)
    private Collection<Binary> binaries=new ArrayList<Binary>();
}

And Binary is:

@DatabaseTable(tableName = Binary.TABLE_NAME)
public class Binary {
    @DatabaseField(
            generatedId = true,
            columnName = BINARY_ID,
            dataType = DataType.LONG_OBJ)
    private Long id;

    @DatabaseField(
            columnName = BINARY_HEADER_ID,
            foreign = true,
            foreignAutoCreate = true,
            foreignAutoRefresh = true,
            //uniqueCombo = true,
            canBeNull = false, //there always must be a link to Item._ID
            columnDefinition = "integer constraint fk_4 references `"+ Header.TABLE_NAME+"`(`"+ Header.HEADER_ID+"`) on delete cascade"
    )
    private Header header=null;

    @DatabaseField(
            columnName = BINARY_ORDER,
            //uniqueCombo = true,
            canBeNull = false,
            dataType = DataType.INTEGER_OBJ,
            defaultValue = "0"
    )
    private Integer order =0;

    @DatabaseField(
            columnName = BINARY_CHUNK,
            dataType = DataType.BYTE_ARRAY)
    private byte[] chunk=null;
}

My problem is in byte[] chunk field, since size of each chunk is kind of 1 mb and their quantity is nearly unlimited, so when I will read Header record OrmLite would implicitly read Collection<Binary> list with huge content - so it might lead to memory depletion.

How should I declare my tables to overcome this issue?

Aucun commentaire:

Enregistrer un commentaire