Package secondarytable

Source Code of secondarytable.Main

/**
* Copyright (C) 2001-2006 France Telecom R&D
*/
package secondarytable;

import org.objectweb.util.monolog.api.BasicLevel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import common.MainHelper;

public class Main extends MainHelper {

    public static void main(String[] args) {
        new Main().init(args).run().end();
    }
   
    public MainHelper run() {
        final int size = 5;
        List as = getData(size);
        logger.log(BasicLevel.INFO, "Create " + size + "' multi table addresses :" + as);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistentAll(as);
        pm.currentTransaction().commit();
       
        logger.log(BasicLevel.INFO, "Empty Cache.");
        as = null;
        pm.evictAll();
       
        pm.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Find all multi table addresses.");
        Query q = pm.newQuery(Address.class);
        Collection c = (Collection) q.execute();
        for (Iterator it = c.iterator(); it.hasNext();) {
            Address a = (Address) it.next();
            logger.log(BasicLevel.INFO, "- Address found:" + a.toString());
        }
        as = new ArrayList(c);
        q.closeAll();
        pm.currentTransaction().commit();
       
        pm.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Delete " + as.size() + " multi table addresses.");
        pm.deletePersistentAll(as);
        pm.currentTransaction().commit();
        pm.close();
        return this;
    }
   
    private List getData(final int size) {
        List as = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            Address a = new Address();
            a.setCity("city_"+ i);
            a.setDeliveryInstructions("deliv_"+ i);
            byte[] map = new byte[20 * (i+1)];
            for (int j = 0; j < map.length; j++) {
                map[j] = (byte) i;
            }
            a.setMapJPG(map);
            a.setSignatureRequired(i % 2 == 1);
            a.setState("state_" + i);
            a.setStreet("street_" + i);
            a.setZip("zip_" + i);
            as.add(a);
        }
        return as;
    }   
}
TOP

Related Classes of secondarytable.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.