Merge branch 'master' of ssh://oggio88.linuxd.org:2022/srv/git/jpacrepo
This commit is contained in:
@@ -32,7 +32,7 @@ dependencies {
|
||||
testCompile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.11.Final'
|
||||
testCompile 'org.jboss.resteasy:resteasy-jaxb-provider:3.0.11.Final'
|
||||
|
||||
testCompile files('/opt/wildfly/bin/client/jboss-client.jar')
|
||||
testCompile files('lib/jboss-client.jar')
|
||||
|
||||
}
|
||||
|
||||
|
@@ -11,13 +11,9 @@ import org.jpacrepo.pacbase.Parser;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.ejb.TransactionManagement;
|
||||
import javax.ejb.TransactionManagementType;
|
||||
import javax.ejb.*;
|
||||
import javax.enterprise.concurrent.ManagedThreadFactory;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
@@ -55,9 +51,10 @@ public class PacmanServiceEJB implements PacmanService
|
||||
|
||||
private Map<String, PkgData> knownPkg;
|
||||
|
||||
@PostConstruct
|
||||
@Schedule(hour = "3", minute = "00")
|
||||
public void syncDB()
|
||||
{
|
||||
logger.log(Level.INFO, "Starting repository cleanup");
|
||||
knownPkg = new HashMap<>();
|
||||
//Elimina i pacchetti sul DB che non esistono più nel filesystem
|
||||
try
|
||||
@@ -71,7 +68,7 @@ public class PacmanServiceEJB implements PacmanService
|
||||
File file = ctx.getFile(p);
|
||||
if (!file.exists())
|
||||
{
|
||||
logger.log(Level.INFO, String.format("Removing package %s", file.getName()));
|
||||
logger.log(Level.INFO, String.format("Removing package %s which was not found in filesystem", file.getName()));
|
||||
em.remove(p);
|
||||
}
|
||||
}
|
||||
@@ -106,11 +103,7 @@ public class PacmanServiceEJB implements PacmanService
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseFile2(Parser p, File file) throws Exception
|
||||
{
|
||||
|
||||
deleteOld();
|
||||
}
|
||||
|
||||
private void parseFile(Parser p, File file) throws Exception
|
||||
@@ -171,6 +164,7 @@ public class PacmanServiceEJB implements PacmanService
|
||||
|
||||
em.remove(pkg);
|
||||
ut.commit();
|
||||
logger.log(Level.INFO,String.format("Package %s has been deleted", filename));
|
||||
}
|
||||
|
||||
private class SyncWorker implements Runnable
|
||||
@@ -220,4 +214,30 @@ public class PacmanServiceEJB implements PacmanService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String deleteQuery = "SELECT p.fileName FROM PkgData p WHERE p.buildDate < :cutoff and p.name.id in \n" +
|
||||
"(SELECT p2.name.id FROM PkgData p2 GROUP BY p2.name.id HAVING count(p2.name.id) > :minVersions\n)";
|
||||
|
||||
private void deleteOld()
|
||||
{
|
||||
TypedQuery<String> query = em.createQuery(deleteQuery, String.class);
|
||||
Calendar cutoff = Calendar.getInstance();
|
||||
cutoff.add(Calendar.YEAR, -2);
|
||||
query.setParameter("cutoff", cutoff.getTime());
|
||||
query.setParameter("minVersions", (long)2);
|
||||
List<String> list = query.getResultList();
|
||||
logger.log(Level.INFO, "Removing obsolete packages");
|
||||
list.forEach((el) -> {
|
||||
try
|
||||
{
|
||||
deletePackage(el);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user