10-29-2007 01:53 PM
package client;
import java.io.File;
import java.util.List;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import entity.AvmNode;
public class Client {
private static Logger log = Logger.getLogger("Client");
private static EntityManagerFactory emf;
private static EntityManager em;
private static String pathSeparator = System.getProperty("file.separator").toString();
private static String baseDirectory = "/opt/alfresco-community-tomcat-2.1.0/alf_data/contentstore";
public static void main(String[] args) {
try {
emf = Persistence.createEntityManagerFactory("alfresco-jpa-check-db");
createEntityManager();
log.info("Check the files:");
checkFiles(new File(baseDirectory), true, "");
log.info("Check the table:");
checkAvmNodes(new File(baseDirectory));
closeEntityManager();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void createTransactionalEntityManager() {
// Create a new EntityManager
em = emf.createEntityManager();
// Begin transaction
em.getTransaction().begin();
}
private static void closeTransactionalEntityManager() {
// Commit the transaction
em.getTransaction().commit();
// Close this EntityManager
em.close();
}
private static void createEntityManager() {
// Create a new EntityManager
em = emf.createEntityManager();
}
private static void closeEntityManager() {
// Close this EntityManager
em.close();
}
public static void checkAvmNodes(File directory) {
List <AvmNode> list = null;
try {
Query q = em.createQuery("select c from AvmNode c");
list = q.getResultList();
for (AvmNode entry : list) {
if (entry.getClassType() != null && "plainfile".equals(entry.getClassType())) {
StringBuilder sb = new StringBuilder();
sb.append(directory.getAbsolutePath());
sb.append(entry.getContentUrl().substring(7));
File f = new File(sb.toString());
if (! f.exists()) {
log.severe(f.getAbsolutePath() + " file doesn't exist");
} else {
if (f.length() != entry.getLength().longValue()) {
log.severe(f.getAbsolutePath() + " size doesn't match");
} else {
log.info(f.getAbsolutePath());
}
}
}
}
} catch (javax.persistence.NoResultException e) {
// System.out.println(name + " not found");
}
}
public static void checkFiles(File directory, boolean recurse, String path) {
File[] entries = directory.listFiles();
for (File entry : entries) {
if (!entry.isDirectory()) {
StringBuilder sb = new StringBuilder();
sb.append("%").append(path).append(pathSeparator).append(entry.getName());
List <AvmNode> list = findAvmNodes(sb.toString());
if (list.size() == 0) {
StringBuilder sbfile = new StringBuilder();
sbfile.append(entry.getAbsoluteFile());
sbfile.append(" ").append(entry.length());
log.severe(sbfile.toString());
}
}
else if (recurse) {
checkFiles(entry, recurse, path + pathSeparator + entry.getName());
}
}
}
@SuppressWarnings("unchecked")
private static List <AvmNode> findAvmNodes(String name) {
List <AvmNode> list = null;
try {
Query q = em.createQuery("select c from AvmNode c where c.contentUrl like :name");
q.setParameter("name", name);
list = q.getResultList();
} catch (javax.persistence.NoResultException e) {
// System.out.println(name + " not found");
}
return list;
}
}
11-01-2007 08:39 PM
org.alfresco.repo.content.cleanup.ContentStoreCleaner
The store will contain content that is (a) orphaned but not old enough or (b) managed by the regular document management side of things (the content lifecycle).
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.