Package org.objectweb.speedo.pobjects.tck

Source Code of org.objectweb.speedo.pobjects.tck.InstanceCallbackNonPersistFdsClass$KeyClass

/*
* Copyright 2001 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/

package org.objectweb.speedo.pobjects.tck;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;

import javax.jdo.Extent;
import javax.jdo.InstanceCallbacks;
import javax.jdo.PersistenceManager;

class InstanceCallbackNonPersistFdsClass implements InstanceCallbacks {
    public int i;      // non-managed
    public char c;     // non-managed
    double d;           // transactional
    short s;            // transactional
    HashSet children;   // non-managed
    Date loadTime;      // non-managed
   
    private int keyValue;  // persistent--used as key field in application identity
    float floatValue; // persistent
    int intValue;  // persistent  --primary key field
   
    static private int nextKeyValue = 1;
   
    static int savedIntValue;
    static float savedFloatValue;
   
    static Date savedLoadTime;
    static String member1 = "one";
    static String member2 = "two";
    static String member3 = "three";
   
    static boolean preClearCalled = false;
    static boolean preStoreCalled = false;
    static boolean preDeleteCalled = false;
    static boolean postloadCalled = false;
    static boolean postloadCalledMultipleTimes = false;
   
    // used in CallingJdoPostload test
    static int beforeGetObjectById = 1;
    static int afterGetObjectById = 2;
    static int savedApplicationStep;
    static int applicationStep;  // values are 0, beforeGetObjectById and afterGetObjectById
   
    // used in ModificationOfNontransactionalNonpersistentFields test
    static ArrayList exceptions = new ArrayList();
    static ArrayList callbackCalled = new ArrayList();
    static ArrayList attributeOpCausingExceptions = new ArrayList();

    static void initializeStaticsForTest()
    {
        savedIntValue = 0;
        savedFloatValue = 0.0f;
        savedLoadTime = null;  
        preClearCalled = false;
        preStoreCalled = false;
        preDeleteCalled = false;
        postloadCalled = false;
        postloadCalledMultipleTimes = false;
        savedApplicationStep = 0;
        applicationStep = 0;
   
        exceptions = new ArrayList();
        callbackCalled = new ArrayList();
        attributeOpCausingExceptions = new ArrayList();
    }   

    static void removeAllInstances(PersistenceManager pm)
    {
        Extent e = pm.getExtent(org.objectweb.speedo.pobjects.tck.InstanceCallbackNonPersistFdsClass.class, true);
        Iterator it = e.iterator();
        while( it.hasNext() ){
            pm.deletePersistent(it.next());
        }       
    }

    InstanceCallbackNonPersistFdsClass()
    {
    }
   
    InstanceCallbackNonPersistFdsClass(float floatValue,int intValue) {
        keyValue = nextKeyValue++;
        this.floatValue = floatValue;
        this.intValue = intValue;
    }
   
    void setNonPersist(int i, char c, double d, short s) {
        this.i = i;
        this.c = c;
        this.d = d;
        this.s = s;
    }
    void setNonManaged(int i, char c) {
        this.i = i;
        this.c = c;
    }
   
    int calcIntValue() {
        return i * c;
    }
   
    float calcFloatValue () {
        return (float)(d * s);
    }
   
    void incrementIntValue() {
        intValue++;
    }
   
    public void jdoPreStore() {
        preStoreCalled = true;
        intValue = calcIntValue();
        floatValue = calcFloatValue();
       
        try {
            i = -30;
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("i = -30;");
        }
        try {
            c = '\u0000';
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("c = '\u0000';");
        }
        try {
            d = 362.5;
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("d = 362.5;");
        }
        try {
            s = 0;
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("s = 0;");
        }
        try {
            loadTime = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("loadTime = null;");
        }
        try {
            children = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreStore ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("children = null;");
        }
    }
   
    public void jdoPreDelete() {
        preDeleteCalled = true;
        try {
            i = 0;
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("i = 0;");
        }
        try {
            c = 'x';
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("c = 'x';");
        }
        try {
            d = 0.0;
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("d = 0.0;");
        }
        try {
            s = -5;
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("s = -5;");
        }
        try {
            loadTime = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("loadTime = null;");
        }
        try {
            children = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreDelete ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("children = null;");
        }
    }
   
    public void jdoPostLoad() {
        postloadCalled = true;
        savedApplicationStep = applicationStep;
        i = -10;
        c = '2';
        d = 30.0;
        s = 40;
        savedIntValue = intValue;
        savedFloatValue = floatValue;
        loadTime = new Date();
        savedLoadTime = loadTime;
        children = new HashSet();
        children.add(member1);
        children.add(member2);
        children.add(member3);
    }
   
    public void jdoPreClear() {
        preClearCalled = true;
        try {
            i = 1;
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("i = 1;");
        }
        try {
            c = '2';
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("c = '2';");
        }
        try {
            d = 3.0;
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("d = 3.0;");
        }
        try {
            s = 4;
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("s = 4;");
        }
        try {
            loadTime = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("loadTime = null;");
        }
        try {
            children = null;
        }catch(Exception e) {
            callbackCalled.add("jdoPreClear ");
            exceptions.add(e);
            attributeOpCausingExceptions.add("children = null;");
        }
    }
   
public static class KeyClass implements Serializable {
    public int keyValue;

    public KeyClass() {
    }

    public KeyClass(String s) {
        try{ keyValue = Integer.parseInt(s);}
        catch(NumberFormatException e){
            keyValue = 0;}
    }   
   
    public boolean equals(Object obj) {
        if( obj == null || !this.getClass().equals(obj.getClass()) ) return false;
        else return keyValue == ((KeyClass)obj).keyValue;
    }
   
    public int hashCode() {
        return keyValue;
    }

    public String toString() {
        return Integer.toString(keyValue);
    }
}
}
TOP

Related Classes of org.objectweb.speedo.pobjects.tck.InstanceCallbackNonPersistFdsClass$KeyClass

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.