2

I have a complicated structure (ArrayList of specific Class which inherits other Class) that I use as part of my calculations.

The thing is that sometimes I want to reuse the data inside this structure again in another time (i.e. after 1 week).

I tried to extend current tables or even create a new table but it didn't work out.

I want to find a way to store this data for future using.

I don't mind to store it in the database but only as-is, and not split it to all the variables types.

The code itself it's quite huge but here is a small example of the idea behind the complexity of the structure (The structure is more complicated):

public class A<T extends B> {
    private DataTable<T> table = null;
    private List<?>[] minimalCommonSets = null;
    private Handler[] allHandlers;
}


public class DataTable<T extends TableElement> {

    private TableElement[] table;
    private int[] size;
}


public abstract class TableElement {

}

public abstract class Handler<T, S>  {

}

public class C extends B {

    private int N;

    private Set<String> S1;


    private Set<String> S2;

    private List<D> d;

    protected E e;
}


private A<C> STORE_IT;

I want to store an instance of A (STORE_IT).

Dvir
  • 301
  • 1
  • 2
  • 16
  • 2
    Is it serializable? you could also use something like gson to create a Json representation if the classes contained are simple enough. – Assafs Jan 07 '19 at 09:58
  • It would be easier to answer if you provide source code. – Bsquare ℬℬ Jan 07 '19 at 09:59
  • @Bsquare - I wanted but it's quite complicated... I tried to build a demo (mini-structure) of my code. hope it will be clear enough. – Dvir Jan 07 '19 at 10:35
  • @Assafs - right now it's not. I thought about the GSON but it's a huge amount of data, and the JSON will be very very big... is it something that acceptable? – Dvir Jan 07 '19 at 10:35
  • Do you want to persist the data model, or the data themself? – Bsquare ℬℬ Jan 07 '19 at 10:44
  • @Bsquare Only data. – Dvir Jan 07 '19 at 10:54
  • OK, what do you mean by 'huge amount of data'? If it is so huge, you should consider using a Buffered system, to dump data in a file, or a database, iteratively, instead of all at once (which may lead to too high Memory consumption). – Bsquare ℬℬ Jan 07 '19 at 13:27
  • I never extract this data so I don't really know what its size, but I assume it's quite big. maybe the JSON conversion will surprise me. anyway - now I'm getting IllegalArgumentException as probably one of the subclasses is making some trouble... – Dvir Jan 07 '19 at 13:59
  • 1
    Do you need to "see" the data in the Database? If not just serialize it as a byte array and store it as BLOB (binara large object). Take a look here for serialization: https://stackoverflow.com/questions/2836646/java-serializable-object-to-byte-array For BLOB look here: https://stackoverflow.com/questions/29511133/what-is-the-significance-of-javax-persistence-lob-annotation-in-jpa – Andreas Hauschild Jan 07 '19 at 15:49
  • @AndreasHauschild - No, I don't need to see. sounds good actually. just a question - if I have a lot of subclasses, including abstracts and interfaces - do I need to serialize each one of them..? 'cause due to the complexity of the structure, I don't think I can... – Dvir Jan 08 '19 at 05:53
  • 1
    @Dvir If you serialize your root object everything which belongs to it will be serialized too. – Andreas Hauschild Jan 08 '19 at 07:37

2 Answers2

0

Possible solutions could be Serialization and Database.

Gson Serialization Library would be my goto for this kind of scenarios. (It is typesafe and handles both serialization and deserialization) https://github.com/google/gson

AagitoEx
  • 484
  • 2
  • 8
  • I thought about the GSON but it's a huge amount of data, and the JSON will be very very big... is it something that acceptable? – Dvir Jan 07 '19 at 10:43
  • are we talking of MB's (1-10MB's) of huge or like 1-10 nested Objects with avg of 10 - 50 params?? I think gson can handle such situattion with breeze, given the fact that it can deserialize for you without any extra work .... – AagitoEx Jan 14 '19 at 07:22
  • interesting actually - does GSON has an advantage over BYTE? (I don't need it to be readable in the DB) – Dvir Jan 16 '19 at 11:31
  • Than you could go for SQLite or any DB with java ORM toolchain available... – AagitoEx Jan 17 '19 at 13:54
0

One solution can be convert the data in Json and store it in a new table in db . When ever data is required Json parsers can be used to again create the complex data structure after retrieving the json from db.

VKR
  • 64
  • 4