0

I have this object that I need to save in a database. Until now I always worked with MySQL but it's really hard to use it for some structures (LinkedList, Hashmap etc...) I want to save it in a database that somehow I will be able to use those object in php too, without hard difficulties...

public class Group {
    private String name = null;
    private LinkedList<Question> track = null;
    private Date startTime = null;
    private Date endTime = null;
    private HashMap<Question, Bitmap> imagePerQuestion;

    public String getName() {
        return name;
    }

    public LinkedList<Question> getTrack() {
        if (startTime == null)
            //First time that you get the track it assigns the startTime
            startTime = new Date();
        return track;
    }

    public Date getStartTime() {
        return startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setFinish(){
        if (endTime == null && startTime != null){
            endTime = new Date();
        }
    }

    public Group(LinkedList<Question> track){
        this.track = track;
        this.imagePerQuestion = new HashMap<>();
    }
}

One thing that is important to say is that my client uses java, but the server (which handles the database) will probably work with php.

If it's really hard/impossible to work with php, I'll be glad to hear about a java-based web framework that will do the job.

Itay
  • 337
  • 5
  • 22
  • It is not normal, except under exceptional circumstances, to save PHP classes in a database. It's not difficult, it is just unusual. Normally you save data like, integers, strings, and the like, in database fields. – KIKO Software Mar 20 '15 at 12:23
  • This is a java class, and working on mysql using LinkedList for example is extremley hard, it's just not built for this. but I need to store this object somehow... – Itay Mar 20 '15 at 12:27
  • Ah, sorry, it would look virtually the same if it was PHP. In PHP you can store objects with `serialize()`. See: http://php.net/manual/en/function.serialize.php You could try to see if there's an equivalent in Java. – KIKO Software Mar 20 '15 at 12:29
  • I thought about this option, but the major problem with it is the fact that the server uses PHP and the client uses Java, and the serialization isn't the same between two different languages. This is why I'm also considering using Java-based web framework. – Itay Mar 20 '15 at 12:33
  • Yes, if will be exceedingly hard to exchange objects between PHP and Java. They may look virtually the same, but there must be many subtle differences. My advice would be not to exchange, or store, the object, but only the data you need to reconstruct the object in either language. – KIKO Software Mar 20 '15 at 12:57

3 Answers3

0

You may consider NoSQL database, but that depends on your requierments. Typically, NoSQL databases (Such as Redis, HBase...) have limited query capabilities.

Do you just need to store your objects or to perform complex queries on them?

Nassim
  • 1
  • 4
  • I need to preform queries on them too, If I wouldn't I would just store a serialised version of them... for example I need to have a query that will be able to push a new key and value to imagePerQuestion Hashmap – Itay Mar 20 '15 at 12:29
0

Check this post regarding PHP and ORM : PHP developer looking for solutions equivalent to Java EE architecture

Maybe you should also consider a REST service, so the PHP does not need to handle the objects directly.

Community
  • 1
  • 1
Nassim
  • 1
  • 4
-1

Not many things are impossible. You could you Hibernate or a JPA implementation like EclipseLink to save your objects into the database via ORM (Object-Relational-Mapping). This can create database structures that you can also read in PHP.

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58