// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

public class ListAfter6 {
    public static void main(String[] args) throws Exception {
        Logger.getLogger("org.hibernate").setLevel(Level.OFF);
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Asset");
        EntityManager em = emf.createEntityManager();
        TypedQuery<AssetJPA> q = em.createQuery("SELECT o FROM AssetJPA AS o", AssetJPA.class);
        List<AssetJPA> res = q.getResultList();
        for(AssetJPA o : res) {
            if(o instanceof TruckAssetJPA) {
                TruckAssetJPA o2 = (TruckAssetJPA)o;
                System.out.printf("%d %s %s %s %d\n", o2.getId(), o2.getDescription(), o2.getModel(), o2.getLicense(), o2.getTowcapacity());
            }
            if(o instanceof TrailerAssetJPA) {
                TrailerAssetJPA o2 = (TrailerAssetJPA)o;
                System.out.printf("%d %s %d %d %d\n", o2.getId(), o2.getDescription(), o2.getOwnWeight(), o2.getMaxCargo(), o2.getRoof());
            }
            if(o instanceof ToolAssetJPA) {
                ToolAssetJPA o2 = (ToolAssetJPA)o;
                System.out.printf("%d %s %s %s %d\n", o2.getId(), o2.getDescription(), o2.getToolType(), o2.getName(), o2.getWeight());
            }
        }
        em.close();
        emf.close();
    }
}
