01: /*
02: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: All rights reserved - see end of file.
04: $Id: MockTransactionModel.java,v 1.9 2008/01/03 15:18:54 chris-dollin Exp $
05: */
06:
07: package com.hp.hpl.jena.assembler.test;
08:
09: import java.util.List;
10:
11: import com.hp.hpl.jena.assembler.*;
12: import com.hp.hpl.jena.assembler.assemblers.ModelAssembler;
13: import com.hp.hpl.jena.graph.Factory;
14: import com.hp.hpl.jena.rdf.model.*;
15: import com.hp.hpl.jena.rdf.model.impl.ModelCom;
16:
17: /**
18: A model assembler that creates a model with controllable supporting of
19: transactions and aborting on adding statements; the model logs transactions
20: and adding-of-models. For testing only.
21: @author kers
22: */
23: final class MockTransactionModel extends ModelAssembler {
24: private final List history;
25: private final Model expected;
26: private final boolean supportsTransactions;
27: private final boolean abortsOnAdd;
28:
29: protected MockTransactionModel(List history, Model expected,
30: boolean supportsTransactions, boolean abortsOnAdd) {
31: super ();
32: this .history = history;
33: this .expected = expected;
34: this .supportsTransactions = supportsTransactions;
35: this .abortsOnAdd = abortsOnAdd;
36: }
37:
38: protected Model openEmptyModel(Assembler a, Resource root,
39: Mode irrelevant) {
40: return new ModelCom(Factory.createDefaultGraph()) {
41: public Model begin() {
42: history.add("begin");
43: TestModelContent.assertTrue(isEmpty());
44: return this ;
45: }
46:
47: public Model add(Model other) {
48: history.add("add");
49: if (abortsOnAdd)
50: throw new RuntimeException(
51: "model aborts on add of " + other);
52: super .add(other);
53: return this ;
54: }
55:
56: public Model abort() {
57: history.add("abort");
58: return this ;
59: }
60:
61: public Model commit() {
62: TestModelContent.assertIsoModels(expected, this );
63: history.add("commit");
64: return this ;
65: }
66:
67: public boolean supportsTransactions() {
68: history.add("supports[" + supportsTransactions + "]");
69: return supportsTransactions;
70: }
71: };
72: }
73: }
74:
75: /*
76: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
77: * reserved.
78: *
79: * Redistribution and use in source and binary forms, with or without
80: * modification, are permitted provided that the following conditions are met:
81: * 1. Redistributions of source code must retain the above copyright notice,
82: * this list of conditions and the following disclaimer. 2. Redistributions in
83: * binary form must reproduce the above copyright notice, this list of
84: * conditions and the following disclaimer in the documentation and/or other
85: * materials provided with the distribution. 3. The name of the author may not
86: * be used to endorse or promote products derived from this software without
87: * specific prior written permission.
88: *
89: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
90: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
91: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
92: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
93: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
94: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
95: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
96: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
97: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
98: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99: */
|