package net.straininfo2.grs.idloader.db;

import net.straininfo2.grs.idloader.bioproject.domain.AdminBioProject;
import net.straininfo2.grs.idloader.bioproject.domain.BioProject;
import net.straininfo2.grs.idloader.bioproject.domain.SubmissionBioProject;
import net.straininfo2.grs.idloader.bioproject.xmlparsing.DomainHandler;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class BioProjectLoader implements DomainHandler {

    // TODO: ADD CLEANUP OF ORGANISM ONE-TO-ONEs (elsewhere)
    /*
    OrganismMorphology
    OrganismEnvironment
    OrganismPhenotype
    OrganismSample
     */
    @Autowired
    SessionFactory sessionFactory;

    private int count = 0;

    public BioProjectLoader() {

    }

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    private void updateCount() {
        if (count++ % 30 == 0) {
            sessionFactory.getCurrentSession().flush();
        }
    }

    @Override
    public void processBioProject(BioProject project) {
        sessionFactory.getCurrentSession().merge(project);
        updateCount();
    }

    @Override
    public void processAdminBioProject(AdminBioProject project) {
        sessionFactory.getCurrentSession().merge(project);
        updateCount();
    }

    @Override
    public void processSubmissionBioProject(SubmissionBioProject project) {
        sessionFactory.getCurrentSession().merge(project);
        updateCount();
    }
}

@@ -358,16 +358,73 @@
 actory;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -478,16 +478,16 @@
 owired;%0A
-
 %0Apublic 
@@ -780,16 +780,104 @@
 t = 0;%0A%0A
+    private final static Logger logger = LoggerFactory.getLogger(DomainHandler.class);%0A%0A
     publ
@@ -1315,32 +1315,106 @@
 ject project) %7B%0A
+        logger.info(%22Saving project with ID %7B%7D%22, project.getProjectId());%0A
         sessionF
@@ -1558,32 +1558,106 @@
 ject project) %7B%0A
+        logger.info(%22Saving project with ID %7B%7D%22, project.getProjectId());%0A
         sessionF
@@ -1735,32 +1735,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -1811,32 +1811,106 @@
 ject project) %7B%0A
+        logger.info(%22Saving project with ID %7B%7D%22, project.getProjectId());%0A
         sessionF

add some logging while loading database