001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.legacy.soda.experiments;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025: import com.db4o.test.legacy.soda.*;
026: import com.db4o.test.legacy.soda.experiments.*;
027:
028: public class STIdentityEvaluation implements STClass1 {
029:
030: public static transient SodaTest st;
031:
032: public Object[] store() {
033:
034: Helper helperA = new Helper("aaa");
035:
036: return new Object[] { new STIdentityEvaluation(null),
037: new STIdentityEvaluation(helperA),
038: new STIdentityEvaluation(helperA),
039: new STIdentityEvaluation(helperA),
040: new STIdentityEvaluation(new HelperDerivate("bbb")),
041: new STIdentityEvaluation(new Helper("dod")) };
042: }
043:
044: public Helper helper;
045:
046: public STIdentityEvaluation() {
047: }
048:
049: public STIdentityEvaluation(Helper h) {
050: this .helper = h;
051: }
052:
053: public void test() {
054: Query q = st.query();
055: Object[] r = store();
056: q.constrain(new Helper("aaa"));
057: ObjectSet os = q.execute();
058: Helper helperA = (Helper) os.next();
059: q = st.query();
060: q.constrain(STIdentityEvaluation.class);
061: q.descend("helper").constrain(helperA).identity();
062: q.constrain(new Evaluation() {
063: public void evaluate(Candidate candidate) {
064: candidate.include(true);
065: }
066: });
067: st.expect(q, new Object[] { r[1], r[2], r[3] });
068: }
069:
070: public void testMemberClassConstraint() {
071: Query q = st.query();
072: Object[] r = store();
073: q.constrain(STIdentityEvaluation.class);
074: q.descend("helper").constrain(HelperDerivate.class);
075: st.expect(q, new Object[] { r[4] });
076: }
077:
078: public static class Helper {
079:
080: public String hString;
081:
082: public Helper() {
083: }
084:
085: public Helper(String str) {
086: hString = str;
087: }
088: }
089:
090: public static class HelperDerivate extends Helper {
091: public HelperDerivate() {
092: }
093:
094: public HelperDerivate(String str) {
095: super(str);
096: }
097:
098: }
099:
100: }
|