From: Tuukka Lehtonen Date: Fri, 20 Jan 2017 08:59:51 +0000 (+0200) Subject: Added missing org.simantics.db.{tests,testing} plug-ins. X-Git-Tag: v1.27.0~14 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=67fd62f9c742337ec80eef658192db198a0efaac;p=simantics%2Fplatform.git Added missing org.simantics.db.{tests,testing} plug-ins. These were previously only in SVN trunk which is now locked and they failed to compile after the recent changes. refs #6994 --- diff --git a/bundles/org.simantics.db.testing/.classpath b/bundles/org.simantics.db.testing/.classpath new file mode 100644 index 000000000..d280a5aa3 --- /dev/null +++ b/bundles/org.simantics.db.testing/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.db.testing/.project b/bundles/org.simantics.db.testing/.project new file mode 100644 index 000000000..5d5910997 --- /dev/null +++ b/bundles/org.simantics.db.testing/.project @@ -0,0 +1,28 @@ + + + org.simantics.db.testing + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.db.testing/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.db.testing/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..f42de363a --- /dev/null +++ b/bundles/org.simantics.db.testing/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF new file mode 100644 index 000000000..0846e8c8a --- /dev/null +++ b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DB Testing Support +Bundle-SymbolicName: org.simantics.db.testing +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Semantum Oy +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.simantics.db.layer0;bundle-version="1.1.0", + org.simantics.graph.db;bundle-version="1.1.5";visibility:=reexport, + org.simantics.project;bundle-version="1.0.1";visibility:=reexport, + org.apache.log4j;bundle-version="1.2.15", + org.simantics.db.procore;bundle-version="1.1.1", + org.simantics.db.services;bundle-version="1.1.0", + org.eclipse.core.runtime;bundle-version="3.6.0", + org.simantics.workbench;bundle-version="1.1.0", + org.simantics.db.management;bundle-version="1.1.0", + org.simantics;bundle-version="1.0.0";visibility:=reexport, + org.simantics.scl.osgi;bundle-version="1.0.4", + org.junit;bundle-version="4.12.0", + org.simantics.db.server, + org.apache.commons.math3 +Export-Package: org.simantics.db.testing.annotation, + org.simantics.db.testing.base, + org.simantics.db.testing.cases, + org.simantics.db.testing.common, + org.simantics.db.testing.impl +Bundle-ClassPath: . diff --git a/bundles/org.simantics.db.testing/build.properties b/bundles/org.simantics.db.testing/build.properties new file mode 100644 index 000000000..34d2e4d2d --- /dev/null +++ b/bundles/org.simantics.db.testing/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Always.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Always.java new file mode 100644 index 000000000..fc6a82c6b --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Always.java @@ -0,0 +1,10 @@ +package org.simantics.db.testing.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +@Retention(RetentionPolicy.RUNTIME) +public @interface Always { + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Fails.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Fails.java new file mode 100644 index 000000000..b6b42541b --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Fails.java @@ -0,0 +1,10 @@ +package org.simantics.db.testing.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +@Retention(RetentionPolicy.RUNTIME) +public @interface Fails { + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Obsolete.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Obsolete.java new file mode 100644 index 000000000..f78c40087 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/annotation/Obsolete.java @@ -0,0 +1,10 @@ +package org.simantics.db.testing.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +@Retention(RetentionPolicy.RUNTIME) +public @interface Obsolete { + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/AllowedThrowable.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/AllowedThrowable.java new file mode 100644 index 000000000..627cba148 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/AllowedThrowable.java @@ -0,0 +1,5 @@ +package org.simantics.db.testing.base; + +public interface AllowedThrowable { + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandList.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandList.java new file mode 100644 index 000000000..0ae4648fc --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandList.java @@ -0,0 +1,9 @@ +package org.simantics.db.testing.base; + +import org.simantics.db.testing.common.Command; + +public interface CommandList { + + T add(T command); + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandListImpl.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandListImpl.java new file mode 100644 index 000000000..d24633956 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandListImpl.java @@ -0,0 +1,21 @@ +package org.simantics.db.testing.base; + +import java.util.ArrayList; + +import org.simantics.db.testing.common.Command; + +public class CommandListImpl implements CommandList { + + public ArrayList commands = new ArrayList(); + + @Override + public T add(T command) { + commands.add(command); + return command; + } + + public Command[] toArray() { + return commands.toArray(new Command[commands.size()]); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandSequenceTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandSequenceTest.java new file mode 100644 index 000000000..f1d21c448 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/CommandSequenceTest.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.testing.base; + +import gnu.trove.list.array.TLongArrayList; + +import org.apache.commons.math3.stat.regression.SimpleRegression; +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.cases.FreshDatabaseTest; +import org.simantics.db.testing.common.Command; +import org.simantics.db.testing.common.CommandSequenceEnvironment; +import org.simantics.db.testing.common.CommandSpec; + + +/** + * + * @author Antti Villberg + * + */ +abstract public class CommandSequenceTest extends FreshDatabaseTest implements CommandSequenceEnvironment { + + private static final boolean TRACE = true; + + protected TLongArrayList executionTimes = new TLongArrayList(); + + protected double getSlowdown() { + + SimpleRegression regression = new SimpleRegression(); + for(int i=0;i[] getFactories() { + return null; + } + + @Override + public Session getSession() { + return super.getSession(); + } + + public int randomNatural() { + return (int)(Math.random() * Integer.MAX_VALUE); + } + + protected Command[] newSequence() throws Exception { + int size = getSequenceSize(); + CommandSpec[] classes = getFactories(); + int index = 0; + Command[] result = new Command[size]; + double totalWeight = 0; + for(CommandSpec p : classes) totalWeight += p.weight; + double[] wts = new double[classes.length]; + index=0; + double previous = 0; + for(CommandSpec p : classes) { + double weight = p.weight/totalWeight; + wts[index++] = previous + weight; + previous += weight; + } + + for(int i=0;i lastProgress) { + System.err.println("[" + counter + "/" + sequence.length + "]: " + progress + "%"); + lastProgress = progress; + } + } + + for(Command command : afterSequence(environment)) { + command.run(environment); + } + + analyse(environment); + + } + + public void invoke(CommandSequenceEnvironment environment, Command command) { + try { + command.run(environment); + } catch (Throwable t) { + if(!isAllowed(t)) { + throw new AssertionError(t); + } + } + } + + boolean isAllowed(Throwable t) { + if(t instanceof AllowedThrowable) return true; + if(t instanceof DatabaseException) { + DatabaseException d = (DatabaseException)t; + if(d.getCause() instanceof AllowedThrowable) return true; + } + return false; + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ExistingDatabaseTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ExistingDatabaseTest.java new file mode 100644 index 000000000..0a50da994 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ExistingDatabaseTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.testing.base; + +import org.junit.After; +import org.junit.Before; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; + +/** + * Base class for Simantics Test Cases. Starts ProCore at the beginning of the + * tests and closes it after tests are done. + * + * @author Marko Luukkainen + * + */ +public class ExistingDatabaseTest extends TestBase { + + @Before + public void setUp() throws Exception { + state = Tests.existingDatabase(); + super.setUp(); + } + @After + public void tearDown() throws Exception { + Tests.shutdown(state); + state = null; + super.tearDown(); + } + public void reconnect() throws Exception { + setPrintStart(false); + tearDown(); + setUp(); + setPrintStart(true); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java new file mode 100644 index 000000000..26e916fc1 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java @@ -0,0 +1,156 @@ +package org.simantics.db.testing.base; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.osgi.framework.BundleContext; +import org.simantics.db.testing.cases.FreshDatabaseTest; +import org.simantics.scl.compiler.module.repository.ModuleRepository; +import org.simantics.scl.compiler.testing.TestRunnable; +import org.simantics.scl.compiler.testing.repository.TestRepository; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.osgi.internal.Activator; +import org.simantics.scl.osgi.internal.ServiceBasedModuleSourceRepository; +import org.simantics.scl.osgi.internal.ServiceBasedTestRepository; + +import gnu.trove.map.hash.THashMap; + +/** + * Utilizies {@link TestRepository} for collecting SCL tests from bundles + * + * @author Jani + * + */ +public class SCLScriptTestBase extends FreshDatabaseTest { + + private Map testRunnables = new THashMap(); + + @Rule public TestName testName = new TestName(); + + /** + * Constructor that initially searches for all SCL test scripts and stores + * them into a Map for later access + */ + public SCLScriptTestBase() { + super(); + BundleContext context = Activator.getContext(); + List runnables = new ArrayList(); + context.getService(context.getServiceReference(TestRepository.class)).collectTests(runnables); + for (TestRunnable runnable : runnables) { + testRunnables.put(runnable.getName(), runnable); + } + } + + /** + * Simplest method for running a SCL test + */ + protected void test() { + test(-1); + } + + /** + * Executes a test case with given timeout as seconds. When time runs out one + * can assume a deadlock has happened. The process is killed after the timeout + * in order to keep the possible multiple tests running. + * + * @param timeout allowed execution time given in seconds + */ + protected void test(int timeout) { + testImpl(timeout); + } + + /** + * Executes a test case with given timeout as seconds + * + * @param timeout allowed execution time given in seconds + */ + private void testImpl(int timeout) { + SCLOsgi.SOURCE_REPOSITORY = new ServiceBasedModuleSourceRepository(Activator.getContext()); + SCLOsgi.MODULE_REPOSITORY = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); + SCLOsgi.TEST_REPOSITORY = new ServiceBasedTestRepository(Activator.getContext()); + + String testName = resolveTestName(); + TestRunnable runnable = testRunnables.get(testName); + + if (timeout > -1) { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + + @Override + public void run() { + String processName = ManagementFactory.getRuntimeMXBean().getName(); + System.out.println("PID: " + processName); + String PID = processName.split("@")[0]; + String command = "taskkill /F /PID " + PID; + System.out.println("Command: " + command); + try { + Runtime.getRuntime().exec(command); + } catch (IOException e) { + e.printStackTrace(); + } + } + + }, timeout*1000); + try { + runnable.run(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + timer.cancel(); + } + } else { + try { + runnable.run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * Resolves the full test name based on the names of classes that extends this + * SCLScriptTestBase class.

+ * + * For example if our tests locate in sclTests/Simantics/Regression/FirstTest.sts + * the class hierarchy would be: + * + *
    + *
  • SCLScriptTestBase + *
      + *
    • Simantics + *
        + *
      • Regression
      • + *
      + *
    • + *
    + *
  • + *
+ * And the script file name is the same than JUnit method name. + * + * @return full testName + */ + private String resolveTestName() { + StringBuilder sb = new StringBuilder(); + Class clazz = this.getClass(); + while (true) { + if (!(clazz.getName() == SCLScriptTestBase.class.getName())) { + String[] classNameParts = clazz.getName().split("\\."); + sb.insert(0, "/"); + sb.insert(0, classNameParts[classNameParts.length - 1]); + clazz = clazz.getSuperclass(); + } else { + sb.append(testName.getMethodName()); + break; + } + } + return sb.toString(); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ScriptTestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ScriptTestBase.java new file mode 100644 index 000000000..9fa724116 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/ScriptTestBase.java @@ -0,0 +1,150 @@ +package org.simantics.db.testing.base; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.datalocation.Location; +import org.junit.Assert; +import org.simantics.db.testing.cases.FreshWorkspaceTest; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.utils.FileUtils; + +public class ScriptTestBase extends FreshWorkspaceTest { + + + String path; + + public ScriptTestBase(String path) { + this.path = path; + } + + /** + * Runs a test case without a timeout + */ + protected void test() { + + String testPath = getTestPath(); + test(0, testPath); + } + + /** + * Runs a test case with given timeout as seconds. + * + * @param allowedExecutionTime allowed execution time given in seconds. + */ + protected void test(int allowedExecutionTime) { + + String testPath = getTestPath(); + test(allowedExecutionTime, testPath); + } + + /** + * Runs a test case with given timeout as seconds. When the time runs out, heapdump and threaddump of the java process is taken and stored to the current workspace. + * The workspace is being compressed to a Zip-file and then copied and stored to the current working directory. In the end the whole java process gets killed to prevent deadlocks. + * + * @param allowedExecutionTime allowed execution time given in seconds. + */ + protected void test(final int allowedExecutionTime, final String testPath) { + + if(allowedExecutionTime > 0) { + Timer timer = new Timer(); + try { + timer.schedule(new TimerTask() { + + @Override + public void run() { + + try { + String workingDir = System.getProperty("user.dir"); + Location location = Platform.getInstanceLocation(); + String workspacePath = location.getURL().getPath().substring(1); + String[] pathToWorkspace = workspacePath.split("/"); +// String[] testName = testPath.split("/"); + +// String hdumpFileName = workspacePath + testName[testName.length - 1] + ".hprof"; +// GetHeapDump.dumpHeap(hdumpFileName, false); + +// String tdumpFileName = workspacePath + testName[testName.length - 1] + ".tdump"; +// GetThreadDump.dumpThread(tdumpFileName); + + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyy_HH.mm.ss"); + String date = sdf.format(new Date()); + String zipDir = workingDir + "/" + pathToWorkspace[pathToWorkspace.length - 1] + "_" + date + ".zip"; + FileUtils.compressZip(workspacePath, zipDir); + + String processName = ManagementFactory.getRuntimeMXBean().getName(); + System.out.println("PID: " + processName); + String PID = processName.split("@")[0]; + String command = "taskkill /F /PID " + PID; + System.out.println("Command: " + command); + Runtime.getRuntime().exec(command); + + } catch (IOException ioe) { + ioe.printStackTrace(); + System.err.println(ioe); + } + + } + }, 1000*allowedExecutionTime); + testImpl(testPath); + } finally { + timer.cancel(); + } + } else { + testImpl(testPath); + } + + } + + protected void testImpl(String testPath) { + + System.out.println("Testing script: " + testPath); + + InputStream stream = getClass().getResourceAsStream(testPath); + if(stream == null) + Assert.fail("Didn't find " + testPath + " at " + getClass().getResource("")); + try { + CommandSession session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null); + TestScriptExecutor executor = new TestScriptExecutor(session, + new BufferedReader(new InputStreamReader(stream)), null); + executor.execute(); + //isDBLogClean(); + } catch(IOException e) { + throw new RuntimeException(e); + } finally { + try { + stream.close(); + } catch (IOException e) { + } + } + } + + public String getTestPath() { + + String methodName = new Exception().getStackTrace()[2].getMethodName(); + String testPath = path + "/" + methodName + ".sts"; + + return testPath; + } + + public void isDBLogClean() throws IOException { + + String workingDir = System.getProperty("user.dir"); + try (BufferedReader br = new BufferedReader(new FileReader(workingDir + "/db-client.log"))) { + Assert.assertEquals(br.readLine(), null); + } + + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SimpleBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SimpleBase.java new file mode 100644 index 000000000..b4c8e2f79 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SimpleBase.java @@ -0,0 +1,34 @@ +package org.simantics.db.testing.base; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import org.simantics.db.Resource; + +abstract public class SimpleBase extends ExistingDatabaseTest { + protected Resource rl; + @Override + public void setUp() throws Exception { + super.setUp(); + rl = getSession().getRootLibrary(); + } +// protected void reconnect() +// throws DatabaseException { +// getSessionHandler().close(); +// // Close the old session and open a new one. +// try { +// Thread.sleep(1000); // milliseconds +// } catch (InterruptedException e) { +// } +// getSessionHandler().connect(); +// } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCleanDb.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCleanDb.java new file mode 100644 index 000000000..e53c5d66b --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCleanDb.java @@ -0,0 +1,38 @@ +package org.simantics.db.testing.base; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import org.junit.Before; +import org.simantics.db.testing.impl.Configuration; + +/** + * Base class for Simantics Test Cases. Starts ProCore at the beginning of the tests and closes it after tests are done. + * + * @author Marko Luukkainen + * + */ +@Deprecated +public class TestCleanDb extends ExistingDatabaseTest { + + private static final String USERNAME = Configuration.get().username; + private static final String PASSWORD = Configuration.get().password; + private final String WORK_DIR = "cleanDb"; + + @Before + public void setUp() throws Exception { +// CoreHandler.initDb(WORK_DIR); +// core = new CoreHandler(); +// Session s = core.launch(WORK_DIR, USERNAME, PASSWORD, null); + super.setUp(); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonNoVirtual.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonNoVirtual.java new file mode 100644 index 000000000..f32f5921b --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonNoVirtual.java @@ -0,0 +1,40 @@ +package org.simantics.db.testing.base; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import org.junit.After; +import org.junit.Before; +import org.simantics.db.testing.impl.Configuration; + +@Deprecated +public class TestCommonNoVirtual extends ExistingDatabaseTest { + protected final boolean VIRTUAL = Configuration.get().virtual; + @Before + public void setUp() throws Exception { + if (!VIRTUAL) + super.setUp(); + } + @After + public void tearDown() throws Exception { + if (!VIRTUAL) + super.tearDown(); + } + protected boolean noVirtual() { + if (VIRTUAL) { + printStart(this); + System.out.println("This test is not suitable for virtual graph."); + return true; + } + return false; + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonPerf.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonPerf.java new file mode 100644 index 000000000..188400da5 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/TestCommonPerf.java @@ -0,0 +1,14 @@ +package org.simantics.db.testing.base; + + +import org.simantics.db.Resource; + +@Deprecated +public class TestCommonPerf extends TestCleanDb { + protected Resource rl; + @Override + public void setUp() throws Exception { + super.setUp(); + rl = getSession().getRootLibrary(); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/WriteReadTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/WriteReadTest.java new file mode 100644 index 000000000..afe135e70 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/WriteReadTest.java @@ -0,0 +1,49 @@ +package org.simantics.db.testing.base; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; + +abstract public class WriteReadTest extends ExistingDatabaseTest { + protected Resource written; + @Test + public void test() throws Exception { + Session s = getSession(); + s.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + written = graph.newResource(); + write(graph); + } + + }); + s.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + read(graph); + } + + }); + } + protected void write(WriteGraph graph) throws DatabaseException {} + protected void read(ReadGraph graph) throws DatabaseException {} +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabase.java new file mode 100644 index 000000000..25cb72a20 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabase.java @@ -0,0 +1,21 @@ +package org.simantics.db.testing.cases; + +import org.junit.Test; + +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +public class FreshDatabase extends FreshDatabaseTest { + @Test + public void test() throws Exception { + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java new file mode 100644 index 000000000..963b2d9f5 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java @@ -0,0 +1,68 @@ +package org.simantics.db.testing.cases; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import org.junit.After; +import org.junit.Before; +import org.simantics.SimanticsPlatform; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.testing.common.DatabaseState; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.TestSettings; +import org.simantics.db.testing.common.Tests; + +public class FreshDatabaseTest extends TestBase { + + public void configure(TestSettings settings) { + + } + + @Before + public void setUp() throws Exception { + + TestBase.printStart(this); + TestSettings testSettings = TestSettings.getInstanceUnsafe(); + configure(testSettings); +// state = AcornTests.newSimanticsWorkspace(testSettings, null); + state = Tests.newSimanticsWorkspace(testSettings, null); + + super.setUp(); + + } + + @After + public void tearDown() throws Exception { + Tests.shutdown(state); + super.tearDown(); + } + + public Resource getProjectResource() { + return SimanticsPlatform.INSTANCE.projectResource; + } + + protected Session getSession() { + return state.getSession(); + } + + public DatabaseState getState() { + return state; + } + + public void reconnect() throws Exception { + setPrintStart(false); + tearDown(); + setUp(); + setPrintStart(true); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java new file mode 100644 index 000000000..0de078564 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java @@ -0,0 +1,30 @@ +package org.simantics.db.testing.cases; + +import org.junit.After; +import org.junit.Before; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.TestSettings; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.impl.Configuration; + +public class FreshWorkspaceTest extends TestBase { + + public void configure(TestSettings settins) { + } + + @Before + public void setUp() throws Exception { + + TestBase.printStart(this); + configure(TestSettings.getInstanceUnsafe()); + state = Tests.freshWorkspace(Configuration.get().coreDir, initialWorkspaceFiles); + super.setUp(); + } + + @After + public void tearDown() throws Exception { + + Tests.shutdown(state); + super.tearDown(); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java new file mode 100644 index 000000000..5f5da8f2e --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java @@ -0,0 +1,64 @@ +package org.simantics.db.testing.common; + +import java.io.File; +import java.util.Properties; + +import org.eclipse.core.runtime.Platform; +import org.simantics.db.Driver; +import org.simantics.db.Driver.Management; +import org.simantics.db.Manager; +import org.simantics.db.ServerI; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; + +/** + * ProCore specific test handler. + * + */ +public class AcornTestHandler { + // private final TestSettings testSettings; + private final Driver driver; + private final File dbFolder; + + AcornTestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException { + // this.testSettings = testSettings; + driver = Manager.getDriver("acorn"); + if (driver == null) + throw new IllegalArgumentException("No driver found for acorn!"); + if (null == dbFolderName) + dbFolder = Platform.getLocation().append("db").toFile(); + else + dbFolder = new File(dbFolderName); + } + + void initNew() throws DatabaseException { + Management m = getManagement(); + if (m.exist()) + m.delete(); + m.create(); + } + + void initIfNeccessary() throws DatabaseException { + Management m = getManagement(); + if (!m.exist()) + m.create(); + } + + public Session getSession() throws DatabaseException { + // Note that we normally user authentication agent for user + // identification. + Properties props = new Properties(); + props.setProperty("user", "Default User"); + props.setProperty("password", ""); + return driver.getSession(dbFolder.getAbsolutePath(), props); + } + + public ServerI getServer() throws DatabaseException { + return driver.getServer(dbFolder.getAbsolutePath(), null); + } + + public Management getManagement() throws DatabaseException { + return driver.getManagement(dbFolder.getAbsolutePath(), null); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTests.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTests.java new file mode 100644 index 000000000..e72ea3280 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTests.java @@ -0,0 +1,154 @@ +package org.simantics.db.testing.common; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; + +import org.eclipse.core.runtime.Platform; +import org.simantics.DefaultChoiceUserAgent; +import org.simantics.Simantics; +import org.simantics.SimanticsPlatform; +import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy; +import org.simantics.SimanticsPlatform.RecoveryPolicy; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingConstructionException; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RuntimeEnvironmentRequest; +import org.simantics.db.management.ISessionContextProvider; +import org.simantics.db.management.ISessionContextProviderSource; +import org.simantics.db.management.SessionContext; +import org.simantics.db.management.SessionContextProvider; +import org.simantics.db.management.SingleSessionContextProviderSource; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.graph.db.TransferableGraphs; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.scl.osgi.SCLOsgi; + +public class AcornTests { + + private static AcornTestHandler testHandler; + + public static DatabaseState freshWorkspace(String CORE_DIR, ArrayList fileFilter) throws Exception { + SimanticsPlatform.INSTANCE.resetWorkspace(null, fileFilter); + return newSimanticsWorkspace(null, CORE_DIR); + } + + public static void freshDatabase() throws Exception { + DatabaseState state = freshWorkspace(Configuration.get().coreDir, null); + AcornTests.shutdown(state); + } + + public static DatabaseState existingDatabase() throws Exception { + return oldSimanticsWorkspace(null, Configuration.get().coreDir); + } + + private static void initSimanticsStuff() { + // Set session context provider. + final ISessionContextProvider provider = new SessionContextProvider(null); + ISessionContextProviderSource source = new SingleSessionContextProviderSource(provider); + Simantics.setSessionContextProviderSource(source); + org.simantics.db.layer0.internal.SimanticsInternal.setSessionContextProviderSource(source); + } + + public static DatabaseState newSimanticsWorkspace(TestSettings testSettings, String address) throws Exception { + AcornTestHandler testHandler = AcornTests.getTestHandler(testSettings, address); + testHandler.initNew(); + initSimanticsStuff(); + SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp("acorn", null, RecoveryPolicy.FixError, + OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent()); + return new DatabaseState(address, sessionContext); + } + + public static DatabaseState oldSimanticsWorkspace(TestSettings testSettings, String address) throws Exception { + AcornTests.getTestHandler(testSettings, address); + initSimanticsStuff(); + SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(null, null, RecoveryPolicy.FixError, + OntologyRecoveryPolicy.Merge, false, null); + return new DatabaseState(address, sessionContext); + } + + public static void shutdown(DatabaseState state) throws Exception { + SCLOsgi.MODULE_REPOSITORY.flush(); + SCLOsgi.SOURCE_REPOSITORY = null; + SCLOsgi.MODULE_REPOSITORY = null; + SCLOsgi.TEST_REPOSITORY = null; + +// VirtualGraphSupport vsupport; +// if (state != null) { +// vsupport = state.getSession().getService(VirtualGraphSupport.class); +// vsupport.discard(); +// } + + if (Platform.isRunning()) { + SimanticsPlatform.INSTANCE.shutdown(null); + return; + } // Cleanup without platform code. + if (null == state) + return; + String address = state.getAddress(); + try { + if (null != address) + getTestHandler(null, address).getManagement().shutdown(); + } catch (Throwable t) { + System.out.println(t); + } + } + + public static void initOntology(Session session, String relative) throws DatabaseException { + // Open transferable graph file for layer0. + Binding binding; + try { + binding = Bindings.getBinding(TransferableGraph1.class); + } catch (BindingConstructionException e) { + throw new DatabaseException(e); + } + File t = new File(TestSettings.getInstance().getWorkspace(), relative); + if (!t.exists()) + throw new DatabaseException("File does not exist. File=" + t + "."); + + TransferableGraph1 layer0; + try { + InputStream is = new FileInputStream(t); + layer0 = (TransferableGraph1) Files.readFile(is, binding); + is.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new DatabaseException(e); + } + try { + TransferableGraphs.importGraph(session, layer0); + } catch (Throwable e) { + e.printStackTrace(); + throw new DatabaseException("Failed to init db.", e); + } + } + + public static AcornTestHandler getTestHandler() throws DatabaseException { + return getTestHandler(null, null); + } + + public static AcornTestHandler getTestHandler(TestSettings testSettings, String address) + throws DatabaseException { + if (null == testHandler) + testHandler = new AcornTestHandler(testSettings, address); + return testHandler; + } + + public static void closeSession(Session session) throws DatabaseException { + try { + LifecycleSupport support = session.getService(LifecycleSupport.class); + support.close(-1, false); + session = null; + } catch (Exception e) { + session = null; + throw new DatabaseException("Sessuion did not close cleanly."); + } + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Client.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Client.java new file mode 100644 index 000000000..0a33176e5 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Client.java @@ -0,0 +1,12 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; + +public interface Client { + + Session getSession(); + String getInstanceName(); + void close() throws DatabaseException; + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ClientFactory.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ClientFactory.java new file mode 100644 index 000000000..180757762 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ClientFactory.java @@ -0,0 +1,12 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.impl.ClientImpl; + +public class ClientFactory { + + public static Client create(String name) throws DatabaseException { + return new ClientImpl(name); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Command.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Command.java new file mode 100644 index 000000000..4dc65002c --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Command.java @@ -0,0 +1,7 @@ +package org.simantics.db.testing.common; + +import org.simantics.databoard.util.Bean; + +abstract public class Command extends Bean { + abstract public void run(T environment) throws Exception; +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandInvoker.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandInvoker.java new file mode 100644 index 000000000..3e71a5c13 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandInvoker.java @@ -0,0 +1,7 @@ +package org.simantics.db.testing.common; + +public interface CommandInvoker { + + void invoke(CommandSequenceEnvironment environment, T parameter) throws Exception; + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSequenceEnvironment.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSequenceEnvironment.java new file mode 100644 index 000000000..a389414ce --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSequenceEnvironment.java @@ -0,0 +1,12 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.Session; + + +public interface CommandSequenceEnvironment { + + Session getSession(); + void reconnect() throws Exception; + void invoke(CommandSequenceEnvironment environment, Command command); + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSpec.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSpec.java new file mode 100644 index 000000000..5edd59cd0 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/CommandSpec.java @@ -0,0 +1,14 @@ +package org.simantics.db.testing.common; + + +public class CommandSpec { + public Class clazz; + public double weight; + private CommandSpec(Class clazz, double weight) { + this.clazz = clazz; + this.weight = weight; + } + public static CommandSpec make(Class clazz, double weight) { + return new CommandSpec(clazz, weight); + } +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseProxy.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseProxy.java new file mode 100644 index 000000000..5e2a70987 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseProxy.java @@ -0,0 +1,274 @@ +package org.simantics.db.testing.common; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.HashMap; +import java.util.Map; + +public class DatabaseProxy implements Runnable { + + private static boolean SMALL_PACKETS = false; + private static int PORT = 8891; + private boolean interrupted = false; + private Map databases = new HashMap(); + + private ServerSocket service = null; + + /** + * Initializes database proxy with static mappings. + * + */ + public DatabaseProxy() { + databases.put("/public/", "192.168.3.11:9101"); + databases.put("FooBar", "localhost:6671"); + } + + public DatabaseProxy(String host, int port) { + databases.put("/test/", host+":"+port); + } + + public void start() { + Thread t = new Thread(this); + init(); + t.start(); + } + + public void stop() { + interrupted = true; + // We have to interrupt the the blocking accept call. + // This is one way of doing it. + if(service != null) + try { + service.close(); + } catch (IOException e) { + } + } + + public int getPort() { + return PORT; + } + + public void init() { + try { + service = new ServerSocket(PORT); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + public void run() { + System.out.println("Accepting connections"); + + int connectionNumber = 0; + while(!interrupted) { + try { + final Socket socket = service.accept(); + String connectionName = "Connection" + ++connectionNumber; + System.out.println(connectionName + ": Client connection accepted."); + + Runnable runnable = new Runnable() { + @Override + public void run() { + try { + serve(socket); + socket.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + }; + Thread t = new Thread(runnable, connectionName); + t.start(); + } catch (IOException e) { + if (interrupted) + break; // Blocking accept call intentionally interrupted by closing the socket. + e.printStackTrace(); + } + } + + // Shutdown service + try { + if(service != null) + service.close(); + } catch (IOException ignore) { + } + } + + /** + * Serves socket connection. Waits for a connection line from the client and parses it. + * The connection line must be in form "CONNECT\tDatabaseIdentifier" + * If the database name is valid, creates a connection to the database and works as a proxy + * between the client and the database. + * + * @param socket + * @throws IOException + */ + private void serve(Socket socket) throws IOException { + String connectionName = Thread.currentThread().getName(); + + BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); + PrintWriter out = new PrintWriter(socket.getOutputStream(), true); + + String line = input.readLine(); + String columns[] = line.split("\t"); + if(columns.length < 2) { + System.out.println(connectionName + ": serve() Invalid connection string [1] '"+line+"'"); + out.write("ERROR Invalid connection string\n"); + return; + } + String command = columns[0]; + String param = columns[1]; + + /** + * CONNECT is the only supported command + */ + if("CONNECT".equals(command)) { + if(databases.containsKey(param) == false) { + System.out.println(connectionName + ": serve() Invalid database '"+param+"'"); + out.write("ERROR Invalid database '"+param+"'\n"); + return; + } + // The second parameter is directly mapped to database name. In future some parsing is required. + String address = databases.get(param); + String[] split = address.split(":"); + if (split.length != 2) + throw new IllegalArgumentException(connectionName+ ": address does not contain a port, missing ':' character"); + InetSocketAddress dbAddress = new InetSocketAddress(split[0], Integer.parseInt(split[1])); + + Socket dbSocket = new Socket(); + try { + dbSocket.connect(dbAddress); + } catch(IOException e) { + System.out.println(connectionName + ":serve() Couldn't connect to database '"+param+"'"); + out.write("ERROR Couldn't connect to database '"+param+"'\n"); + return; + } + + out.write("OK\n"); + out.flush(); + proxy(dbSocket, socket); + + dbSocket.close(); + } else { + System.out.println(connectionName + ": serve() Invalid command '"+command+"'"); + out.write("ERROR Invalid command '"+command+"'\n"); + return; + } + } + + /** + * Proxies data from socket a to socket b and vice versa + * This method blocks until one of the sockets closes or exception is thrown. + * + * @param a + * @param b + */ + private void proxy(final Socket a, final Socket b) { + // A -> B + Runnable ab = new Runnable() { + @Override + public void run() { + try { + byte buffer[] = new byte[256]; + while(a.isConnected() && b.isConnected()) { + int n = a.getInputStream().read(buffer); + if (n < 1) + break; + if (SMALL_PACKETS) { + for (int i=0; i A + Runnable ba = new Runnable() { + @Override + public void run() { + try { + byte buffer[] = new byte[256]; + while(b.isConnected() && a.isConnected()) { + int n = b.getInputStream().read(buffer); + if (n < 1) + break; + if (SMALL_PACKETS) { + for (int i=0; iclient"); + Thread tba = new Thread(ba, t + " client->server"); + + tab.start(); + tba.start(); + + try { + while(tba.isAlive() && tab.isAlive()) { + Thread.sleep(1000); + } + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + DatabaseProxy proxy = new DatabaseProxy(); + proxy.init(); + proxy.run(); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseState.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseState.java new file mode 100644 index 000000000..6320f2ff5 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/DatabaseState.java @@ -0,0 +1,28 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.Session; +import org.simantics.db.management.SessionContext; + +public class DatabaseState { + + private SessionContext sessionContext; + private String address; + + public DatabaseState(String address, SessionContext sessionContext) { + this.sessionContext = sessionContext; + this.address = address; + } + + public Session getSession() { + return sessionContext.getSession(); + } + + public SessionContext getSessionContext() { + return sessionContext; + } + + public String getAddress() { + return address; + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ExceptionUtils.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ExceptionUtils.java new file mode 100644 index 000000000..c2c6cd923 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ExceptionUtils.java @@ -0,0 +1,27 @@ +package org.simantics.db.testing.common; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import java.io.PrintWriter; +import java.io.StringWriter; + +public class ExceptionUtils { + + public static String getStackTrace(Throwable e) { + + StringWriter w = new StringWriter(); + PrintWriter pw = new PrintWriter(w); + e.printStackTrace(pw); + return w.toString(); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Failures.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Failures.java new file mode 100644 index 000000000..4ca8908d3 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Failures.java @@ -0,0 +1,10 @@ +package org.simantics.db.testing.common; + +import org.simantics.databoard.util.Bean; + +public class Failures extends Bean { + public String[] names; + Failures() { + names = new String[0]; + } +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Kill.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Kill.java new file mode 100644 index 000000000..d98695713 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Kill.java @@ -0,0 +1,10 @@ +package org.simantics.db.testing.common; + + +public class Kill extends Command { + + @Override + public void run(CommandSequenceEnvironment environment) throws Exception { + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ReadCommand.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ReadCommand.java new file mode 100644 index 000000000..f25597d7e --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/ReadCommand.java @@ -0,0 +1,25 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; + +abstract public class ReadCommand extends Command { + + @Override + public void run(final T environment) throws Exception { + environment.getSession().sync(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + ReadCommand.this.run(graph, environment); + } + + }); + } + + protected void run(ReadGraph graph, T environment) throws DatabaseException { + + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Reconnect.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Reconnect.java new file mode 100644 index 000000000..fed17ad32 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Reconnect.java @@ -0,0 +1,11 @@ +package org.simantics.db.testing.common; + + +public class Reconnect extends Command { + + @Override + public void run(CommandSequenceEnvironment environment) throws Exception { + environment.reconnect(); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionFilter.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionFilter.java new file mode 100644 index 000000000..cd2b4b211 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionFilter.java @@ -0,0 +1,109 @@ +package org.simantics.db.testing.common; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; +import org.simantics.db.testing.annotation.Always; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.annotation.Obsolete; +import org.simantics.utils.FileUtils; + +public class RegressionFilter extends Filter { + + public static final String CLASSIFICATION_KEY = "regressionFilterClassification"; + public static final String CLASSIFICATION_KEY_1 = "1"; + public static final String CLASSIFICATION_KEY_2 = "2"; + public static final String CLASSIFICATION_KEY_3 = "3"; + public static final String CLASSIFICATION_KEY_4 = "4"; + + private Failures tests; + + public RegressionFilter() { + super(); + getTestCaseNames(); + } + + public String describe() { + return "Filters out all failing tests."; + } + + enum Classification { + REGRESSION1,REGRESSION2,REGRESSION3,REGRESSION4,ALWAYS + } + + EnumSet ALWAYS_CLASSES = EnumSet.of(Classification.REGRESSION1, Classification.REGRESSION2, Classification.ALWAYS); + + public Classification classify(Description d) { + + String testName = d.getDisplayName(); +// System.err.println("classify " + testName); + + Always a = d.getAnnotation(Always.class); + if(a != null) return Classification.ALWAYS; + + Obsolete o = d.getAnnotation(Obsolete.class); + if(o != null) return Classification.REGRESSION4; + + Fails f = d.getAnnotation(Fails.class); + if(f != null) return Classification.REGRESSION3; + + Test t = d.getAnnotation(Test.class); + if(t == null) return Classification.ALWAYS; + + if (tests == null) return Classification.REGRESSION1; + + for (int i = 0; i < tests.names.length; i++) + if (testName.contains(tests.names[i])) + return Classification.REGRESSION2; + + return Classification.REGRESSION1; + + } + + private Classification getPass() { + String s = System.getProperty(CLASSIFICATION_KEY); + if(CLASSIFICATION_KEY_1.equals(s)) return Classification.REGRESSION1; + else if(CLASSIFICATION_KEY_2.equals(s)) return Classification.REGRESSION2; + else if(CLASSIFICATION_KEY_3.equals(s)) return Classification.REGRESSION3; + else if(CLASSIFICATION_KEY_4.equals(s)) return Classification.REGRESSION4; + else return null; + } + + public boolean shouldRun(Description d) { + Classification cls = classify(d); +// System.err.println("-" + cls); + if(Classification.ALWAYS == cls) return true; + Classification pass = getPass(); + if(pass == null && ALWAYS_CLASSES.contains(cls)) return true; + return pass == cls; + } + + private void getTestCaseNames() { + + if(tests != null) return; + + try { + + String csv = FileUtils.getContents("failures.dat").replace("\r", ""); + tests = new Failures(); + Set ss = new HashSet(); + for(String s : csv.split("\n")) + if(!s.isEmpty()) ss.add(s); + tests.names = ss.toArray(new String[ss.size()]); + +// System.err.println("tests.names = " + Arrays.toString(tests.names)); + + } catch (Exception e) { + + tests = new Failures(); + tests.names = new String[] { }; + + } + + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionSuiteRunner.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionSuiteRunner.java new file mode 100644 index 000000000..ec20055f9 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/RegressionSuiteRunner.java @@ -0,0 +1,33 @@ +package org.simantics.db.testing.common; + + +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.RunnerBuilder; + +public class RegressionSuiteRunner extends Suite { + + private static Class load(Class clazz) { + try { + clazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return clazz; + } + + public RegressionSuiteRunner(Class clazz, RunnerBuilder builder) throws InitializationError { + super(load(clazz), builder); + Filter f = new RegressionFilter(); + try { + f.apply(this); + } catch (NoTestsRemainException ex) { + //throw new RuntimeException(ex); + } + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Server4Remote.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Server4Remote.java new file mode 100644 index 000000000..f4de43757 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Server4Remote.java @@ -0,0 +1,52 @@ +package org.simantics.db.testing.common; + + +import org.simantics.db.ServerI; +import org.simantics.db.exception.DatabaseException; + +public class Server4Remote implements ServerI { + private boolean active = false; + private String host = null; + private int port = 0; + public Server4Remote(String host, int port) { + this.host = host; + this.port = port; + } + + @Override + public void start() throws DatabaseException { + active = true; + } + + @Override + public void stop() throws DatabaseException { + active = false; + } + + @Override + public boolean isActive() { + return active; + } + + @Override + public String getAddress() throws DatabaseException { + return "" + host + ":" + port; + } + +// @Override +// public synchronized ServerAddress getServerAddress() +// throws DatabaseException { +// return new ServerAddress(host, port); +// } + + @Override + public String execute(String command) throws DatabaseException { + throw new DatabaseException("Execute method not supported for remote server."); + } + + @Override + public String executeAndDisconnect(String command) throws DatabaseException { + throw new DatabaseException("ExecuteAndDisconnect method not supported for remote server."); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/SessionTrait.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/SessionTrait.java new file mode 100644 index 000000000..6a9fd066b --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/SessionTrait.java @@ -0,0 +1,11 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.Session; + +public interface SessionTrait { + + Session getSession(); + void kill() throws Exception; + void reconnect() throws Exception; + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Terminator.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Terminator.java new file mode 100644 index 000000000..807a547e1 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Terminator.java @@ -0,0 +1,25 @@ +package org.simantics.db.testing.common; + +import java.util.concurrent.TimeUnit; + +import org.simantics.Simantics; + +public class Terminator implements Runnable { + + private boolean disarmed = false; + + public Terminator(int seconds) { + Simantics.async(this, seconds, TimeUnit.SECONDS); + } + + public void run() { + if(disarmed) return; + System.exit(-1); + } + + public void disarm() { + disarmed = true; + } + + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java new file mode 100644 index 000000000..574ab95f6 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java @@ -0,0 +1,341 @@ +package org.simantics.db.testing.common; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import java.security.Permission; +import java.util.ArrayList; +import java.util.UUID; + +import org.eclipse.core.runtime.Platform; +import org.junit.After; +import org.junit.Before; +import org.simantics.SimanticsPlatform; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceNotFoundException; +import org.simantics.db.management.SessionContext; +import org.simantics.db.request.Read; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.layer0.Layer0; +import org.simantics.utils.FileUtils; + +/** + * Base class for Simantics Test Cases. Assumes that ProCore is already running. + * + * @author Marko Luukkainen + * + */ +abstract public class TestBase /*extends TestCase*/ { + public static final boolean DEBUG = Configuration.get().debug; + public static final String ROOT_LIBRARY_URI = "http:/"; + private NoExitSecurityManager noExitSecurityManager; + private SecurityManager securityManager; + protected DatabaseState state; + public Throwable exception2; + protected Layer0 L0; + static boolean printStart = true; + public static final ArrayList initialWorkspaceFiles = FileUtils.createFileFilter(Platform.getLocation().toFile(), null); + public static void printStart(Object t) { + if(printStart) System.out.println("Test is " + t.getClass().getName() /*+ "." + t.getName()*/); + } + protected static void setPrintStart(boolean value) { + printStart = value; + } + + public Resource getProjectResource() { + return SimanticsPlatform.INSTANCE.projectResource; + } + + @Before + public void setUp() throws Exception { + printStart(this); + securityManager = System.getSecurityManager(); + noExitSecurityManager = new NoExitSecurityManager(state.getSession()); + System.setSecurityManager(noExitSecurityManager); + Session session = state.getSession(); + L0 = Layer0.getInstance(session); + } + @After + public void tearDown() throws Exception { + if (noExitSecurityManager != null) { + System.setSecurityManager(securityManager); + noExitSecurityManager.dispose(); + noExitSecurityManager = null; + } + L0 = null; + state = null; + exception2 = null; + securityManager = null; + commonTearDown(); + } + public static void commonTearDown() { + Runtime rt = Runtime.getRuntime(); + rt.gc(); + rt.gc(); + rt.gc(); + if (DEBUG) { + System.out.println("Max=" + rt.maxMemory() + + " tot=" + rt.totalMemory() + + " fre=" + rt.freeMemory()); + } + } + + public static String getRandomString() { + return UUID.randomUUID().toString(); + } + + protected Session getSession() throws DatabaseException { + return state.getSession(); + } + protected SessionContext getSessionContext() { + return state.getSessionContext(); + } + +// protected Resource getRootLibrary() throws DatabaseException { +// return getRootLibrary(getSession()); +// } +// +// protected Resource getRootLibrary(Session session) throws DatabaseException { +// return session.syncRequest(new ReadQuery() { +// @Override +// public void run(ReadGraph g) throws DatabaseException { +// result = g.getResource(ROOT_LIBRARY_URI); +// assertTrue(result.getResourceId() != SessionManagerSource.NullSubjectId); +// } +// }); +// } + + protected abstract class ReadQuery implements Read { + protected Result result = null; + + public abstract void run(ReadGraph graph) throws Throwable; + + @Override + public Result perform(ReadGraph graph) { + try { + run(graph); + return result; + } catch(Throwable t) { + if (DEBUG) { + new Exception().printStackTrace(); + t.printStackTrace(); + } + if (null == exception2) + exception2 = t; + return null; + } + } + + } + + protected abstract class TestReadRequest extends ReadQuery { + } + + protected abstract class WriteOnlyQuery + extends WriteOnlyRequest + { + + public abstract void run(WriteOnlyGraph g) throws Throwable; + + /** + * Since some SimpleGraphRequest can only handle Exceptions, we need to wrap other Throwables inside Exceptions + */ + @Override + public final void perform(WriteOnlyGraph g) { + try { + run(g); + } catch(Throwable t) { + new Exception().printStackTrace(); + t.printStackTrace(); + if (null == exception2) + exception2 = t; + throw new RuntimeException("Wrapping thrown non exception to exception.", t); + } + } + public void run(WriteGraph g) throws Throwable { + run((WriteOnlyGraph)g); + } + + } + + protected void checkException() throws DatabaseException { + if (exception2 != null) + if (exception2 instanceof DatabaseException) + throw (DatabaseException)exception2; + else + throw new DatabaseException(exception2); + } + + protected boolean hasException() { + return null != exception2; + } + + protected Throwable getException() { + return exception2; + } + + protected static class ExitException extends SecurityException { + private static final long serialVersionUID = -1982617086752946683L; + public final int status; + + public ExitException(int status) { + super("There is no escape!"); + this.status = status; + } + } + + private static class NoExitSecurityManager extends SecurityManager { + Session session; +// Thread thread; + NoExitSecurityManager(Session session) { + this.session = session; +// this.thread = Thread.currentThread(); + } + + public void dispose() { + session = null; + } + + @Override + public void checkPermission(Permission perm) { + // allow anything. + } + + @Override + public void checkPermission(Permission perm, Object context) { + // allow anything. + } + + @Override + public void checkExit(int status) { + super.checkExit(status); + if(session != null) { + try { + session.getService(LifecycleSupport.class).close(0, true); + } catch (ServiceNotFoundException e) { + Logger.defaultLogError(e); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } + } +// if (!Thread.currentThread().equals(thread)) { +// ThreadUtil.interruptThreadGroup("Query Thread Group"); +// ThreadUtil.interruptThreadGroup("Session Thread Group"); +// ThreadUtil.interruptThreadGroup("Connection Thread Group"); +// thread.interrupt(); +// throw new ExitException(status); +// } + } + } + + protected String getName() { + return getClass().getSimpleName(); + } + + protected static void fail() { + throw new AssertionError(); + } + + protected void fail(String cause) { + throw new AssertionError(cause); + } + + protected void fail(String cause, Object a) { + if (a instanceof Throwable) { + Throwable t = (Throwable)a; + Throwable c = t.getCause(); + if (null != c) + throw new AssertionError(new Error(t.getMessage(), c)); + } + throw new AssertionError(cause + " " + a); + } + + protected void assertEquals(Object a, Object b) { + if(!a.equals(b)) + throw new AssertionError(); + } + + protected void assertEquals(int a, int b) { + if(a != b) + throw new AssertionError(); + } + + protected void assertEquals(double a, double b, double tolerance) { + if(Math.abs(a - b) > tolerance) + throw new AssertionError(); + } + + protected void assertLess(double a, double b) { + if(a >= b) + throw new AssertionError(a + " is not less than " + b); + } + + protected void assertLess(double a, double b, String info) { + if(a >= b) { + System.err.println("assertion info:\n" + info + "\n"); + throw new AssertionError(a + " is not less than " + b); + } + } + + protected void assertEquals(String a, String b) { + if(!a.equals(b)) + throw new AssertionError(); + } + + protected void assertEquals(String message, int a, int b) { + if(a != b) + throw new AssertionError(message); + } + + protected void assertEquals(String message, boolean a, boolean b) { + if(a != b) + throw new AssertionError(message); + } + + protected void assertNotNull(Object a) { + if(a == null) + throw new AssertionError(); + } + + protected void assertNotNull(String message, Object a) { + if(a == null) + throw new AssertionError(message); + } + + protected void assertTrue(String message, boolean a) { + if(!a) + throw new AssertionError(message); + } + + protected void assertTrue(boolean a) { + if(!a) + throw new AssertionError(); + } + + protected void assertFalse(boolean a) { + if(a) + throw new AssertionError(); + } + + protected void assertFalse(String message, boolean a) { + if(a) + throw new AssertionError(message); + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestHandler.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestHandler.java new file mode 100644 index 000000000..ecda4ccb6 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestHandler.java @@ -0,0 +1,68 @@ +package org.simantics.db.testing.common; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.core.runtime.Platform; +import org.simantics.db.Driver; +import org.simantics.db.Driver.Management; +import org.simantics.db.Manager; +import org.simantics.db.ServerI; +import org.simantics.db.Session; +import org.simantics.db.SessionManager; +import org.simantics.db.SessionReference; +import org.simantics.db.exception.DatabaseException; + +import fi.vtt.simantics.procore.ProCoreServerReference; +import fi.vtt.simantics.procore.ProCoreSessionReference; +import fi.vtt.simantics.procore.SessionManagerSource; + +/** + * ProCore specific test handler. + * + */ +public class TestHandler { +// private final TestSettings testSettings; + private final Driver driver; + private final File dbFolder; + TestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException { +// this.testSettings = testSettings; + driver = Manager.getDriver("procore"); + if (null == dbFolderName) + dbFolder = Platform.getLocation().append("db").toFile(); + else + dbFolder = new File(dbFolderName); + } + void initNew() throws DatabaseException { + Management m = getManagement(); + if (m.exist()) + m.delete(); + m.create(); + } + void initIfNeccessary() throws DatabaseException { + Management m = getManagement(); + if (!m.exist()) + m.create(); + } + public Session getSession() throws DatabaseException { + // Note that we normally user authentication agent for user identification. + Properties props = new Properties(); + props.setProperty("user", "Default User"); + props.setProperty("password", ""); + return driver.getSession(dbFolder.getAbsolutePath(), props); + } + public ServerI getServer() throws DatabaseException { + return driver.getServer(dbFolder.getAbsolutePath(), null); + } + public Management getManagement() throws DatabaseException { + return driver.getManagement(dbFolder.getAbsolutePath(), null); + } + public Session regSession(long sessionId) throws DatabaseException, IOException { + SessionManager sm = SessionManagerSource.getSessionManager(); + ProCoreServerReference ser = new ProCoreServerReference(dbFolder.toPath()); + SessionReference ses = new ProCoreSessionReference(ser, sessionId); + return sm.createSession(ses, null); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestSettings.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestSettings.java new file mode 100644 index 000000000..c53dd2696 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestSettings.java @@ -0,0 +1,62 @@ +package org.simantics.db.testing.common; + +import java.io.File; + +public class TestSettings { + + private static TestSettings INSTANCE = new TestSettings(); + + private String[] adapters = new String[0]; + private String[] ontologies = new String[0]; + private File workspace; + + private boolean initialized = false; + + private TestSettings() { + } + + public static TestSettings getInstance() { + if(!INSTANCE.initialized) throw new IllegalStateException("POJO settings have not been defined. Please run a suitable configuration test."); + return INSTANCE; + } + + public void setInitialized() { + initialized = true; + } + + public static void setInstance(TestSettings settings) { + INSTANCE = settings; + } + + public String[] getAdapters() { + return adapters; + } + + public void setAdapters(String[] adapters) { + this.adapters = adapters; + } + + public String[] getOntologies() { + return ontologies; + } + + public void setOntologies(String[] ontologies) { + this.ontologies = ontologies; + } + + public File getWorkspace() { + return workspace; + } + + public void setWorkspace(File workspace) { + this.workspace = workspace; + } + + /* + * Only for initialization purposes. + */ + public static TestSettings getInstanceUnsafe() { + return INSTANCE; + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingException.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingException.java new file mode 100644 index 000000000..be90c7379 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingException.java @@ -0,0 +1,34 @@ +package org.simantics.db.testing.common; +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +public class TestingException extends Exception { + + private static final long serialVersionUID = -6769705659201047678L; + + public TestingException() { + } + + public TestingException(String message) { + super(message); + } + + public TestingException(Throwable cause) { + super(cause); + } + + public TestingException(String message, Throwable cause) { + super(message, cause); + } + +} + diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingUtils.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingUtils.java new file mode 100644 index 000000000..819be7807 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestingUtils.java @@ -0,0 +1,138 @@ +package org.simantics.db.testing.common; + +import java.io.File; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.BinaryRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.db.layer0.request.ActivateModel; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.request.Read; +import org.simantics.graph.db.TransferableGraphs; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.representation.TransferableGraphFileReader; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; + +public class TestingUtils { + + public static Resource importModel(final Resource toLocation, File fromFile, String withName) throws Exception { + + TransferableGraphFileReader importer = new TransferableGraphFileReader(fromFile); + TransferableGraph1 tg = importer.readTG(); + importer.close(); + + final DefaultPasteImportAdvisor advisor = new DefaultPasteImportAdvisor(toLocation) { + @Override + public void analyzeType(ReadGraph graph, Root root) throws DatabaseException { + Resource typeResource = graph.getResource(root.type); + if (graph.isInheritedFrom(typeResource, SimulationResource.getInstance(graph).Model)) { + library = toLocation; + } + } + }; + + TransferableGraphs.importGraph1(Simantics.getSession(), tg, advisor, null); + + Simantics.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + String name = graph.getPossibleRelatedValue(advisor.getRoot(), L0.HasName); + if (name != null) + graph.claimLiteral(advisor.getRoot(), L0.HasLabel, name); + graph.syncRequest(new ActivateModel(toLocation, advisor.getRoot())); + + } + }); + + return advisor.getRoot(); + + } + + public static Resource getResource(final Resource base, final String suffix) throws DatabaseException { + + return Simantics.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + String baseURI = graph.getURI(base); + return graph.getResource(baseURI + suffix); + } + + }); + + } + + public static double readConfiguration(Resource model, String rvi) throws DatabaseException { + + class ReadConfiguration extends BinaryRead { + + public ReadConfiguration(Resource model, String rvi) { + super(model, rvi); + } + + @Override + public Double perform(ReadGraph graph) throws DatabaseException { + Variable state = Variables.getVariable(graph, graph.getURI(parameter) + parameter2); + float result = state.getValue(graph); + return (double)result; + } + + } + + return Simantics.getSession().syncRequest(new ReadConfiguration(model, rvi)); + + } + + public static double readState(Resource run, String rvi) throws DatabaseException { + + class ReadState extends BinaryRead { + + public ReadState(Resource run, String rvi) { + super(run, rvi); + } + + @Override + public Double perform(ReadGraph graph) throws DatabaseException { + Variable state = Variables.getVariable(graph, graph.getURI(parameter) + parameter2); + float result = state.getValue(graph); + return (double)result; + } + + } + + return Simantics.getSession().syncRequest(new ReadState(run, rvi)); + + } + + public static boolean lineEquals(String s1, String s2) { + if(s1 == null) { + if(s2 == null) return true; + else return false; + } else { + if(s2 == null) return false; + else return s1.equals(s2); + } + } + + public static String compare(String s1, String s2) { + if(s1.equals(s2)) return null; + String[] lines1 = s1.split("\n"); + String[] lines2 = s2.split("\n"); + for(int i=0;i stms, Resource predicate, Resource object) { + for(Statement stm : stms) { + if(stm.getPredicate().equals(predicate) && stm.getObject().equals(object)) return true; + } + return false; + } + + public static boolean contains(Collection stms, Resource subject, Resource predicate, Resource object) { + for(Statement stm : stms) { + if(stm.getSubject().equals(subject) && stm.getPredicate().equals(predicate) && stm.getObject().equals(object)) return true; + } + return false; + } + public static DatabaseState freshWorkspace(String CORE_DIR, ArrayList fileFilter) throws Exception { + SimanticsPlatform.INSTANCE.resetWorkspace(null, fileFilter); + return newSimanticsWorkspace(null, CORE_DIR); + } + public static void freshDatabase() throws Exception { + DatabaseState state = freshWorkspace(Configuration.get().coreDir, null); + Tests.shutdown(state); + } + public static DatabaseState existingDatabase() throws Exception { + return oldSimanticsWorkspace(null, Configuration.get().coreDir); + } + private static void initSimanticsStuff() { + // Set session context provider. + final ISessionContextProvider provider = new SessionContextProvider(null); + ISessionContextProviderSource source = new SingleSessionContextProviderSource(provider); + Simantics.setSessionContextProviderSource(source); + org.simantics.db.layer0.internal.SimanticsInternal.setSessionContextProviderSource(source); + } + public static DatabaseState newSimanticsWorkspace(TestSettings testSettings, String address) throws Exception { + TestHandler testHandler = Tests.getTestHandler(testSettings, address); + testHandler.initNew(); + initSimanticsStuff(); + SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent()); + return new DatabaseState(address, sessionContext); + } + public static DatabaseState oldSimanticsWorkspace(TestSettings testSettings, String address) throws Exception { + Tests.getTestHandler(testSettings, address); + initSimanticsStuff(); + SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, false, null); + return new DatabaseState(address, sessionContext); + } +// for (String ontology : testSettings.getOntologies()) { +// initOntology(session, ontology); +// } +// String[] adapters = testSettings.getAdapters(); +// if(adapters != null) { +// File[] files = new File[adapters.length]; +// for(int i=0;i extends Command { + + @Override + public void run(final T environment) throws Exception { + Simantics.getSession().sync(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + WriteCommand.this.run(graph, environment); + } + + @Override + public String toString() { + return WriteCommand.this.toString(); + } + + }); + afterRun(environment); + } + + protected void run(WriteGraph graph, T environment) throws DatabaseException { + + } + + protected void afterRun(T environment) throws Exception { + + } + + @Override + public String toString() { + return "WriteCommand " + getClass().getSimpleName(); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteQuery.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteQuery.java new file mode 100644 index 000000000..d928c45c2 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteQuery.java @@ -0,0 +1,42 @@ +package org.simantics.db.testing.common; + +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; + +public abstract class WriteQuery extends WriteRequest { + + /** + * + */ + private final TestBase testBase; + + /** + * @param testBase + */ + public WriteQuery(TestBase testBase) { + this.testBase = testBase; + } + + /** + * Since some SimpleGraphRequest can only handle Exceptions, we need to wrap other Throwables inside Exceptions + * @throws Exception + */ + @Override + public final void perform(WriteGraph g) throws DatabaseException { + try { + run(g); + } catch(Throwable t) { + new Exception().printStackTrace(); + t.printStackTrace(); + if (null == this.testBase.exception2) + this.testBase.exception2 = t; + if (t instanceof Exception) + throw new DatabaseException(t); + throw new DatabaseException("Wrapping thrown non exception to exception.", t); + } + } + + public abstract void run(WriteGraph g) throws Throwable; + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/BaseClient.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/BaseClient.java new file mode 100644 index 000000000..74f8be2c6 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/BaseClient.java @@ -0,0 +1,36 @@ +package org.simantics.db.testing.impl; + + +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.common.Tests; + +public class BaseClient { + protected static final boolean DEBUG = false; +// protected static final String HOST = Configuration.get().host; +// protected final int PORT = Configuration.get().port; +// protected static final String USERNAME = Configuration.get().username; +// protected static final String PASSWORD = Configuration.get().password; +// protected Driver driver; + protected Session session; + protected final String random; + public BaseClient(String name) + throws DatabaseException { + random = name; + session = Tests.getTestHandler().getSession(); + } + public void close() throws DatabaseException { + try { + if (null != session) { + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(); + } + } finally { + session = null; + } + } + public Session getSession() { + return session; + } +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/ClientImpl.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/ClientImpl.java new file mode 100644 index 000000000..882631592 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/ClientImpl.java @@ -0,0 +1,17 @@ +package org.simantics.db.testing.impl; + + +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.common.Client; + +public class ClientImpl extends BaseClient implements Client { + private final String instanceName = "RefreshTestInstanceName" + random + "#"; + private int instanceNumber = 0; + public ClientImpl(String name) throws DatabaseException { + super(name); + } + public String getInstanceName() { + return instanceName + (++instanceNumber); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Configuration.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Configuration.java new file mode 100644 index 000000000..77933df34 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Configuration.java @@ -0,0 +1,131 @@ +package org.simantics.db.testing.impl; + +import org.eclipse.core.runtime.Platform; + +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +public class Configuration { + public final boolean purge = false; // Used to test purge. + public final boolean debug = false; // Used to initialize DEBUG flag on various places. + public final boolean remoteCore = false; // If true connects to remote core. + public final boolean useJournal = false; + public final boolean useFailedTests; + public final boolean virtual; + public final boolean transactionKeep; +// public final String driverName; + public final String workspace = "../../"; + public final String coreDir = Platform.getLocation().append("db").toFile().getAbsolutePath(); + public final String host = "127.0.0.1"; +// public final String host = "Linux-64-Ubuntu-1"; +// public final String host = "Espvm3k973"; + public final int port = (remoteCore) ? 6666 : 0; + public final boolean skipServerCreation = (remoteCore) ? true : false; + public final String username = "Default User"; + public final String password = ""; + public final int connectionReconnectCount; + public final int connectionThreadCount; + public final int connectionSaveCount; + public final int connectionInstanceCount; + public final int modellingLoopCount; + public final int modellingOpCount; + public final String textIndexingFile; + public final int rwQueryThreds; + public final int rwQueryCount; + public final int importOuterCount; + public final int importInnerCount; + public final int cachedClusterCount; // limited by the number of bits reserved for clusters (32768 for now and system needs a few) + public final int cachedClusterRounds; + public final int generateCount; + public final String generateModel; + public final int publishLoopCount; + public final int collectedLoopCount; + public final int refreshLoopCount; + public final int refreshAddCount; + public final int callLoopCount; + public final int callCallCount; + public final int callThreadCount; + public final int i3199ResourceCount; + public final int i3176BlockCount; + public final int i3176BigBlockCount; + public final int i1659LoopCount; + public final String databaseInitFile = "graph.txt"; + private static Configuration current = new Configuration(); + + protected Configuration() { + String configuration = System.getProperty("test.configuration", "regression"); + virtual = System.getProperty("test.graph.impl", "").equals("virtual"); +// driverName = virtual ? ProCoreDriver.ProCoreDriverNameVirtual : ProCoreDriver.ProCoreDriverName; + transactionKeep = System.getProperty("test.transaction.policy", "keep").equals("keep"); + useFailedTests = System.getProperty("test.use.failed", "false").equals("true"); + @SuppressWarnings("unused") + String timeout = System.getProperty("test.exit.timeout", "30000"); + if (configuration.equals("stress")) { + connectionReconnectCount = 100; + connectionThreadCount = 10; + connectionSaveCount = 10; + connectionInstanceCount = 10; + modellingLoopCount = 1000; + modellingOpCount = 1000; + textIndexingFile = "./data/cprrn10.txt"; + rwQueryThreds = 10; + rwQueryCount = 1000000; + importOuterCount = 10; + importInnerCount = 100000; + cachedClusterCount = 4096; + cachedClusterRounds = 10; + generateCount = 1000; + generateModel = "devs"; + publishLoopCount = 200; + collectedLoopCount = 1000; + refreshLoopCount = 2; + refreshAddCount = 1000000; + callLoopCount = 2; + callCallCount = 100000; + callThreadCount = 100; + i3199ResourceCount = 100 * 1000 * 1000; + i3176BlockCount = 1000; + i3176BigBlockCount = 5000; + i1659LoopCount = 100; + } else { // regression + connectionReconnectCount = 2; + connectionThreadCount = 1; + connectionSaveCount = 1; + connectionInstanceCount = 1; + modellingLoopCount = 2; + modellingOpCount = 100; + textIndexingFile = "./data/cprrn00.txt"; + rwQueryThreds = 1; + rwQueryCount = 100; + importOuterCount = 10; + importInnerCount = 100; + cachedClusterCount = 10; + cachedClusterRounds = 2; + generateCount = 1; + generateModel = "test"; + publishLoopCount = 2; + collectedLoopCount = 1; + refreshLoopCount = 2; + refreshAddCount = 100; + callLoopCount = 2; + callCallCount = 100; + callThreadCount = 10; + i3199ResourceCount = 200 * 1000; + i3176BlockCount = 2; + i3176BigBlockCount = 10; + i1659LoopCount = 10; + } + } + public static Configuration get() { + return current; + } +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Proxy.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Proxy.java new file mode 100644 index 000000000..e21323f40 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/Proxy.java @@ -0,0 +1,174 @@ +package org.simantics.db.testing.impl; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; + + +public class Proxy { + + private static int PORT = 6668; + private static String SERVER_ADDRESS="localhost:6666"; + private boolean interrupted = false; + + public Proxy() { + } + + public void run() { + ServerSocket service = null; + try { + service = new ServerSocket(PORT); + } catch (IOException e) { + e.printStackTrace(); + return; + } + + System.out.println("Accepting connections"); + + int connectionNumber = 0; + while(!interrupted) { + try { + final Socket socket = service.accept(); + String connectionName = "Connection" + ++connectionNumber; + System.out.println(connectionName + ": Client connection accepted."); + Runnable runnable = new Runnable() { + @Override + public void run() { + try { + serve(socket); + socket.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + }; + Thread t = new Thread(runnable, connectionName); + t.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Shutdown service + try { + if(service != null) + service.close(); + } catch (IOException ignore) { + } + } + + /** + * Serves socket connection. + * + * @param socket + * @throws IOException + */ + private void serve(Socket socket) throws IOException { + String[] split = SERVER_ADDRESS.split(":"); + if (split.length != 2) + throw new IllegalArgumentException("address does not contain a port, missing ':' character"); + + InetSocketAddress dbAddress = new InetSocketAddress(split[0], Integer.parseInt(split[1])); + Socket dbSocket = new Socket(); + try { + dbSocket.connect(dbAddress); + } catch(IOException e) { + dbSocket.close(); + System.out.println("serve() Couldn't connect to database '" + SERVER_ADDRESS +"'"); + return; + } + String t = Thread.currentThread().getName(); + System.out.println(t + ": Server connection ok."); + proxy(dbSocket, socket, "db", "client"); + dbSocket.close(); + System.out.println(t + ": Client connection closed."); + } + + /** + * Proxies data from socket a to socket b and vice versa + * This method blocks until one of the sockets closes or exception is thrown. + * + * @param a + * @param b + */ + private void proxy(final Socket a, final Socket b, final String aName, final String bName) { + // A -> B + Runnable ab = new Runnable() { + @Override + public void run() { + try { + byte buffer[] = new byte[256]; + while(a.isConnected() && b.isConnected()) { + int n = a.getInputStream().read(buffer); + if (n < 1) + break; + b.getOutputStream().write(buffer, 0, n); + b.getOutputStream().flush(); + } + } catch(IOException e) { + return; // for debugging + } + } + }; + + // B -> A + Runnable ba = new Runnable() { + @Override + public void run() { + try { + byte buffer[] = new byte[256]; + while(b.isConnected() && a.isConnected()) { + int n = b.getInputStream().read(buffer); + if (n < 1) + break; + a.getOutputStream().write(buffer, 0, n); + a.getOutputStream().flush(); + } + } catch(IOException e) { + return; // for debugging + } + } + }; + String t = Thread.currentThread().getName(); + Thread tab = new Thread(ab, t + " " + aName + "->" + bName); + Thread tba = new Thread(ba, t + " " + bName + "->" + aName); + + tab.start(); + tba.start(); + + try { + while(tba.isAlive() && tab.isAlive()) { + Thread.sleep(1000); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + a.close(); + b.close(); + } catch (IOException e) { + } + } + + /** + * @param args + */ + public static void main(String[] args) { + Proxy proxy = new Proxy(); + proxy.run(); + } + +} diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/TempTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/TempTest.java new file mode 100644 index 000000000..d1456cc03 --- /dev/null +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/impl/TempTest.java @@ -0,0 +1,54 @@ +package org.simantics.db.testing.impl; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +public class TempTest extends ExistingDatabaseTest { + @Test + public void test() throws DatabaseException { + final Resource rl = getSession().getRootLibrary(); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection rs = g.getObjects(rl, b.IsRelatedTo); + Set done = new HashSet(); + Set todo = new HashSet(); + for (Resource r : rs) + todo.add(r); + while (!todo.isEmpty()) { + Resource r = todo.iterator().next(); + todo.remove(r); + done.add(r); + Collection rs2 = g.getObjects(r, b.IsRelatedTo); + for (Resource rr : rs2) + if (!done.contains(rr)) + todo.add(rr); + if (DEBUG) + System.out.println("" + done.size()); + } + System.out.println("" + done.size()); + } + }); + } +} \ No newline at end of file diff --git a/releng/org.simantics.sdk.build.p2.site/pom.xml b/releng/org.simantics.sdk.build.p2.site/pom.xml index 828ae537f..404103dcd 100644 --- a/releng/org.simantics.sdk.build.p2.site/pom.xml +++ b/releng/org.simantics.sdk.build.p2.site/pom.xml @@ -216,6 +216,11 @@ commons-io:commons-io:1.4 true + + org.apache.commons:commons-math3:3.6.1 + true + + org.apache.pdfbox:pdfbox:2.0.3 true diff --git a/tests/org.simantics.db.tests/.classpath b/tests/org.simantics.db.tests/.classpath new file mode 100644 index 000000000..f49834373 --- /dev/null +++ b/tests/org.simantics.db.tests/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/org.simantics.db.tests/.externalToolBuilders/org.simantics.db.tests build.xml [Builder].launch b/tests/org.simantics.db.tests/.externalToolBuilders/org.simantics.db.tests build.xml [Builder].launch new file mode 100644 index 000000000..1a2cf9116 --- /dev/null +++ b/tests/org.simantics.db.tests/.externalToolBuilders/org.simantics.db.tests build.xml [Builder].launch @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/.project b/tests/org.simantics.db.tests/.project new file mode 100644 index 000000000..51f077a3b --- /dev/null +++ b/tests/org.simantics.db.tests/.project @@ -0,0 +1,38 @@ + + + org.simantics.db.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.simantics.db.tests build.xml [Builder].launch + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/tests/org.simantics.db.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.simantics.db.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..3a2153707 --- /dev/null +++ b/tests/org.simantics.db.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/tests/org.simantics.db.tests/.settings/org.eclipse.ltk.core.refactoring.prefs b/tests/org.simantics.db.tests/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 000000000..2049590df --- /dev/null +++ b/tests/org.simantics.db.tests/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,3 @@ +#Wed Jul 28 09:12:48 EEST 2010 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/tests/org.simantics.db.tests/META-INF/MANIFEST.MF b/tests/org.simantics.db.tests/META-INF/MANIFEST.MF new file mode 100644 index 000000000..708ba69a5 --- /dev/null +++ b/tests/org.simantics.db.tests/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests Plug-in +Bundle-SymbolicName: org.simantics.db.tests +Bundle-Version: 0.8.0.qualifier +Bundle-Activator: org.simantics.db.tests.common.Activator +Require-Bundle: org.eclipse.core.runtime, + org.junit;bundle-version="4.12.0", + org.simantics.db;bundle-version="0.8.0", + org.simantics.db.services;bundle-version="0.8.0", + org.simantics.db.procore;bundle-version="1.1.1", + org.simantics.layer0.utils, + org.simantics.db.management;bundle-version="0.8.0", + gnu.trove3;bundle-version="3.0.3", + org.simantics.fastlz;bundle-version="1.0.0", + org.apache.log4j;bundle-version="1.2.15", + org.simantics.db.impl;bundle-version="0.8.0", + org.simantics.db.layer0;bundle-version="0.8.0", + org.simantics.project;bundle-version="1.0.1", + org.eclipse.equinox.p2.metadata;bundle-version="2.0.0", + org.simantics.graph.db;bundle-version="1.0.0", + org.simantics.graph;bundle-version="1.0.0", + org.simantics.layer0;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="1.1.1", + org.simantics.db.testing;bundle-version="1.0.0";visibility:=reexport, + org.simantics.datatypes.ontology;bundle-version="1.0.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.simantics.db.tests.common, + org.simantics.db.tests.suite diff --git a/tests/org.simantics.db.tests/TODO.txt b/tests/org.simantics.db.tests/TODO.txt new file mode 100644 index 000000000..6ad748ed5 --- /dev/null +++ b/tests/org.simantics.db.tests/TODO.txt @@ -0,0 +1 @@ +Tests for cyclic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/build.properties b/tests/org.simantics.db.tests/build.properties new file mode 100644 index 000000000..dfa46571b --- /dev/null +++ b/tests/org.simantics.db.tests/build.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2007, 2010 Association for Decentralized Information Management +# in Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/tests/org.simantics.db.tests/build.xml b/tests/org.simantics.db.tests/build.xml new file mode 100644 index 000000000..da0a86faa --- /dev/null +++ b/tests/org.simantics.db.tests/build.xml @@ -0,0 +1,395 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + target.dir=${target.dir} + test.deadlock.timeout=${test.deadlock.timeout} + test.exit.timeout=${test.exit.timeout} + test.configuration=${test.configuration} + test.graph.impl=${test.graph.impl} + test.transaction.policy=${test.transaction.policy} + test.thread.model=${test.thread.model} + test.use.failed=${test.use.failed} + jvmarg.Xmx=${jvmarg.Xmx} + jvmarg.ea=${jvmarg.ea} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests done. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/data/cprrn00.txt b/tests/org.simantics.db.tests/data/cprrn00.txt new file mode 100644 index 000000000..bddcc0d47 --- /dev/null +++ b/tests/org.simantics.db.tests/data/cprrn00.txt @@ -0,0 +1,301 @@ +THE CRITIQUE OF PURE REASON + +by Immanuel Kant + +translated by J. M. D. Meiklejohn + + + +PREFACE TO THE FIRST EDITION, 1781 + +Human reason, in one sphere of its cognition, is called upon to +consider questions, which it cannot decline, as they are presented +by its own nature, but which it cannot answer, as they transcend every +faculty of the mind. + +It falls into this difficulty without any fault of its own. It +begins with principles, which cannot be dispensed with in the field +of experience, and the truth and sufficiency of which are, at the same +time, insured by experience. With these principles it rises, in +obedience to the laws of its own nature, to ever higher and more +remote conditions. But it quickly discovers that, in this way, its +labours must remain ever incomplete, because new questions never cease +to present themselves; and thus it finds itself compelled to have +recourse to principles which transcend the region of experience, while +they are regarded by common sense without distrust. It thus falls into +confusion and contradictions, from which it conjectures the presence +of latent errors, which, however, it is unable to discover, because +the principles it employs, transcending the limits of experience, +cannot be tested by that criterion. The arena of these endless +contests is called Metaphysic. + +Time was, when she was the queen of all the sciences; and, if we +take the will for the deed, she certainly deserves, so far as +regards the high importance of her object-matter, this title of +honour. Now, it is the fashion of the time to heap contempt and +scorn upon her; and the matron mourns, forlorn and forsaken, like +Hecuba: + + Modo maxima rerum, + Tot generis, natisque potens... + Nunc trahor exul, inops. + -- Ovid, Metamorphoses. xiii + +At first, her government, under the administration of the +dogmatists, was an absolute despotism. But, as the legislative +continued to show traces of the ancient barbaric rule, her empire +gradually broke up, and intestine wars introduced the reign of +anarchy; while the sceptics, like nomadic tribes, who hate a permanent +habitation and settled mode of living, attacked from time to time +those who had organized themselves into civil communities. But their +number was, very happily, small; and thus they could not entirely +put a stop to the exertions of those who persisted in raising new +edifices, although on no settled or uniform plan. In recent times +the hope dawned upon us of seeing those disputes settled, and the +legitimacy of her claims established by a kind of physiology of the +human understanding--that of the celebrated Locke. But it was found +that--although it was affirmed that this so-called queen could not +refer her descent to any higher source than that of common experience, +a circumstance which necessarily brought suspicion on her claims--as +this genealogy was incorrect, she persisted in the advancement of +her claims to sovereignty. Thus metaphysics necessarily fell back into +the antiquated and rotten constitution of dogmatism, and again +became obnoxious to the contempt from which efforts had been made to +save it. At present, as all methods, according to the general +persuasion, have been tried in vain, there reigns nought but weariness +and complete indifferentism--the mother of chaos and night in the +scientific world, but at the same time the source of, or at least +the prelude to, the re-creation and reinstallation of a science, +when it has fallen into confusion, obscurity, and disuse from ill +directed effort. + +For it is in reality vain to profess indifference in regard to +such inquiries, the object of which cannot be indifferent to humanity. +Besides, these pretended indifferentists, however much they may try +to disguise themselves by the assumption of a popular style and by +changes on the language of the schools, unavoidably fall into +metaphysical declarations and propositions, which they profess to +regard with so much contempt. At the same time, this indifference, +which has arisen in the world of science, and which relates to that +kind of knowledge which we should wish to see destroyed the last, is +a phenomenon that well deserves our attention and reflection. It is +plainly not the effect of the levity, but of the matured judgement* +of the age, which refuses to be any longer entertained with illusory +knowledge, It is, in fact, a call to reason, again to undertake the +most laborious of all tasks--that of self-examination, and to +establish a tribunal, which may secure it in its well-grounded claims, +while it pronounces against all baseless assumptions and +pretensions, not in an arbitrary manner, but according to its own +eternal and unchangeable laws. This tribunal is nothing less than +the critical investigation of pure reason. + +[*Footnote: We very often hear complaints of the shallowness of the +present age, and of the decay of profound science. But I do not think +that those which rest upon a secure foundation, such as mathematics, +physical science, etc., in the least deserve this reproach, but that +they rather maintain their ancient fame, and in the latter case, +indeed, far surpass it. The same would be the case with the other +kinds of cognition, if their principles were but firmly established. +In the absence of this security, indifference, doubt, and finally, +severe criticism are rather signs of a profound habit of thought. +Our age is the age of criticism, to which everything must be +subjected. The sacredness of religion, and the authority of +legislation, are by many regarded as grounds of exemption from the +examination of this tribunal. But, if they on they are exempted, +they become the subjects of just suspicion, and cannot lay claim to +sincere respect, which reason accords only to that which has stood +the test of a free and public examination.] + +I do not mean by this a criticism of books and systems, but a +critical inquiry into the faculty of reason, with reference to the +cognitions to which it strives to attain without the aid of +experience; in other words, the solution of the question regarding +the possibility or impossibility of metaphysics, and the determination +of the origin, as well as of the extent and limits of this science. +All this must be done on the basis of principles. + +This path--the only one now remaining--has been entered upon by +me; and I flatter myself that I have, in this way, discovered the +cause of--and consequently the mode of removing--all the errors +which have hitherto set reason at variance with itself, in the +sphere of non-empirical thought. I have not returned an evasive answer +to the questions of reason, by alleging the inability and limitation +of the faculties of the mind; I have, on the contrary, examined them +completely in the light of principles, and, after having discovered +the cause of the doubts and contradictions into which reason fell, +have solved them to its perfect satisfaction. It is true, these +questions have not been solved as dogmatism, in its vain fancies and +desires, had expected; for it can only be satisfied by the exercise +of magical arts, and of these I have no knowledge. But neither do these +come within the compass of our mental powers; and it was the duty of +philosophy to destroy the illusions which had their origin in +misconceptions, whatever darling hopes and valued expectations may +be ruined by its explanations. My chief aim in this work has been +thoroughness; and I make bold to say that there is not a single +metaphysical problem that does not find its solution, or at least +the key to its solution, here. Pure reason is a perfect unity; and +therefore, if the principle presented by it prove to be insufficient +for the solution of even a single one of those questions to which +the very nature of reason gives birth, we must reject it, as we could +not be perfectly certain of its sufficiency in the case of the others. + +While I say this, I think I see upon the countenance of the reader +signs of dissatisfaction mingled with contempt, when he hears +declarations which sound so boastful and extravagant; and yet they +are beyond comparison more moderate than those advanced by the commonest +author of the commonest philosophical programme, in which the +dogmatist professes to demonstrate the simple nature of the soul, or +the necessity of a primal being. Such a dogmatist promises to extend +human knowledge beyond the limits of possible experience; while I +humbly confess that this is completely beyond my power. Instead of +any such attempt, I confine myself to the examination of reason alone +and its pure thought; and I do not need to seek far for the +sum-total of its cognition, because it has its seat in my own mind. +Besides, common logic presents me with a complete and systematic +catalogue of all the simple operations of reason; and it is my task +to answer the question how far reason can go, without the material +presented and the aid furnished by experience. + +So much for the completeness and thoroughness necessary in the +execution of the present task. The aims set before us are not +arbitrarily proposed, but are imposed upon us by the nature of +cognition itself. + +The above remarks relate to the matter of our critical inquiry. As +regards the form, there are two indispensable conditions, which any +one who undertakes so difficult a task as that of a critique of pure +reason, is bound to fulfil. These conditions are certitude and +clearness. + +As regards certitude, I have fully convinced myself that, in this +sphere of thought, opinion is perfectly inadmissible, and that +everything which bears the least semblance of an hypothesis must be +excluded, as of no value in such discussions. For it is a necessary +condition of every cognition that is to be established upon a priori +grounds that it shall be held to be absolutely necessary; much more +is this the case with an attempt to determine all pure a priori +cognition, and to furnish the standard--and consequently an example-- +of all apodeictic (philosophical) certitude. Whether I have +succeeded in what I professed to do, it is for the reader to +determine; it is the author's business merely to adduce grounds and +reasons, without determining what influence these ought to have on +the mind of his judges. But, lest anything he may have said may become +the innocent cause of doubt in their minds, or tend to weaken the effect +which his arguments might otherwise produce--he may be allowed to +point out those passages which may occasion mistrust or difficulty, +although these do not concern the main purpose of the present work. +He does this solely with the view of removing from the mind of the +reader any doubts which might affect his judgement of the work as a +whole, and in regard to its ultimate aim. + +I know no investigations more necessary for a full insight into +the nature of the faculty which we call understanding, and at the same +time for the determination of the rules and limits of its use, than +those undertaken in the second chapter of the "Transcendental +Analytic," under the title of "Deduction of the Pure Conceptions of +the Understanding"; and they have also cost me by far the greatest +labour--labour which, I hope, will not remain uncompensated. The +view there taken, which goes somewhat deeply into the subject, has +two sides, The one relates to the objects of the pure understanding, +and is intended to demonstrate and to render comprehensible the +objective validity of its a priori conceptions; and it forms for +this reason an essential part of the Critique. The other considers +the pure understanding itself, its possibility and its powers of +cognition--that is, from a subjective point of view; and, although +this exposition is of great importance, it does not belong essentially +to the main purpose of the work, because the grand question is what +and how much can reason and understanding, apart from experience, +cognize, and not, how is the faculty of thought itself possible? As +the latter is an inquiry into the cause of a given effect, and has +thus in it some semblance of an hypothesis (although, as I shall +show on another occasion, this is really not the fact), it would +seem that, in the present instance, I had allowed myself to enounce +a mere opinion, and that the reader must therefore be at liberty to +hold a different opinion. But I beg to remind him that, if my +subjective deduction does not produce in his mind the conviction of +its certitude at which I aimed, the objective deduction, with which +alone the present work is properly concerned, is in every respect +satisfactory. + +As regards clearness, the reader has a right to demand, in the first +place, discursive or logical clearness, that is, on the basis of +conceptions, and, secondly, intuitive or aesthetic clearness, by means +of intuitions, that is, by examples or other modes of illustration +in concreto. I have done what I could for the first kind of +intelligibility. This was essential to my purpose; and it thus +became the accidental cause of my inability to do complete justice +to the second requirement. I have been almost always at a loss, during +the progress of this work, how to settle this question. Examples and +illustrations always appeared to me necessary, and, in the first +sketch of the Critique, naturally fell into their proper places. But +I very soon became aware of the magnitude of my task, and the numerous +problems with which I should be engaged; and, as I perceived that this +critical investigation would, even if delivered in the driest +scholastic manner, be far from being brief, I found it unadvisable +to enlarge it still more with examples and explanations, which are +necessary only from a popular point of view. I was induced to take +this course from the consideration also that the present work is not +intended for popular use, that those devoted to science do not require +such helps, although they are always acceptable, and that they would +have materially interfered with my present purpose. Abbe Terrasson +remarks with great justice that, if we estimate the size of a work, +not from the number of its pages, but from the time which we require +to make ourselves master of it, it may be said of many a book that +it would be much shorter, if it were not so short. On the other +hand, as regards the comprehensibility of a system of speculative +cognition, connected under a single principle, we may say with equal +justice: many a book would have been much clearer, if it had not +been intended to be so very clear. For explanations and examples, +and other helps to intelligibility, aid us in the comprehension of +parts, but they distract the attention, dissipate the mental power +of the reader, and stand in the way of his forming a clear +conception of the whole; as he cannot attain soon enough to a survey +of the system, and the colouring and embellishments bestowed upon it +prevent his observing its articulation or organization--which is the +most important consideration with him, when he comes to judge of its +unity and stability. + +The reader must naturally have a strong inducement to co-operate +with the present author, if he has formed the intention of erecting +a complete and solid edifice of metaphysical science, according to +the plan now laid before him. Metaphysics, as here represented, is +the only science which admits of completion--and with little labour, +if it is united, in a short time; so that nothing will be left to future +generations except the task of illustrating and applying it +didactically. For this science is nothing more than the inventory of +all that is given us by pure reason, systematically arranged. +Nothing can escape our notice; for what reason produces from itself +cannot lie concealed, but must be brought to the light by reason +itself, so soon as we have discovered the common principle of the +ideas we seek. The perfect unity of this kind of cognitions, which +are based upon pure conceptions, and uninfluenced by any empirical +element, or any peculiar intuition leading to determinate +experience, renders this completeness not only practicable, but also +necessary. + + Tecum habita, et noris quam sit tibi curta supellex. + -- Persius. Satirae iv. 52. + +Such a system of pure speculative reason I hope to be able to +publish under the title of Metaphysic of Nature*. The content of this +work (which will not be half so long) will be very much richer than +that of the present Critique, which has to discover the sources of +this cognition and expose the conditions of its possibility, and at +the same time to clear and level a fit foundation for the scientific +edifice. In the present work, I look for the patient hearing and the +impartiality of a judge; in the other, for the good-will and +assistance of a co-labourer. For, however complete the list of +principles for this system may be in the Critique, the correctness +of the system requires that no deduced conceptions should be absent. +These cannot be presented a priori, but must be gradually +discovered; and, while the synthesis of conceptions has been fully +exhausted in the Critique, it is necessary that, in the proposed work, +the same should be the case with their analysis. But this will be +rather an amusement than a labour. + +[*Footnote: In contradistinction to the Metaphysic of Ethics. This +work was never published.] + + + + diff --git a/tests/org.simantics.db.tests/data/cprrn10.txt b/tests/org.simantics.db.tests/data/cprrn10.txt new file mode 100644 index 000000000..7b7138ef6 --- /dev/null +++ b/tests/org.simantics.db.tests/data/cprrn10.txt @@ -0,0 +1,21275 @@ +THE CRITIQUE OF PURE REASON + +by Immanuel Kant + +translated by J. M. D. Meiklejohn + + + +PREFACE TO THE FIRST EDITION, 1781 + +Human reason, in one sphere of its cognition, is called upon to +consider questions, which it cannot decline, as they are presented +by its own nature, but which it cannot answer, as they transcend every +faculty of the mind. + +It falls into this difficulty without any fault of its own. It +begins with principles, which cannot be dispensed with in the field +of experience, and the truth and sufficiency of which are, at the same +time, insured by experience. With these principles it rises, in +obedience to the laws of its own nature, to ever higher and more +remote conditions. But it quickly discovers that, in this way, its +labours must remain ever incomplete, because new questions never cease +to present themselves; and thus it finds itself compelled to have +recourse to principles which transcend the region of experience, while +they are regarded by common sense without distrust. It thus falls into +confusion and contradictions, from which it conjectures the presence +of latent errors, which, however, it is unable to discover, because +the principles it employs, transcending the limits of experience, +cannot be tested by that criterion. The arena of these endless +contests is called Metaphysic. + +Time was, when she was the queen of all the sciences; and, if we +take the will for the deed, she certainly deserves, so far as +regards the high importance of her object-matter, this title of +honour. Now, it is the fashion of the time to heap contempt and +scorn upon her; and the matron mourns, forlorn and forsaken, like +Hecuba: + + Modo maxima rerum, + Tot generis, natisque potens... + Nunc trahor exul, inops. + -- Ovid, Metamorphoses. xiii + +At first, her government, under the administration of the +dogmatists, was an absolute despotism. But, as the legislative +continued to show traces of the ancient barbaric rule, her empire +gradually broke up, and intestine wars introduced the reign of +anarchy; while the sceptics, like nomadic tribes, who hate a permanent +habitation and settled mode of living, attacked from time to time +those who had organized themselves into civil communities. But their +number was, very happily, small; and thus they could not entirely +put a stop to the exertions of those who persisted in raising new +edifices, although on no settled or uniform plan. In recent times +the hope dawned upon us of seeing those disputes settled, and the +legitimacy of her claims established by a kind of physiology of the +human understanding--that of the celebrated Locke. But it was found +that--although it was affirmed that this so-called queen could not +refer her descent to any higher source than that of common experience, +a circumstance which necessarily brought suspicion on her claims--as +this genealogy was incorrect, she persisted in the advancement of +her claims to sovereignty. Thus metaphysics necessarily fell back into +the antiquated and rotten constitution of dogmatism, and again +became obnoxious to the contempt from which efforts had been made to +save it. At present, as all methods, according to the general +persuasion, have been tried in vain, there reigns nought but weariness +and complete indifferentism--the mother of chaos and night in the +scientific world, but at the same time the source of, or at least +the prelude to, the re-creation and reinstallation of a science, +when it has fallen into confusion, obscurity, and disuse from ill +directed effort. + +For it is in reality vain to profess indifference in regard to +such inquiries, the object of which cannot be indifferent to humanity. +Besides, these pretended indifferentists, however much they may try +to disguise themselves by the assumption of a popular style and by +changes on the language of the schools, unavoidably fall into +metaphysical declarations and propositions, which they profess to +regard with so much contempt. At the same time, this indifference, +which has arisen in the world of science, and which relates to that +kind of knowledge which we should wish to see destroyed the last, is +a phenomenon that well deserves our attention and reflection. It is +plainly not the effect of the levity, but of the matured judgement* +of the age, which refuses to be any longer entertained with illusory +knowledge, It is, in fact, a call to reason, again to undertake the +most laborious of all tasks--that of self-examination, and to +establish a tribunal, which may secure it in its well-grounded claims, +while it pronounces against all baseless assumptions and +pretensions, not in an arbitrary manner, but according to its own +eternal and unchangeable laws. This tribunal is nothing less than +the critical investigation of pure reason. + +[*Footnote: We very often hear complaints of the shallowness of the +present age, and of the decay of profound science. But I do not think +that those which rest upon a secure foundation, such as mathematics, +physical science, etc., in the least deserve this reproach, but that +they rather maintain their ancient fame, and in the latter case, +indeed, far surpass it. The same would be the case with the other +kinds of cognition, if their principles were but firmly established. +In the absence of this security, indifference, doubt, and finally, +severe criticism are rather signs of a profound habit of thought. +Our age is the age of criticism, to which everything must be +subjected. The sacredness of religion, and the authority of +legislation, are by many regarded as grounds of exemption from the +examination of this tribunal. But, if they on they are exempted, +they become the subjects of just suspicion, and cannot lay claim to +sincere respect, which reason accords only to that which has stood +the test of a free and public examination.] + +I do not mean by this a criticism of books and systems, but a +critical inquiry into the faculty of reason, with reference to the +cognitions to which it strives to attain without the aid of +experience; in other words, the solution of the question regarding +the possibility or impossibility of metaphysics, and the determination +of the origin, as well as of the extent and limits of this science. +All this must be done on the basis of principles. + +This path--the only one now remaining--has been entered upon by +me; and I flatter myself that I have, in this way, discovered the +cause of--and consequently the mode of removing--all the errors +which have hitherto set reason at variance with itself, in the +sphere of non-empirical thought. I have not returned an evasive answer +to the questions of reason, by alleging the inability and limitation +of the faculties of the mind; I have, on the contrary, examined them +completely in the light of principles, and, after having discovered +the cause of the doubts and contradictions into which reason fell, +have solved them to its perfect satisfaction. It is true, these +questions have not been solved as dogmatism, in its vain fancies and +desires, had expected; for it can only be satisfied by the exercise +of magical arts, and of these I have no knowledge. But neither do these +come within the compass of our mental powers; and it was the duty of +philosophy to destroy the illusions which had their origin in +misconceptions, whatever darling hopes and valued expectations may +be ruined by its explanations. My chief aim in this work has been +thoroughness; and I make bold to say that there is not a single +metaphysical problem that does not find its solution, or at least +the key to its solution, here. Pure reason is a perfect unity; and +therefore, if the principle presented by it prove to be insufficient +for the solution of even a single one of those questions to which +the very nature of reason gives birth, we must reject it, as we could +not be perfectly certain of its sufficiency in the case of the others. + +While I say this, I think I see upon the countenance of the reader +signs of dissatisfaction mingled with contempt, when he hears +declarations which sound so boastful and extravagant; and yet they +are beyond comparison more moderate than those advanced by the commonest +author of the commonest philosophical programme, in which the +dogmatist professes to demonstrate the simple nature of the soul, or +the necessity of a primal being. Such a dogmatist promises to extend +human knowledge beyond the limits of possible experience; while I +humbly confess that this is completely beyond my power. Instead of +any such attempt, I confine myself to the examination of reason alone +and its pure thought; and I do not need to seek far for the +sum-total of its cognition, because it has its seat in my own mind. +Besides, common logic presents me with a complete and systematic +catalogue of all the simple operations of reason; and it is my task +to answer the question how far reason can go, without the material +presented and the aid furnished by experience. + +So much for the completeness and thoroughness necessary in the +execution of the present task. The aims set before us are not +arbitrarily proposed, but are imposed upon us by the nature of +cognition itself. + +The above remarks relate to the matter of our critical inquiry. As +regards the form, there are two indispensable conditions, which any +one who undertakes so difficult a task as that of a critique of pure +reason, is bound to fulfil. These conditions are certitude and +clearness. + +As regards certitude, I have fully convinced myself that, in this +sphere of thought, opinion is perfectly inadmissible, and that +everything which bears the least semblance of an hypothesis must be +excluded, as of no value in such discussions. For it is a necessary +condition of every cognition that is to be established upon a priori +grounds that it shall be held to be absolutely necessary; much more +is this the case with an attempt to determine all pure a priori +cognition, and to furnish the standard--and consequently an example-- +of all apodeictic (philosophical) certitude. Whether I have +succeeded in what I professed to do, it is for the reader to +determine; it is the author's business merely to adduce grounds and +reasons, without determining what influence these ought to have on +the mind of his judges. But, lest anything he may have said may become +the innocent cause of doubt in their minds, or tend to weaken the effect +which his arguments might otherwise produce--he may be allowed to +point out those passages which may occasion mistrust or difficulty, +although these do not concern the main purpose of the present work. +He does this solely with the view of removing from the mind of the +reader any doubts which might affect his judgement of the work as a +whole, and in regard to its ultimate aim. + +I know no investigations more necessary for a full insight into +the nature of the faculty which we call understanding, and at the same +time for the determination of the rules and limits of its use, than +those undertaken in the second chapter of the "Transcendental +Analytic," under the title of "Deduction of the Pure Conceptions of +the Understanding"; and they have also cost me by far the greatest +labour--labour which, I hope, will not remain uncompensated. The +view there taken, which goes somewhat deeply into the subject, has +two sides, The one relates to the objects of the pure understanding, +and is intended to demonstrate and to render comprehensible the +objective validity of its a priori conceptions; and it forms for +this reason an essential part of the Critique. The other considers +the pure understanding itself, its possibility and its powers of +cognition--that is, from a subjective point of view; and, although +this exposition is of great importance, it does not belong essentially +to the main purpose of the work, because the grand question is what +and how much can reason and understanding, apart from experience, +cognize, and not, how is the faculty of thought itself possible? As +the latter is an inquiry into the cause of a given effect, and has +thus in it some semblance of an hypothesis (although, as I shall +show on another occasion, this is really not the fact), it would +seem that, in the present instance, I had allowed myself to enounce +a mere opinion, and that the reader must therefore be at liberty to +hold a different opinion. But I beg to remind him that, if my +subjective deduction does not produce in his mind the conviction of +its certitude at which I aimed, the objective deduction, with which +alone the present work is properly concerned, is in every respect +satisfactory. + +As regards clearness, the reader has a right to demand, in the first +place, discursive or logical clearness, that is, on the basis of +conceptions, and, secondly, intuitive or aesthetic clearness, by means +of intuitions, that is, by examples or other modes of illustration +in concreto. I have done what I could for the first kind of +intelligibility. This was essential to my purpose; and it thus +became the accidental cause of my inability to do complete justice +to the second requirement. I have been almost always at a loss, during +the progress of this work, how to settle this question. Examples and +illustrations always appeared to me necessary, and, in the first +sketch of the Critique, naturally fell into their proper places. But +I very soon became aware of the magnitude of my task, and the numerous +problems with which I should be engaged; and, as I perceived that this +critical investigation would, even if delivered in the driest +scholastic manner, be far from being brief, I found it unadvisable +to enlarge it still more with examples and explanations, which are +necessary only from a popular point of view. I was induced to take +this course from the consideration also that the present work is not +intended for popular use, that those devoted to science do not require +such helps, although they are always acceptable, and that they would +have materially interfered with my present purpose. Abbe Terrasson +remarks with great justice that, if we estimate the size of a work, +not from the number of its pages, but from the time which we require +to make ourselves master of it, it may be said of many a book that +it would be much shorter, if it were not so short. On the other +hand, as regards the comprehensibility of a system of speculative +cognition, connected under a single principle, we may say with equal +justice: many a book would have been much clearer, if it had not +been intended to be so very clear. For explanations and examples, +and other helps to intelligibility, aid us in the comprehension of +parts, but they distract the attention, dissipate the mental power +of the reader, and stand in the way of his forming a clear +conception of the whole; as he cannot attain soon enough to a survey +of the system, and the colouring and embellishments bestowed upon it +prevent his observing its articulation or organization--which is the +most important consideration with him, when he comes to judge of its +unity and stability. + +The reader must naturally have a strong inducement to co-operate +with the present author, if he has formed the intention of erecting +a complete and solid edifice of metaphysical science, according to +the plan now laid before him. Metaphysics, as here represented, is +the only science which admits of completion--and with little labour, +if it is united, in a short time; so that nothing will be left to future +generations except the task of illustrating and applying it +didactically. For this science is nothing more than the inventory of +all that is given us by pure reason, systematically arranged. +Nothing can escape our notice; for what reason produces from itself +cannot lie concealed, but must be brought to the light by reason +itself, so soon as we have discovered the common principle of the +ideas we seek. The perfect unity of this kind of cognitions, which +are based upon pure conceptions, and uninfluenced by any empirical +element, or any peculiar intuition leading to determinate +experience, renders this completeness not only practicable, but also +necessary. + + Tecum habita, et noris quam sit tibi curta supellex. + -- Persius. Satirae iv. 52. + +Such a system of pure speculative reason I hope to be able to +publish under the title of Metaphysic of Nature*. The content of this +work (which will not be half so long) will be very much richer than +that of the present Critique, which has to discover the sources of +this cognition and expose the conditions of its possibility, and at +the same time to clear and level a fit foundation for the scientific +edifice. In the present work, I look for the patient hearing and the +impartiality of a judge; in the other, for the good-will and +assistance of a co-labourer. For, however complete the list of +principles for this system may be in the Critique, the correctness +of the system requires that no deduced conceptions should be absent. +These cannot be presented a priori, but must be gradually +discovered; and, while the synthesis of conceptions has been fully +exhausted in the Critique, it is necessary that, in the proposed work, +the same should be the case with their analysis. But this will be +rather an amusement than a labour. + +[*Footnote: In contradistinction to the Metaphysic of Ethics. This +work was never published.] + + + + +PREFACE TO THE SECOND EDITION, 1787 + +Whether the treatment of that portion of our knowledge which lies +within the province of pure reason advances with that undeviating +certainty which characterizes the progress of science, we shall be +at no loss to determine. If we find those who are engaged in +metaphysical pursuits, unable to come to an understanding as to the +method which they ought to follow; if we find them, after the most +elaborate preparations, invariably brought to a stand before the +goal is reached, and compelled to retrace their steps and strike +into fresh paths, we may then feel quite sure that they are far from +having attained to the certainty of scientific progress and may rather +be said to be merely groping about in the dark. In these circumstances +we shall render an important service to reason if we succeed in simply +indicating the path along which it must travel, in order to arrive +at any results--even if it should be found necessary to abandon many +of those aims which, without reflection, have been proposed for its +attainment. + +That logic has advanced in this sure course, even from the +earliest times, is apparent from the fact that, since Aristotle, it +has been unable to advance a step and, thus, to all appearance has +reached its completion. For, if some of the moderns have thought to +enlarge its domain by introducing psychological discussions on the +mental faculties, such as imagination and wit, metaphysical, +discussions on the origin of knowledge and the different kinds of +certitude, according to the difference of the objects (idealism, +scepticism, and so on), or anthropological discussions on +prejudices, their causes and remedies: this attempt, on the part of +these authors, only shows their ignorance of the peculiar nature of +logical science. We do not enlarge but disfigure the sciences when +we lose sight of their respective limits and allow them to run into +one another. Now logic is enclosed within limits which admit of +perfectly clear definition; it is a science which has for its object +nothing but the exposition and proof of the formal laws of all +thought, whether it be a priori or empirical, whatever be its origin +or its object, and whatever the difficulties--natural or accidental-- +which it encounters in the human mind. + +The early success of logic must be attributed exclusively to the +narrowness of its field, in which abstraction may, or rather must, +be made of all the objects of cognition with their characteristic +distinctions, and in which the understanding has only to deal with +itself and with its own forms. It is, obviously, a much more difficult +task for reason to strike into the sure path of science, where it +has to deal not simply with itself, but with objects external to +itself. Hence, logic is properly only a propaedeutic--forms, as it +were, the vestibule of the sciences; and while it is necessary to +enable us to form a correct judgement with regard to the various +branches of knowledge, still the acquisition of real, substantive +knowledge is to be sought only in the sciences properly so called, +that is, in the objective sciences. + +Now these sciences, if they can be termed rational at all, must +contain elements of a priori cognition, and this cognition may stand +in a twofold relation to its object. Either it may have to determine +the conception of the object--which must be supplied extraneously, +or it may have to establish its reality. The former is theoretical, +the latter practical, rational cognition. In both, the pure or a +priori element must be treated first, and must be carefully +distinguished from that which is supplied from other sources. Any +other method can only lead to irremediable confusion. + +Mathematics and physics are the two theoretical sciences which +have to determine their objects a priori. The former is purely a +priori, the latter is partially so, but is also dependent on other +sources of cognition. + +In the earliest times of which history affords us any record, +mathematics had already entered on the sure course of science, among +that wonderful nation, the Greeks. Still it is not to be supposed that +it was as easy for this science to strike into, or rather to construct +for itself, that royal road, as it was for logic, in which reason +has only to deal with itself. On the contrary, I believe that it +must have remained long--chiefly among the Egyptians--in the stage +of blind groping after its true aims and destination, and that it +was revolutionized by the happy idea of one man, who struck out and +determined for all time the path which this science must follow, and +which admits of an indefinite advancement. The history of this +intellectual revolution--much more important in its results than the +discovery of the passage round the celebrated Cape of Good Hope--and +of its author, has not been preserved. But Diogenes Laertius, in +naming the supposed discoverer of some of the simplest elements of +geometrical demonstration--elements which, according to the ordinary +opinion, do not even require to be proved--makes it apparent that +the change introduced by the first indication of this new path, must +have seemed of the utmost importance to the mathematicians of that +age, and it has thus been secured against the chance of oblivion. A +new light must have flashed on the mind of the first man (Thales, or +whatever may have been his name) who demonstrated the properties of +the isosceles triangle. For he found that it was not sufficient to +meditate on the figure, as it lay before his eyes, or the conception +of it, as it existed in his mind, and thus endeavour to get at the +knowledge of its properties, but that it was necessary to produce +these properties, as it were, by a positive a priori construction; +and that, in order to arrive with certainty at a priori cognition, +he must not attribute to the object any other properties than those +which necessarily followed from that which he had himself, in accordance +with his conception, placed in the object. + +A much longer period elapsed before physics entered on the highway +of science. For it is only about a century and a half since the wise +Bacon gave a new direction to physical studies, or rather--as others +were already on the right track--imparted fresh vigour to the +pursuit of this new direction. Here, too, as in the case of +mathematics, we find evidence of a rapid intellectual revolution. In +the remarks which follow I shall confine myself to the empirical +side of natural science. + +When Galilei experimented with balls of a definite weight on the +inclined plane, when Torricelli caused the air to sustain a weight +which he had calculated beforehand to be equal to that of a definite +column of water, or when Stahl, at a later period, converted metals +into lime, and reconverted lime into metal, by the addition and +subtraction of certain elements; [Footnote: I do not here follow +with exactness the history of the experimental method, of which, +indeed, the first steps are involved in some obscurity.] a light broke +upon all natural philosophers. They learned that reason only perceives +that which it produces after its own design; that it must not be content +to follow, as it were, in the leading-strings of nature, but must proceed +in advance with principles of judgement according to unvarying laws, +and compel nature to reply its questions. For accidental observations, +made according to no preconceived plan, cannot be united under a +necessary law. But it is this that reason seeks for and requires. It +is only the principles of reason which can give to concordant +phenomena the validity of laws, and it is only when experiment is +directed by these rational principles that it can have any real +utility. Reason must approach nature with the view, indeed, of +receiving information from it, not, however, in the character of a +pupil, who listens to all that his master chooses to tell him, but +in that of a judge, who compels the witnesses to reply to those +questions which he himself thinks fit to propose. To this single +idea must the revolution be ascribed, by which, after groping in the +dark for so many centuries, natural science was at length conducted +into the path of certain progress. + +We come now to metaphysics, a purely speculative science, which +occupies a completely isolated position and is entirely independent +of the teachings of experience. It deals with mere conceptions--not, +like mathematics, with conceptions applied to intuition--and in it, +reason is the pupil of itself alone. It is the oldest of the sciences, +and would still survive, even if all the rest were swallowed up in +the abyss of an all-destroying barbarism. But it has not yet had the +good fortune to attain to the sure scientific method. This will be +apparent; if we apply the tests which we proposed at the outset. We +find that reason perpetually comes to a stand, when it attempts to +gain a priori the perception even of those laws which the most +common experience confirms. We find it compelled to retrace its +steps in innumerable instances, and to abandon the path on which it +had entered, because this does not lead to the desired result. We +find, too, that those who are engaged in metaphysical pursuits are +far from being able to agree among themselves, but that, on the +contrary, this science appears to furnish an arena specially adapted +for the display of skill or the exercise of strength in mock-contests-- +a field in which no combatant ever yet succeeded in gaining an inch +of ground, in which, at least, no victory was ever yet crowned with +permanent possession. + +This leads us to inquire why it is that, in metaphysics, the sure +path of science has not hitherto been found. Shall we suppose that +it is impossible to discover it? Why then should nature have visited +our reason with restless aspirations after it, as if it were one of +our weightiest concerns? Nay, more, how little cause should we have +to place confidence in our reason, if it abandons us in a matter about +which, most of all, we desire to know the truth--and not only so, +but even allures us to the pursuit of vain phantoms, only to betray +us in the end? Or, if the path has only hitherto been missed, what +indications do we possess to guide us in a renewed investigation, +and to enable us to hope for greater success than has fallen to the +lot of our predecessors? + +It appears to me that the examples of mathematics and natural +philosophy, which, as we have seen, were brought into their present +condition by a sudden revolution, are sufficiently remarkable to fix +our attention on the essential circumstances of the change which has +proved so advantageous to them, and to induce us to make the +experiment of imitating them, so far as the analogy which, as rational +sciences, they bear to metaphysics may permit. It has hitherto been +assumed that our cognition must conform to the objects; but all +attempts to ascertain anything about these objects a priori, by +means of conceptions, and thus to extend the range of our knowledge, +have been rendered abortive by this assumption. Let us then make the +experiment whether we may not be more successful in metaphysics, if +we assume that the objects must conform to our cognition. This appears, +at all events, to accord better with the possibility of our gaining +the end we have in view, that is to say, of arriving at the +cognition of objects a priori, of determining something with respect +to these objects, before they are given to us. We here propose to do +just what Copernicus did in attempting to explain the celestial +movements. When he found that he could make no progress by assuming +that all the heavenly bodies revolved round the spectator, he reversed +the process, and tried the experiment of assuming that the spectator +revolved, while the stars remained at rest. We may make the same +experiment with regard to the intuition of objects. If the intuition +must conform to the nature of the objects, I do not see how we can +know anything of them a priori. If, on the other hand, the object +conforms to the nature of our faculty of intuition, I can then +easily conceive the possibility of such an a priori knowledge. Now +as I cannot rest in the mere intuitions, but--if they are to become +cognitions--must refer them, as representations, to something, as +object, and must determine the latter by means of the former, here +again there are two courses open to me. Either, first, I may assume +that the conceptions, by which I effect this determination, conform +to the object--and in this case I am reduced to the same perplexity +as before; or secondly, I may assume that the objects, or, which is +the same thing, that experience, in which alone as given objects they +are cognized, conform to my conceptions--and then I am at no loss +how to proceed. For experience itself is a mode of cognition which +requires understanding. Before objects, are given to me, that is, a +priori, I must presuppose in myself laws of the understanding which +are expressed in conceptions a priori. To these conceptions, then, +all the objects of experience must necessarily conform. Now there are +objects which reason thinks, and that necessarily, but which cannot +be given in experience, or, at least, cannot be given so as reason +thinks them. The attempt to think these objects will hereafter furnish +an excellent test of the new method of thought which we have adopted, +and which is based on the principle that we only cognize in things +a priori that which we ourselves place in them.* + +[*Footnote: This method, accordingly, which we have borrowed from the +natural philosopher, consists in seeking for the elements of pure reason +in that which admits of confirmation or refutation by experiment. Now +the propositions of pure reason, especially when they transcend the +limits of possible experience, do not admit of our making any experiment +with their objects, as in natural science. Hence, with regard to those +conceptions and principles which we assume a priori, our only course +ill be to view them from two different sides. We must regard one and +the same conception, on the one hand, in relation to experience as +an object of the senses and of the understanding, on the other hand, +in relation to reason, isolated and transcending the limits of +experience, as an object of mere thought. Now if we find that, when +we regard things from this double point of view, the result is in harmony +with the principle of pure reason, but that, when we regard them +from a single point of view, reason is involved in self-contradiction, +then the experiment will establish the correctness of this +distinction.] + +This attempt succeeds as well as we could desire, and promises to +metaphysics, in its first part--that is, where it is occupied with +conceptions a priori, of which the corresponding objects may be +given in experience--the certain course of science. For by this new +method we are enabled perfectly to explain the possibility of a priori +cognition, and, what is more, to demonstrate satisfactorily the laws +which lie a priori at the foundation of nature, as the sum of the +objects of experience--neither of which was possible according to +the procedure hitherto followed. But from this deduction of the +faculty of a priori cognition in the first part of metaphysics, we +derive a surprising result, and one which, to all appearance, +militates against the great end of metaphysics, as treated in the +second part. For we come to the conclusion that our faculty of +cognition is unable to transcend the limits of possible experience; +and yet this is precisely the most essential object of this science. +The estimate of our rational cognition a priori at which we arrive +is that it has only to do with phenomena, and that things in +themselves, while possessing a real existence, lie beyond its +sphere. Here we are enabled to put the justice of this estimate to +the test. For that which of necessity impels us to transcend the limits +of experience and of all phenomena is the unconditioned, which reason +absolutely requires in things as they are in themselves, in order to +complete the series of conditions. Now, if it appears that when, on +the one hand, we assume that our cognition conforms to its objects +as things in themselves, the unconditioned cannot be thought without +contradiction, and that when, on the other hand, we assume that our +representation of things as they are given to us, does not conform +to these things as they are in themselves, but that these objects, +as phenomena, conform to our mode of representation, the contradiction +disappears: we shall then be convinced of the truth of that which we +began by assuming for the sake of experiment; we may look upon it as +established that the unconditioned does not lie in things as we know +them, or as they are given to us, but in things as they are in +themselves, beyond the range of our cognition.* + +[*Footnote: This experiment of pure reason has a great similarity to +that of the chemists, which they term the experiment of reduction, +or, more usually, the synthetic process. The analysis of the metaphysician +separates pure cognition a priori into two heterogeneous elements, +viz., the cognition of things as phenomena, and of things in +themselves. Dialectic combines these again into harmony with the +necessary rational idea of the unconditioned, and finds that this +harmony never results except through the above distinction, which +is, therefore, concluded to be just.] + +But, after we have thus denied the power of speculative reason to +make any progress in the sphere of the supersensible, it still remains +for our consideration whether data do not exist in practical cognition +which may enable us to determine the transcendent conception of the +unconditioned, to rise beyond the limits of all possible experience +from a practical point of view, and thus to satisfy the great ends +of metaphysics. Speculative reason has thus, at least, made room for +such an extension of our knowledge: and, if it must leave this space +vacant, still it does not rob us of the liberty to fill it up, if we +can, by means of practical data--nay, it even challenges us to make +the attempt.* + +[*Footnote: So the central laws of the movements of the heavenly bodies +established the truth of that which Copernicus, first, assumed only +as a hypothesis, and, at the same time, brought to light that invisible +force (Newtonian attraction) which holds the universe together. The +latter would have remained forever undiscovered, if Copernicus had +not ventured on the experiment--contrary to the senses but still just-- +of looking for the observed movements not in the heavenly bodies, +but in the spectator. In this Preface I treat the new metaphysical +method as a hypothesis with the view of rendering apparent the first +attempts at such a change of method, which are always hypothetical. +But in the Critique itself it will be demonstrated, not +hypothetically, but apodeictically, from the nature of our +representations of space and time, and from the elementary conceptions +of the understanding.] + +This attempt to introduce a complete revolution in the procedure +of metaphysics, after the example of the geometricians and natural +philosophers, constitutes the aim of the Critique of Pure +Speculative Reason. It is a treatise on the method to be followed, +not a system of the science itself. But, at the same time, it marks +out and defines both the external boundaries and the internal structure +of this science. For pure speculative reason has this peculiarity, +that, in choosing the various objects of thought, it is able to define +the limits of its own faculties, and even to give a complete +enumeration of the possible modes of proposing problems to itself, +and thus to sketch out the entire system of metaphysics. For, on the +one hand, in cognition a priori, nothing must be attributed to the +objects but what the thinking subject derives from itself; and, on +the other hand, reason is, in regard to the principles of cognition, +a perfectly distinct, independent unity, in which, as in an organized +body, every member exists for the sake of the others, and all for the +sake of each, so that no principle can be viewed, with safety, in one +relationship, unless it is, at the same time, viewed in relation to +the total use of pure reason. Hence, too, metaphysics has this +singular advantage--an advantage which falls to the lot of no other +science which has to do with objects--that, if once it is conducted +into the sure path of science, by means of this criticism, it can then +take in the whole sphere of its cognitions, and can thus complete +its work, and leave it for the use of posterity, as a capital which +can never receive fresh accessions. For metaphysics has to deal only +with principles and with the limitations of its own employment as +determined by these principles. To this perfection it is, therefore, +bound, as the fundamental science, to attain, and to it the maxim +may justly be applied: + + Nil actum reputans, si quid superesset agendum. + +But, it will be asked, what kind of a treasure is this that we +propose to bequeath to posterity? What is the real value of this +system of metaphysics, purified by criticism, and thereby reduced to +a permanent condition? A cursory view of the present work will lead +to the supposition that its use is merely negative, that it only serves +to warn us against venturing, with speculative reason, beyond the +limits of experience. This is, in fact, its primary use. But this, +at once, assumes a positive value, when we observe that the principles +with which speculative reason endeavours to transcend its limits +lead inevitably, not to the extension, but to the contraction of the +use of reason, inasmuch as they threaten to extend the limits of +sensibility, which is their proper sphere, over the entire realm of +thought and, thus, to supplant the pure (practical) use of reason. +So far, then, as this criticism is occupied in confining speculative +reason within its proper bounds, it is only negative; but, inasmuch +as it thereby, at the same time, removes an obstacle which impedes +and even threatens to destroy the use of practical reason, it possesses +a positive and very important value. In order to admit this, we have +only to be convinced that there is an absolutely necessary use of pure +reason--the moral use--in which it inevitably transcends the limits +of sensibility, without the aid of speculation, requiring only to be +insured against the effects of a speculation which would involve it +in contradiction with itself. To deny the positive advantage of the +service which this criticism renders us would be as absurd as to +maintain that the system of police is productive of no positive +benefit, since its main business is to prevent the violence which +citizen has to apprehend from citizen, that so each may pursue his +vocation in peace and security. That space and time are only forms +of sensible intuition, and hence are only conditions of the +existence of things as phenomena; that, moreover, we have no +conceptions of the understanding, and, consequently, no elements for +the cognition of things, except in so far as a corresponding intuition +can be given to these conceptions; that, accordingly, we can have no +cognition of an object, as a thing in itself, but only as an object +of sensible intuition, that is, as phenomenon--all this is proved in +the analytical part of the Critique; and from this the limitation of +all possible speculative cognition to the mere objects of +experience, follows as a necessary result. At the same time, it must +be carefully borne in mind that, while we surrender the power of +cognizing, we still reserve the power of thinking objects, as things +in themselves.* For, otherwise, we should require to affirm the +existence of an appearance, without something that appears--which +would be absurd. Now let us suppose, for a moment, that we had not +undertaken this criticism and, accordingly, had not drawn the +necessary distinction between things as objects of experience and +things as they are in themselves. The principle of causality, and, +by consequence, the mechanism of nature as determined by causality, +would then have absolute validity in relation to all things as +efficient causes. I should then be unable to assert, with regard to +one and the same being, e.g., the human soul, that its will is free, +and yet, at the same time, subject to natural necessity, that is, +not free, without falling into a palpable contradiction, for in both +propositions I should take the soul in the same signification, as a +thing in general, as a thing in itself--as, without previous +criticism, I could not but take it. Suppose now, on the other hand, +that we have undertaken this criticism, and have learnt that an object +may be taken in two senses, first, as a phenomenon, secondly, as a +thing in itself; and that, according to the deduction of the +conceptions of the understanding, the principle of causality has +reference only to things in the first sense. We then see how it does +not involve any contradiction to assert, on the one hand, that the +will, in the phenomenal sphere--in visible action--is necessarily +obedient to the law of nature, and, in so far, not free; and, on the +other hand, that, as belonging to a thing in itself, it is not subject +to that law, and, accordingly, is free. Now, it is true that I cannot, +by means of speculative reason, and still less by empirical +observation, cognize my soul as a thing in itself and consequently, +cannot cognize liberty as the property of a being to which I ascribe +effects in the world of sense. For, to do so, I must cognize this +being as existing, and yet not in time, which--since I cannot +support my conception by any intuition--is impossible. At the same +time, while I cannot cognize, I can quite well think freedom, that +is to say, my representation of it involves at least no contradiction, +if we bear in mind the critical distinction of the two modes of +representation (the sensible and the intellectual) and the +consequent limitation of the conceptions of the pure understanding +and of the principles which flow from them. Suppose now that morality +necessarily presupposed liberty, in the strictest sense, as a property +of our will; suppose that reason contained certain practical, original +principles a priori, which were absolutely impossible without this +presupposition; and suppose, at the same time, that speculative reason +had proved that liberty was incapable of being thought at all. It +would then follow that the moral presupposition must give way to the +speculative affirmation, the opposite of which involves an obvious +contradiction, and that liberty and, with it, morality must yield to +the mechanism of nature; for the negation of morality involves no +contradiction, except on the presupposition of liberty. Now morality +does not require the speculative cognition of liberty; it is enough +that I can think it, that its conception involves no contradiction, +that it does not interfere with the mechanism of nature. But even this +requirement we could not satisfy, if we had not learnt the twofold +sense in which things may be taken; and it is only in this way that +the doctrine of morality and the doctrine of nature are confined +within their proper limits. For this result, then, we are indebted +to a criticism which warns us of our unavoidable ignorance with regard +to things in themselves, and establishes the necessary limitation of +our theoretical cognition to mere phenomena. + +[*Footnote: In order to cognize an object, I must be able to prove +its possibility, either from its reality as attested by experience, +or a priori, by means of reason. But I can think what I please, provided +only I do not contradict myself; that is, provided my conception is +a possible thought, though I may be unable to answer for the existence +of a corresponding object in the sum of possibilities. But something +more is required before I can attribute to such a conception objective +validity, that is real possibility--the other possibility being merely +logical. We are not, however, confined to theoretical sources of +cognition for the means of satisfying this additional requirement, +but may derive them from practical sources.] + +The positive value of the critical principles of pure reason in +relation to the conception of God and of the simple nature of the +soul, admits of a similar exemplification; but on this point I shall +not dwell. I cannot even make the assumption--as the practical +interests of morality require--of God, freedom, and immortality, if +I do not deprive speculative reason of its pretensions to transcendent +insight. For to arrive at these, it must make use of principles which, +in fact, extend only to the objects of possible experience, and +which cannot be applied to objects beyond this sphere without +converting them into phenomena, and thus rendering the practical +extension of pure reason impossible. I must, therefore, abolish +knowledge, to make room for belief. The dogmatism of metaphysics, that +is, the presumption that it is possible to advance in metaphysics +without previous criticism, is the true source of the unbelief (always +dogmatic) which militates against morality. + +Thus, while it may be no very difficult task to bequeath a legacy to +posterity, in the shape of a system of metaphysics constructed in +accordance with the Critique of Pure Reason, still the value of such +a bequest is not to be depreciated. It will render an important +service to reason, by substituting the certainty of scientific +method for that random groping after results without the guidance of +principles, which has hitherto characterized the pursuit of +metaphysical studies. It will render an important service to the +inquiring mind of youth, by leading the student to apply his powers +to the cultivation of genuine science, instead of wasting them, as +at present, on speculations which can never lead to any result, or +on the idle attempt to invent new ideas and opinions. But, above all, +it will confer an inestimable benefit on morality and religion, by +showing that all the objections urged against them may be silenced +for ever by the Socratic method, that is to say, by proving the ignorance +of the objector. For, as the world has never been, and, no doubt, never +will be without a system of metaphysics of one kind or another, it +is the highest and weightiest concern of philosophy to render it +powerless for harm, by closing up the sources of error. + +This important change in the field of the sciences, this loss of its +fancied possessions, to which speculative reason must submit, does +not prove in any way detrimental to the general interests of humanity. +The advantages which the world has derived from the teachings of pure +reason are not at all impaired. The loss falls, in its whole extent, +on the monopoly of the schools, but does not in the slightest degree +touch the interests of mankind. I appeal to the most obstinate +dogmatist, whether the proof of the continued existence of the soul +after death, derived from the simplicity of its substance; of the +freedom of the will in opposition to the general mechanism of +nature, drawn from the subtle but impotent distinction of subjective +and objective practical necessity; or of the existence of God, deduced +from the conception of an ens realissimum--the contingency of the +changeable, and the necessity of a prime mover, has ever been able +to pass beyond the limits of the schools, to penetrate the public +mind, or to exercise the slightest influence on its convictions. It +must be admitted that this has not been the case and that, owing to +the unfitness of the common understanding for such subtle +speculations, it can never be expected to take place. On the contrary, +it is plain that the hope of a future life arises from the feeling, +which exists in the breast of every man, that the temporal is +inadequate to meet and satisfy the demands of his nature. In like +manner, it cannot be doubted that the clear exhibition of duties in +opposition to all the claims of inclination, gives rise to the +consciousness of freedom, and that the glorious order, beauty, and +providential care, everywhere displayed in nature, give rise to the +belief in a wise and great Author of the Universe. Such is the genesis +of these general convictions of mankind, so far as they depend on +rational grounds; and this public property not only remains +undisturbed, but is even raised to greater importance, by the doctrine +that the schools have no right to arrogate to themselves a more +profound insight into a matter of general human concernment than +that to which the great mass of men, ever held by us in the highest +estimation, can without difficulty attain, and that the schools +should, therefore, confine themselves to the elaboration of these +universally comprehensible and, from a moral point of view, amply +satisfactory proofs. The change, therefore, affects only the +arrogant pretensions of the schools, which would gladly retain, in +their own exclusive possession, the key to the truths which they +impart to the public. + +Quod mecum nescit, solus vult scire videri. + +At the same time it does not deprive the speculative philosopher of +his just title to be the sole depositor of a science which benefits +the public without its knowledge--I mean, the Critique of Pure Reason. +This can never become popular and, indeed, has no occasion to be so; +for finespun arguments in favour of useful truths make just as +little impression on the public mind as the equally subtle +objections brought against these truths. On the other hand, since both +inevitably force themselves on every man who rises to the height of +speculation, it becomes the manifest duty of the schools to enter upon +a thorough investigation of the rights of speculative reason and, +thus, to prevent the scandal which metaphysical controversies are +sure, sooner or later, to cause even to the masses. It is only by +criticism that metaphysicians (and, as such, theologians too) can be +saved from these controversies and from the consequent perversion of +their doctrines. Criticism alone can strike a blow at the root of +materialism, fatalism, atheism, free-thinking, fanaticism, and +superstition, which are universally injurious--as well as of +idealism and scepticism, which are dangerous to the schools, but can +scarcely pass over to the public. If governments think proper to +interfere with the affairs of the learned, it would be more consistent +with a wise regard for the interests of science, as well as for +those of society, to favour a criticism of this kind, by which alone +the labours of reason can be established on a firm basis, than to +support the ridiculous despotism of the schools, which raise a loud +cry of danger to the public over the destruction of cobwebs, of +which the public has never taken any notice, and the loss of which, +therefore, it can never feel. + +This critical science is not opposed to the dogmatic procedure of +reason in pure cognition; for pure cognition must always be +dogmatic, that is, must rest on strict demonstration from sure +principles a priori--but to dogmatism, that is, to the presumption +that it is possible to make any progress with a pure cognition, +derived from (philosophical) conceptions, according to the +principles which reason has long been in the habit of employing-- +without first inquiring in what way and by what right reason has +come into the possession of these principles. Dogmatism is thus the +dogmatic procedure of pure reason without previous criticism of its +own powers, and in opposing this procedure, we must not be supposed +to lend any countenance to that loquacious shallowness which arrogates +to itself the name of popularity, nor yet to scepticism, which makes +short work with the whole science of metaphysics. On the contrary, +our criticism is the necessary preparation for a thoroughly scientific +system of metaphysics which must perform its task entirely a priori, +to the complete satisfaction of speculative reason, and must, +therefore, be treated, not popularly, but scholastically. In +carrying out the plan which the Critique prescribes, that is, in the +future system of metaphysics, we must have recourse to the strict +method of the celebrated Wolf, the greatest of all dogmatic +philosophers. He was the first to point out the necessity of +establishing fixed principles, of clearly defining our conceptions, +and of subjecting our demonstrations to the most severe scrutiny, +instead of rashly jumping at conclusions. The example which he set +served to awaken that spirit of profound and thorough investigation +which is not yet extinct in Germany. He would have been peculiarly +well fitted to give a truly scientific character to metaphysical +studies, had it occurred to him to prepare the field by a criticism +of the organum, that is, of pure reason itself. That he failed to +perceive the necessity of such a procedure must be ascribed to the +dogmatic mode of thought which characterized his age, and on this +point the philosophers of his time, as well as of all previous +times, have nothing to reproach each other with. Those who reject at +once the method of Wolf, and of the Critique of Pure Reason, can +have no other aim but to shake off the fetters of science, to change +labour into sport, certainty into opinion, and philosophy into +philodoxy. + +In this second edition, I have endeavoured, as far as possible, to +remove the difficulties and obscurity which, without fault of mine +perhaps, have given rise to many misconceptions even among acute +thinkers. In the propositions themselves, and in the demonstrations +by which they are supported, as well as in the form and the entire +plan of the work, I have found nothing to alter; which must be attributed +partly to the long examination to which I had subjected the whole +before offering it to the public and partly to the nature of the case. +For pure speculative reason is an organic structure in which there +is nothing isolated or independent, but every Single part is essential +to all the rest; and hence, the slightest imperfection, whether defect +or positive error, could not fail to betray itself in use. I +venture, further, to hope, that this system will maintain the same +unalterable character for the future. I am led to entertain this +confidence, not by vanity, but by the evidence which the equality of +the result affords, when we proceed, first, from the simplest elements +up to the complete whole of pure reason and, and then, backwards +from the whole to each part. We find that the attempt to make the +slightest alteration, in any part, leads inevitably to contradictions, +not merely in this system, but in human reason itself. At the same +time, there is still much room for improvement in the exposition of +the doctrines contained in this work. In the present edition, I have +endeavoured to remove misapprehensions of the aesthetical part, +especially with regard to the conception of time; to clear away the +obscurity which has been found in the deduction of the conceptions +of the understanding; to supply the supposed want of sufficient +evidence in the demonstration of the principles of the pure +understanding; and, lastly, to obviate the misunderstanding of the +paralogisms which immediately precede the rational psychology. +Beyond this point--the end of the second main division of the +"Transcendental Dialectic"--I have not extended my alterations,* +partly from want of time, and partly because I am not aware that any +portion of the remainder has given rise to misconceptions among +intelligent and impartial critics, whom I do not here mention with +that praise which is their due, but who will find that their +suggestions have been attended to in the work itself. + +[*Footnote: The only addition, properly so called--and that only in +the method of proof--which I have made in the present edition, consists +of a new refutation of psychological idealism, and a strict +demonstration--the only one possible, as I believe--of the objective +reality of external intuition. However harmless idealism may be +considered--although in reality it is not so--in regard to the +essential ends of metaphysics, it must still remain a scandal to +philosophy and to the general human reason to be obliged to assume, +as an article of mere belief, the existence of things external to +ourselves (from which, yet, we derive the whole material of +cognition for the internal sense), and not to be able to oppose a +satisfactory proof to any one who may call it in question. As there +is some obscurity of expression in the demonstration as it stands in +the text, I propose to alter the passage in question as follows: +"But this permanent cannot be an intuition in me. For all the +determining grounds of my existence which can be found in me are +representations and, as such, do themselves require a permanent, +distinct from them, which may determine my existence in relation to +their changes, that is, my existence in time, wherein they change." +It may, probably, be urged in opposition to this proof that, after +all, I am only conscious immediately of that which is in me, that is, +of my representation of external things, and that, consequently, it +must always remain uncertain whether anything corresponding to this +representation does or does not exist externally to me. But I am +conscious, through internal experience, of my existence in time +(consequently, also, of the determinability of the former in the +latter), and that is more than the simple consciousness of my +representation. It is, in fact, the same as the empirical +consciousness of my existence, which can only be determined in +relation to something, which, while connected with my existence, is +external to me. This consciousness of my existence in time is, +therefore, identical with the consciousness of a relation to something +external to me, and it is, therefore, experience, not fiction, +sense, not imagination, which inseparably connects the external with +my internal sense. For the external sense is, in itself, the +relation of intuition to something real, external to me; and the +reality of this something, as opposed to the mere imagination of it, +rests solely on its inseparable connection with internal experience +as the condition of its possibility. If with the intellectual +consciousness of my existence, in the representation: I am, which +accompanies all my judgements, and all the operations of my +understanding, I could, at the same time, connect a determination of +my existence by intellectual intuition, then the consciousness of a +relation to something external to me would not be necessary. But the +internal intuition in which alone my existence can be determined, +though preceded by that purely intellectual consciousness, is itself +sensible and attached to the condition of time. Hence this +determination of my existence, and consequently my internal experience +itself, must depend on something permanent which is not in me, which +can be, therefore, only in something external to me, to which I must +look upon myself as being related. Thus the reality of the external +sense is necessarily connected with that of the internal, in order +to the possibility of experience in general; that is, I am just as +certainly conscious that there are things external to me related to +my sense as I am that I myself exist as determined in time. But in +order to ascertain to what given intuitions objects, external me, +really correspond, in other words, what intuitions belong to the +external sense and not to imagination, I must have recourse, in +every particular case, to those rules according to which experience +in general (even internal experience) is distinguished from +imagination, and which are always based on the proposition that +there really is an external experience. We may add the remark that +the representation of something permanent in existence, is not the +same thing as the permanent representation; for a representation may +be very variable and changing--as all our representations, even that +of matter, are--and yet refer to something permanent, which must, +therefore, be distinct from all my representations and external to +me, the existence of which is necessarily included in the determination +of my own existence, and with it constitutes one experience--an +experience which would not even be possible internally, if it were +not also at the same time, in part, external. To the question How? +we are no more able to reply, than we are, in general, to think the +stationary in time, the coexistence of which with the variable, +produces the conception of change.] + +In attempting to render the exposition of my views as intelligible +as possible, I have been compelled to leave out or abridge various +passages which were not essential to the completeness of the work, +but which many readers might consider useful in other respects, and +might be unwilling to miss. This trifling loss, which could not be +avoided without swelling the book beyond due limits, may be +supplied, at the pleasure of the reader, by a comparison with the +first edition, and will, I hope, be more than compensated for by the +greater clearness of the exposition as it now stands. + +I have observed, with pleasure and thankfulness, in the pages of +various reviews and treatises, that the spirit of profound and +thorough investigation is not extinct in Germany, though it may have +been overborne and silenced for a time by the fashionable tone of a +licence in thinking, which gives itself the airs of genius, and that +the difficulties which beset the paths of criticism have not prevented +energetic and acute thinkers from making themselves masters of the +science of pure reason to which these paths conduct--a science which +is not popular, but scholastic in its character, and which alone can +hope for a lasting existence or possess an abiding value. To these +deserving men, who so happily combine profundity of view with a talent +for lucid exposition--a talent which I myself am not conscious of +possessing--I leave the task of removing any obscurity which may still +adhere to the statement of my doctrines. For, in this case, the danger +is not that of being refuted, but of being misunderstood. For my own +part, I must henceforward abstain from controversy, although I shall +carefully attend to all suggestions, whether from friends or +adversaries, which may be of use in the future elaboration of the +system of this propaedeutic. As, during these labours, I have advanced +pretty far in years this month I reach my sixty-fourth year--it will +be necessary for me to economize time, if I am to carry out my plan +of elaborating the metaphysics of nature as well as of morals, in +confirmation of the correctness of the principles established in +this Critique of Pure Reason, both speculative and practical; and I +must, therefore, leave the task of clearing up the obscurities of +the present work--inevitable, perhaps, at the outset--as well as, +the defence of the whole, to those deserving men, who have made my +system their own. A philosophical system cannot come forward armed +at all points like a mathematical treatise, and hence it may be +quite possible to take objection to particular passages, while the +organic structure of the system, considered as a unity, has no +danger to apprehend. But few possess the ability, and still fewer +the inclination, to take a comprehensive view of a new system. By +confining the view to particular passages, taking these out of their +connection and comparing them with one another, it is easy to pick +out apparent contradictions, especially in a work written with any +freedom of style. These contradictions place the work in an unfavourable +light in the eyes of those who rely on the judgement of others, but +are easily reconciled by those who have mastered the idea of the whole. +If a theory possesses stability in itself, the action and reaction +which seemed at first to threaten its existence serve only, in the +course of time, to smooth down any superficial roughness or +inequality, and--if men of insight, impartiality, and truly popular +gifts, turn their attention to it--to secure to it, in a short time, +the requisite elegance also. + + + +Konigsberg, April 1787. +INTRODUCTION + + + + +I. Of the difference between Pure and Empirical Knowledge + +That all our knowledge begins with experience there can be no doubt. +For how is it possible that the faculty of cognition should be +awakened into exercise otherwise than by means of objects which affect +our senses, and partly of themselves produce representations, partly +rouse our powers of understanding into activity, to compare to +connect, or to separate these, and so to convert the raw material of +our sensuous impressions into a knowledge of objects, which is +called experience? In respect of time, therefore, no knowledge of ours +is antecedent to experience, but begins with it. + +But, though all our knowledge begins with experience, it by no means +follows that all arises out of experience. For, on the contrary, it +is quite possible that our empirical knowledge is a compound of that +which we receive through impressions, and that which the faculty of +cognition supplies from itself (sensuous impressions giving merely +the occasion), an addition which we cannot distinguish from the original +element given by sense, till long practice has made us attentive to, +and skilful in separating it. It is, therefore, a question which +requires close investigation, and not to be answered at first sight, +whether there exists a knowledge altogether independent of experience, +and even of all sensuous impressions? Knowledge of this kind is called +a priori, in contradistinction to empirical knowledge, which has its +sources a posteriori, that is, in experience. + +But the expression, "a priori," is not as yet definite enough +adequately to indicate the whole meaning of the question above +started. For, in speaking of knowledge which has its sources in +experience, we are wont to say, that this or that may be known a +priori, because we do not derive this knowledge immediately from +experience, but from a general rule, which, however, we have itself +borrowed from experience. Thus, if a man undermined his house, we say, +"he might know a priori that it would have fallen;" that is, he needed +not to have waited for the experience that it did actually fall. But +still, a priori, he could not know even this much. For, that bodies +are heavy, and, consequently, that they fall when their supports are +taken away, must have been known to him previously, by means of +experience. + +By the term "knowledge a priori," therefore, we shall in the +sequel understand, not such as is independent of this or that kind +of experience, but such as is absolutely so of all experience. Opposed +to this is empirical knowledge, or that which is possible only a +posteriori, that is, through experience. Knowledge a priori is +either pure or impure. Pure knowledge a priori is that with which no +empirical element is mixed up. For example, the proposition, "Every +change has a cause," is a proposition a priori, but impure, because +change is a conception which can only be derived from experience. + + + +II. The Human Intellect, even in an Unphilosophical State, + is in Possession of Certain Cognitions "a priori". + +The question now is as to a criterion, by which we may securely +distinguish a pure from an empirical cognition. Experience no doubt +teaches us that this or that object is constituted in such and such +a manner, but not that it could not possibly exist otherwise. Now, +in the first place, if we have a proposition which contains the idea +of necessity in its very conception, it is a if, moreover, it is not +derived from any other proposition, unless from one equally +involving the idea of necessity, it is absolutely priori. Secondly, +an empirical judgement never exhibits strict and absolute, but only +assumed and comparative universality (by induction); therefore, the +most we can say is--so far as we have hitherto observed, there is no +exception to this or that rule. If, on the other hand, a judgement +carries with it strict and absolute universality, that is, admits of +no possible exception, it is not derived from experience, but is valid +absolutely a priori. + +Empirical universality is, therefore, only an arbitrary extension of +validity, from that which may be predicated of a proposition valid +in most cases, to that which is asserted of a proposition which +holds good in all; as, for example, in the affirmation, "All bodies +are heavy." When, on the contrary, strict universality characterizes +a judgement, it necessarily indicates another peculiar source of +knowledge, namely, a faculty of cognition a priori. Necessity and +strict universality, therefore, are infallible tests for +distinguishing pure from empirical knowledge, and are inseparably +connected with each other. But as in the use of these criteria the +empirical limitation is sometimes more easily detected than the +contingency of the judgement, or the unlimited universality which we +attach to a judgement is often a more convincing proof than its +necessity, it may be advisable to use the criteria separately, each +being by itself infallible. + +Now, that in the sphere of human cognition we have judgements +which are necessary, and in the strictest sense universal, +consequently pure a priori, it will be an easy matter to show. If we +desire an example from the sciences, we need only take any proposition +in mathematics. If we cast our eyes upon the commonest operations of +the understanding, the proposition, "Every change must have a +cause," will amply serve our purpose. In the latter case, indeed, +the conception of a cause so plainly involves the conception of a +necessity of connection with an effect, and of a strict universality +of the law, that the very notion of a cause would entirely +disappear, were we to derive it, like Hume, from a frequent +association of what happens with that which precedes; and the habit +thence originating of connecting representations--the necessity +inherent in the judgement being therefore merely subjective. +Besides, without seeking for such examples of principles existing a +priori in cognition, we might easily show that such principles are +the indispensable basis of the possibility of experience itself, and +consequently prove their existence a priori. For whence could our +experience itself acquire certainty, if all the rules on which it +depends were themselves empirical, and consequently fortuitous? No +one, therefore, can admit the validity of the use of such rules as +first principles. But, for the present, we may content ourselves +with having established the fact, that we do possess and exercise a +faculty of pure a priori cognition; and, secondly, with having pointed +out the proper tests of such cognition, namely, universality and +necessity. + +Not only in judgements, however, but even in conceptions, is an a +priori origin manifest. For example, if we take away by degrees from +our conceptions of a body all that can be referred to mere sensuous +experience--colour, hardness or softness, weight, even +impenetrability--the body will then vanish; but the space which it +occupied still remains, and this it is utterly impossible to +annihilate in thought. Again, if we take away, in like manner, from +our empirical conception of any object, corporeal or incorporeal, +all properties which mere experience has taught us to connect with +it, still we cannot think away those through which we cogitate it as +substance, or adhering to substance, although our conception of +substance is more determined than that of an object. Compelled, +therefore, by that necessity with which the conception of substance +forces itself upon us, we must confess that it has its seat in our +faculty of cognition a priori. + + + +III. Philosophy stands in need of a Science which shall + Determine the Possibility, Principles, and Extent of + Human Knowledge "a priori" + +Of far more importance than all that has been above said, is the +consideration that certain of our cognitions rise completely above +the sphere of all possible experience, and by means of conceptions, +to which there exists in the whole extent of experience no +corresponding object, seem to extend the range of our judgements +beyond its bounds. And just in this transcendental or supersensible +sphere, where experience affords us neither instruction nor +guidance, lie the investigations of reason, which, on account of their +importance, we consider far preferable to, and as having a far more +elevated aim than, all that the understanding can achieve within the +sphere of sensuous phenomena. So high a value do we set upon these +investigations, that even at the risk of error, we persist in +following them out, and permit neither doubt nor disregard nor +indifference to restrain us from the pursuit. These unavoidable +problems of mere pure reason are God, freedom (of will), and +immortality. The science which, with all its preliminaries, has for +its especial object the solution of these problems is named +metaphysics--a science which is at the very outset dogmatical, that +is, it confidently takes upon itself the execution of this task +without any previous investigation of the ability or inability of +reason for such an undertaking. + +Now the safe ground of experience being thus abandoned, it seems +nevertheless natural that we should hesitate to erect a building +with the cognitions we possess, without knowing whence they come, +and on the strength of principles, the origin of which is +undiscovered. Instead of thus trying to build without a foundation, +it is rather to be expected that we should long ago have put the +question, how the understanding can arrive at these a priori +cognitions, and what is the extent, validity, and worth which they +may possess? We say, "This is natural enough," meaning by the word +natural, that which is consistent with a just and reasonable way of +thinking; but if we understand by the term, that which usually +happens, nothing indeed could be more natural and more +comprehensible than that this investigation should be left long +unattempted. For one part of our pure knowledge, the science of +mathematics, has been long firmly established, and thus leads us to +form flattering expectations with regard to others, though these may +be of quite a different nature. Besides, when we get beyond the bounds +of experience, we are of course safe from opposition in that +quarter; and the charm of widening the range of our knowledge is so +great that, unless we are brought to a standstill by some evident +contradiction, we hurry on undoubtingly in our course. This, +however, may be avoided, if we are sufficiently cautious in the +construction of our fictions, which are not the less fictions on +that account. + +Mathematical science affords us a brilliant example, how far, +independently of all experience, we may carry our a priori +knowledge. It is true that the mathematician occupies himself with +objects and cognitions only in so far as they can be represented by +means of intuition. But this circumstance is easily overlooked, +because the said intuition can itself be given a priori, and therefore +is hardly to be distinguished from a mere pure conception. Deceived +by such a proof of the power of reason, we can perceive no limits to +the extension of our knowledge. The light dove cleaving in free flight +the thin air, whose resistance it feels, might imagine that her +movements would be far more free and rapid in airless space. Just in +the same way did Plato, abandoning the world of sense because of the +narrow limits it sets to the understanding, venture upon the wings +of ideas beyond it, into the void space of pure intellect. He did +not reflect that he made no real progress by all his efforts; for he +met with no resistance which might serve him for a support, as it +were, whereon to rest, and on which he might apply his powers, in +order to let the intellect acquire momentum for its progress. It is, +indeed, the common fate of human reason in speculation, to finish +the imposing edifice of thought as rapidly as possible, and then for +the first time to begin to examine whether the foundation is a solid +one or no. Arrived at this point, all sorts of excuses are sought +after, in order to console us for its want of stability, or rather, +indeed, to enable Us to dispense altogether with so late and dangerous +an investigation. But what frees us during the process of building +from all apprehension or suspicion, and flatters us into the belief +of its solidity, is this. A great part, perhaps the greatest part, +of the business of our reason consists in the analysation of the +conceptions which we already possess of objects. By this means we gain +a multitude of cognitions, which although really nothing more than +elucidations or explanations of that which (though in a confused +manner) was already thought in our conceptions, are, at least in +respect of their form, prized as new introspections; whilst, so far +as regards their matter or content, we have really made no addition +to our conceptions, but only disinvolved them. But as this process +does furnish a real priori knowledge, which has a sure progress and +useful results, reason, deceived by this, slips in, without being +itself aware of it, assertions of a quite different kind; in which, +to given conceptions it adds others, a priori indeed, but entirely +foreign to them, without our knowing how it arrives at these, and, +indeed, without such a question ever suggesting itself. I shall +therefore at once proceed to examine the difference between these +two modes of knowledge. + + + +IV. Of the Difference Between Analytical and Synthetical Judgements. + +In all judgements wherein the relation of a subject to the predicate +is cogitated (I mention affirmative judgements only here; the +application to negative will be very easy), this relation is +possible in two different ways. Either the predicate B belongs to +the subject A, as somewhat which is contained (though covertly) in +the conception A; or the predicate B lies completely out of the conception +A, although it stands in connection with it. In the first instance, +I term the judgement analytical, in the second, synthetical. +Analytical judgements (affirmative) are therefore those in which the +connection of the predicate with the subject is cogitated through +identity; those in which this connection is cogitated without +identity, are called synthetical judgements. The former may be +called explicative, the latter augmentative judgements; because the +former add in the predicate nothing to the conception of the +subject, but only analyse it into its constituent conceptions, which +were thought already in the subject, although in a confused manner; +the latter add to our conceptions of the subject a predicate which +was not contained in it, and which no analysis could ever have +discovered therein. For example, when I say, "All bodies are +extended," this is an analytical judgement. For I need not go beyond +the conception of body in order to find extension connected with it, +but merely analyse the conception, that is, become conscious of the +manifold properties which I think in that conception, in order to +discover this predicate in it: it is therefore an analytical +judgement. On the other hand, when I say, "All bodies are heavy," +the predicate is something totally different from that which I think +in the mere conception of a body. By the addition of such a predicate, +therefore, it becomes a synthetical judgement. + +Judgements of experience, as such, are always synthetical. For it +would be absurd to think of grounding an analytical judgement on +experience, because in forming such a judgement I need not go out of +the sphere of my conceptions, and therefore recourse to the +testimony of experience is quite unnecessary. That "bodies are +extended" is not an empirical judgement, but a proposition which +stands firm a priori. For before addressing myself to experience, I +already have in my conception all the requisite conditions for the +judgement, and I have only to extract the predicate from the +conception, according to the principle of contradiction, and thereby +at the same time become conscious of the necessity of the judgement, +a necessity which I could never learn from experience. On the other +hand, though at first I do not at all include the predicate of +weight in my conception of body in general, that conception still +indicates an object of experience, a part of the totality of +experience, to which I can still add other parts; and this I do when +I recognize by observation that bodies are heavy. I can cognize +beforehand by analysis the conception of body through the +characteristics of extension, impenetrability, shape, etc., all +which are cogitated in this conception. But now I extend my knowledge, +and looking back on experience from which I had derived this +conception of body, I find weight at all times connected with the +above characteristics, and therefore I synthetically add to my +conceptions this as a predicate, and say, "All bodies are heavy." Thus +it is experience upon which rests the possibility of the synthesis +of the predicate of weight with the conception of body, because both +conceptions, although the one is not contained in the other, still +belong to one another (only contingently, however), as parts of a +whole, namely, of experience, which is itself a synthesis of +intuitions. + +But to synthetical judgements a priori, such aid is entirely +wanting. If I go out of and beyond the conception A, in order to +recognize another B as connected with it, what foundation have I to +rest on, whereby to render the synthesis possible? I have here no +longer the advantage of looking out in the sphere of experience for +what I want. Let us take, for example, the proposition, "Everything +that happens has a cause." In the conception of "something that +happens," I indeed think an existence which a certain time +antecedes, and from this I can derive analytical judgements. But the +conception of a cause lies quite out of the above conception, and +indicates something entirely different from "that which happens," +and is consequently not contained in that conception. How then am I +able to assert concerning the general conception--"that which +happens"--something entirely different from that conception, and to +recognize the conception of cause although not contained in it, yet +as belonging to it, and even necessarily? what is here the unknown += X, upon which the understanding rests when it believes it has found, +out of the conception A a foreign predicate B, which it nevertheless +considers to be connected with it? It cannot be experience, because +the principle adduced annexes the two representations, cause and +effect, to the representation existence, not only with universality, +which experience cannot give, but also with the expression of +necessity, therefore completely a priori and from pure conceptions. +Upon such synthetical, that is augmentative propositions, depends +the whole aim of our speculative knowledge a priori; for although +analytical judgements are indeed highly important and necessary, +they are so, only to arrive at that clearness of conceptions which +is requisite for a sure and extended synthesis, and this alone is a +real acquisition. + + + +V. In all Theoretical Sciences of Reason, Synthetical Judgements +"a priori" are contained as Principles. + +1. Mathematical judgements are always synthetical. Hitherto this +fact, though incontestably true and very important in its +consequences, seems to have escaped the analysts of the human mind, +nay, to be in complete opposition to all their conjectures. For as +it was found that mathematical conclusions all proceed according to +the principle of contradiction (which the nature of every apodeictic +certainty requires), people became persuaded that the fundamental +principles of the science also were recognized and admitted in the +same way. But the notion is fallacious; for although a synthetical +proposition can certainly be discerned by means of the principle of +contradiction, this is possible only when another synthetical +proposition precedes, from which the latter is deduced, but never +of itself. + +Before all, be it observed, that proper mathematical propositions +are always judgements a priori, and not empirical, because they +carry along with them the conception of necessity, which cannot be +given by experience. If this be demurred to, it matters not; I will +then limit my assertion to pure mathematics, the very conception of +which implies that it consists of knowledge altogether non-empirical +and a priori. + +We might, indeed at first suppose that the proposition 7 + 5 = 12 is +a merely analytical proposition, following (according to the principle +of contradiction) from the conception of a sum of seven and five. +But if we regard it more narrowly, we find that our conception of +the sum of seven and five contains nothing more than the uniting of +both sums into one, whereby it cannot at all be cogitated what this +single number is which embraces both. The conception of twelve is by +no means obtained by merely cogitating the union of seven and five; +and we may analyse our conception of such a possible sum as long as +we will, still we shall never discover in it the notion of twelve. +We must go beyond these conceptions, and have recourse to an intuition +which corresponds to one of the two--our five fingers, for example, +or like Segner in his Arithmetic five points, and so by degrees, add +the units contained in the five given in the intuition, to the +conception of seven. For I first take the number 7, and, for the +conception of 5 calling in the aid of the fingers of my hand as +objects of intuition, I add the units, which I before took together +to make up the number 5, gradually now by means of the material image +my hand, to the number 7, and by this process, I at length see the +number 12 arise. That 7 should be added to 5, I have certainly +cogitated in my conception of a sum = 7 + 5, but not that this sum +was equal to 12. Arithmetical propositions are therefore always +synthetical, of which we may become more clearly convinced by trying +large numbers. For it will thus become quite evident that, turn and +twist our conceptions as we may, it is impossible, without having +recourse to intuition, to arrive at the sum total or product by +means of the mere analysis of our conceptions. Just as little is any +principle of pure geometry analytical. "A straight line between two +points is the shortest," is a synthetical proposition. For my +conception of straight contains no notion of quantity, but is merely +qualitative. The conception of the shortest is therefore fore wholly +an addition, and by no analysis can it be extracted from our +conception of a straight line. Intuition must therefore here lend +its aid, by means of which, and thus only, our synthesis is possible. + +Some few principles preposited by geometricians are, indeed, +really analytical, and depend on the principle of contradiction. +They serve, however, like identical propositions, as links in the +chain of method, not as principles--for example, a = a, the whole is +equal to itself, or (a+b) > a, the whole is greater than its part. +And yet even these principles themselves, though they derive their +validity from pure conceptions, are only admitted in mathematics +because they can be presented in intuition. What causes us here +commonly to believe that the predicate of such apodeictic judgements +is already contained in our conception, and that the judgement is +therefore analytical, is merely the equivocal nature of the +expression. We must join in thought a certain predicate to a given +conception, and this necessity cleaves already to the conception. +But the question is, not what we must join in thought to the given +conception, but what we really think therein, though only obscurely, +and then it becomes manifest that the predicate pertains to these +conceptions, necessarily indeed, yet not as thought in the +conception itself, but by virtue of an intuition, which must be +added to the conception. + +2. The science of natural philosophy (physics) contains in itself +synthetical judgements a priori, as principles. I shall adduce two +propositions. For instance, the proposition, "In all changes of the +material world, the quantity of matter remains unchanged"; or, that, +"In all communication of motion, action and reaction must always be +equal." In both of these, not only is the necessity, and therefore +their origin a priori clear, but also that they are synthetical +propositions. For in the conception of matter, I do not cogitate its +permanency, but merely its presence in space, which it fills. I +therefore really go out of and beyond the conception of matter, in +order to think on to it something a priori, which I did not think in +it. The proposition is therefore not analytical, but synthetical, +and nevertheless conceived a priori; and so it is with regard to the +other propositions of the pure part of natural philosophy. + +3. As to metaphysics, even if we look upon it merely as an attempted +science, yet, from the nature of human reason, an indispensable one, +we find that it must contain synthetical propositions a priori. It +is not merely the duty of metaphysics to dissect, and thereby +analytically to illustrate the conceptions which we form a priori of +things; but we seek to widen the range of our a priori knowledge. +For this purpose, we must avail ourselves of such principles as add +something to the original conception--something not identical with, +nor contained in it, and by means of synthetical judgements a +priori, leave far behind us the limits of experience; for example, +in the proposition, "the world must have a beginning," and such +like. Thus metaphysics, according to the proper aim of the science, +consists merely of synthetical propositions a priori. + + + +VI. The Universal Problem of Pure Reason. + +It is extremely advantageous to be able to bring a number of +investigations under the formula of a single problem. For in this +manner, we not only facilitate our own labour, inasmuch as we define +it clearly to ourselves, but also render it more easy for others to +decide whether we have done justice to our undertaking. The proper +problem of pure reason, then, is contained in the question: "How are +synthetical judgements a priori possible?" + +That metaphysical science has hitherto remained in so vacillating +a state of uncertainty and contradiction, is only to be attributed +to the fact that this great problem, and perhaps even the difference +between analytical and synthetical judgements, did not sooner +suggest itself to philosophers. Upon the solution of this problem, +or upon sufficient proof of the impossibility of synthetical knowledge +a priori, depends the existence or downfall of the science of +metaphysics. Among philosophers, David Hume came the nearest of all +to this problem; yet it never acquired in his mind sufficient +precision, nor did he regard the question in its universality. On +the contrary, he stopped short at the synthetical proposition of the +connection of an effect with its cause (principium causalitatis), +insisting that such proposition a priori was impossible. According +to his conclusions, then, all that we term metaphysical science is +a mere delusion, arising from the fancied insight of reason into that +which is in truth borrowed from experience, and to which habit has +given the appearance of necessity. Against this assertion, destructive +to all pure philosophy, he would have been guarded, had he had our +problem before his eyes in its universality. For he would then have +perceived that, according to his own argument, there likewise could +not be any pure mathematical science, which assuredly cannot exist +without synthetical propositions a priori--an absurdity from which +his good understanding must have saved him. + +In the solution of the above problem is at the same time +comprehended the possibility of the use of pure reason in the +foundation and construction of all sciences which contain +theoretical knowledge a priori of objects, that is to say, the +answer to the following questions: + +How is pure mathematical science possible? + +How is pure natural science possible? + +Respecting these sciences, as they do certainly exist, it may with +propriety be asked, how they are possible?--for that they must be +possible is shown by the fact of their really existing.* But as to +metaphysics, the miserable progress it has hitherto made, and the fact +that of no one system yet brought forward, far as regards its true +aim, can it be said that this science really exists, leaves any one +at liberty to doubt with reason the very possibility of its existence. + +[*Footnote: As to the existence of pure natural science, or physics, +perhaps many may still express doubts. But we have only to look at +the different propositions which are commonly treated of at the +commencement of proper (empirical) physical science--those, for +example, relating to the permanence of the same quantity of matter, +the vis inertiae, the equality of action and reaction, etc.--to be +soon convinced that they form a science of pure physics (physica pura, +or rationalis), which well deserves to be separately exposed as a +special science, in its whole extent, whether that be great or +confined.] + +Yet, in a certain sense, this kind of knowledge must +unquestionably be looked upon as given; in other words, metaphysics +must be considered as really existing, if not as a science, +nevertheless as a natural disposition of the human mind (metaphysica +naturalis). For human reason, without any instigations imputable to +the mere vanity of great knowledge, unceasingly progresses, urged on +by its own feeling of need, towards such questions as cannot be +answered by any empirical application of reason, or principles derived +therefrom; and so there has ever really existed in every man some +system of metaphysics. It will always exist, so soon as reason +awakes to the exercise of its power of speculation. And now the +question arises: "How is metaphysics, as a natural disposition, +possible?" In other words, how, from the nature of universal human +reason, do those questions arise which pure reason proposes to itself, +and which it is impelled by its own feeling of need to answer as +well as it can? + +But as in all the attempts hitherto made to answer the questions +which reason is prompted by its very nature to propose to itself, +for example, whether the world had a beginning, or has existed from +eternity, it has always met with unavoidable contradictions, we must +not rest satisfied with the mere natural disposition of the mind to +metaphysics, that is, with the existence of the faculty of pure +reason, whence, indeed, some sort of metaphysical system always +arises; but it must be possible to arrive at certainty in regard to +the question whether we know or do not know the things of which +metaphysics treats. We must be able to arrive at a decision on the +subjects of its questions, or on the ability or inability of reason +to form any judgement respecting them; and therefore either to extend +with confidence the bounds of our pure reason, or to set strictly +defined and safe limits to its action. This last question, which +arises out of the above universal problem, would properly run thus: +"How is metaphysics possible as a science?" + +Thus, the critique of reason leads at last, naturally and +necessarily, to science; and, on the other hand, the dogmatical use +of reason without criticism leads to groundless assertions, against +which others equally specious can always be set, thus ending unavoidably +in scepticism. + +Besides, this science cannot be of great and formidable prolixity, +because it has not to do with objects of reason, the variety of +which is inexhaustible, but merely with Reason herself and her +problems; problems which arise out of her own bosom, and are not +proposed to her by the nature of outward things, but by her own +nature. And when once Reason has previously become able completely +to understand her own power in regard to objects which she meets +with in experience, it will be easy to determine securely the extent +and limits of her attempted application to objects beyond the confines +of experience. + +We may and must, therefore, regard the attempts hitherto made to +establish metaphysical science dogmatically as non-existent. For +what of analysis, that is, mere dissection of conceptions, is +contained in one or other, is not the aim of, but only a preparation +for metaphysics proper, which has for its object the extension, by +means of synthesis, of our a priori knowledge. And for this purpose, +mere analysis is of course useless, because it only shows what is +contained in these conceptions, but not how we arrive, a priori, at +them; and this it is her duty to show, in order to be able +afterwards to determine their valid use in regard to all objects of +experience, to all knowledge in general. But little self-denial, +indeed, is needed to give up these pretensions, seeing the undeniable, +and in the dogmatic mode of procedure, inevitable contradictions of +Reason with herself, have long since ruined the reputation of every +system of metaphysics that has appeared up to this time. It will +require more firmness to remain undeterred by difficulty from +within, and opposition from without, from endeavouring, by a method +quite opposed to all those hitherto followed, to further the growth +and fruitfulness of a science indispensable to human reason--a science +from which every branch it has borne may be cut away, but whose +roots remain indestructible. + + + +VII. Idea and Division of a Particular Science, under the + Name of a Critique of Pure Reason. + +From all that has been said, there results the idea of a +particular science, which may be called the Critique of Pure Reason. +For reason is the faculty which furnishes us with the principles of +knowledge a priori. Hence, pure reason is the faculty which contains +the principles of cognizing anything absolutely a priori. An organon +of pure reason would be a compendium of those principles according +to which alone all pure cognitions a priori can be obtained. The +completely extended application of such an organon would afford us +a system of pure reason. As this, however, is demanding a great deal, +and it is yet doubtful whether any extension of our knowledge be +here possible, or, if so, in what cases; we can regard a science of +the mere criticism of pure reason, its sources and limits, as the +propaedeutic to a system of pure reason. Such a science must not be +called a doctrine, but only a critique of pure reason; and its use, +in regard to speculation, would be only negative, not to enlarge the +bounds of, but to purify, our reason, and to shield it against +error--which alone is no little gain. I apply the term +transcendental to all knowledge which is not so much occupied with +objects as with the mode of our cognition of these objects, so far +as this mode of cognition is possible a priori. A system of such +conceptions would be called transcendental philosophy. But this, +again, is still beyond the bounds of our present essay. For as such +a science must contain a complete exposition not only of our +synthetical a priori, but of our analytical a priori knowledge, it +is of too wide a range for our present purpose, because we do not +require to carry our analysis any farther than is necessary to +understand, in their full extent, the principles of synthesis a +priori, with which alone we have to do. This investigation, which we +cannot properly call a doctrine, but only a transcendental critique, +because it aims not at the enlargement, but at the correction and +guidance, of our knowledge, and is to serve as a touchstone of the +worth or worthlessness of all knowledge a priori, is the sole object +of our present essay. Such a critique is consequently, as far as +possible, a preparation for an organon; and if this new organon should +be found to fail, at least for a canon of pure reason, according to +which the complete system of the philosophy of pure reason, whether +it extend or limit the bounds of that reason, might one day be set +forth both analytically and synthetically. For that this is +possible, nay, that such a system is not of so great extent as to +preclude the hope of its ever being completed, is evident. For we have +not here to do with the nature of outward objects, which is +infinite, but solely with the mind, which judges of the nature of +objects, and, again, with the mind only in respect of its cognition +a priori. And the object of our investigations, as it is not to be +sought without, but, altogether within, ourselves, cannot remain +concealed, and in all probability is limited enough to be completely +surveyed and fairly estimated, according to its worth or +worthlessness. Still less let the reader here expect a critique of +books and systems of pure reason; our present object is exclusively +a critique of the faculty of pure reason itself. Only when we make +this critique our foundation, do we possess a pure touchstone for +estimating the philosophical value of ancient and modern writings on +this subject; and without this criterion, the incompetent historian +or judge decides upon and corrects the groundless assertions of others +with his own, which have themselves just as little foundation. + +Transcendental philosophy is the idea of a science, for which the +Critique of Pure Reason must sketch the whole plan +architectonically, that is, from principles, with a full guarantee +for the validity and stability of all the parts which enter into the +building. It is the system of all the principles of pure reason. If +this Critique itself does not assume the title of transcendental +philosophy, it is only because, to be a complete system, it ought to +contain a full analysis of all human knowledge a priori. Our +critique must, indeed, lay before us a complete enumeration of all +the radical conceptions which constitute the said pure knowledge. But +from the complete analysis of these conceptions themselves, as also +from a complete investigation of those derived from them, it abstains +with reason; partly because it would be deviating from the end in view +to occupy itself with this analysis, since this process is not +attended with the difficulty and insecurity to be found in the +synthesis, to which our critique is entirely devoted, and partly +because it would be inconsistent with the unity of our plan to +burden this essay with the vindication of the completeness of such +an analysis and deduction, with which, after all, we have at present +nothing to do. This completeness of the analysis of these radical +conceptions, as well as of the deduction from the conceptions a priori +which may be given by the analysis, we can, however, easily attain, +provided only that we are in possession of all these radical +conceptions, which are to serve as principles of the synthesis, and +that in respect of this main purpose nothing is wanting. + +To the Critique of Pure Reason, therefore, belongs all that +constitutes transcendental philosophy; and it is the complete idea +of transcendental philosophy, but still not the science itself; +because it only proceeds so far with the analysis as is necessary to +the power of judging completely of our synthetical knowledge a priori. + +The principal thing we must attend to, in the division of the +parts of a science like this, is that no conceptions must enter it +which contain aught empirical; in other words, that the knowledge a +priori must be completely pure. Hence, although the highest principles +and fundamental conceptions of morality are certainly cognitions a +priori, yet they do not belong to transcendental philosophy; +because, though they certainly do not lay the conceptions of pain, +pleasure, desires, inclinations, etc. (which are all of empirical +origin), at the foundation of its precepts, yet still into the +conception of duty--as an obstacle to be overcome, or as an incitement +which should not be made into a motive--these empirical conceptions +must necessarily enter, in the construction of a system of pure +morality. Transcendental philosophy is consequently a philosophy of +the pure and merely speculative reason. For all that is practical, +so far as it contains motives, relates to feelings, and these belong +to empirical sources of cognition. + +If we wish to divide this science from the universal point of view +of a science in general, it ought to comprehend, first, a Doctrine +of the Elements, and, secondly, a Doctrine of the Method of pure +reason. Each of these main divisions will have its subdivisions, the +separate reasons for which we cannot here particularize. Only so +much seems necessary, by way of introduction of premonition, that +there are two sources of human knowledge (which probably spring from +a common, but to us unknown root), namely, sense and understanding. +By the former, objects are given to us; by the latter, thought. So +far as the faculty of sense may contain representations a priori, which +form the conditions under which objects are given, in so far it +belongs to transcendental philosophy. The transcendental doctrine of +sense must form the first part of our science of elements, because +the conditions under which alone the objects of human knowledge are +given must precede those under which they are thought. + + + + +I. TRANSCENDENTAL DOCTRINE OF ELEMENTS. + +FIRST PART. TRANSCENDENTAL AESTHETIC. + +SS I. Introductory. + +In whatsoever mode, or by whatsoever means, our knowledge may relate +to objects, it is at least quite clear that the only manner in which +it immediately relates to them is by means of an intuition. To this +as the indispensable groundwork, all thought points. But an intuition +can take place only in so far as the object is given to us. This, again, +is only possible, to man at least, on condition that the object affect +the mind in a certain manner. The capacity for receiving +representations (receptivity) through the mode in which we are +affected by objects, objects, is called sensibility. By means of +sensibility, therefore, objects are given to us, and it alone +furnishes us with intuitions; by the understanding they are thought, +and from it arise conceptions. But an thought must directly, or +indirectly, by means of certain signs, relate ultimately to +intuitions; consequently, with us, to sensibility, because in no other +way can an object be given to us. + +The effect of an object upon the faculty of representation, so far +as we are affected by the said object, is sensation. That sort of +intuition which relates to an object by means of sensation is called +an empirical intuition. The undetermined object of an empirical +intuition is called phenomenon. That which in the phenomenon +corresponds to the sensation, I term its matter; but that which +effects that the content of the phenomenon can be arranged under +certain relations, I call its form. But that in which our sensations +are merely arranged, and by which they are susceptible of assuming +a certain form, cannot be itself sensation. It is, then, the matter +of all phenomena that is given to us a posteriori; the form must lie +ready a priori for them in the mind, and consequently can be +regarded separately from all sensation. + +I call all representations pure, in the transcendental meaning of +the word, wherein nothing is met with that belongs to sensation. And +accordingly we find existing in the mind a priori, the pure form of +sensuous intuitions in general, in which all the manifold content of +the phenomenal world is arranged and viewed under certain relations. +This pure form of sensibility I shall call pure intuition. Thus, if +I take away from our representation of a body all that the +understanding thinks as belonging to it, as substance, force, +divisibility, etc., and also whatever belongs to sensation, as +impenetrability, hardness, colour, etc.; yet there is still +something left us from this empirical intuition, namely, extension +and shape. These belong to pure intuition, which exists a priori in +the mind, as a mere form of sensibility, and without any real object +of the senses or any sensation. + +The science of all the principles of sensibility a priori, I call +transcendental aesthetic.* There must, then, be such a science forming +the first part of the transcendental doctrine of elements, in +contradistinction to that part which contains the principles of pure +thought, and which is called transcendental logic. + +[Footnote: The Germans are the only people who at present use this +word to indicate what others call the critique of taste. At the foundation +of this term lies the disappointed hope, which the eminent analyst, +Baumgarten, conceived, of subjecting the criticism of the beautiful +to principles of reason, and so of elevating its rules into a science. +But his endeavours were vain. For the said rules or criteria are, in +respect to their chief sources, merely empirical, consequently never +can serve as determinate laws a priori, by which our judgement in +matters of taste is to be directed. It is rather our judgement which +forms the proper test as to the correctness of the principles. On this +account it is advisable to give up the use of the term as +designating the critique of taste, and to apply it solely to that +doctrine, which is true science--the science of the laws of +sensibility--and thus come nearer to the language and the sense of +the ancients in their well-known division of the objects of cognition +into aiotheta kai noeta, or to share it with speculative philosophy, +and employ it partly in a transcendental, partly in a psychological +signification.] + +In the science of transcendental aesthetic accordingly, we shall +first isolate sensibility or the sensuous faculty, by separating +from it all that is annexed to its perceptions by the conceptions of +understanding, so that nothing be left but empirical intuition. In +the next place we shall take away from this intuition all that belongs +to sensation, so that nothing may remain but pure intuition, and the +mere form of phenomena, which is all that the sensibility can afford +a priori. From this investigation it will be found that there are two +pure forms of sensuous intuition, as principles of knowledge a priori, +namely, space and time. To the consideration of these we shall now +proceed. + + + +SECTION I. Of Space. + +SS 2. Metaphysical Exposition of this Conception. + +By means of the external sense (a property of the mind), we +represent to ourselves objects as without us, and these all in +space. Herein alone are their shape, dimensions, and relations to each +other determined or determinable. The internal sense, by means of +which the mind contemplates itself or its internal state, gives, +indeed, no intuition of the soul as an object; yet there is +nevertheless a determinate form, under which alone the contemplation +of our internal state is possible, so that all which relates to the +inward determinations of the mind is represented in relations of time. +Of time we cannot have any external intuition, any more than we can +have an internal intuition of space. What then are time and space? +Are they real existences? Or, are they merely relations or +determinations of things, such, however, as would equally belong to +these things in themselves, though they should never become objects +of intuition; or, are they such as belong only to the form of +intuition, and consequently to the subjective constitution of the +mind, without which these predicates of time and space could not be +attached to any object? In order to become informed on these points, +we shall first give an exposition of the conception of space. By +exposition, I mean the clear, though not detailed, representation of +that which belongs to a conception; and an exposition is +metaphysical when it contains that which represents the conception +as given a priori. + +1. Space is not a conception which has been derived from outward +experiences. For, in order that certain sensations may relate to +something without me (that is, to something which occupies a different +part of space from that in which I am); in like manner, in order +that I may represent them not merely as without, of, and near to +each other, but also in separate places, the representation of space +must already exist as a foundation. Consequently, the representation +of space cannot be borrowed from the relations of external phenomena +through experience; but, on the contrary, this external experience +is itself only possible through the said antecedent representation. + +2. Space then is a necessary representation a priori, which serves +for the foundation of all external intuitions. We never can imagine +or make a representation to ourselves of the non-existence of space, +though we may easily enough think that no objects are found in it. +It must, therefore, be considered as the condition of the +possibility of phenomena, and by no means as a determination dependent +on them, and is a representation a priori, which necessarily +supplies the basis for external phenomena. + +3. Space is no discursive, or as we say, general conception of the +relations of things, but a pure intuition. For, in the first place, +we can only represent to ourselves one space, and, when we talk of +divers spaces, we mean only parts of one and the same space. Moreover, +these parts cannot antecede this one all-embracing space, as the +component parts from which the aggregate can be made up, but can be +cogitated only as existing in it. Space is essentially one, and +multiplicity in it, consequently the general notion of spaces, of this +or that space, depends solely upon limitations. Hence it follows +that an a priori intuition (which is not empirical) lies at the root +of all our conceptions of space. Thus, moreover, the principles of +geometry--for example, that "in a triangle, two sides together are +greater than the third," are never deduced from general conceptions +of line and triangle, but from intuition, and this a priori, with +apodeictic certainty. + +4. Space is represented as an infinite given quantity. Now every +conception must indeed be considered as a representation which is +contained in an infinite multitude of different possible +representations, which, therefore, comprises these under itself; but +no conception, as such, can be so conceived, as if it contained within +itself an infinite multitude of representations. Nevertheless, space +is so conceived of, for all parts of space are equally capable of +being produced to infinity. Consequently, the original +representation of space is an intuition a priori, and not a +conception. + + + +SS 3. Transcendental Exposition of the Conception of Space. + +By a transcendental exposition, I mean the explanation of a +conception, as a principle, whence can be discerned the possibility +of other synthetical a priori cognitions. For this purpose, it is +requisite, firstly, that such cognitions do really flow from the given +conception; and, secondly, that the said cognitions are only +possible under the presupposition of a given mode of explaining this +conception. + +Geometry is a science which determines the properties of space +synthetically, and yet a priori. What, then, must be our +representation of space, in order that such a cognition of it may be +possible? It must be originally intuition, for from a mere conception, +no propositions can be deduced which go out beyond the conception, +and yet this happens in geometry. (Introd. V.) But this intuition must +be found in the mind a priori, that is, before any perception of +objects, consequently must be pure, not empirical, intuition. For +geometrical principles are always apodeictic, that is, united with +the consciousness of their necessity, as: "Space has only three +dimensions." But propositions of this kind cannot be empirical +judgements, nor conclusions from them. (Introd. II.) Now, how can an +external intuition anterior to objects themselves, and in which our +conception of objects can be determined a priori, exist in the human +mind? Obviously not otherwise than in so far as it has its seat in +the subject only, as the formal capacity of the subject's being affected +by objects, and thereby of obtaining immediate representation, that +is, intuition; consequently, only as the form of the external sense +in general. + +Thus it is only by means of our explanation that the possibility +of geometry, as a synthetical science a priori, becomes +comprehensible. Every mode of explanation which does not show us +this possibility, although in appearance it may be similar to ours, +can with the utmost certainty be distinguished from it by these marks. + + + +SS 4. Conclusions from the foregoing Conceptions. + +(a) Space does not represent any property of objects as +things in themselves, nor does it represent them in their relations +to each other; in other words, space does not represent to us any +determination of objects such as attaches to the objects themselves, +and would remain, even though all subjective conditions of the +intuition were abstracted. For neither absolute nor relative +determinations of objects can be intuited prior to the existence of +the things to which they belong, and therefore not a priori. + +(b) Space is nothing else than the form of all phenomena of the +external sense, that is, the subjective condition of the +sensibility, under which alone external intuition is possible. Now, +because the receptivity or capacity of the subject to be affected by +objects necessarily antecedes all intuitions of these objects, it is +easily understood how the form of all phenomena can be given in the +mind previous to all actual perceptions, therefore a priori, and how +it, as a pure intuition, in which all objects must be determined, +can contain principles of the relations of these objects prior to +all experience. + +It is therefore from the human point of view only that we can +speak of space, extended objects, etc. If we depart from the +subjective condition, under which alone we can obtain external +intuition, or, in other words, by means of which we are affected by +objects, the representation of space has no meaning whatsoever. This +predicate is only applicable to things in so far as they appear to +us, that is, are objects of sensibility. The constant form of this +receptivity, which we call sensibility, is a necessary condition of +all relations in which objects can be intuited as existing without +us, and when abstraction of these objects is made, is a pure intuition, +to which we give the name of space. It is clear that we cannot make +the special conditions of sensibility into conditions of the possibility +of things, but only of the possibility of their existence as far as +they are phenomena. And so we may correctly say that space contains +all which can appear to us externally, but not all things considered +as things in themselves, be they intuited or not, or by whatsoever +subject one will. As to the intuitions of other thinking beings, we +cannot judge whether they are or are not bound by the same +conditions which limit our own intuition, and which for us are +universally valid. If we join the limitation of a judgement to the +conception of the subject, then the judgement will possess +unconditioned validity. For example, the proposition, "All objects +are beside each other in space," is valid only under the limitation +that these things are taken as objects of our sensuous intuition. But +if I join the condition to the conception and say, "All things, as +external phenomena, are beside each other in space," then the rule +is valid universally, and without any limitation. Our expositions, +consequently, teach the reality (i.e., the objective validity) of +space in regard of all which can be presented to us externally as +object, and at the same time also the ideality of space in regard to +objects when they are considered by means of reason as things in +themselves, that is, without reference to the constitution of our +sensibility. We maintain, therefore, the empirical reality of space +in regard to all possible external experience, although we must admit +its transcendental ideality; in other words, that it is nothing, so +soon as we withdraw the condition upon which the possibility of all +experience depends and look upon space as something that belongs to +things in themselves. + +But, with the exception of space, there is no representation, +subjective and referring to something external to us, which could +be called objective a priori. For there are no other subjective +representations from which we can deduce synthetical propositions a +priori, as we can from the intuition of space. (See SS 3.) +Therefore, to speak accurately, no ideality whatever belongs to these, +although they agree in this respect with the representation of +space, that they belong merely to the subjective nature of the mode +of sensuous perception; such a mode, for example, as that of sight, +of hearing, and of feeling, by means of the sensations of colour, +sound, and heat, but which, because they are only sensations and not +intuitions, do not of themselves give us the cognition of any +object, least of all, an a priori cognition. My purpose, in the +above remark, is merely this: to guard any one against illustrating +the asserted ideality of space by examples quite insufficient, for +example, by colour, taste, etc.; for these must be contemplated not +as properties of things, but only as changes in the subject, changes +which may be different in different men. For, in such a case, that +which is originally a mere phenomenon, a rose, for example, is taken +by the empirical understanding for a thing in itself, though to +every different eye, in respect of its colour, it may appear +different. On the contrary, the transcendental conception of phenomena +in space is a critical admonition, that, in general, nothing which +is intuited in space is a thing in itself, and that space is not a +form which belongs as a property to things; but that objects are quite +unknown to us in themselves, and what we call outward objects, are +nothing else but mere representations of our sensibility, whose form +is space, but whose real correlate, the thing in itself, is not +known by means of these representations, nor ever can be, but +respecting which, in experience, no inquiry is ever made. + + + + +SECTION II. Of Time. + +SS 5. Metaphysical Exposition of this Conception. + +1. Time is not an empirical conception. For neither coexistence +nor succession would be perceived by us, if the representation of time +did not exist as a foundation a priori. Without this presupposition +we could not represent to ourselves that things exist together at one +and the same time, or at different times, that is, contemporaneously, +or in succession. + +2. Time is a necessary representation, lying at the foundation of +all our intuitions. With regard to phenomena in general, we cannot +think away time from them, and represent them to ourselves as out of +and unconnected with time, but we can quite well represent to +ourselves time void of phenomena. Time is therefore given a priori. +In it alone is all reality of phenomena possible. These may all be +annihilated in thought, but time itself, as the universal condition +of their possibility, cannot be so annulled. + +3. On this necessity a priori is also founded the possibility of +apodeictic principles of the relations of time, or axioms of time in +general, such as: "Time has only one dimension," "Different times +are not coexistent but successive" (as different spaces are not +successive but coexistent). These principles cannot be derived from +experience, for it would give neither strict universality, nor +apodeictic certainty. We should only be able to say, "so common +experience teaches us," but not "it must be so." They are valid as +rules, through which, in general, experience is possible; and they +instruct us respecting experience, and not by means of it. + +4. Time is not a discursive, or as it is called, general conception, +but a pure form of the sensuous intuition. Different times are +merely parts of one and the same time. But the representation which +can only be given by a single object is an intuition. Besides, the +proposition that different times cannot be coexistent could not be +derived from a general conception. For this proposition is +synthetical, and therefore cannot spring out of conceptions alone. +It is therefore contained immediately in the intuition and +representation of time. + +5. The infinity of time signifies nothing more than that every +determined quantity of time is possible only through limitations of +one time lying at the foundation. Consequently, the original +representation, time, must be given as unlimited. But as the +determinate representation of the parts of time and of every +quantity of an object can only be obtained by limitation, the complete +representation of time must not be furnished by means of +conceptions, for these contain only partial representations. +Conceptions, on the contrary, must have immediate intuition for +their basis. + + + +SS 6 Transcendental Exposition of the Conception of Time. + +I may here refer to what is said above (SS 5, 3), where, for or sake +of brevity, I have placed under the head of metaphysical exposition, +that which is properly transcendental. Here I shall add that the +conception of change, and with it the conception of motion, as +change of place, is possible only through and in the representation +of time; that if this representation were not an intuition (internal) +a priori, no conception, of whatever kind, could render comprehensible +the possibility of change, in other words, of a conjunction of +contradictorily opposed predicates in one and the same object, for +example, the presence of a thing in a place and the non-presence of +the same thing in the same place. It is only in time that it is +possible to meet with two contradictorily opposed determinations in +one thing, that is, after each other. Thus our conception of time +explains the possibility of so much synthetical knowledge a priori, +as is exhibited in the general doctrine of motion, which is not a +little fruitful. + + + +SS 7. Conclusions from the above Conceptions. + +(a) Time is not something which subsists of itself, or which inheres +in things as an objective determination, and therefore remains, when +abstraction is made of the subjective conditions of the intuition of +things. For in the former case, it would be something real, yet +without presenting to any power of perception any real object. In +the latter case, as an order or determination inherent in things +themselves, it could not be antecedent to things, as their +condition, nor discerned or intuited by means of synthetical +propositions a priori. But all this is quite possible when we regard +time as merely the subjective condition under which all our intuitions +take place. For in that case, this form of the inward intuition can +be represented prior to the objects, and consequently a priori. + +(b) Time is nothing else than the form of the internal sense, that +is, of the intuitions of self and of our internal state. For time +cannot be any determination of outward phenomena. It has to do neither +with shape nor position; on the contrary, it determines the relation +of representations in our internal state. And precisely because this +internal intuition presents to us no shape or form, we endeavour to +supply this want by analogies, and represent the course of time by +a line progressing to infinity, the content of which constitutes a +series which is only of one dimension; and we conclude from the +properties of this line as to all the properties of time, with this +single exception, that the parts of the line are coexistent, whilst +those of time are successive. From this it is clear also that the +representation of time is itself an intuition, because all its +relations can be expressed in an external intuition. + +(c) Time is the formal condition a priori of all phenomena whatsoever. +Space, as the pure form of external intuition, is limited as a +condition a priori to external phenomena alone. On the other hand, +because all representations, whether they have or have not external +things for their objects, still in themselves, as determinations of the +mind, belong to our internal state; and because this internal state is +subject to the formal condition of the internal intuition, that is, to +time--time is a condition a priori of all phenomena whatsoever--the +immediate condition of all internal, and thereby the mediate condition +of all external phenomena. If I can say a priori, "All outward +phenomena are in space, and determined a priori according to the +relations of space," I can also, from the principle of the internal +sense, affirm universally, "All phenomena in general, that is, all +objects of the senses, are in time and stand necessarily in relations +of time." + +If we abstract our internal intuition of ourselves and all external +intuitions, possible only by virtue of this internal intuition and +presented to us by our faculty of representation, and consequently take +objects as they are in themselves, then time is nothing. It is only of +objective validity in regard to phenomena, because these are things +which we regard as objects of our senses. It no longer objective we, +make abstraction of the sensuousness of our intuition, in other words, +of that mode of representation which is peculiar to us, and speak of +things in general. Time is therefore merely a subjective condition of +our (human) intuition (which is always sensuous, that is, so far as we +are affected by objects), and in itself, independently of the mind or +subject, is nothing. Nevertheless, in respect of all phenomena, +consequently of all things which come within the sphere of our +experience, it is necessarily objective. We cannot say, "All things are +in time," because in this conception of things in general, we abstract +and make no mention of any sort of intuition of things. But this is the +proper condition under which time belongs to our representation of +objects. If we add the condition to the conception, and say, "All +things, as phenomena, that is, objects of sensuous intuition, are in +time," then the proposition has its sound objective validity and +universality a priori. + +What we have now set forth teaches, therefore, the empirical reality +of time; that is, its objective validity in reference to all objects +which can ever be presented to our senses. And as our intuition is +always sensuous, no object ever can be presented to us in +experience, which does not come under the conditions of time. On the +other hand, we deny to time all claim to absolute reality; that is, +we deny that it, without having regard to the form of our sensuous +intuition, absolutely inheres in things as a condition or property. +Such properties as belong to objects as things in themselves never +can be presented to us through the medium of the senses. Herein +consists, therefore, the transcendental ideality of time, according +to which, if we abstract the subjective conditions of sensuous intuition, +it is nothing, and cannot be reckoned as subsisting or inhering in +objects as things in themselves, independently of its relation to +our intuition. This ideality, like that of space, is not to be +proved or illustrated by fallacious analogies with sensations, for +this reason--that in such arguments or illustrations, we make the +presupposition that the phenomenon, in which such and such +predicates inhere, has objective reality, while in this case we can +only find such an objective reality as is itself empirical, that is, +regards the object as a mere phenomenon. In reference to this subject, +see the remark in Section I (SS 4) + + + +SS 8. Elucidation. + +Against this theory, which grants empirical reality to time, but denies +to it absolute and transcendental reality, I have heard from +intelligent men an objection so unanimously urged that I conclude that +it must naturally present itself to every reader to whom these +considerations are novel. It runs thus: "Changes are real" (this the +continual change in our own representations demonstrates, even though +the existence of all external phenomena, together with their changes, +is denied). Now, changes are only possible in time, and therefore time +must be something real. But there is no difficulty in answering this. I +grant the whole argument. Time, no doubt, is something real, that is, +it is the real form of our internal intuition. It therefore has +subjective reality, in reference to our internal experience, that is, I +have really the representation of time and of my determinations +therein. Time, therefore, is not to be regarded as an object, but as +the mode of representation of myself as an object. But if I could +intuite myself, or be intuited by another being, without this condition +of sensibility, then those very determinations which we now represent +to ourselves as changes, would present to us a knowledge in which the +representation of time, and consequently of change, would not appear. +The empirical reality of time, therefore, remains, as the condition of +all our experience. But absolute reality, according to what has been +said above, cannot be granted it. Time is nothing but the form of our +internal intuition.* If we take away from it the special condition of +our sensibility, the conception of time also vanishes; and it inheres +not in the objects themselves, but solely in the subject (or mind) +which intuites them. + +[*Footnote: I can indeed say "my representations follow one another, +or are successive"; but this means only that we are conscious of them +as in a succession, that is, according to the form of the internal +sense. Time, therefore, is not a thing in itself, nor is it any objective +determination pertaining to, or inherent in things.] + +But the reason why this objection is so unanimously brought +against our doctrine of time, and that too by disputants who cannot +start any intelligible arguments against the doctrine of the +ideality of space, is this--they have no hope of demonstrating +apodeictically the absolute reality of space, because the doctrine +of idealism is against them, according to which the reality of +external objects is not capable of any strict proof. On the other +hand, the reality of the object of our internal sense (that is, myself +and my internal state) is clear immediately through consciousness. +The former--external objects in space--might be a mere delusion, but +the latter--the object of my internal perception--is undeniably real. +They do not, however, reflect that both, without question of their +reality as representations, belong only to the genus phenomenon, which +has always two aspects, the one, the object considered as a thing in +itself, without regard to the mode of intuiting it, and the nature +of which remains for this very reason problematical, the other, the +form of our intuition of the object, which must be sought not in the +object as a thing in itself, but in the subject to which it appears-- +which form of intuition nevertheless belongs really and necessarily +to the phenomenal object. + +Time and space are, therefore, two sources of knowledge, from which, +a priori, various synthetical cognitions can be drawn. Of this we find +a striking example in the cognitions of space and its relations, which +form the foundation of pure mathematics. They are the two pure forms +of all intuitions, and thereby make synthetical propositions a +priori possible. But these sources of knowledge being merely +conditions of our sensibility, do therefore, and as such, strictly +determine their own range and purpose, in that they do not and +cannot present objects as things in themselves, but are applicable +to them solely in so far as they are considered as sensuous phenomena. +The sphere of phenomena is the only sphere of their validity, and if +we venture out of this, no further objective use can be made of +them. For the rest, this formal reality of time and space leaves the +validity of our empirical knowledge unshaken; for our certainty in +that respect is equally firm, whether these forms necessarily inhere +in the things themselves, or only in our intuitions of them. On the +other hand, those who maintain the absolute reality of time and space, +whether as essentially subsisting, or only inhering, as modifications, +in things, must find themselves at utter variance with the +principles of experience itself. For, if they decide for the first +view, and make space and time into substances, this being the side +taken by mathematical natural philosophers, they must admit two +self-subsisting nonentities, infinite and eternal, which exist (yet +without there being anything real) for the purpose of containing in +themselves everything that is real. If they adopt the second view of +inherence, which is preferred by some metaphysical natural +philosophers, and regard space and time as relations (contiguity in +space or succession in time), abstracted from experience, though +represented confusedly in this state of separation, they find +themselves in that case necessitated to deny the validity of +mathematical doctrines a priori in reference to real things (for +example, in space)--at all events their apodeictic certainty. For such +certainty cannot be found in an a posteriori proposition; and the +conceptions a priori of space and time are, according to this opinion, +mere creations of the imagination, having their source really in +experience, inasmuch as, out of relations abstracted from +experience, imagination has made up something which contains, +indeed, general statements of these relations, yet of which no +application can be made without the restrictions attached thereto by +nature. The former of these parties gains this advantage, that they +keep the sphere of phenomena free for mathematical science. On the +other hand, these very conditions (space and time) embarrass them +greatly, when the understanding endeavours to pass the limits of +that sphere. The latter has, indeed, this advantage, that the +representations of space and time do not come in their way when they +wish to judge of objects, not as phenomena, but merely in their +relation to the understanding. Devoid, however, of a true and +objectively valid a priori intuition, they can neither furnish any +basis for the possibility of mathematical cognitions a priori, nor +bring the propositions of experience into necessary accordance with +those of mathematics. In our theory of the true nature of these two +original forms of the sensibility, both difficulties are surmounted. + +In conclusion, that transcendental aesthetic cannot contain any more +than these two elements--space and time, is sufficiently obvious +from the fact that all other conceptions appertaining to +sensibility, even that of motion, which unites in itself both +elements, presuppose something empirical. Motion, for example, +presupposes the perception of something movable. But space +considered in itself contains nothing movable, consequently motion +must be something which is found in space only through experience-- +in other words, an empirical datum. In like manner, transcendental +aesthetic cannot number the conception of change among its data a +priori; for time itself does not change, but only something which is +in time. To acquire the conception of change, therefore, the +perception of some existing object and of the succession of its +determinations, in one word, experience, is necessary. + + + +SS 9. General Remarks on Transcendental Aesthetic. + +I. In order to prevent any misunderstanding, it will be requisite, +in the first place, to recapitulate, as clearly as possible, what +our opinion is with respect to the fundamental nature of our +sensuous cognition in general. We have intended, then, to say that +all our intuition is nothing but the representation of phenomena; that +the things which we intuite, are not in themselves the same as our +representations of them in intuition, nor are their relations in +themselves so constituted as they appear to us; and that if we take +away the subject, or even only the subjective constitution of our +senses in general, then not only the nature and relations of objects +in space and time, but even space and time themselves disappear; and +that these, as phenomena, cannot exist in themselves, but only in +us. What may be the nature of objects considered as things in +themselves and without reference to the receptivity of our sensibility +is quite unknown to us. We know nothing more than our mode of +perceiving them, which is peculiar to us, and which, though not of +necessity pertaining to every animated being, is so to the whole human +race. With this alone we have to do. Space and time are the pure forms +thereof; sensation the matter. The former alone can we cognize a +priori, that is, antecedent to all actual perception; and for this +reason such cognition is called pure intuition. The latter is that +in our cognition which is called cognition a posteriori, that is, +empirical intuition. The former appertain absolutely and necessarily +to our sensibility, of whatsoever kind our sensations may be; the +latter may be of very diversified character. Supposing that we +should carry our empirical intuition even to the very highest degree +of clearness, we should not thereby advance one step nearer to a +knowledge of the constitution of objects as things in themselves. +For we could only, at best, arrive at a complete cognition of our +own mode of intuition, that is of our sensibility, and this always +under the conditions originally attaching to the subject, namely, +the conditions of space and time; while the question: "What are +objects considered as things in themselves?" remains unanswerable even +after the most thorough examination of the phenomenal world. + +To say, then, that all our sensibility is nothing but the confused +representation of things containing exclusively that which belongs +to them as things in themselves, and this under an accumulation of +characteristic marks and partial representations which we cannot +distinguish in consciousness, is a falsification of the conception +of sensibility and phenomenization, which renders our whole doctrine +thereof empty and useless. The difference between a confused and a +clear representation is merely logical and has nothing to do with +content. No doubt the conception of right, as employed by a sound +understanding, contains all that the most subtle investigation could +unfold from it, although, in the ordinary practical use of the word, +we are not conscious of the manifold representations comprised in +the conception. But we cannot for this reason assert that the ordinary +conception is a sensuous one, containing a mere phenomenon, for +right cannot appear as a phenomenon; but the conception of it lies +in the understanding, and represents a property (the moral property) +of actions, which belongs to them in themselves. On the other hand, +the representation in intuition of a body contains nothing which could +belong to an object considered as a thing in itself, but merely the +phenomenon or appearance of something, and the mode in which we are +affected by that appearance; and this receptivity of our faculty of +cognition is called sensibility, and remains toto caelo different from +the cognition of an object in itself, even though we should examine +the content of the phenomenon to the very bottom. + +It must be admitted that the Leibnitz-Wolfian philosophy has +assigned an entirely erroneous point of view to all investigations +into the nature and origin of our cognitions, inasmuch as it regards +the distinction between the sensuous and the intellectual as merely +logical, whereas it is plainly transcendental, and concerns not merely +the clearness or obscurity, but the content and origin of both. For +the faculty of sensibility not only does not present us with an +indistinct and confused cognition of objects as things in +themselves, but, in fact, gives us no knowledge of these at all. On +the contrary, so soon as we abstract in thought our own subjective +nature, the object represented, with the properties ascribed to it +by sensuous intuition, entirely disappears, because it was only this +subjective nature that determined the form of the object as a +phenomenon. + +In phenomena, we commonly, indeed, distinguish that which +essentially belongs to the intuition of them, and is valid for the +sensuous faculty of every human being, from that which belongs to +the same intuition accidentally, as valid not for the sensuous faculty +in general, but for a particular state or organization of this or that +sense. Accordingly, we are accustomed to say that the former is a +cognition which represents the object itself, whilst the latter +presents only a particular appearance or phenomenon thereof. This +distinction, however, is only empirical. If we stop here (as is +usual), and do not regard the empirical intuition as itself a mere +phenomenon (as we ought to do), in which nothing that can appertain +to a thing in itself is to be found, our transcendental distinction +is lost, and we believe that we cognize objects as things in +themselves, although in the whole range of the sensuous world, +investigate the nature of its objects as profoundly as we may, we have +to do with nothing but phenomena. Thus, we call the rainbow a mere +appearance of phenomenon in a sunny shower, and the rain, the +reality or thing in itself; and this is right enough, if we understand +the latter conception in a merely physical sense, that is, as that +which in universal experience, and under whatever conditions of +sensuous perception, is known in intuition to be so and so determined, +and not otherwise. But if we consider this empirical datum +generally, and inquire, without reference to its accordance with all +our senses, whether there can be discovered in it aught which +represents an object as a thing in itself (the raindrops of course +are not such, for they are, as phenomena, empirical objects), the question +of the relation of the representation to the object is transcendental; +and not only are the raindrops mere phenomena, but even their circular +form, nay, the space itself through which they fall, is nothing in +itself, but both are mere modifications or fundamental dispositions +of our sensuous intuition, whilst the transcendental object remains +for us utterly unknown. + +The second important concern of our aesthetic is that it does not +obtain favour merely as a plausible hypothesis, but possess as +undoubted a character of certainty as can be demanded of any theory +which is to serve for an organon. In order fully to convince the +reader of this certainty, we shall select a case which will serve to +make its validity apparent, and also to illustrate what has been +said in SS 3. + +Suppose, then, that space and time are in themselves objective, +and conditions of the--possibility of objects as things in themselves. +In the first place, it is evident that both present us, with very many +apodeictic and synthetic propositions a priori, but especially +space--and for this reason we shall prefer it for investigation at +present. As the propositions of geometry are cognized synthetically +a priori, and with apodeictic certainty, I inquire: Whence do you +obtain propositions of this kind, and on what basis does the +understanding rest, in order to arrive at such absolutely necessary +and universally valid truths? + +There is no other way than through intuitions or conceptions, as +such; and these are given either a priori or a posteriori. The latter, +namely, empirical conceptions, together with the empirical intuition +on which they are founded, cannot afford any synthetical +proposition, except such as is itself also empirical, that is, a +proposition of experience. But an empirical proposition cannot possess +the qualities of necessity and absolute universality, which, +nevertheless, are the characteristics of all geometrical propositions. +As to the first and only means to arrive at such cognitions, namely, +through mere conceptions or intuitions a priori, it is quite clear +that from mere conceptions no synthetical cognitions, but only +analytical ones, can be obtained. Take, for example, the +proposition: "Two straight lines cannot enclose a space, and with +these alone no figure is possible," and try to deduce it from the +conception of a straight line and the number two; or take the +proposition: "It is possible to construct a figure with three straight +lines," and endeavour, in like manner, to deduce it from the mere +conception of a straight line and the number three. All your +endeavours are in vain, and you find yourself forced to have +recourse to intuition, as, in fact, geometry always does. You +therefore give yourself an object in intuition. But of what kind is +this intuition? Is it a pure a priori, or is it an empirical +intuition? If the latter, then neither an universally valid, much less +an apodeictic proposition can arise from it, for experience never +can give us any such proposition. You must, therefore, give yourself +an object a priori in intuition, and upon that ground your synthetical +proposition. Now if there did not exist within you a faculty of +intuition a priori; if this subjective condition were not in respect +to its form also the universal condition a priori under which alone +the object of this external intuition is itself possible; if the +object (that is, the triangle) were something in itself, without +relation to you the subject; how could you affirm that that which lies +necessarily in your subjective conditions in order to construct a +triangle, must also necessarily belong to the triangle in itself? +For to your conceptions of three lines, you could not add anything +new (that is, the figure); which, therefore, must necessarily be found +in the object, because the object is given before your cognition, +and not by means of it. If, therefore, space (and time also) were +not a mere form of your intuition, which contains conditions a priori, +under which alone things can become external objects for you, and +without which subjective conditions the objects are in themselves +nothing, you could not construct any synthetical proposition +whatsoever regarding external objects. It is therefore not merely +possible or probable, but indubitably certain, that space and time, +as the necessary conditions of all our external and internal +experience, are merely subjective conditions of all our intuitions, +in relation to which all objects are therefore mere phenomena, and +not things in themselves, presented to us in this particular manner. +And for this reason, in respect to the form of phenomena, much may +be said a priori, whilst of the thing in itself, which may lie at the +foundation of these phenomena, it is impossible to say anything. + +II. In confirmation of this theory of the ideality of the external +as well as internal sense, consequently of all objects of sense, as +mere phenomena, we may especially remark that all in our cognition +that belongs to intuition contains nothing more than mere relations. +(The feelings of pain and pleasure, and the will, which are not +cognitions, are excepted.) The relations, to wit, of place in an +intuition (extension), change of place (motion), and laws according +to which this change is determined (moving forces). That, however, +which is present in this or that place, or any operation going on, +or result taking place in the things themselves, with the exception +of change of place, is not given to us by intuition. Now by means of +mere relations, a thing cannot be known in itself; and it may therefore +be fairly concluded, that, as through the external sense nothing but +mere representations of relations are given us, the said external +sense in its representation can contain only the relation of the +object to the subject, but not the essential nature of the object as +a thing in itself. + +The same is the case with the internal intuition, not only +because, in the internal intuition, the representation of the external +senses constitutes the material with which the mind is occupied; but +because time, in which we place, and which itself antecedes the +consciousness of, these representations in experience, and which, as +the formal condition of the mode according to which objects are placed +in the mind, lies at the foundation of them, contains relations of +the successive, the coexistent, and of that which always must be +coexistent with succession, the permanent. Now that which, as +representation, can antecede every exercise of thought (of an object), +is intuition; and when it contains nothing but relations, it is the +form of the intuition, which, as it presents us with no +representation, except in so far as something is placed in the mind, +can be nothing else than the mode in which the mind is affected by +its own activity, to wit--its presenting to itself representations, +consequently the mode in which the mind is affected by itself; that +is, it can be nothing but an internal sense in respect to its form. +Everything that is represented through the medium of sense is so far +phenomenal; consequently, we must either refuse altogether to admit +an internal sense, or the subject, which is the object of that sense, +could only be represented by it as phenomenon, and not as it would +judge of itself, if its intuition were pure spontaneous activity, that +is, were intellectual. The difficulty here lies wholly in the +question: How can the subject have an internal intuition of itself? +But this difficulty is common to every theory. The consciousness of +self (apperception) is the simple representation of the "ego"; and +if by means of that representation alone, all the manifold +representations in the subject were spontaneously given, then our +internal intuition would be intellectual. This consciousness in man +requires an internal perception of the manifold representations +which are previously given in the subject; and the manner in which +these representations are given in the mind without spontaneity, must, +on account of this difference (the want of spontaneity), be called +sensibility. If the faculty of self-consciousness is to apprehend what +lies in the mind, it must all act that and can in this way alone +produce an intuition of self. But the form of this intuition, which +lies in the original constitution of the mind, determines, in the +representation of time, the manner in which the manifold +representations are to combine themselves in the mind; since the +subject intuites itself, not as it would represent itself +immediately and spontaneously, but according to the manner in which +the mind is internally affected, consequently, as it appears, and +not as it is. + +III. When we say that the intuition of external objects, and also +the self-intuition of the subject, represent both, objects and +subject, in space and time, as they affect our senses, that is, as +they appear--this is by no means equivalent to asserting that these +objects are mere illusory appearances. For when we speak of things +as phenomena, the objects, nay, even the properties which we ascribe +to them, are looked upon as really given; only that, in so far as this +or that property depends upon the mode of intuition of the subject, +in the relation of the given object to the subject, the object as +phenomenon is to be distinguished from the object as a thing in +itself. Thus I do not say that bodies seem or appear to be external +to me, or that my soul seems merely to be given in my self-consciousness, +although I maintain that the properties of space and time, in +conformity to which I set both, as the condition of their existence, +abide in my mode of intuition, and not in the objects in themselves. +It would be my own fault, if out of that which I should reckon as +phenomenon, I made mere illusory appearance.* But this will not +happen, because of our principle of the ideality of all sensuous +intuitions. On the contrary, if we ascribe objective reality to +these forms of representation, it becomes impossible to avoid changing +everything into mere appearance. For if we regard space and time as +properties, which must be found in objects as things in themselves, +as sine quibus non of the possibility of their existence, and reflect +on the absurdities in which we then find ourselves involved, +inasmuch as we are compelled to admit the existence of two infinite +things, which are nevertheless not substances, nor anything really +inhering in substances, nay, to admit that they are the necessary +conditions of the existence of all things, and moreover, that they +must continue to exist, although all existing things were annihilated-- +we cannot blame the good Berkeley for degrading bodies to mere +illusory appearances. Nay, even our own existence, which would in this +case depend upon the self-existent reality of such a mere nonentity +as time, would necessarily be changed with it into mere appearance--an +absurdity which no one has as yet been guilty of. + +[*Footnote: The predicates of the phenomenon can be affixed to the +object itself in relation to our sensuous faculty; for example, the +red colour or the perfume to the rose. But (illusory) appearance never +can be attributed as a predicate to an object, for this very reason, +that it attributes to this object in itself that which belongs to it +only in relation to our sensuous faculty, or to the subject in +general, e.g., the two handles which were formerly ascribed to Saturn. +That which is never to be found in the object itself, but always in +the relation of the object to the subject, and which moreover is +inseparable from our representation of the object, we denominate +phenomenon. Thus the predicates of space and time are rightly +attributed to objects of the senses as such, and in this there is no +illusion. On the contrary, if I ascribe redness of the rose as a thing +in itself, or to Saturn his handles, or extension to all external +objects, considered as things in themselves, without regarding the +determinate relation of these objects to the subject, and without +limiting my judgement to that relation--then, and then only, arises +illusion.] + +IV. In natural theology, where we think of an object--God--which +never can be an object of intuition to us, and even to himself can +never be an object of sensuous intuition, we carefully avoid +attributing to his intuition the conditions of space and time--and +intuition all his cognition must be, and not thought, which always +includes limitation. But with what right can we do this if we make +them forms of objects as things in themselves, and such, moreover, +as would continue to exist as a priori conditions of the existence +of things, even though the things themselves were annihilated? For +as conditions of all existence in general, space and time must be +conditions of the existence of the Supreme Being also. But if we do +not thus make them objective forms of all things, there is no other +way left than to make them subjective forms of our mode of +intuition--external and internal; which is called sensuous, because +it is not primitive, that is, is not such as gives in itself the +existence of the object of the intuition (a mode of intuition which, +so far as we can judge, can belong only to the Creator), but is +dependent on the existence of the object, is possible, therefore, only +on condition that the representative faculty of the subject is +affected by the object. + +It is, moreover, not necessary that we should limit the mode of +intuition in space and time to the sensuous faculty of man. It may +well be that all finite thinking beings must necessarily in this +respect agree with man (though as to this we cannot decide), but +sensibility does not on account of this universality cease to be +sensibility, for this very reason, that it is a deduced (intuitus +derivativus), and not an original (intuitus originarius), consequently +not an intellectual intuition, and this intuition, as such, for +reasons above mentioned, seems to belong solely to the Supreme +Being, but never to a being dependent, quoad its existence, as well +as its intuition (which its existence determines and limits relatively +to given objects). This latter remark, however, must be taken only +as an illustration, and not as any proof of the truth of our +aesthetical theory. + + + +SS 10. Conclusion of the Transcendental Aesthetic. + +We have now completely before us one part of the solution of the +grand general problem of transcendental philosophy, namely, the +question: "How are synthetical propositions a priori possible?" That +is to say, we have shown that we are in possession of pure a priori +intuitions, namely, space and time, in which we find, when in a +judgement a priori we pass out beyond the given conception, +something which is not discoverable in that conception, but is +certainly found a priori in the intuition which corresponds to the +conception, and can be united synthetically with it. But the +judgements which these pure intuitions enable us to make, never +reach farther than to objects of the senses, and are valid only for +objects of possible experience. + + + + +SECOND PART. TRANSCENDENTAL LOGIC. + +INTRODUCTION. Idea of a Transcendental Logic. + +I. Of Logic in General. + +Our knowledge springs from two main sources in the mind, first of +which is the faculty or power of receiving representations +(receptivity for impressions); the second is the power of cognizing +by means of these representations (spontaneity in the production of +conceptions). Through the first an object is given to us; through +the second, it is, in relation to the representation (which is a +mere determination of the mind), thought. Intuition and conceptions +constitute, therefore, the elements of all our knowledge, so that +neither conceptions without an intuition in some way corresponding +to them, nor intuition without conceptions, can afford us a cognition. +Both are either pure or empirical. They are empirical, when sensation +(which presupposes the actual presence of the object) is contained +in them; and pure, when no sensation is mixed with the representation. +Sensations we may call the matter of sensuous cognition. Pure +intuition consequently contains merely the form under which +something is intuited, and pure conception only the form of the +thought of an object. Only pure intuitions and pure conceptions are +possible a priori; the empirical only a posteriori. + +We apply the term sensibility to the receptivity of the mind for +impressions, in so far as it is in some way affected; and, on the +other hand, we call the faculty of spontaneously producing +representations, or the spontaneity of cognition, understanding. Our +nature is so constituted that intuition with us never can be other +than sensuous, that is, it contains only the mode in which we are +affected by objects. On the other hand, the faculty of thinking the +object of sensuous intuition is the understanding. Neither of these +faculties has a preference over the other. Without the sensuous +faculty no object would be given to us, and without the +understanding no object would be thought. Thoughts without content +are void; intuitions without conceptions, blind. Hence it is as +necessary for the mind to make its conceptions sensuous (that is, to +join to them the object in intuition), as to make its intuitions +intelligible (that is, to bring them under conceptions). Neither of +these faculties can exchange its proper function. Understanding cannot +intuite, and the sensuous faculty cannot think. In no other way than +from the united operation of both, can knowledge arise. But no one +ought, on this account, to overlook the difference of the elements +contributed by each; we have rather great reason carefully to separate +and distinguish them. We therefore distinguish the science of the laws +of sensibility, that is, aesthetic, from the science of the laws of +the understanding, that is, logic. + +Now, logic in its turn may be considered as twofold--namely, as +logic of the general, or of the particular use of the understanding. +The first contains the absolutely necessary laws of thought, without +which no use whatsoever of the understanding is possible, and gives +laws therefore to the understanding, without regard to the +difference of objects on which it may be employed. The logic of the +particular use of the understanding contains the laws of correct +thinking upon a particular class of objects. The former may be +called elemental logic--the latter, the organon of this or that +particular science. The latter is for the most part employed in the +schools, as a propaedeutic to the sciences, although, indeed, +according to the course of human reason, it is the last thing we +arrive at, when the science has been already matured, and needs only +the finishing touches towards its correction and completion; for our +knowledge of the objects of our attempted science must be tolerably +extensive and complete before we can indicate the laws by which a +science of these objects can be established. + +General logic is again either pure or applied. In the former, we +abstract all the empirical conditions under which the understanding +is exercised; for example, the influence of the senses, the play of +the fantasy or imagination, the laws of the memory, the force of habit, +of inclination, etc., consequently also, the sources of prejudice--in +a word, we abstract all causes from which particular cognitions arise, +because these causes regard the understanding under certain +circumstances of its application, and, to the knowledge of them +experience is required. Pure general logic has to do, therefore, +merely with pure a priori principles, and is a canon of +understanding and reason, but only in respect of the formal part of +their use, be the content what it may, empirical or transcendental. +General logic is called applied, when it is directed to the laws of +the use of the understanding, under the subjective empirical +conditions which psychology teaches us. It has therefore empirical +principles, although, at the same time, it is in so far general, +that it applies to the exercise of the understanding, without regard +to the difference of objects. On this account, moreover, it is neither +a canon of the understanding in general, nor an organon of a +particular science, but merely a cathartic of the human understanding. + +In general logic, therefore, that part which constitutes pure +logic must be carefully distinguished from that which constitutes +applied (though still general) logic. The former alone is properly +science, although short and dry, as the methodical exposition of an +elemental doctrine of the understanding ought to be. In this, +therefore, logicians must always bear in mind two rules: + +1. As general logic, it makes abstraction of all content of the +cognition of the understanding, and of the difference of objects, +and has to do with nothing but the mere form of thought. + +2. As pure logic, it has no empirical principles, and consequently +draws nothing (contrary to the common persuasion) from psychology, +which therefore has no influence on the canon of the understanding. +It is a demonstrated doctrine, and everything in it must be certain +completely a priori. + +What I called applied logic (contrary to the common acceptation of +this term, according to which it should contain certain exercises +for the scholar, for which pure logic gives the rules), is a +representation of the understanding, and of the rules of its necessary +employment in concreto, that is to say, under the accidental +conditions of the subject, which may either hinder or promote this +employment, and which are all given only empirically. Thus applied +logic treats of attention, its impediments and consequences, of the +origin of error, of the state of doubt, hesitation, conviction, +etc., and to it is related pure general logic in the same way that +pure morality, which contains only the necessary moral laws of a +free will, is related to practical ethics, which considers these +laws under all the impediments of feelings, inclinations, and passions +to which men are more or less subjected, and which never can furnish +us with a true and demonstrated science, because it, as well as +applied logic, requires empirical and psychological principles. + + + +II. Of Transcendental Logic. + +General logic, as we have seen, makes abstraction of all content +of cognition, that is, of all relation of cognition to its object, +and regards only the logical form in the relation of cognitions to +each other, that is, the form of thought in general. But as we have +both pure and empirical intuitions (as transcendental aesthetic proves), +in like manner a distinction might be drawn between pure and empirical +thought (of objects). In this case, there would exist a kind of logic, +in which we should not make abstraction of all content of cognition; +for or logic which should comprise merely the laws of pure thought +(of an object), would of course exclude all those cognitions which +were of empirical content. This kind of logic would also examine the +origin of our cognitions of objects, so far as that origin cannot be +ascribed to the objects themselves; while, on the contrary, general +logic has nothing to do with the origin of our cognitions, but contemplates +our representations, be they given primitively a priori in +ourselves, or be they only of empirical origin, solely according to +the laws which the understanding observes in employing them in the +process of thought, in relation to each other. Consequently, general +logic treats of the form of the understanding only, which can be +applied to representations, from whatever source they may have arisen. + +And here I shall make a remark, which the reader must bear well in +mind in the course of the following considerations, to wit, that not +every cognition a priori, but only those through which we cognize that +and how certain representations (intuitions or conceptions) are +applied or are possible only a priori; that is to say, the a priori +possibility of cognition and the a priori use of it are +transcendental. Therefore neither is space, nor any a priori +geometrical determination of space, a transcendental Representation, +but only the knowledge that such a representation is not of +empirical origin, and the possibility of its relating to objects of +experience, although itself a priori, can be called transcendental. +So also, the application of space to objects in general would be +transcendental; but if it be limited to objects of sense it is +empirical. Thus, the distinction of the transcendental and empirical +belongs only to the critique of cognitions, and does not concern the +relation of these to their object. + +Accordingly, in the expectation that there may perhaps be +conceptions which relate a priori to objects, not as pure or +sensuous intuitions, but merely as acts of pure thought (which are +therefore conceptions, but neither of empirical nor aesthetical +origin)--in this expectation, I say, we form to ourselves, by +anticipation, the idea of a science of pure understanding and rational +cognition, by means of which we may cogitate objects entirely a +priori. A science of this kind, which should determine the origin, +the extent, and the objective validity of such cognitions, must be +called transcendental logic, because it has not, like general logic, +to do with the laws of understanding and reason in relation to +empirical as well as pure rational cognitions without distinction, +but concerns itself with these only in an a priori relation to objects. + + + +III. Of the Division of General Logic into Analytic and Dialectic. + +The old question with which people sought to push logicians into a +corner, so that they must either have recourse to pitiful sophisms +or confess their ignorance, and consequently the vanity of their whole +art, is this: "What is truth?" The definition of the word truth, to +wit, "the accordance of the cognition with its object," is presupposed +in the question; but we desire to be told, in the answer to it, what +is the universal and secure criterion of the truth of every cognition. + +To know what questions we may reasonably propose is in itself a +strong evidence of sagacity and intelligence. For if a question be +in itself absurd and unsusceptible of a rational answer, it is +attended with the danger--not to mention the shame that falls upon +the person who proposes it--of seducing the unguarded listener into +making absurd answers, and we are presented with the ridiculous spectacle +of one (as the ancients said) "milking the he-goat, and the other +holding a sieve." + +If truth consists in the accordance of a cognition with its +object, this object must be, ipso facto, distinguished from all +others; for a cognition is false if it does not accord with the object +to which it relates, although it contains something which may be +affirmed of other objects. Now an universal criterion of truth would +be that which is valid for all cognitions, without distinction of +their objects. But it is evident that since, in the case of such a +criterion, we make abstraction of all the content of a cognition (that +is, of all relation to its object), and truth relates precisely to +this content, it must be utterly absurd to ask for a mark of the truth +of this content of cognition; and that, accordingly, a sufficient, +and at the same time universal, test of truth cannot possibly be found. +As we have already termed the content of a cognition its matter, we +shall say: "Of the truth of our cognitions in respect of their matter, +no universal test can be demanded, because such a demand is +self-contradictory." + +On the other hand, with regard to our cognition in respect of its +mere form (excluding all content), it is equally manifest that +logic, in so far as it exhibits the universal and necessary laws of +the understanding, must in these very laws present us with criteria +of truth. Whatever contradicts these rules is false, because thereby +the understanding is made to contradict its own universal laws of +thought; that is, to contradict itself. These criteria, however, apply +solely to the form of truth, that is, of thought in general, and in +so far they are perfectly accurate, yet not sufficient. For although +a cognition may be perfectly accurate as to logical form, that is, +not self-contradictory, it is notwithstanding quite possible that it +may not stand in agreement with its object. Consequently, the merely +logical criterion of truth, namely, the accordance of a cognition with +the universal and formal laws of understanding and reason, is +nothing more than the conditio sine qua non, or negative condition +of all truth. Farther than this logic cannot go, and the error which +depends not on the form, but on the content of the cognition, it has +no test to discover. + +General logic, then, resolves the whole formal business of +understanding and reason into its elements, and exhibits them as +principles of all logical judging of our cognitions. This part of +logic may, therefore, be called analytic, and is at least the negative +test of truth, because all cognitions must first of an be estimated +and tried according to these laws before we proceed to investigate +them in respect of their content, in order to discover whether they +contain positive truth in regard to their object. Because, however, +the mere form of a cognition, accurately as it may accord with logical +laws, is insufficient to supply us with material (objective) truth, +no one, by means of logic alone, can venture to predicate anything +of or decide concerning objects, unless he has obtained, independently +of logic, well-grounded information about them, in order afterwards +to examine, according to logical laws, into the use and connection, +in a cohering whole, of that information, or, what is still better, +merely to test it by them. Notwithstanding, there lies so seductive +a charm in the possession of a specious art like this--an art which +gives to all our cognitions the form of the understanding, although +with respect to the content thereof we may be sadly deficient--that +general logic, which is merely a canon of judgement, has been employed +as an organon for the actual production, or rather for the semblance +of production, of objective assertions, and has thus been grossly +misapplied. Now general logic, in its assumed character of organon, +is called dialectic. + +Different as are the significations in which the ancients used +this term for a science or an art, we may safely infer, from their +actual employment of it, that with them it was nothing else than a +logic of illusion--a sophistical art for giving ignorance, nay, even +intentional sophistries, the colouring of truth, in which the +thoroughness of procedure which logic requires was imitated, and their +topic employed to cloak the empty pretensions. Now it may be taken +as a safe and useful warning, that general logic, considered as an +organon, must always be a logic of illusion, that is, be +dialectical, for, as it teaches us nothing whatever respecting the +content of our cognitions, but merely the formal conditions of their +accordance with the understanding, which do not relate to and are +quite indifferent in respect of objects, any attempt to employ it as +an instrument (organon) in order to extend and enlarge the range of +our knowledge must end in mere prating; any one being able to maintain +or oppose, with some appearance of truth, any single assertion +whatever. + +Such instruction is quite unbecoming the dignity of philosophy. +For these reasons we have chosen to denominate this part of logic +dialectic, in the sense of a critique of dialectical illusion, and +we wish the term to be so understood in this place. + + + +IV. Of the Division of Transcendental Logic into Transcendental + Analytic and Dialectic. + +In transcendental logic we isolate the understanding (as in +transcendental aesthetic the sensibility) and select from our +cognition merely that part of thought which has its origin in the +understanding alone. The exercise of this pure cognition, however, +depends upon this as its condition, that objects to which it may be +applied be given to us in intuition, for without intuition the whole +of our cognition is without objects, and is therefore quite void. That +part of transcendental logic, then, which treats of the elements of +pure cognition of the understanding, and of the principles without +which no object at all can be thought, is transcendental analytic, +and at the same time a logic of truth. For no cognition can contradict +it, without losing at the same time all content, that is, losing all +reference to an object, and therefore all truth. But because we are +very easily seduced into employing these pure cognitions and +principles of the understanding by themselves, and that even beyond +the boundaries of experience, which yet is the only source whence we +can obtain matter (objects) on which those pure conceptions may be +employed--understanding runs the risk of making, by means of empty +sophisms, a material and objective use of the mere formal principles +of the pure understanding, and of passing judgements on objects +without distinction--objects which are not given to us, nay, perhaps +cannot be given to us in any way. Now, as it ought properly to be only +a canon for judging of the empirical use of the understanding, this +kind of logic is misused when we seek to employ it as an organon of +the universal and unlimited exercise of the understanding, and attempt +with the pure understanding alone to judge synthetically, affirm, +and determine respecting objects in general. In this case the exercise +of the pure understanding becomes dialectical. The second part of +our transcendental logic must therefore be a critique of dialectical +illusion, and this critique we shall term transcendental dialectic-- +not meaning it as an art of producing dogmatically such illusion (an +art which is unfortunately too current among the practitioners of +metaphysical juggling), but as a critique of understanding and +reason in regard to their hyperphysical use. This critique will expose +the groundless nature of the pretensions of these two faculties, and +invalidate their claims to the discovery and enlargement of our +cognitions merely by means of transcendental principles, and show that +the proper employment of these faculties is to test the judgements +made by the pure understanding, and to guard it from sophistical +delusion. + + + + +TRANSCENDENTAL LOGIC. FIRST DIVISION. + +TRANSCENDENTAL ANALYTIC. + +SS I. + +Transcendental analytic is the dissection of the whole of our a priori +knowledge into the elements of the pure cognition of the understanding. +In order to effect our purpose, it is necessary: (1) That the +conceptions be pure and not empirical; (2) That they belong not to +intuition and sensibility, but to thought and understanding; (3) That +they be elementary conceptions, and as such, quite different from +deduced or compound conceptions; (4) That our table of these elementary +conceptions be complete, and fill up the whole sphere of the pure +understanding. Now this completeness of a science cannot be accepted +with confidence on the guarantee of a mere estimate of its existence in +an aggregate formed only by means of repeated experiments and attempts. +The completeness which we require is possible only by means of an idea +of the totality of the a priori cognition of the understanding, and +through the thereby determined division of the conceptions which form +the said whole; consequently, only by means of their connection in a +system. Pure understanding distinguishes itself not merely from +everything empirical, but also completely from all sensibility. It is a +unity self-subsistent, self-sufficient, and not to be enlarged by any +additions from without. Hence the sum of its cognition constitutes a +system to be determined by and comprised under an idea; and the +completeness and articulation of this system can at the same time serve +as a test of the correctness and genuineness of all the parts of +cognition that belong to it. The whole of this part of transcendental +logic consists of two books, of which the one contains the conceptions, +and the other the principles of pure understanding. + + + +BOOK I. + +SS 2. Analytic of Conceptions. + +By the term Analytic of Conceptions, I do not understand the +analysis of these, or the usual process in philosophical +investigations of dissecting the conceptions which present themselves, +according to their content, and so making them clear; but I mean the +hitherto little attempted dissection of the faculty of understanding +itself, in order to investigate the possibility of conceptions a +priori, by looking for them in the understanding alone, as their +birthplace, and analysing the pure use of this faculty. For this is +the proper duty of a transcendental philosophy; what remains is the +logical treatment of the conceptions in philosophy in general. We +shall therefore follow up the pure conceptions even to their germs +and beginnings in the human understanding, in which they lie, until +they are developed on occasions presented by experience, and, freed +by the same understanding from the empirical conditions attaching to +them, are set forth in their unalloyed purity. + + + +CHAPTER I. Of the Transcendental Clue to the Discovery of all Pure + Conceptions of the Understanding. + +SS 3. Introductory. + +When we call into play a faculty of cognition, different conceptions +manifest themselves according to the different circumstances, and make +known this faculty, and assemble themselves into a more or less +extensive collection, according to the time or penetration that has +been applied to the consideration of them. Where this process, +conducted as it is mechanically, so to speak, will end, cannot be +determined with certainty. Besides, the conceptions which we +discover in this haphazard manner present themselves by no means in +order and systematic unity, but are at last coupled together only +according to resemblances to each other, and arranged in series, +according to the quantity of their content, from the simpler to the +more complex--series which are anything but systematic, though not +altogether without a certain kind of method in their construction. + +Transcendental philosophy has the advantage, and moreover the +duty, of searching for its conceptions according to a principle; +because these conceptions spring pure and unmixed out of the +understanding as an absolute unity, and therefore must be connected +with each other according to one conception or idea. A connection of +this kind, however, furnishes us with a ready prepared rule, by +which its proper place may be assigned to every pure conception of +the understanding, and the completeness of the system of all be determined +a priori--both which would otherwise have been dependent on mere +choice or chance. + + + +SS 4. SECTION 1. Of defined above Use of understanding in General. + +The understanding was defined above only negatively, as a +non-sensuous faculty of cognition. Now, independently of +sensibility, we cannot possibly have any intuition; consequently, +the understanding is no faculty of intuition. But besides intuition +there is no other mode of cognition, except through conceptions; +consequently, the cognition of every, at least of every human, +understanding is a cognition through conceptions--not intuitive, but +discursive. All intuitions, as sensuous, depend on affections; +conceptions, therefore, upon functions. By the word function I +understand the unity of the act of arranging diverse representations +under one common representation. Conceptions, then, are based on the +spontaneity of thought, as sensuous intuitions are on the +receptivity of impressions. Now, the understanding cannot make any +other use of these conceptions than to judge by means of them. As no +representation, except an intuition, relates immediately to its +object, a conception never relates immediately to an object, but +only to some other representation thereof, be that an intuition or +itself a conception. A judgement, therefore, is the mediate +cognition of an object, consequently the representation of a +representation of it. In every judgement there is a conception which +applies to, and is valid for many other conceptions, and which among +these comprehends also a given representation, this last being +immediately connected with an object. For example, in the judgement-- +"All bodies are divisible," our conception of divisible applies to +various other conceptions; among these, however, it is here +particularly applied to the conception of body, and this conception +of body relates to certain phenomena which occur to us. These objects, +therefore, are mediately represented by the conception of +divisibility. All judgements, accordingly, are functions of unity in +our representations, inasmuch as, instead of an immediate, a higher +representation, which comprises this and various others, is used for +our cognition of the object, and thereby many possible cognitions +are collected into one. But we can reduce all acts of the +understanding to judgements, so that understanding may be +represented as the faculty of judging. For it is, according to what +has been said above, a faculty of thought. Now thought is cognition +by means of conceptions. But conceptions, as predicates of possible +judgements, relate to some representation of a yet undetermined +object. Thus the conception of body indicates something--for +example, metal--which can be cognized by means of that conception. +It is therefore a conception, for the reason alone that other +representations are contained under it, by means of which it can +relate to objects. It is therefore the predicate to a possible +judgement; for example: "Every metal is a body." All the functions +of the understanding therefore can be discovered, when we can +completely exhibit the functions of unity in judgements. And that this +may be effected very easily, the following section will show. + + + +SS 5. SECTION II. Of the Logical Function of the Understanding in + Judgements. + +If we abstract all the content of a judgement, and consider only the +intellectual form thereof, we find that the function of thought in +a judgement can be brought under four heads, of which each contains +three momenta. These may be conveniently represented in the +following table: + + 1 + Quantity of judgements + Universal + Particular + Singular + + 2 3 + Quality Relation + Affirmative Categorical + Negative Hypothetical + Infinite Disjunctive + + 4 + Modality + Problematical + Assertorical + Apodeictical + + +As this division appears to differ in some, though not essential +points, from the usual technique of logicians, the following +observations, for the prevention of otherwise possible +misunderstanding, will not be without their use. + +1. Logicians say, with justice, that in the use of judgements in +syllogisms, singular judgements may be treated like universal ones. +For, precisely because a singular judgement has no extent at all, +its predicate cannot refer to a part of that which is contained in +the conception of the subject and be excluded from the rest. The predicate +is valid for the whole conception just as if it were a general +conception, and had extent, to the whole of which the predicate +applied. On the other hand, let us compare a singular with a general +judgement, merely as a cognition, in regard to quantity. The +singular judgement relates to the general one, as unity to infinity, +and is therefore in itself essentially different. Thus, if we estimate +a singular judgement (judicium singulare) not merely according to +its intrinsic validity as a judgement, but also as a cognition +generally, according to its quantity in comparison with that of +other cognitions, it is then entirely different from a general +judgement (judicium commune), and in a complete table of the momenta +of thought deserves a separate place--though, indeed, this would not +be necessary in a logic limited merely to the consideration of the +use of judgements in reference to each other. + +2. In like manner, in transcendental logic, infinite must be +distinguished from affirmative judgements, although in general logic +they are rightly enough classed under affirmative. General logic +abstracts all content of the predicate (though it be negative), and +only considers whether the said predicate be affirmed or denied of +the subject. But transcendental logic considers also the worth or +content of this logical affirmation--an affirmation by means of a +merely negative predicate, and inquires how much the sum total of +our cognition gains by this affirmation. For example, if I say of +the soul, "It is not mortal"--by this negative judgement I should at +least ward off error. Now, by the proposition, "The soul is not +mortal," I have, in respect of the logical form, really affirmed, +inasmuch as I thereby place the soul in the unlimited sphere of +immortal beings. Now, because of the whole sphere of possible +existences, the mortal occupies one part, and the immortal the +other, neither more nor less is affirmed by the proposition than +that the soul is one among the infinite multitude of things which +remain over, when I take away the whole mortal part. But by this +proceeding we accomplish only this much, that the infinite sphere of +all possible existences is in so far limited that the mortal is +excluded from it, and the soul is placed in the remaining part of +the extent of this sphere. But this part remains, notwithstanding this +exception, infinite, and more and more parts may be taken away from +the whole sphere, without in the slightest degree thereby augmenting +or affirmatively determining our conception of the soul. These +judgements, therefore, infinite in respect of their logical extent, +are, in respect of the content of their cognition, merely +limitative; and are consequently entitled to a place in our +transcendental table of all the momenta of thought in judgements, +because the function of the understanding exercised by them may +perhaps be of importance in the field of its pure a priori cognition. + +3. All relations of thought in judgements are those (a) of the +predicate to the subject; (b) of the principle to its consequence; +(c) of the divided cognition and all the members of the division to +each other. In the first of these three classes, we consider only two +conceptions; in the second, two judgements; in the third, several +judgements in relation to each other. The hypothetical proposition, +"If perfect justice exists, the obstinately wicked are punished," +contains properly the relation to each other of two propositions, +namely, "Perfect justice exists," and "The obstinately wicked are +punished." Whether these propositions are in themselves true is a +question not here decided. Nothing is cogitated by means of this +judgement except a certain consequence. Finally, the disjunctive +judgement contains a relation of two or more propositions to each +other--a relation not of consequence, but of logical opposition, in +so far as the sphere of the one proposition excludes that of the other. +But it contains at the same time a relation of community, in so far +as all the propositions taken together fill up the sphere of the +cognition. The disjunctive judgement contains, therefore, the relation +of the parts of the whole sphere of a cognition, since the sphere of +each part is a complemental part of the sphere of the other, each +contributing to form the sum total of the divided cognition. Take, +for example, the proposition, "The world exists either through blind +chance, or through internal necessity, or through an external +cause." Each of these propositions embraces a part of the sphere of +our possible cognition as to the existence of a world; all of them +taken together, the whole sphere. To take the cognition out of one +of these spheres, is equivalent to placing it in one of the others; +and, on the other hand, to place it in one sphere is equivalent to +taking it out of the rest. There is, therefore, in a disjunctive +judgement a certain community of cognitions, which consists in this, +that they mutually exclude each other, yet thereby determine, as a +whole, the true cognition, inasmuch as, taken together, they make up +the complete content of a particular given cognition. And this is +all that I find necessary, for the sake of what follows, to remark +in this place. + +4. The modality of judgements is a quite peculiar function, with +this distinguishing characteristic, that it contributes nothing to +the content of a judgement (for besides quantity, quality, and relation, +there is nothing more that constitutes the content of a judgement), +but concerns itself only with the value of the copula in relation to +thought in general. Problematical judgements are those in which the +affirmation or negation is accepted as merely possible (ad libitum). +In the assertorical, we regard the proposition as real (true); in +the apodeictical, we look on it as necessary.* Thus the two judgements +(antecedens et consequens), the relation of which constitutes a +hypothetical judgement, likewise those (the members of the division) +in whose reciprocity the disjunctive consists, are only problematical. +In the example above given the proposition, "There exists perfect +justice," is not stated assertorically, but as an ad libitum +judgement, which someone may choose to adopt, and the consequence +alone is assertorical. Hence such judgements may be obviously false, +and yet, taken problematically, be conditions of our cognition of +the truth. Thus the proposition, "The world exists only by blind +chance," is in the disjunctive judgement of problematical import only: +that is to say, one may accept it for the moment, and it helps us +(like the indication of the wrong road among all the roads that one +can take) to find out the true proposition. The problematical +proposition is, therefore, that which expresses only logical +possibility (which is not objective); that is, it expresses a free +choice to admit the validity of such a proposition--a merely arbitrary +reception of it into the understanding. The assertorical speaks of +logical reality or truth; as, for example, in a hypothetical +syllogism, the antecedens presents itself in a problematical form in +the major, in an assertorical form in the minor, and it shows that +the proposition is in harmony with the laws of the understanding. The +apodeictical proposition cogitates the assertorical as determined by +these very laws of the understanding, consequently as affirming a +priori, and in this manner it expresses logical necessity. Now because +all is here gradually incorporated with the understanding--inasmuch +as in the first place we judge problematically; then accept +assertorically our judgement as true; lastly, affirm it as inseparably +united with the understanding, that is, as necessary and apodeictical-- +we may safely reckon these three functions of modality as so many +momenta of thought. + +[*Footnote: Just as if thought were in the first instance a function +of the understanding; in the second, of judgement; in the third, of +reason. A remark which will be explained in the sequel.] + + + +SS 6. SECTION III. Of the Pure Conceptions of the Understanding, or + Categories. + +General logic, as has been repeatedly said, makes abstraction of all +content of cognition, and expects to receive representations from some +other quarter, in order, by means of analysis, to convert them into +conceptions. On the contrary, transcendental logic has lying before +it the manifold content of a priori sensibility, which transcendental +aesthetic presents to it in order to give matter to the pure +conceptions of the understanding, without which transcendental logic +would have no content, and be therefore utterly void. Now space and +time contain an infinite diversity of determinations of pure a +priori intuition, but are nevertheless the condition of the mind's +receptivity, under which alone it can obtain representations of +objects, and which, consequently, must always affect the conception +of these objects. But the spontaneity of thought requires that this +diversity be examined after a certain manner, received into the +mind, and connected, in order afterwards to form a cognition out of +it. This Process I call synthesis. + +By the word synthesis, in its most general signification, I +understand the process of joining different representations to each +other and of comprehending their diversity in one cognition. This +synthesis is pure when the diversity is not given empirically but a +priori (as that in space and time). Our representations must be +given previously to any analysis of them; and no conceptions can +arise, quoad their content, analytically. But the synthesis of a +diversity (be it given a priori or empirically) is the first requisite +for the production of a cognition, which in its beginning, indeed, +may be crude and confused, and therefore in need of analysis--still, +synthesis is that by which alone the elements of our cognitions are +collected and united into a certain content, consequently it is the +first thing on which we must fix our attention, if we wish to +investigate the origin of our knowledge. + +Synthesis, generally speaking, is, as we shall afterwards see, the +mere operation of the imagination--a blind but indispensable +function of the soul, without which we should have no cognition +whatever, but of the working of which we are seldom even conscious. +But to reduce this synthesis to conceptions is a function of the +understanding, by means of which we attain to cognition, in the proper +meaning of the term. + +Pure synthesis, represented generally, gives us the pure +conception of the understanding. But by this pure synthesis, I mean +that which rests upon a basis of a priori synthetical unity. Thus, +our numeration (and this is more observable in large numbers) is a +synthesis according to conceptions, because it takes place according +to a common basis of unity (for example, the decade). By means of this +conception, therefore, the unity in the synthesis of the manifold +becomes necessary. + +By means of analysis different representations are brought under one +conception--an operation of which general logic treats. On the other +hand, the duty of transcendental logic is to reduce to conceptions, +not representations, but the pure synthesis of representations. The +first thing which must be given to us for the sake of the a priori +cognition of all objects, is the diversity of the pure intuition; +the synthesis of this diversity by means of the imagination is the +second; but this gives, as yet, no cognition. The conceptions which +give unity to this pure synthesis, and which consist solely in the +representation of this necessary synthetical unity, furnish the +third requisite for the cognition of an object, and these +conceptions are given by the understanding. + +The same function which gives unity to the different +representation in a judgement, gives also unity to the mere +synthesis of different representations in an intuition; and this unity +we call the pure conception of the understanding. Thus, the same +understanding, and by the same operations, whereby in conceptions, +by means of analytical unity, it produced the logical form of a +judgement, introduces, by means of the synthetical unity of the +manifold in intuition, a transcendental content into its +representations, on which account they are called pure conceptions +of the understanding, and they apply a priori to objects, a result +not within the power of general logic. + +In this manner, there arise exactly so many pure conceptions of +the understanding, applying a priori to objects of intuition in +general, as there are logical functions in all possible judgements. +For there is no other function or faculty existing in the +understanding besides those enumerated in that table. These +conceptions we shall, with Aristotle, call categories, our purpose +being originally identical with his, notwithstanding the great +difference in the execution. + + TABLE OF THE CATEGORIES + + 1 2 + + Of Quantity Of Quality + Unity Reality + Plurality Negation + Totality Limitation + + 3 + Of Relation + Of Inherence and Subsistence (substantia et accidens) + Of Causality and Dependence (cause and effect) + Of Community (reciprocity between the agent and patient) + + 4 + Of Modality + Possibility--Impossibility + Existence--Non-existence + Necessity--Contingence + + +This, then, is a catalogue of all the originally pure conceptions of +the synthesis which the understanding contains a priori, and these +conceptions alone entitle it to be called a pure understanding; +inasmuch as only by them it can render the manifold of intuition +conceivable, in other words, think an object of intuition. This +division is made systematically from a common principle, namely the +faculty of judgement (which is just the same as the power of thought), +and has not arisen rhapsodically from a search at haphazard after pure +conceptions, respecting the full number of which we never could be +certain, inasmuch as we employ induction alone in our search, +without considering that in this way we can never understand wherefore +precisely these conceptions, and none others, abide in the pure +understanding. It was a design worthy of an acute thinker like +Aristotle, to search for these fundamental conceptions. Destitute, +however, of any guiding principle, he picked them up just as they +occurred to him, and at first hunted out ten, which he called +categories (predicaments). Afterwards be believed that he had +discovered five others, which were added under the name of post +predicaments. But his catalogue still remained defective. Besides, +there are to be found among them some of the modes of pure sensibility +(quando, ubi, situs, also prius, simul), and likewise an empirical +conception (motus)--which can by no means belong to this +genealogical register of the pure understanding. Moreover, there are +deduced conceptions (actio, passio) enumerated among the original +conceptions, and, of the latter, some are entirely wanting. + +With regard to these, it is to be remarked, that the categories, +as the true primitive conceptions of the pure understanding, have also +their pure deduced conceptions, which, in a complete system of +transcendental philosophy, must by no means be passed over; though +in a merely critical essay we must be contented with the simple +mention of the fact. + +Let it be allowed me to call these pure, but deduced conceptions +of the understanding, the predicables of the pure understanding, in +contradistinction to predicaments. If we are in possession of the +original and primitive, the deduced and subsidiary conceptions can +easily be added, and the genealogical tree of the understanding +completely delineated. As my present aim is not to set forth a +complete system, but merely the principles of one, I reserve this task +for another time. It may be easily executed by any one who will +refer to the ontological manuals, and subordinate to the category of +causality, for example, the predicables of force, action, passion; +to that of community, those of presence and resistance; to the +categories of modality, those of origination, extinction, change; +and so with the rest. The categories combined with the modes of pure +sensibility, or with one another, afford a great number of deduced +a priori conceptions; a complete enumeration of which would be a +useful and not unpleasant, but in this place a perfectly +dispensable, occupation. + +I purposely omit the definitions of the categories in this treatise. +I shall analyse these conceptions only so far as is necessary for +the doctrine of method, which is to form a part of this critique. In +a system of pure reason, definitions of them would be with justice +demanded of me, but to give them here would only bide from our view +the main aim of our investigation, at the same time raising doubts +and objections, the consideration of which, without injustice to our +main purpose, may be very well postponed till another opportunity. +Meanwhile, it ought to be sufficiently clear, from the little we +have already said on this subject, that the formation of a complete +vocabulary of pure conceptions, accompanied by all the requisite +explanations, is not only a possible, but an easy undertaking. The +compartments already exist; it is only necessary to fill them up; +and a systematic topic like the present, indicates with perfect +precision the proper place to which each conception belongs, while +it readily points out any that have not yet been filled up. + + + +SS 7. + +Our table of the categories suggests considerations of some +importance, which may perhaps have significant results in regard to +the scientific form of all rational cognitions. For, that this table +is useful in the theoretical part of philosophy, nay, indispensable +for the sketching of the complete plan of a science, so far as that +science rests upon conceptions a priori, and for dividing it +mathematically, according to fixed principles, is most manifest from +the fact that it contains all the elementary conceptions of the +understanding, nay, even the form of a system of these in the +understanding itself, and consequently indicates all the momenta, +and also the internal arrangement of a projected speculative +science, as I have elsewhere shown. [Footnote: In the +Metaphysical Principles of Natural Science.] Here follow some of these +observations. + +I. This table, which contains four classes of conceptions of the +understanding, may, in the first instance, be divided into two +classes, the first of which relates to objects of intuition--pure as +well as empirical; the second, to the existence of these objects, +either in relation to one another, or to the understanding. + +The former of these classes of categories I would entitle the +mathematical, and the latter the dynamical categories. The former, +as we see, has no correlates; these are only to be found in the second +class. This difference must have a ground in the nature of the human +understanding. + +II. The number of the categories in each class is always the same, +namely, three--a fact which also demands some consideration, because +in all other cases division a priori through conceptions is +necessarily dichotomy. It is to be added, that the third category in +each triad always arises from the combination of the second with the +first. + +Thus totality is nothing else but plurality contemplated as unity; +limitation is merely reality conjoined with negation; community is +the causality of a substance, reciprocally determining, and determined +by other substances; and finally, necessity is nothing but +existence, which is given through the possibility itself. Let it not +be supposed, however, that the third category is merely a deduced, +and not a primitive conception of the pure understanding. For the +conjunction of the first and second, in order to produce the third +conception, requires a particular function of the understanding, which +is by no means identical with those which are exercised in the first +and second. Thus, the conception of a number (which belongs to the +category of totality) is not always possible, where the conceptions +of multitude and unity exist (for example, in the representation of +the infinite). Or, if I conjoin the conception of a cause with that +of a substance, it does not follow that the conception of influence, +that is, how one substance can be the cause of something in another +substance, will be understood from that. Thus it is evident that a +particular act of the understanding is here necessary; and so in the +other instances. + +III. With respect to one category, namely, that of community, +which is found in the third class, it is not so easy as with the +others to detect its accordance with the form of the disjunctive +judgement which corresponds to it in the table of the logical +functions. + +In order to assure ourselves of this accordance, we must observe +that in every disjunctive judgement, the sphere of the judgement (that +is, the complex of all that is contained in it) is represented as a +whole divided into parts; and, since one part cannot be contained in +the other, they are cogitated as co-ordinated with, not subordinated +to each other, so that they do not determine each other +unilaterally, as in a linear series, but reciprocally, as in an +aggregate--(if one member of the division is posited, all the rest +are excluded; and conversely). + +Now a like connection is cogitated in a whole of things; for one +thing is not subordinated, as effect, to another as cause of its +existence, but, on the contrary, is co-ordinated contemporaneously +and reciprocally, as a cause in relation to the determination of the +others (for example, in a body--the parts of which mutually attract +and repel each other). And this is an entirely different kind of +connection from that which we find in the mere relation of the cause +to the effect (the principle to the consequence), for in such a +connection the consequence does not in its turn determine the +principle, and therefore does not constitute, with the latter, a +whole--just as the Creator does not with the world make up a whole. +The process of understanding by which it represents to itself the +sphere of a divided conception, is employed also when we think of a +thing as divisible; and in the same manner as the members of the +division in the former exclude one another, and yet are connected in +one sphere, so the understanding represents to itself the parts of +the latter, as having--each of them--an existence (as substances), +independently of the others, and yet as united in one whole. + + + +SS 8. + +In the transcendental philosophy of the ancients there exists one more +leading division, which contains pure conceptions of the understanding, +and which, although not numbered among the categories, ought, according +to them, as conceptions a priori, to be valid of objects. But in this +case they would augment the number of the categories; which cannot be. +These are set forth in the proposition, so renowned among the +schoolmen--"Quodlibet ens est UNUM, VERUM, BONUM." Now, though the +inferences from this principle were mere tautological propositions, and +though it is allowed only by courtesy to retain a place in modern +metaphysics, yet a thought which maintained itself for such a length of +time, however empty it seems to be, deserves an investigation of its +origin, and justifies the conjecture that it must be grounded in some +law of the understanding, which, as is often the case, has only been +erroneously interpreted. These pretended transcendental predicates are, +in fact, nothing but logical requisites and criteria of all cognition +of objects, and they employ, as the basis for this cognition, the +categories of quantity, namely, unity, plurality, and totality. But +these, which must be taken as material conditions, that is, as +belonging to the possibility of things themselves, they employed merely +in a formal signification, as belonging to the logical requisites of +all cognition, and yet most unguardedly changed these criteria of +thought into properties of objects, as things in themselves. Now, in +every cognition of an object, there is unity of conception, which may +be called qualitative unity, so far as by this term we understand only +the unity in our connection of the manifold; for example, unity of the +theme in a play, an oration, or a story. Secondly, there is truth in +respect of the deductions from it. The more true deductions we have +from a given conception, the more criteria of its objective reality. +This we might call the qualitative plurality of characteristic marks, +which belong to a conception as to a common foundation, but are not +cogitated as a quantity in it. Thirdly, there is perfection--which +consists in this, that the plurality falls back upon the unity of the +conception, and accords completely with that conception and with no +other. This we may denominate qualitative completeness. Hence it is +evident that these logical criteria of the possibility of cognition are +merely the three categories of quantity modified and transformed to +suit an unauthorized manner of applying them. That is to say, the three +categories, in which the unity in the production of the quantum must be +homogeneous throughout, are transformed solely with a view to the +connection of heterogeneous parts of cognition in one act of +consciousness, by means of the quality of the cognition, which is the +principle of that connection. Thus the criterion of the possibility of +a conception (not of its object) is the definition of it, in which the +unity of the conception, the truth of all that may be immediately +deduced from it, and finally, the completeness of what has been thus +deduced, constitute the requisites for the reproduction of the whole +conception. Thus also, the criterion or test of an hypothesis is the +intelligibility of the received principle of explanation, or its unity +(without help from any subsidiary hypothesis)--the truth of our +deductions from it (consistency with each other and with +experience)--and lastly, the completeness of the principle of the +explanation of these deductions, which refer to neither more nor less +than what was admitted in the hypothesis, restoring analytically and a +posteriori, what was cogitated synthetically and a priori. By the +conceptions, therefore, of unity, truth, and perfection, we have made +no addition to the transcendental table of the categories, which is +complete without them. We have, on the contrary, merely employed the +three categories of quantity, setting aside their application to +objects of experience, as general logical laws of the consistency of +cognition with itself. + + + +CHAPTER II Of the Deduction of the Pure Conceptions of the Understanding. + +SS 9. SECTION I Of the Principles of a Transcendental Deduction + in general. + +Teachers of jurisprudence, when speaking of rights and claims, +distinguish in a cause the question of right (quid juris) from the +question of fact (quid facti), and while they demand proof of both, +they give to the proof of the former, which goes to establish right +or claim in law, the name of deduction. Now we make use of a great +number of empirical conceptions, without opposition from any one; and +consider ourselves, even without any attempt at deduction, justified +in attaching to them a sense, and a supposititious signification, +because we have always experience at hand to demonstrate their +objective reality. There exist also, however, usurped conceptions, +such as fortune, fate, which circulate with almost universal +indulgence, and yet are occasionally challenged by the question, "quid +juris?" In such cases, we have great difficulty in discovering any +deduction for these terms, inasmuch as we cannot produce any +manifest ground of right, either from experience or from reason, on +which the claim to employ them can be founded. + +Among the many conceptions, which make up the very variegated web of +human cognition, some are destined for pure use a priori, +independent of all experience; and their title to be so employed +always requires a deduction, inasmuch as, to justify such use of them, +proofs from experience are not sufficient; but it is necessary to know +how these conceptions can apply to objects without being derived +from experience. I term, therefore, an examination of the manner in +which conceptions can apply a priori to objects, the transcendental +deduction of conceptions, and I distinguish it from the empirical +deduction, which indicates the mode in which conception is obtained +through experience and reflection thereon; consequently, does not +concern itself with the right, but only with the fact of our obtaining +conceptions in such and such a manner. We have already seen that we +are in possession of two perfectly different kinds of conceptions, +which nevertheless agree with each other in this, that they both apply +to objects completely a priori. These are the conceptions of space +and time as forms of sensibility, and the categories as pure conceptions +of the understanding. To attempt an empirical deduction of either of +these classes would be labour in vain, because the distinguishing +characteristic of their nature consists in this, that they apply to +their objects, without having borrowed anything from experience +towards the representation of them. Consequently, if a deduction of +these conceptions is necessary, it must always be transcendental. + +Meanwhile, with respect to these conceptions, as with respect to all +our cognition, we certainly may discover in experience, if not the +principle of their possibility, yet the occasioning causes of their +production. It will be found that the impressions of sense give the +first occasion for bringing into action the whole faculty of +cognition, and for the production of experience, which contains two +very dissimilar elements, namely, a matter for cognition, given by +the senses, and a certain form for the arrangement of this matter, +arising out of the inner fountain of pure intuition and thought; and +these, on occasion given by sensuous impressions, are called into exercise +and produce conceptions. Such an investigation into the first efforts +of our faculty of cognition to mount from particular perceptions to +general conceptions is undoubtedly of great utility; and we have to +thank the celebrated Locke for having first opened the way for this +inquiry. But a deduction of the pure a priori conceptions of course +never can be made in this way, seeing that, in regard to their +future employment, which must be entirely independent of experience, +they must have a far different certificate of birth to show from +that of a descent from experience. This attempted physiological +derivation, which cannot properly be called deduction, because it +relates merely to a quaestio facti, I shall entitle an explanation +of the possession of a pure cognition. It is therefore manifest that +there can only be a transcendental deduction of these conceptions +and by no means an empirical one; also, that all attempts at an +empirical deduction, in regard to pure a priori conceptions, are vain, +and can only be made by one who does not understand the altogether +peculiar nature of these cognitions. + +But although it is admitted that the only possible deduction of pure +a priori cognition is a transcendental deduction, it is not, for +that reason, perfectly manifest that such a deduction is absolutely +necessary. We have already traced to their sources the conceptions +of space and time, by means of a transcendental deduction, and we have +explained and determined their objective validity a priori. +Geometry, nevertheless, advances steadily and securely in the province +of pure a priori cognitions, without needing to ask from philosophy +any certificate as to the pure and legitimate origin of its +fundamental conception of space. But the use of the conception in this +science extends only to the external world of sense, the pure form +of the intuition of which is space; and in this world, therefore, +all geometrical cognition, because it is founded upon a priori +intuition, possesses immediate evidence, and the objects of this +cognition are given a priori (as regards their form) in intuition by +and through the cognition itself. With the pure conceptions of +understanding, on the contrary, commences the absolute necessity of +seeking a transcendental deduction, not only of these conceptions +themselves, but likewise of space, because, inasmuch as they make +affirmations concerning objects not by means of the predicates of +intuition and sensibility, but of pure thought a priori, they apply +to objects without any of the conditions of sensibility. Besides, not +being founded on experience, they are not presented with any object +in a priori intuition upon which, antecedently to experience, they +might base their synthesis. Hence results, not only doubt as to the +objective validity and proper limits of their use, but that even our +conception of space is rendered equivocal; inasmuch as we are very +ready with the aid of the categories, to carry the use of this +conception beyond the conditions of sensuous intuition--and, for +this reason, we have already found a transcendental deduction of it +needful. The reader, then, must be quite convinced of the absolute +necessity of a transcendental deduction, before taking a single step +in the field of pure reason; because otherwise he goes to work +blindly, and after he has wondered about in all directions, returns +to the state of utter ignorance from which he started. He ought, +moreover, clearly to recognize beforehand the unavoidable difficulties +in his undertaking, so that he may not afterwards complain of the +obscurity in which the subject itself is deeply involved, or become +too soon impatient of the obstacles in his path; because we have a +choice of only two things--either at once to give up all pretensions +to knowledge beyond the limits of possible experience, or to bring +this critical investigation to completion. + +We have been able, with very little trouble, to make it +comprehensible how the conceptions of space and time, although a +priori cognitions, must necessarily apply to external objects, and +render a synthetical cognition of these possible, independently of +all experience. For inasmuch as only by means of such pure form of +sensibility an object can appear to us, that is, be an object of +empirical intuition, space and time are pure intuitions, which contain +a priori the condition of the possibility of objects as phenomena, +and an a priori synthesis in these intuitions possesses objective +validity. + +On the other hand, the categories of the understanding do not +represent the conditions under which objects are given to us in +intuition; objects can consequently appear to us without necessarily +connecting themselves with these, and consequently without any +necessity binding on the understanding to contain a priori the +conditions of these objects. Thus we find ourselves involved in a +difficulty which did not present itself in the sphere of +sensibility, that is to say, we cannot discover how the subjective +conditions of thought can have objective validity, in other words, +can become conditions of the possibility of all cognition of objects; +for phenomena may certainly be given to us in intuition without any +help from the functions of the understanding. Let us take, for +example, the conception of cause, which indicates a peculiar kind of +synthesis, namely, that with something, A, something entirely +different, B, is connected according to a law. It is not a priori +manifest why phenomena should contain anything of this kind (we are +of course debarred from appealing for proof to experience, for the +objective validity of this conception must be demonstrated a +priori), and it hence remains doubtful a priori, whether such a +conception be not quite void and without any corresponding object +among phenomena. For that objects of sensuous intuition must +correspond to the formal conditions of sensibility existing a priori +in the mind is quite evident, from the fact that without these they +could not be objects for us; but that they must also correspond to +the conditions which understanding requires for the synthetical unity +of thought is an assertion, the grounds for which are not so easily +to be discovered. For phenomena might be so constituted as not to +correspond to the conditions of the unity of thought; and all things +might lie in such confusion that, for example, nothing could be met +with in the sphere of phenomena to suggest a law of synthesis, and +so correspond to the conception of cause and effect; so that this +conception would be quite void, null, and without significance. Phenomena +would nevertheless continue to present objects to our intuition; for +mere intuition does not in any respect stand in need of the functions +of thought. + +If we thought to free ourselves from the labour of these +investigations by saying: "Experience is constantly offering us +examples of the relation of cause and effect in phenomena, and +presents us with abundant opportunity of abstracting the conception +of cause, and so at the same time of corroborating the objective validity +of this conception"; we should in this case be overlooking the fact, +that the conception of cause cannot arise in this way at all; that, +on the contrary, it must either have an a priori basis in the +understanding, or be rejected as a mere chimera. For this conception +demands that something, A, should be of such a nature that something +else, B, should follow from it necessarily, and according to an +absolutely universal law. We may certainly collect from phenomena a +law, according to which this or that usually happens, but the +element of necessity is not to be found in it. Hence it is evident +that to the synthesis of cause and effect belongs a dignity, which +is utterly wanting in any empirical synthesis; for it is no mere +mechanical synthesis, by means of addition, but a dynamical one; +that is to say, the effect is not to be cogitated as merely annexed +to the cause, but as posited by and through the cause, and resulting +from it. The strict universality of this law never can be a +characteristic of empirical laws, which obtain through induction +only a comparative universality, that is, an extended range of +practical application. But the pure conceptions of the understanding +would entirely lose all their peculiar character, if we treated them +merely as the productions of experience. + + + +SS 10. Transition to the Transcendental Deduction of the + Categories. + +There are only two possible ways in which synthetical representation +and its objects can coincide with and relate necessarily to each +other, and, as it were, meet together. Either the object alone makes +the representation possible, or the representation alone makes the +object possible. In the former case, the relation between them is only +empirical, and an a priori representation is impossible. And this is +the case with phenomena, as regards that in them which is referable +to mere sensation. In the latter case--although representation alone +(for of its causality, by means of the will, we do not here speak) +does not produce the object as to its existence, it must nevertheless +be a priori determinative in regard to the object, if it is only by +means of the representation that we can cognize anything as an object. +Now there are only two conditions of the possibility of a cognition +of objects; firstly, intuition, by means of which the object, though +only as phenomenon, is given; secondly, conception, by means of which +the object which corresponds to this intuition is thought. But it is +evident from what has been said on aesthetic that the first condition, +under which alone objects can be intuited, must in fact exist, as a +formal basis for them, a priori in the mind. With this formal +condition of sensibility, therefore, all phenomena necessarily +correspond, because it is only through it that they can be phenomena +at all; that is, can be empirically intuited and given. Now the +question is whether there do not exist, a priori in the mind, +conceptions of understanding also, as conditions under which alone +something, if not intuited, is yet thought as object. If this question +be answered in the affirmative, it follows that all empirical +cognition of objects is necessarily conformable to such conceptions, +since, if they are not presupposed, it is impossible that anything +can be an object of experience. Now all experience contains, besides +the intuition of the senses through which an object is given, a conception +also of an object that is given in intuition. Accordingly, conceptions +of objects in general must lie as a priori conditions at the +foundation of all empirical cognition; and consequently, the objective +validity of the categories, as a priori conceptions, will rest upon +this, that experience (as far as regards the form of thought) is +possible only by their means. For in that case they apply +necessarily and a priori to objects of experience, because only +through them can an object of experience be thought. + +The whole aim of the transcendental deduction of all a priori +conceptions is to show that these conceptions are a priori +conditions of the possibility of all experience. Conceptions which +afford us the objective foundation of the possibility of experience +are for that very reason necessary. But the analysis of the +experiences in which they are met with is not deduction, but only an +illustration of them, because from experience they could never +derive the attribute of necessity. Without their original +applicability and relation to all possible experience, in which all +objects of cognition present themselves, the relation of the +categories to objects, of whatever nature, would be quite +incomprehensible. + +The celebrated Locke, for want of due reflection on these points, +and because he met with pure conceptions of the understanding in +experience, sought also to deduce them from experience, and yet +proceeded so inconsequently as to attempt, with their aid, to arrive +it cognitions which lie far beyond the limits of all experience. David +Hume perceived that, to render this possible, it was necessary that +the conceptions should have an a priori origin. But as he could not +explain how it was possible that conceptions which are not connected +with each other in the understanding must nevertheless be thought as +necessarily connected in the object--and it never occurred to him that +the understanding itself might, perhaps, by means of these +conceptions, be the author of the experience in which its objects were +presented to it--he was forced to drive these conceptions from +experience, that is, from a subjective necessity arising from repeated +association of experiences erroneously considered to be objective-- +in one word, from habit. But he proceeded with perfect consequence +and declared it to be impossible, with such conceptions and the principles +arising from them, to overstep the limits of experience. The empirical +derivation, however, which both of these philosophers attributed to +these conceptions, cannot possibly be reconciled with the fact that +we do possess scientific a priori cognitions, namely, those of pure +mathematics and general physics. + +The former of these two celebrated men opened a wide door to +extravagance--(for if reason has once undoubted right on its side, +it will not allow itself to be confined to set limits, by vague +recommendations of moderation); the latter gave himself up entirely +to scepticism--a natural consequence, after having discovered, as he +thought, that the faculty of cognition was not trustworthy. We now +intend to make a trial whether it be not possible safely to conduct +reason between these two rocks, to assign her determinate limits, +and yet leave open for her the entire sphere of her legitimate +activity. + +I shall merely premise an explanation of what the categories are. +They are conceptions of an object in general, by means of which its +intuition is contemplated as determined in relation to one of the +logical functions of judgement. The following will make this plain. +The function of the categorical judgement is that of the relation of +subject to predicate; for example, in the proposition: "All bodies +are divisible." But in regard to the merely logical use of the +understanding, it still remains undetermined to which Of these two +conceptions belongs the function Of subject and to which that of +predicate. For we could also say: "Some divisible is a body." But +the category of substance, when the conception of a body is brought +under it, determines that; and its empirical intuition in experience +must be contemplated always as subject and never as mere predicate. +And so with all the other categories. + + + +SS 11. SECTION II Transcendental Deduction of the pure Conceptions of + the Understanding. + +Of the Possibility of a Conjunction of the manifold representations +given by Sense. + +The manifold content in our representations can be given in an +intuition which is merely sensuous--in other words, is nothing but +susceptibility; and the form of this intuition can exist a priori in +our faculty of representation, without being anything else but the +mode in which the subject is affected. But the conjunction +(conjunctio) of a manifold in intuition never can be given us by the +senses; it cannot therefore be contained in the pure form of +sensuous intuition, for it is a spontaneous act of the faculty of +representation. And as we must, to distinguish it from sensibility, +entitle this faculty understanding; so all conjunction whether +conscious or unconscious, be it of the manifold in intuition, sensuous +or non-sensuous, or of several conceptions--is an act of the +understanding. To this act we shall give the general appellation of +synthesis, thereby to indicate, at the same time, that we cannot +represent anything as conjoined in the object without having +previously conjoined it ourselves. Of all mental notions, that of +conjunction is the only one which cannot be given through objects, +but can be originated only by the subject itself, because it is an +act of its purely spontaneous activity. The reader will easily enough +perceive that the possibility of conjunction must be grounded in the +very nature of this act, and that it must be equally valid for all +conjunction, and that analysis, which appears to be its contrary, +must, nevertheless, always presuppose it; for where the +understanding has not previously conjoined, it cannot dissect or +analyse, because only as conjoined by it, must that which is to be +analysed have been given to our faculty of representation. + +But the conception of conjunction includes, besides the conception +of the manifold and of the synthesis of it, that of the unity of it +also. Conjunction is the representation of the synthetical unity of +the manifold.* This idea of unity, therefore, cannot arise out of that +of conjunction; much rather does that idea, by combining itself with +the representation of the manifold, render the conception of +conjunction possible. This unity, which a priori precedes all +conceptions of conjunction, is not the category of unity (SS 6); for +all the categories are based upon logical functions of judgement, +and in these functions we already have conjunction, and consequently +unity of given conceptions. It is therefore evident that the +category of unity presupposes conjunction. We must therefore look +still higher for this unity (as qualitative, SS 8), in that, namely, +which contains the ground of the unity of diverse conceptions in +judgements, the ground, consequently, of the possibility of the +existence of the understanding, even in regard to its logical use. + +[*Footnote: Whether the representations are in themselves identical, +and consequently whether one can be thought analytically by means of +and through the other, is a question which we need not at present +consider. Our Consciousness of the one, when we speak of the manifold, +is always distinguishable from our consciousness of the other; and +it is only respecting the synthesis of this (possible) consciousness +that we here treat.] + + + +SS 12. Of the Originally Synthetical Unity of Apperception. + +The "I think" must accompany all my representations, for otherwise +something would be represented in me which could not be thought; in +other words, the representation would either be impossible, or at +least be, in relation to me, nothing. That representation which can +be given previously to all thought is called intuition. All the diversity +or manifold content of intuition, has, therefore, a necessary relation +to the "I think," in the subject in which this diversity is found. +But this representation, "I think," is an act of spontaneity; that +is to say, it cannot be regarded as belonging to mere sensibility. +I call it pure apperception, in order to distinguish it from empirical; +or primitive apperception, because it is self-consciousness which, +whilst it gives birth to the representation "I think," must necessarily +be capable of accompanying all our representations. It is in all acts +of consciousness one and the same, and unaccompanied by it, no +representation can exist for me. The unity of this apperception I call +the transcendental unity of self-consciousness, in order to indicate +the possibility of a priori cognition arising from it. For the +manifold representations which are given in an intuition would not +all of them be my representations, if they did not all belong to one +self-consciousness, that is, as my representations (even although I +am not conscious of them as such), they must conform to the condition +under which alone they can exist together in a common +self-consciousness, because otherwise they would not all without +exception belong to me. From this primitive conjunction follow many +important results. + +For example, this universal identity of the apperception of the +manifold given in intuition contains a synthesis of representations +and is possible only by means of the consciousness of this +synthesis. For the empirical consciousness which accompanies different +representations is in itself fragmentary and disunited, and without +relation to the identity of the subject. This relation, then, does +not exist because I accompany every representation with consciousness, +but because I join one representation to another, and am conscious +of the synthesis of them. Consequently, only because I can connect +a variety of given representations in one consciousness, is it +possible that I can represent to myself the identity of +consciousness in these representations; in other words, the analytical +unity of apperception is possible only under the presupposition of +a synthetical unity.* The thought, "These representations given in +intuition belong all of them to me," is accordingly just the same +as, "I unite them in one self-consciousness, or can at least so +unite them"; and although this thought is not itself the consciousness +of the synthesis of representations, it presupposes the possibility +of it; that is to say, for the reason alone that I can comprehend the +variety of my representations in one consciousness, do I call them +my representations, for otherwise I must have as many-coloured and +various a self as are the representations of which I am conscious. +Synthetical unity of the manifold in intuitions, as given a priori, +is therefore the foundation of the identity of apperception itself, +which antecedes a priori all determinate thought. But the conjunction +of representations into a conception is not to be found in objects +themselves, nor can it be, as it were, borrowed from them and taken +up into the understanding by perception, but it is on the contrary +an operation of the understanding itself, which is nothing more than +the faculty of conjoining a priori and of bringing the variety of +given representations under the unity of apperception. This +principle is the highest in all human cognition. + +[*Footnote: All general conceptions--as such--depend, for their existence, +on the analytical unity of consciousness. For example, when I think +of red in general, I thereby think to myself a property which (as a +characteristic mark) can be discovered somewhere, or can be united +with other representations; consequently, it is only by means of a +forethought possible synthetical unity that I can think to myself +the analytical. A representation which is cogitated as common to +different representations, is regarded as belonging to such as, +besides this common representation, contain something different; +consequently it must be previously thought in synthetical unity with +other although only possible representations, before I can think in +it the analytical unity of consciousness which makes it a conceptas +communis. And thus the synthetical unity of apperception is the +highest point with which we must connect every operation of the +understanding, even the whole of logic, and after it our +transcendental philosophy; indeed, this faculty is the understanding +itself.] + +This fundamental principle of the necessary unity of apperception is +indeed an identical, and therefore analytical, proposition; but it +nevertheless explains the necessity for a synthesis of the manifold +given in an intuition, without which the identity of +self-consciousness would be incogitable. For the ego, as a simple +representation, presents us with no manifold content; only in +intuition, which is quite different from the representation ego, can +it be given us, and by means of conjunction it is cogitated in one +self-consciousness. An understanding, in which all the manifold should +be given by means of consciousness itself, would be intuitive; our +understanding can only think and must look for its intuition to sense. +I am, therefore, conscious of my identical self, in relation to all +the variety of representations given to me in an intuition, because +I call all of them my representations. In other words, I am +conscious myself of a necessary a priori synthesis of my +representations, which is called the original synthetical unity of +apperception, under which rank all the representations presented to +me, but that only by means of a synthesis. + + + +SS 13. The Principle of the Synthetical Unity of Apperception is + the highest Principle of all exercise of the Understanding. + +The supreme principle of the possibility of all intuition in +relation to sensibility was, according to our transcendental +aesthetic, that all the manifold in intuition be subject to the formal +conditions of space and time. The supreme principle of the possibility +of it in relation to the understanding is that all the manifold in +it be subject to conditions of the originally synthetical unity or +apperception.* To the former of these two principles are subject all +the various representations of intuition, in so far as they are +given to us; to the latter, in so far as they must be capable of +conjunction in one consciousness; for without this nothing can be +thought or cognized, because the given representations would not +have in common the act Of the apperception "I think" and therefore +could not be connected in one self-consciousness. + +[*Footnote: Space and time, and all portions thereof, are intuitions; +consequently are, with a manifold for their content, single +representations. (See the Transcendental Aesthetic.) Consequently, +they are not pure conceptions, by means of which the same +consciousness is found in a great number of representations; but, on +the contrary, they are many representations contained in one, the +consciousness of which is, so to speak, compounded. The unity of +consciousness is nevertheless synthetical and, therefore, primitive. +From this peculiar character of consciousness follow many important +consequences. (See SS 21.)] + +Understanding is, to speak generally, the faculty Of cognitions. +These consist in the determined relation of given representation to +an object. But an object is that, in the conception of which the manifold +in a given intuition is united. Now all union of representations +requires unity of consciousness in the synthesis of them. +Consequently, it is the unity of consciousness alone that +constitutes the possibility of representations relating to an +object, and therefore of their objective validity, and of their +becoming cognitions, and consequently, the possibility of the +existence of the understanding itself. + +The first pure cognition of understanding, then, upon which is +founded all its other exercise, and which is at the same time +perfectly independent of all conditions of mere sensuous intuition, +is the principle of the original synthetical unity of apperception. +Thus the mere form of external sensuous intuition, namely, space, +affords us, per se, no cognition; it merely contributes the manifold +in a priori intuition to a possible cognition. But, in order to +cognize something in space (for example, a line), I must draw it, +and thus produce synthetically a determined conjunction of the given +manifold, so that the unity of this act is at the same time the +unity of consciousness (in the conception of a line), and by this +means alone is an object (a determinate space) cognized. The +synthetical unity of consciousness is, therefore, an objective +condition of all cognition, which I do not merely require in order +to cognize an object, but to which every intuition must necessarily +be subject, in order to become an object for me; because in any other +way, and without this synthesis, the manifold in intuition could not +be united in one consciousness. + +This proposition is, as already said, itself analytical, although it +constitutes the synthetical unity, the condition of all thought; for +it states nothing more than that all my representations in any given +intuition must be subject to the condition which alone enables me to +connect them, as my representation with the identical self, and so +to unite them synthetically in one apperception, by means of the +general expression, "I think." + +But this principle is not to be regarded as a principle for every +possible understanding, but only for the understanding by means of +whose pure apperception in the thought I am, no manifold content is +given. The understanding or mind which contained the manifold in +intuition, in and through the act itself of its own +self-consciousness, in other words, an understanding by and in the +representation of which the objects of the representation should at +the same time exist, would not require a special act of synthesis of +the manifold as the condition of the unity of its consciousness, an +act of which the human understanding, which thinks only and cannot +intuite, has absolute need. But this principle is the first +principle of all the operations of our understanding, so that we +cannot form the least conception of any other possible +understanding, either of one such as should be itself intuition, or +possess a sensuous intuition, but with forms different from those of +space and time. + + + +SS 14. What Objective Unity of Self-consciousness is. + +It is by means of the transcendental unity of apperception that +all the manifold, given in an intuition is united into a conception +of the object. On this account it is called objective, and must be +distinguished from the subjective unity of consciousness, which is +a determination of the internal sense, by means of which the said +manifold in intuition is given empirically to be so united. Whether +I can be empirically conscious of the manifold as coexistent or as +successive, depends upon circumstances, or empirical conditions. Hence +the empirical unity of consciousness by means of association of +representations, itself relates to a phenomenal world and is wholly +contingent. On the contrary, the pure form of intuition in time, +merely as an intuition, which contains a given manifold, is subject +to the original unity of consciousness, and that solely by means of +the necessary relation of the manifold in intuition to the "I think," +consequently by means of the pure synthesis of the understanding, +which lies a priori at the foundation of all empirical synthesis. +The transcendental unity of apperception is alone objectively valid; +the empirical which we do not consider in this essay, and which is +merely a unity deduced from the former under given conditions in +concreto, possesses only subjective validity. One person connects +the notion conveyed in a word with one thing, another with another +thing; and the unity of consciousness in that which is empirical, +is, in relation to that which is given by experience, not +necessarily and universally valid. + + + +SS 15. The Logical Form of all Judgements consists in the Objective + Unity of Apperception of the Conceptions contained therein. + +I could never satisfy myself with the definition which logicians +give of a judgement. It is, according to them, the representation of +a relation between two conceptions. I shall not dwell here on the +faultiness of this definition, in that it suits only for categorical +and not for hypothetical or disjunctive judgements, these latter +containing a relation not of conceptions but of judgements themselves-- +a blunder from which many evil results have followed.* It is more +important for our present purpose to observe, that this definition +does not determine in what the said relation consists. + +[*Footnote: The tedious doctrine of the four syllogistic figures concerns +only categorical syllogisms; and although it is nothing more than an +artifice by surreptitiously introducing immediate conclusions +(consequentiae immediatae) among the premises of a pure syllogism, +to give ism' give rise to an appearance of more modes of drawing a +conclusion than that in the first figure, the artifice would not +have had much success, had not its authors succeeded in bringing +categorical judgements into exclusive respect, as those to which all +others must be referred--a doctrine, however, which, according to SS +5, is utterly false.] + +But if I investigate more closely the relation of given cognitions +in every judgement, and distinguish it, as belonging to the +understanding, from the relation which is produced according to laws +of the reproductive imagination (which has only subjective +validity), I find that judgement is nothing but the mode of bringing +given cognitions under the objective unit of apperception. This is +plain from our use of the term of relation is in judgements, in +order to distinguish the objective unity of given representations from +the subjective unity. For this term indicates the relation of these +representations to the original apperception, and also their necessary +unity, even although the judgement is empirical, therefore contingent, +as in the judgement: "All bodies are heavy." I do not mean by this, +that these representations do necessarily belong to each other in +empirical intuition, but that by means of the necessary unity of +appreciation they belong to each other in the synthesis of intuitions, +that is to say, they belong to each other according to principles of +the objective determination of all our representations, in so far as +cognition can arise from them, these principles being all deduced from +the main principle of the transcendental unity of apperception. In +this way alone can there arise from this relation a judgement, that +is, a relation which has objective validity, and is perfectly distinct +from that relation of the very same representations which has only +subjective validity--a relation, to wit, which is produced according +to laws of association. According to these laws, I could only say: +"When I hold in my hand or carry a body, I feel an impression of +weight"; but I could not say: "It, the body, is heavy"; for this is +tantamount to saying both these representations are conjoined in the +object, that is, without distinction as to the condition of the +subject, and do not merely stand together in my perception, however +frequently the perceptive act may be repeated. + + + +SS 16. All Sensuous Intuitions are subject to the Categories, as + Conditions under which alone the manifold Content of them + can be united in one Consciousness. + +The manifold content given in a sensuous intuition comes necessarily +under the original synthetical unity of apperception, because +thereby alone is the unity of intuition possible (SS 13). But that +act of the understanding, by which the manifold content of given +representations (whether intuitions or conceptions) is brought under +one apperception, is the logical function of judgements (SS 15). All +the manifold, therefore, in so far as it is given in one empirical +intuition, is determined in relation to one of the logical functions +of judgement, by means of which it is brought into union in one +consciousness. Now the categories are nothing else than these +functions of judgement so far as the manifold in a given intuition +is determined in relation to them (SS 9). Consequently, the manifold +in a given intuition is necessarily subject to the categories of the +understanding. + + + +SS 17. Observation. + +The manifold in an intuition, which I call mine, is represented by +means of the synthesis of the understanding, as belonging to the +necessary unity of self-consciousness, and this takes place by means +of the category.* The category indicates accordingly that the +empirical consciousness of a given manifold in an intuition is subject +to a pure self-consciousness a priori, in the same manner as an +empirical intuition is subject to a pure sensuous intuition, which +is also a priori. In the above proposition, then, lies the beginning +of a deduction of the pure conceptions of the understanding. Now, as +the categories have their origin in the understanding alone, +independently of sensibility, I must in my deduction make +abstraction of the mode in which the manifold of an empirical +intuition is given, in order to fix my attention exclusively on the +unity which is brought by the understanding into the intuition by +means of the category. In what follows (SS 22), it will be shown, from +the mode in which the empirical intuition is given in the faculty of +sensibility, that the unity which belongs to it is no other than +that which the category (according to SS 16) imposes on the manifold +in a given intuition, and thus, its a priori validity in regard to +all objects of sense being established, the purpose of our deduction +will be fully attained. + +[*Footnote: The proof of this rests on the represented unity of intuition, +by means of which an object is given, and which always includes in +itself a synthesis of the manifold to be intuited, and also the relation +of this latter to unity of apperception.] + +But there is one thing in the above demonstration of which I could +not make abstraction, namely, that the manifold to be intuited must +be given previously to the synthesis of the understanding, and +independently of it. How this takes place remains here undetermined. +For if I cogitate an understanding which was itself intuitive (as, +for example, a divine understanding which should not represent given +objects, but by whose representation the objects themselves should +be given or produced), the categories would possess no significance +in relation to such a faculty of cognition. They are merely rules for +an understanding, whose whole power consists in thought, that is, in +the act of submitting the synthesis of the manifold which is presented +to it in intuition from a very different quarter, to the unity of +apperception; a faculty, therefore, which cognizes nothing per se, +but only connects and arranges the material of cognition, the intuition, +namely, which must be presented to it by means of the object. But to +show reasons for this peculiar character of our understandings, that +it produces unity of apperception a priori only by means of +categories, and a certain kind and number thereof, is as impossible +as to explain why we are endowed with precisely so many functions of +judgement and no more, or why time and space are the only forms of +our intuition. + + + +SS 18. In Cognition, its Application to Objects of Experience is + the only legitimate use of the Category. + +To think an object and to cognize an object are by no means the same +thing. In cognition there are two elements: firstly, the conception, +whereby an object is cogitated (the category); and, secondly, the +intuition, whereby the object is given. For supposing that to the +conception a corresponding intuition could not be given, it would +still be a thought as regards its form, but without any object, and +no cognition of anything would be possible by means of it, inasmuch +as, so far as I knew, there existed and could exist nothing to which +my thought could be applied. Now all intuition possible to us is +sensuous; consequently, our thought of an object by means of a pure +conception of the understanding, can become cognition for us only in +so far as this conception is applied to objects of the senses. +Sensuous intuition is either pure intuition (space and time) or +empirical intuition--of that which is immediately represented in space +and time by means of sensation as real. Through the determination of +pure intuition we obtain a priori cognitions of objects, as in +mathematics, but only as regards their form as phenomena; whether +there can exist things which must be intuited in this form is not +thereby established. All mathematical conceptions, therefore, are +not per se cognition, except in so far as we presuppose that there +exist things which can only be represented conformably to the form +of our pure sensuous intuition. But things in space and time are given +only in so far as they are perceptions (representations accompanied +with sensation), therefore only by empirical representation. +Consequently the pure conceptions of the understanding, even when they +are applied to intuitions a priori (as in mathematics), produce +cognition only in so far as these (and therefore the conceptions of +the understanding by means of them) can be applied to empirical +intuitions. Consequently the categories do not, even by means of +pure intuition afford us any cognition of things; they can only do +so in so far as they can be applied to empirical intuition. That is +to say, the categories serve only to render empirical cognition +possible. But this is what we call experience. Consequently, in +cognition, their application to objects of experience is the only +legitimate use of the categories. + + + +SS 19. + +The foregoing proposition is of the utmost importance, for it +determines the limits of the exercise of the pure conceptions of the +understanding in regard to objects, just as transcendental aesthetic +determined the limits of the exercise of the pure form of our sensuous +intuition. Space and time, as conditions of the possibility of the +presentation of objects to us, are valid no further than for objects +of sense, consequently, only for experience. Beyond these limits +they represent to us nothing, for they belong only to sense, and +have no reality apart from it. The pure conceptions of the +understanding are free from this limitation, and extend to objects +of intuition in general, be the intuition like or unlike to ours, +provided only it be sensuous, and not intellectual. But this extension +of conceptions beyond the range of our intuition is of no advantage; +for they are then mere empty conceptions of objects, as to the +possibility or impossibility of the existence of which they furnish +us with no means of discovery. They are mere forms of thought, without +objective reality, because we have no intuition to which the +synthetical unity of apperception, which alone the categories contain, +could be applied, for the purpose of determining an object. Our +sensuous and empirical intuition can alone give them significance +and meaning. + +If, then, we suppose an object of a non-sensuous intuition to be +given we can in that case represent it by all those predicates which +are implied in the presupposition that nothing appertaining to +sensuous intuition belongs to it; for example, that it is not +extended, or in space; that its duration is not time; that in it no +change (the effect of the determinations in time) is to be met with, +and so on. But it is no proper knowledge if I merely indicate what +the intuition of the object is not, without being able to say what +is contained in it, for I have not shown the possibility of an object +to which my pure conception of understanding could be applicable, +because I have not been able to furnish any intuition corresponding +to it, but am only able to say that our intuition is not valid for +it. But the most important point is this, that to a something of this +kind not one category can be found applicable. Take, for example, the +conception of substance, that is, something that can exist as subject, +but never as mere predicate; in regard to this conception I am quite +ignorant whether there can really be anything to correspond to such +a determination of thought, if empirical intuition did not afford me +the occasion for its application. But of this more in the sequel. + + + +SS 20. Of the Application of the Categories to Objects of the + Senses in general. + +The pure conceptions of the understanding apply to objects of +intuition in general, through the understanding alone, whether the +intuition be our own or some other, provided only it be sensuous, +but are, for this very reason, mere forms of thought, by means of +which alone no determined object can be cognized. The synthesis or +conjunction of the manifold in these conceptions relates, we have +said, only to the unity of apperception, and is for this reason the +ground of the possibility of a priori cognition, in so far as this +cognition is dependent on the understanding. This synthesis is, +therefore, not merely transcendental, but also purely intellectual. +But because a certain form of sensuous intuition exists in the mind +a priori which rests on the receptivity of the representative +faculty (sensibility), the understanding, as a spontaneity, is able +to determine the internal sense by means of the diversity of given +representations, conformably to the synthetical unity of apperception, +and thus to cogitate the synthetical unity of the apperception of +the manifold of sensuous intuition a priori, as the condition to which +must necessarily be submitted all objects of human intuition. And in +this manner the categories as mere forms of thought receive +objective reality, that is, application to objects which are given +to us in intuition, but that only as phenomena, for it is only of +phenomena that we are capable of a priori intuition. + +This synthesis of the manifold of sensuous intuition, which is +possible and necessary a priori, may be called figurative (synthesis +speciosa), in contradistinction to that which is cogitated in the mere +category in regard to the manifold of an intuition in general, and +is called connection or conjunction of the understanding (synthesis +intellectualis). Both are transcendental, not merely because they +themselves precede a priori all experience, but also because they form +the basis for the possibility of other cognition a priori. + +But the figurative synthesis, when it has relation only to the +originally synthetical unity of apperception, that is to the +transcendental unity cogitated in the categories, must, to be +distinguished from the purely intellectual conjunction, be entitled +the transcendental synthesis of imagination. Imagination is the +faculty of representing an object even without its presence in +intuition. Now, as all our intuition is sensuous, imagination, by +reason of the subjective condition under which alone it can give a +corresponding intuition to the conceptions of the understanding, +belongs to sensibility. But in so far as the synthesis of the +imagination is an act of spontaneity, which is determinative, and not, +like sense, merely determinable, and which is consequently able to +determine sense a priori, according to its form, conformably to the +unity of apperception, in so far is the imagination a faculty of +determining sensibility a priori, and its synthesis of intuitions +according to the categories must be the transcendental synthesis of +the imagination. It is an operation of the understanding on +sensibility, and the first application of the understanding to objects +of possible intuition, and at the same time the basis for the exercise +of the other functions of that faculty. As figurative, it is +distinguished from the merely intellectual synthesis, which is +produced by the understanding alone, without the aid of imagination. +Now, in so far as imagination is spontaneity, I sometimes call it also +the productive imagination, and distinguish it from the +reproductive, the synthesis of which is subject entirely to +empirical laws, those of association, namely, and which, therefore, +contributes nothing to the explanation of the possibility of a +priori cognition, and for this reason belongs not to transcendental +philosophy, but to psychology. + +We have now arrived at the proper place for explaining the paradox +which must have struck every one in our exposition of the internal +sense (SS 6), namely--how this sense represents us to our own +consciousness, only as we appear to ourselves, not as we are in +ourselves, because, to wit, we intuite ourselves only as we are +inwardly affected. Now this appears to be contradictory, inasmuch as +we thus stand in a passive relation to ourselves; and therefore in +the systems of psychology, the internal sense is commonly held to be +one with the faculty of apperception, while we, on the contrary, carefully +distinguish them. + +That which determines the internal sense is the understanding, and +its original power of conjoining the manifold of intuition, that is, +of bringing this under an apperception (upon which rests the +possibility of the understanding itself). Now, as the human +understanding is not in itself a faculty of intuition, and is unable +to exercise such a power, in order to conjoin, as it were, the +manifold of its own intuition, the synthesis of understanding is, +considered per se, nothing but the unity of action, of which, as such, +it is self-conscious, even apart from sensibility, by which, moreover, +it is able to determine our internal sense in respect of the +manifold which may be presented to it according to the form of +sensuous intuition. Thus, under the name of a transcendental synthesis +of imagination, the understanding exercises an activity upon the +passive subject, whose faculty it is; and so we are right in saying +that the internal sense is affected thereby. Apperception and its +synthetical unity are by no means one and the same with the internal +sense. The former, as the source of all our synthetical conjunction, +applies, under the name of the categories, to the manifold of +intuition in general, prior to all sensuous intuition of objects. +The internal sense, on the contrary, contains merely the form of +intuition, but without any synthetical conjunction of the manifold +therein, and consequently does not contain any determined intuition, +which is possible only through consciousness of the determination of +the manifold by the transcendental act of the imagination (synthetical +influence of the understanding on the internal sense), which I have +named figurative synthesis. + +This we can indeed always perceive in ourselves. We cannot +cogitate a geometrical line without drawing it in thought, nor a +circle without describing it, nor represent the three dimensions of +space without drawing three lines from the same point perpendicular +to one another. We cannot even cogitate time, unless, in drawing a +straight line (which is to serve as the external figurative +representation of time), we fix our attention on the act of the +synthesis of the manifold, whereby we determine successively the +internal sense, and thus attend also to the succession of this +determination. Motion as an act of the subject (not as a determination +of an object),* consequently the synthesis of the manifold in space, +if we make abstraction of space and attend merely to the act by +which we determine the internal sense according to its form, is that +which produces the conception of succession. The understanding, +therefore, does by no means find in the internal sense any such +synthesis of the manifold, but produces it, in that it affects this +sense. At the same time, how "I who think" is distinct from the "I" +which intuites itself (other modes of intuition being cogitable as +at least possible), and yet one and the same with this latter as the +same subject; how, therefore, I am able to say: "I, as an intelligence +and thinking subject, cognize myself as an object thought, so far as +I am, moreover, given to myself in intuition--only, like other +phenomena, not as I am in myself, and as considered by the +understanding, but merely as I appear"--is a question that has in it +neither more nor less difficulty than the question--"How can I be an +object to myself?" or this--"How I can be an object of my own +intuition and internal perceptions?" But that such must be the fact, +if we admit that space is merely a pure form of the phenomena of +external sense, can be clearly proved by the consideration that we +cannot represent time, which is not an object of external intuition, +in any other way than under the image of a line, which we draw in +thought, a mode of representation without which we could not cognize +the unity of its dimension, and also that we are necessitated to +take our determination of periods of time, or of points of time, for +all our internal perceptions from the changes which we perceive in +outward things. It follows that we must arrange the determinations +of the internal sense, as phenomena in time, exactly in the same +manner as we arrange those of the external senses in space. And +consequently, if we grant, respecting this latter, that by means of +them we know objects only in so far as we are affected externally, +we must also confess, with regard to the internal sense, that by means +of it we intuite ourselves only as we are internally affected by +ourselves; in other words, as regards internal intuition, we cognize +our own subject only as phenomenon, and not as it is in itself.*[2] + + +[*Footnote: Motion of an object in space does not belong to a pure +science, consequently not to geometry; because, that a thing is movable +cannot be known a priori, but only from experience. But motion, +considered as the description of a space, is a pure act of the +successive synthesis of the manifold in external intuition by means +of productive imagination, and belongs not only to geometry, but even +to transcendental philosophy.] + +[*[2]Footnote: I do not see why so much difficulty should be found +in admitting that our internal sense is affected by ourselves. Every +act of attention exemplifies it. In such an act the understanding +determines the internal sense by the synthetical conjunction which +it cogitates, conformably to the internal intuition which +corresponds to the manifold in the synthesis of the understanding. +How much the mind is usually affected thereby every one will be able +to perceive in himself.] + + + +SS 21. + +On the other hand, in the transcendental synthesis of the manifold +content of representations, consequently in the synthetical unity of +apperception, I am conscious of myself, not as I appear to myself, +nor as I am in myself, but only that "I am." This representation is +a thought, not an intuition. Now, as in order to cognize ourselves, +in addition to the act of thinking, which subjects the manifold of +every possible intuition to the unity of apperception, there is +necessary a determinate mode of intuition, whereby this manifold is +given; although my own existence is certainly not mere phenomenon +(much less mere illusion), the determination of my existence* Can only +take place conformably to the form of the internal sense, according +to the particular mode in which the manifold which I conjoin is given +in internal intuition, and I have therefore no knowledge of myself +as I am, but merely as I appear to myself. The consciousness of self +is thus very far from a knowledge of self, in which I do not use the +categories, whereby I cogitate an object, by means of the +conjunction of the manifold in one apperception. In the same way as +I require, for the sake of the cognition of an object distinct from +myself, not only the thought of an object in general (in the +category), but also an intuition by which to determine that general +conception, in the same way do I require, in order to the cognition +of myself, not only the consciousness of myself or the thought that +I think myself, but in addition an intuition of the manifold in +myself, by which to determine this thought. It is true that I exist +as an intelligence which is conscious only of its faculty of +conjunction or synthesis, but subjected in relation to the manifold +which this intelligence has to conjoin to a limitative conjunction +called the internal sense. My intelligence (that is, I) can render +that conjunction or synthesis perceptible only according to the +relations of time, which are quite beyond the proper sphere of the +conceptions of the understanding and consequently cognize itself in +respect to an intuition (which cannot possibly be intellectual, nor +given by the understanding), only as it appears to itself, and not +as it would cognize itself, if its intuition were intellectual. + + +[*Footnote: The "I think" expresses the act of determining my own +existence. My existence is thus already given by the act of consciousness; +but the mode in which I must determine my existence, that is, the mode +in which I must place the manifold belonging to my existence, is not +thereby given. For this purpose intuition of self is required, and +this intuition possesses a form given a priori, namely, time, which +is sensuous, and belongs to our receptivity of the determinable. Now, +as I do not possess another intuition of self which gives the +determining in me (of the spontaneity of which I am conscious), +prior to the act of determination, in the same manner as time gives +the determinable, it is clear that I am unable to determine my own +existence as that of a spontaneous being, but I am only able to +represent to myself the spontaneity of my thought, that is, of my +determination, and my existence remains ever determinable in a +purely sensuous manner, that is to say, like the existence of a +phenomenon. But it is because of this spontaneity that I call myself +an intelligence.] + + + +SS 22. Transcendental Deduction of the universally possible employment + in experience of the Pure Conceptions of the Understanding. + +In the metaphysical deduction, the a priori origin of categories was +proved by their complete accordance with the general logical of +thought; in the transcendental deduction was exhibited the possibility +of the categories as a priori cognitions of objects of an intuition +in general (SS 16 and 17).At present we are about to explain the +possibility of cognizing, a priori, by means of the categories, all +objects which can possibly be presented to our senses, not, indeed, +according to the form of their intuition, but according to the laws +of their conjunction or synthesis, and thus, as it were, of prescribing +laws to nature and even of rendering nature possible. For if the +categories were inadequate to this task, it would not be evident to +us why everything that is presented to our senses must be subject to +those laws which have an a priori origin in the understanding itself. + +I premise that by the term synthesis of apprehension I understand +the combination of the manifold in an empirical intuition, whereby +perception, that is, empirical consciousness of the intuition (as +phenomenon), is possible. + +We have a priori forms of the external and internal sensuous +intuition in the representations of space and time, and to these +must the synthesis of apprehension of the manifold in a phenomenon +be always comformable, because the synthesis itself can only take +place according to these forms. But space and time are not merely +forms of sensuous intuition, but intuitions themselves (which +contain a manifold), and therefore contain a priori the +determination of the unity of this manifold.* (See the Transcendent +Aesthetic.) Therefore is unity of the synthesis of the manifold +without or within us, consequently also a conjunction to which all +that is to be represented as determined in space or time must +correspond, given a priori along with (not in) these intuitions, as +the condition of the synthesis of all apprehension of them. But this +synthetical unity can be no other than that of the conjunction of +the manifold of a given intuition in general, in a primitive act of +consciousness, according to the categories, but applied to our +sensuous intuition. Consequently all synthesis, whereby alone is +even perception possible, is subject to the categories. And, as +experience is cognition by means of conjoined perceptions, the +categories are conditions of the possibility of experience and are +therefore valid a priori for all objects of experience. + +[*Footnote: Space represented as an object (as geometry really requires +it to be) contains more than the mere form of the intuition; namely, +a combination of the manifold given according to the form of sensibility +into a representation that can be intuited; so that the form of the +intuition gives us merely the manifold, but the formal intuition gives +unity of representation. In the aesthetic, I regarded this unity as +belonging entirely to sensibility, for the purpose of indicating +that it antecedes all conceptions, although it presupposes a synthesis +which does not belong to sense, through which alone, however, all +our conceptions of space and time are possible. For as by means of +this unity alone (the understanding determining the sensibility) space +and time are given as intuitions, it follows that the unity of this +intuition a priori belongs to space and time, and not to the +conception of the understanding (SS 20).] + +When, then, for example, I make the empirical intuition of a house +by apprehension of the manifold contained therein into a perception, +the necessary unity of space and of my external sensuous intuition +lies at the foundation of this act, and I, as it were, draw the form +of the house conformably to this synthetical unity of the manifold +in space. But this very synthetical unity remains, even when I +abstract the form of space, and has its seat in the understanding, +and is in fact the category of the synthesis of the homogeneous in +an intuition; that is to say, the category of quantity, to which the +aforesaid synthesis of apprehension, that is, the perception, must +be completely conformable.* + +[*Footnote: In this manner it is proved, that the synthesis of +apprehension, which is empirical, must necessarily be conformable to +the synthesis of apperception, which is intellectual, and contained +a priori in the category. It is one and the same spontaneity which +at one time, under the name of imagination, at another under that of +understanding, produces conjunction in the manifold of intuition.] + +To take another example, when I perceive the freezing of water, I +apprehend two states (fluidity and solidity), which, as such, stand +toward each other mutually in a relation of time. But in the time, +which I place as an internal intuition, at the foundation of this +phenomenon, I represent to myself synthetical unity of the manifold, +without which the aforesaid relation could not be given in an +intuition as determined (in regard to the succession of time). Now +this synthetical unity, as the a priori condition under which I +conjoin the manifold of an intuition, is, if I make abstraction of +the permanent form of my internal intuition (that is to say, of time), +the category of cause, by means of which, when applied to my +sensibility, I determine everything that occurs according to relations +of time. Consequently apprehension in such an event, and the event +itself, as far as regards the possibility of its perception, stands +under the conception of the relation of cause and effect: and so in +all other cases. + +Categories are conceptions which prescribe laws a priori to +phenomena, consequently to nature as the complex of all phenomena +(natura materialiter spectata). And now the question arises-- +inasmuch as these categories are not derived from nature, and do not +regulate themselves according to her as their model (for in that +case they would be empirical)--how it is conceivable that nature +must regulate herself according to them, in other words, how the +categories can determine a priori the synthesis of the manifold of +nature, and yet not derive their origin from her. The following is +the solution of this enigma. + +It is not in the least more difficult to conceive how the laws of the +phenomena of nature must harmonize with the understanding and with its +a priori form--that is, its faculty of conjoining the manifold--than +it is to understand how the phenomena themselves must correspond with +the a priori form of our sensuous intuition. For laws do not exist in +the phenomena any more than the phenomena exist as things in +themselves. Laws do not exist except by relation to the subject in +which the phenomena inhere, in so far as it possesses understanding, +just as phenomena have no existence except by relation to the same +existing subject in so far as it has senses. To things as things in +themselves, conformability to law must necessarily belong independently +of an understanding to cognize them. But phenomena are only +representations of things which are utterly unknown in respect to what +they are in themselves. But as mere representations, they stand under +no law of conjunction except that which the conjoining faculty +prescribes. Now that which conjoins the manifold of sensuous intuition +is imagination, a mental act to which understanding contributes unity +of intellectual synthesis, and sensibility, manifoldness of +apprehension. Now as all possible perception depends on the synthesis +of apprehension, and this empirical synthesis itself on the +transcendental, consequently on the categories, it is evident that all +possible perceptions, and therefore everything that can attain to +empirical consciousness, that is, all phenomena of nature, must, as +regards their conjunction, be subject to the categories. And nature +(considered merely as nature in general) is dependent on them, as the +original ground of her necessary conformability to law (as natura +formaliter spectata). But the pure faculty (of the understanding) of +prescribing laws a priori to phenomena by means of mere categories, is +not competent to enounce other or more laws than those on which a +nature in general, as a conformability to law of phenomena of space and +time, depends. Particular laws, inasmuch as they concern empirically +determined phenomena, cannot be entirely deduced from pure laws, +although they all stand under them. Experience must be superadded in +order to know these particular laws; but in regard to experience in +general, and everything that can be cognized as an object thereof, +these a priori laws are our only rule and guide. + + + +SS 23. Result of this Deduction of the Conceptions of the + Understanding. + +We cannot think any object except by means of the categories; we +cannot cognize any thought except by means of intuitions corresponding +to these conceptions. Now all our intuitions are sensuous, and our +cognition, in so far as the object of it is given, is empirical. But +empirical cognition is experience; consequently no a priori +cognition is possible for us, except of objects of possible +experience.* + +[Footnote: Lest my readers should stumble at this assertion, and the +conclusions that may be too rashly drawn from it, I must remind them +that the categories in the act of thought are by no means limited by +the conditions of our sensuous intuition, but have an unbounded sphere +of action. It is only the cognition of the object of thought, the +determining of the object, which requires intuition. In the absence +of intuition, our thought of an object may still have true and useful +consequences in regard to the exercise of reason by the subject. But +as this exercise of reason is not always directed on the determination +of the object, in other words, on cognition thereof, but also on the +determination of the subject and its volition, I do not intend to +treat of it in this place.] + +But this cognition, which is limited to objects of experience, is +not for that reason derived entirely, from, experience, but--and +this is asserted of the pure intuitions and the pure conceptions of +the understanding--there are, unquestionably, elements of cognition, +which exist in the mind a priori. Now there are only two ways in which +a necessary harmony of experience with the conceptions of its +objects can be cogitated. Either experience makes these conceptions +possible, or the conceptions make experience possible. The former of +these statements will not bold good with respect to the categories +(nor in regard to pure sensuous intuition), for they are a priori +conceptions, and therefore independent of experience. The assertion +of an empirical origin would attribute to them a sort of generatio +aequivoca. Consequently, nothing remains but to adopt the second +alternative (which presents us with a system, as it were, of the +epigenesis of pure reason), namely, that on the part of the +understanding the categories do contain the grounds of the possibility +of all experience. But with respect to the questions how they make +experience possible, and what are the principles of the possibility +thereof with which they present us in their application to +phenomena, the following section on the transcendental exercise of +the faculty of judgement will inform the reader. + +It is quite possible that someone may propose a species of +preformation-system of pure reason--a middle way between the two--to +wit, that the categories are neither innate and first a priori +principles of cognition, nor derived from experience, but are merely +subjective aptitudes for thought implanted in us contemporaneously +with our existence, which were so ordered and disposed by our Creator, +that their exercise perfectly harmonizes with the laws of nature which +regulate experience. Now, not to mention that with such an +hypothesis it is impossible to say at what point we must stop in the +employment of predetermined aptitudes, the fact that the categories +would in this case entirely lose that character of necessity which +is essentially involved in the very conception of them, is a +conclusive objection to it. The conception of cause, for example, +which expresses the necessity of an effect under a presupposed +condition, would be false, if it rested only upon such an arbitrary +subjective necessity of uniting certain empirical representations +according to such a rule of relation. I could not then say--"The +effect is connected with its cause in the object (that is, +necessarily)," but only, "I am so constituted that I can think this +representation as so connected, and not otherwise." Now this is just +what the sceptic wants. For in this case, all our knowledge, depending +on the supposed objective validity of our judgement, is nothing but +mere illusion; nor would there be wanting people who would deny any +such subjective necessity in respect to themselves, though they must +feel it. At all events, we could not dispute with any one on that +which merely depends on the manner in which his subject is organized. + + + +Short view of the above Deduction. + +The foregoing deduction is an exposition of the pure conceptions +of the understanding (and with them of all theoretical a priori +cognition), as principles of the possibility of experience, but of +experience as the determination of all phenomena in space and time +in general--of experience, finally, from the principle of the original +synthetical unity of apperception, as the form of the understanding +in relation to time and space as original forms of sensibility. + +I consider the division by paragraphs to be necessary only up to +this point, because we had to treat of the elementary conceptions. +As we now proceed to the exposition of the employment of these, I +shall not designate the chapters in this manner any further. + + + + +BOOK II. + +Analytic of Principles. + +General logic is constructed upon a plan which coincides exactly +with the division of the higher faculties of cognition. These are, +understanding, judgement, and reason. This science, accordingly, +treats in its analytic of conceptions, judgements, and conclusions +in exact correspondence with the functions and order of those mental +powers which we include generally under the generic denomination of +understanding. + +As this merely formal logic makes abstraction of all content of +cognition, whether pure or empirical, and occupies itself with the +mere form of thought (discursive cognition), it must contain in its +analytic a canon for reason. For the form of reason has its law, +which, without taking into consideration the particular nature of +the cognition about which it is employed, can be discovered a +priori, by the simple analysis of the action of reason into its +momenta. + +Transcendental logic, limited as it is to a determinate content, +that of pure a priori cognitions, to wit, cannot imitate general logic +in this division. For it is evident that the transcendental employment +of reason is not objectively valid, and therefore does not belong to +the logic of truth (that is, to analytic), but as a logic of illusion, +occupies a particular department in the scholastic system under the +name of transcendental dialectic. + +Understanding and judgement accordingly possess in transcendental +logic a canon of objectively valid, and therefore true exercise, and +are comprehended in the analytical department of that logic. But +reason, in her endeavours to arrive by a priori means at some true +statement concerning objects and to extend cognition beyond the bounds +of possible experience, is altogether dialectic, and her illusory +assertions cannot be constructed into a canon such as an analytic +ought to contain. + +Accordingly, the analytic of principles will be merely a canon for +the faculty of judgement, for the instruction of this faculty in its +application to phenomena of the pure conceptions of the understanding, +which contain the necessary condition for the establishment of a +priori laws. On this account, although the subject of the following +chapters is the especial principles of understanding, I shall make +use of the term Doctrine of the faculty of judgement, in order to define +more particularly my present purpose. + + + +INTRODUCTION. Of the Transcendental Faculty of judgement in General. + +If understanding in general be defined as the faculty of laws or +rules, the faculty of judgement may be termed the faculty of +subsumption under these rules; that is, of distinguishing whether this +or that does or does not stand under a given rule (casus datae legis). +General logic contains no directions or precepts for the faculty of +judgement, nor can it contain any such. For as it makes abstraction +of all content of cognition, no duty is left for it, except that of +exposing analytically the mere form of cognition in conceptions, +judgements, and conclusions, and of thereby establishing formal +rules for all exercise of the understanding. Now if this logic +wished to give some general direction how we should subsume under +these rules, that is, how we should distinguish whether this or that +did or did not stand under them, this again could not be done +otherwise than by means of a rule. But this rule, precisely because +it is a rule, requires for itself direction from the faculty of +judgement. Thus, it is evident that the understanding is capable of +being instructed by rules, but that the judgement is a peculiar +talent, which does not, and cannot require tuition, but only exercise. +This faculty is therefore the specific quality of the so-called mother +wit, the want of which no scholastic discipline can compensate. + +For although education may furnish, and, as it were, engraft upon +a limited understanding rules borrowed from other minds, yet the power +of employing these rules correctly must belong to the pupil himself; +and no rule which we can prescribe to him with this purpose is, in +the absence or deficiency of this gift of nature, secure from misuse.* +A physician therefore, a judge or a statesman, may have in his head +many admirable pathological, juridical, or political rules, in a degree +that may enable him to be a profound teacher in his particular +science, and yet in the application of these rules he may very +possibly blunder--either because he is wanting in natural judgement +(though not in understanding) and, whilst he can comprehend the +general in abstracto, cannot distinguish whether a particular case +in concreto ought to rank under the former; or because his faculty +of judgement has not been sufficiently exercised by examples and +real practice. Indeed, the grand and only use of examples, is to +sharpen the judgement. For as regards the correctness and precision +of the insight of the understanding, examples are commonly injurious +rather than otherwise, because, as casus in terminis they seldom +adequately fulfil the conditions of the rule. Besides, they often +weaken the power of our understanding to apprehend rules or laws in +their universality, independently of particular circumstances of +experience; and hence, accustom us to employ them more as formulae +than as principles. Examples are thus the go-cart of the judgement, +which he who is naturally deficient in that faculty cannot afford to +dispense with. + +[*Footnote: Deficiency in judgement is properly that which is called +stupidity; and for such a failing we know no remedy. A dull or +narrow-minded person, to whom nothing is wanting but a proper degree +of understanding, may be improved by tuition, even so far as to deserve +the epithet of learned. But as such persons frequently labour under +a deficiency in the faculty of judgement, it is not uncommon to find +men extremely learned who in the application of their science betray +a lamentable degree this irremediable want.] + +But although general logic cannot give directions to the faculty +of judgement, the case is very different as regards transcendental +logic, insomuch that it appears to be the especial duty of the +latter to secure and direct, by means of determinate rules, the +faculty of judgement in the employment of the pure understanding. For, +as a doctrine, that is, as an endeavour to enlarge the sphere of the +understanding in regard to pure a priori cognitions, philosophy is +worse than useless, since from all the attempts hitherto made, +little or no ground has been gained. But, as a critique, in order to +guard against the mistakes of the faculty of judgement (lapsus +judicii) in the employment of the few pure conceptions of the +understanding which we possess, although its use is in this case +purely negative, philosophy is called upon to apply all its +acuteness and penetration. + +But transcendental philosophy has this peculiarity, that besides +indicating the rule, or rather the general condition for rules, +which is given in the pure conception of the understanding, it can, +at the same time, indicate a priori the case to which the rule must +be applied. The cause of the superiority which, in this respect, +transcendental philosophy possesses above all other sciences except +mathematics, lies in this: it treats of conceptions which must +relate a priori to their objects, whose objective validity +consequently cannot be demonstrated a posteriori, and is, at the +same time, under the obligation of presenting in general but +sufficient tests, the conditions under which objects can be given in +harmony with those conceptions; otherwise they would be mere logical +forms, without content, and not pure conceptions of the understanding. + +Our transcendental doctrine of the faculty of judgement will contain +two chapters. The first will treat of the sensuous condition under +which alone pure conceptions of the understanding can be employed-- +that is, of the schematism of the pure understanding. The second +will treat of those synthetical judgements which are derived a +priori from pure conceptions of the understanding under those +conditions, and which lie a priori at the foundation of all other +cognitions, that is to say, it will treat of the principles of the +pure understanding. + + + +TRANSCENDENTAL DOCTRINE OF THE FACULTY OF JUDGEMENT +OR, ANALYTIC OF PRINCIPLES. + +CHAPTER I. Of the Schematism at of the Pure Conceptions + of the Understanding. + +In all subsumptions of an object under a conception, the +representation of the object must be homogeneous with the +conception; in other words, the conception must contain that which +is represented in the object to be subsumed under it. For this is +the meaning of the expression: "An object is contained under a +conception." Thus the empirical conception of a plate is homogeneous +with the pure geometrical conception of a circle, inasmuch as the +roundness which is cogitated in the former is intuited in the latter. + +But pure conceptions of the understanding, when compared with +empirical intuitions, or even with sensuous intuitions in general, +are quite heterogeneous, and never can be discovered in any intuition. +How then is the subsumption of the latter under the former, and +consequently the application of the categories to phenomena, +possible?--For it is impossible to say, for example: "Causality can +be intuited through the senses and is contained in the phenomenon."--This +natural and important question forms the real cause of the necessity +of a transcendental doctrine of the faculty of judgement, with the +purpose, to wit, of showing how pure conceptions of the +understanding can be applied to phenomena. In all other sciences, +where the conceptions by which the object is thought in the general +are not so different and heterogeneous from those which represent +the object in concreto--as it is given, it is quite unnecessary to +institute any special inquiries concerning the application of the +former to the latter. + +Now it is quite clear that there must be some third thing, which +on the one side is homogeneous with the category, and with the +phenomenon on the other, and so makes the application of the former +to the latter possible. This mediating representation must be pure +(without any empirical content), and yet must on the one side be +intellectual, on the other sensuous. Such a representation is the +transcendental schema. + +The conception of the understanding contains pure synthetical +unity of the manifold in general. Time, as the formal condition of +the manifold of the internal sense, consequently of the conjunction +of all representations, contains a priori a manifold in the pure intuition. +Now a transcendental determination of time is so far homogeneous +with the category, which constitutes the unity thereof, that it is +universal and rests upon a rule a priori. On the other hand, it is +so far homogeneous with the phenomenon, inasmuch as time is +contained in every empirical representation of the manifold. Thus an +application of the category to phenomena becomes possible, by means +of the transcendental determination of time, which, as the schema of +the conceptions of the understanding, mediates the subsumption of +the latter under the former. + +After what has been proved in our deduction of the categories, no +one, it is to be hoped, can hesitate as to the proper decision of +the question, whether the employment of these pure conceptions of +the understanding ought to be merely empirical or also transcendental; +in other words, whether the categories, as conditions of a possible +experience, relate a priori solely to phenomena, or whether, as +conditions of the possibility of things in general, their +application can be extended to objects as things in themselves. For +we have there seen that conceptions are quite impossible, and utterly +without signification, unless either to them, or at least to the +elements of which they consist, an object be given; and that, +consequently, they cannot possibly apply to objects as things in +themselves without regard to the question whether and how these may +be given to us; and, further, that the only manner in which objects +can be given to us is by means of the modification of our sensibility; +and, finally, that pure a priori conceptions, in addition to the +function of the understanding in the category, must contain a priori +formal conditions of sensibility (of the internal sense, namely), +which again contain the general condition under which alone the +category can be applied to any object. This formal and pure +condition of sensibility, to which the conception of the understanding +is restricted in its employment, we shall name the schema of the +conception of the understanding, and the procedure of the +understanding with these schemata we shall call the schematism of +the pure understanding. + +The schema is, in itself, always a mere product of the +imagination. But, as the synthesis of imagination has for its aim no +single intuition, but merely unity in the determination of +sensibility, the schema is clearly distinguishable from the image. +Thus, if I place five points one after another .... this is an image +of the number five. On the other hand, if I only think a number in +general, which may be either five or a hundred, this thought is rather +the representation of a method of representing in an image a sum +(e.g., a thousand) in conformity with a conception, than the image +itself, an image which I should find some little difficulty in +reviewing, and comparing with the conception. Now this +representation of a general procedure of the imagination to present +its image to a conception, I call the schema of this conception. + +In truth, it is not images of objects, but schemata, which lie at +the foundation of our pure sensuous conceptions. No image could ever +be adequate to our conception of a triangle in general. For the +generalness of the conception it never could attain to, as this +includes under itself all triangles, whether right-angled, +acute-angled, etc., whilst the image would always be limited to a +single part of this sphere. The schema of the triangle can exist +nowhere else than in thought, and it indicates a rule of the synthesis +of the imagination in regard to pure figures in space. Still less is +an object of experience, or an image of the object, ever to the +empirical conception. On the contrary, the conception always relates +immediately to the schema of the imagination, as a rule for the +determination of our intuition, in conformity with a certain general +conception. The conception of a dog indicates a rule, according to +which my imagination can delineate the figure of a four-footed +animal in general, without being limited to any particular +individual form which experience presents to me, or indeed to any +possible image that I can represent to myself in concreto. This +schematism of our understanding in regard to phenomena and their +mere form, is an art, hidden in the depths of the human soul, whose +true modes of action we shall only with difficulty discover and +unveil. Thus much only can we say: "The image is a product of the +empirical faculty of the productive imagination--the schema of +sensuous conceptions (of figures in space, for example) is a +product, and, as it were, a monogram of the pure imagination a priori, +whereby and according to which images first become possible, which, +however, can be connected with the conception only mediately by +means of the schema which they indicate, and are in themselves never +fully adequate to it." On the other hand, the schema of a pure +conception of the understanding is something that cannot be reduced +into any image--it is nothing else than the pure synthesis expressed +by the category, conformably, to a rule of unity according to +conceptions. It is a transcendental product of the imagination, a +product which concerns the determination of the internal sense, +according to conditions of its form (time) in respect to all +representations, in so far as these representations must be +conjoined a priori in one conception, conformably to the unity of +apperception. + +Without entering upon a dry and tedious analysis of the essential +requisites of transcendental schemata of the pure conceptions of the +understanding, we shall rather proceed at once to give an +explanation of them according to the order of the categories, and in +connection therewith. + +For the external sense the pure image of all quantities +(quantorum) is space; the pure image of all objects of sense in +general, is time. But the pure schema of quantity (quantitatis) as +a conception of the understanding, is number, a representation which +comprehends the successive addition of one to one (homogeneous +quantities). Thus, number is nothing else than the unity of the +synthesis of the manifold in a homogeneous intuition, by means of my +generating time itself in my apprehension of the intuition. + +Reality, in the pure conception of the understanding, is that +which corresponds to a sensation in general; that, consequently, the +conception of which indicates a being (in time). Negation is that +the conception of which represents a not-being (in time). The +opposition of these two consists therefore in the difference of one +and the same time, as a time filled or a time empty. Now as time is +only the form of intuition, consequently of objects as phenomena, that +which in objects corresponds to sensation is the transcendental matter +of all objects as things in themselves (Sachheit, reality). Now +every sensation has a degree or quantity by which it can fill time, +that is to say, the internal sense in respect of the representation +of an object, more or less, until it vanishes into nothing (= 0 = +negatio). Thus there is a relation and connection between reality +and negation, or rather a transition from the former to the latter, +which makes every reality representable to us as a quantum; and the +schema of a reality as the quantity of something in so far as it fills +time, is exactly this continuous and uniform generation of the reality +in time, as we descend in time from the sensation which has a +certain degree, down to the vanishing thereof, or gradually ascend +from negation to the quantity thereof. + +The schema of substance is the permanence of the real in time; +that is, the representation of it as a substratum of the empirical +determination of time; a substratum which therefore remains, whilst +all else changes. (Time passes not, but in it passes the existence +of the changeable. To time, therefore, which is itself unchangeable +and permanent, corresponds that which in the phenomenon is +unchangeable in existence, that is, substance, and it is only by it +that the succession and coexistence of phenomena can be determined +in regard to time.) + +The schema of cause and of the causality of a thing is the real +which, when posited, is always followed by something else. It +consists, therefore, in the succession of the manifold, in so far as +that succession is subjected to a rule. + +The schema of community (reciprocity of action and reaction), or the +reciprocal causality of substances in respect of their accidents, is +the coexistence of the determinations of the one with those of the +other, according to a general rule. + +The schema of possibility is the accordance of the synthesis of +different representations with the conditions of time in general +(as, for example, opposites cannot exist together at the same time +in the same thing, but only after each other), and is therefore the +determination of the representation of a thing at any time. + +The schema of reality is existence in a determined time. + +The schema of necessity is the existence of an object in all time. + +It is clear, from all this, that the schema of the category of +quantity contains and represents the generation (synthesis) of time +itself, in the successive apprehension of an object; the schema of +quality the synthesis of sensation with the representation of time, +or the filling up of time; the schema of relation the relation of +perceptions to each other in all time (that is, according to a rule +of the determination of time): and finally, the schema of modality +and its categories, time itself, as the correlative of the determination +of an object--whether it does belong to time, and how. The schemata, +therefore, are nothing but a priori determinations of time according +to rules, and these, in regard to all possible objects, following +the arrangement of the categories, relate to the series in time, the +content in time, the order in time, and finally, to the complex or +totality in time. + +Hence it is apparent that the schematism of the understanding, by +means of the transcendental synthesis of the imagination, amounts to +nothing else than the unity of the manifold of intuition in the +internal sense, and thus indirectly to the unity of apperception, as +a function corresponding to the internal sense (a receptivity). Thus, +the schemata of the pure conceptions of the understanding are the true +and only conditions whereby our understanding receives an +application to objects, and consequently significance. Finally, +therefore, the categories are only capable of empirical use, +inasmuch as they serve merely to subject phenomena to the universal +rules of synthesis, by means of an a priori necessary unity (on +account of the necessary union of all consciousness in one original +apperception); and so to render them susceptible of a complete +connection in one experience. But within this whole of possible +experience lie all our cognitions, and in the universal relation to +this experience consists transcendental truth, which antecedes all +empirical truth, and renders the latter possible. + +It is, however, evident at first sight, that although the schemata +of sensibility are the sole agents in realizing the categories, they +do, nevertheless, also restrict them, that is, they limit the +categories by conditions which lie beyond the sphere of understanding-- +namely, in sensibility. Hence the schema is properly only the +phenomenon, or the sensuous conception of an object in harmony with +the category. (Numerus est quantitas phaenomenon--sensatio realitas +phaenomenon; constans et perdurabile rerum substantia phaenomenon-- +aeternitas, necessitas, phaenomena, etc.) Now, if we remove a +restrictive condition, we thereby amplify, it appears, the formerly +limited conception. In this way, the categories in their pure +signification, free from all conditions of sensibility, ought to be +valid of things as they are, and not, as the schemata represent +them, merely as they appear; and consequently the categories must have +a significance far more extended, and wholly independent of all +schemata. In truth, there does always remain to the pure conceptions +of the understanding, after abstracting every sensuous condition, a +value and significance, which is, however, merely logical. But in this +case, no object is given them, and therefore they have no meaning +sufficient to afford us a conception of an object. The notion of +substance, for example, if we leave out the sensuous determination +of permanence, would mean nothing more than a something which can be +cogitated as subject, without the possibility of becoming a +predicate to anything else. Of this representation I can make nothing, +inasmuch as it does not indicate to me what determinations the thing +possesses which must thus be valid as premier subject. Consequently, +the categories, without schemata are merely functions of the +understanding for the production of conceptions, but do not +represent any object. This significance they derive from +sensibility, which at the same time realizes the understanding and +restricts it. + + + +CHAPTER II. System of all Principles of the Pure Understanding. + +In the foregoing chapter we have merely considered the general +conditions under which alone the transcendental faculty of judgement +is justified in using the pure conceptions of the understanding for +synthetical judgements. Our duty at present is to exhibit in +systematic connection those judgements which the understanding +really produces a priori. For this purpose, our table of the +categories will certainly afford us the natural and safe guidance. +For it is precisely the categories whose application to possible +experience must constitute all pure a priori cognition of the +understanding; and the relation of which to sensibility will, on +that very account, present us with a complete and systematic catalogue +of all the transcendental principles of the use of the understanding. + +Principles a priori are so called, not merely because they contain +in themselves the grounds of other judgements, but also because they +themselves are not grounded in higher and more general cognitions. +This peculiarity, however, does not raise them altogether above the +need of a proof. For although there could be found no higher +cognition, and therefore no objective proof, and although such a +principle rather serves as the foundation for all cognition of the +object, this by no means hinders us from drawing a proof from the +subjective sources of the possibility of the cognition of an object. +Such a proof is necessary, moreover, because without it the +principle might be liable to the imputation of being a mere gratuitous +assertion. + +In the second place, we shall limit our investigations to those +principles which relate to the categories. For as to the principles +of transcendental aesthetic, according to which space and time are +the conditions of the possibility of things as phenomena, as also the +restriction of these principles, namely, that they cannot be applied +to objects as things in themselves--these, of course, do not fall +within the scope of our present inquiry. In like manner, the +principles of mathematical science form no part of this system, +because they are all drawn from intuition, and not from the pure +conception of the understanding. The possibility of these +principles, however, will necessarily be considered here, inasmuch +as they are synthetical judgements a priori, not indeed for the +purpose of proving their accuracy and apodeictic certainty, which is +unnecessary, but merely to render conceivable and deduce the +possibility of such evident a priori cognitions. + +But we shall have also to speak of the principle of analytical +judgements, in opposition to synthetical judgements, which is the +proper subject of our inquiries, because this very opposition will +free the theory of the latter from all ambiguity, and place it clearly +before our eyes in its true nature. + + + +SYSTEM OF THE PRINCIPLES OF THE PURE UNDERSTANDING. + +SECTION I. Of the Supreme Principle of all Analytical Judgements. + +Whatever may be the content of our cognition, and in whatever manner +our cognition may be related to its object, the universal, although +only negative conditions of all our judgements is that they do not +contradict themselves; otherwise these judgements are in themselves +(even without respect to the object) nothing. But although there may +exist no contradiction in our judgement, it may nevertheless connect +conceptions in such a manner that they do not correspond to the +object, or without any grounds either a priori or a posteriori for +arriving at such a judgement, and thus, without being +self-contradictory, a judgement may nevertheless be either false or +groundless. + +Now, the proposition: "No subject can have a predicate that +contradicts it," is called the principle of contradiction, and is a +universal but purely negative criterion of all truth. But it belongs +to logic alone, because it is valid of cognitions, merely as +cognitions and without respect to their content, and declares that +the contradiction entirely nullifies them. We can also, however, make +a positive use of this principle, that is, not merely to banish +falsehood and error (in so far as it rests upon contradiction), but +also for the cognition of truth. For if the judgement is analytical, +be it affirmative or negative, its truth must always be recognizable +by means of the principle of contradiction. For the contrary of that +which lies and is cogitated as conception in the cognition of the +object will be always properly negatived, but the conception itself +must always be affirmed of the object, inasmuch as the contrary +thereof would be in contradiction to the object. + +We must therefore hold the principle of contradiction to be the +universal and fully sufficient Principle of all analytical +cognition. But as a sufficient criterion of truth, it has no further +utility or authority. For the fact that no cognition can be at +variance with this principle without nullifying itself, constitutes +this principle the sine qua non, but not the determining ground of +the truth of our cognition. As our business at present is properly +with the synthetical part of our knowledge only, we shall always be +on our guard not to transgress this inviolable principle; but at the +same time not to expect from it any direct assistance in the +establishment of the truth of any synthetical proposition. + +There exists, however, a formula of this celebrated principle--a +principle merely formal and entirely without content--which contains +a synthesis that has been inadvertently and quite unnecessarily mixed +up with it. It is this: "It is impossible for a thing to be and not +to be at the same time." Not to mention the superfluousness of the +addition of the word impossible to indicate the apodeictic +certainty, which ought to be self-evident from the proposition itself, +the proposition is affected by the condition of time, and as it were +says: "A thing = A, which is something = B, cannot at the same time +be non-B." But both, B as well as non-B, may quite well exist in +succession. For example, a man who is young cannot at the same time +be old; but the same man can very well be at one time young, and at +another not young, that is, old. Now the principle of contradiction +as a merely logical proposition must not by any means limit its +application merely to relations of time, and consequently a formula +like the preceding is quite foreign to its true purpose. The +misunderstanding arises in this way. We first of all separate a +predicate of a thing from the conception of the thing, and +afterwards connect with this predicate its opposite, and hence do +not establish any contradiction with the subject, but only with its +predicate, which has been conjoined with the subject synthetically-- +a contradiction, moreover, which obtains only when the first and +second predicate are affirmed in the same time. If I say: "A man who +is ignorant is not learned," the condition "at the same time" must +be added, for he who is at one time ignorant, may at another be +learned. But if I say: "No ignorant man is a learned man," the +proposition is analytical, because the characteristic ignorance is +now a constituent part of the conception of the subject; and in this +case the negative proposition is evident immediately from the +proposition of contradiction, without the necessity of adding the +condition "the same time." This is the reason why I have altered the +formula of this principle--an alteration which shows very clearly +the nature of an analytical proposition. + + + +SECTION II. Of the Supreme Principle of all Synthetical Judgements. + +The explanation of the possibility of synthetical judgements is a task +with which general logic has nothing to do; indeed she needs not even +be acquainted with its name. But in transcendental logic it is the most +important matter to be dealt with--indeed the only one, if the question +is of the possibility of synthetical judgements a priori, the +conditions and extent of their validity. For when this question is +fully decided, it can reach its aim with perfect ease, the +determination, to wit, of the extent and limits of the pure +understanding. + +In an analytical judgement I do not go beyond the given conception, in +order to arrive at some decision respecting it. If the judgement is +affirmative, I predicate of the conception only that which was already +cogitated in it; if negative, I merely exclude from the conception its +contrary. But in synthetical judgements, I must go beyond the given +conception, in order to cogitate, in relation with it, something quite +different from that which was cogitated in it, a relation which is +consequently never one either of identity or contradiction, and by +means of which the truth or error of the judgement cannot be discerned +merely from the judgement itself. + +Granted, then, that we must go out beyond a given conception, in +order to compare it synthetically with another, a third thing is +necessary, in which alone the synthesis of two conceptions can +originate. Now what is this tertium quid that is to be the medium of +all synthetical judgements? It is only a complex in which all our +representations are contained, the internal sense to wit, and its form +a priori, time. + +The synthesis of our representations rests upon the imagination; +their synthetical unity (which is requisite to a judgement), upon +the unity of apperception. In this, therefore, is to be sought the +possibility of synthetical judgements, and as all three contain the +sources of a priori representations, the possibility of pure +synthetical judgements also; nay, they are necessary upon these +grounds, if we are to possess a knowledge of objects, which rests +solely upon the synthesis of representations. + +If a cognition is to have objective reality, that is, to relate to +an object, and possess sense and meaning in respect to it, it is +necessary that the object be given in some way or another. Without +this, our conceptions are empty, and we may indeed have thought by +means of them, but by such thinking we have not, in fact, cognized +anything, we have merely played with representation. To give an +object, if this expression be understood in the sense of "to +present" the object, not mediately but immediately in intuition, means +nothing else than to apply the representation of it to experience, +be that experience real or only possible. Space and time themselves, +pure as these conceptions are from all that is empirical, and +certain as it is that they are represented fully a priori in the mind, +would be completely without objective validity, and without sense +and significance, if their necessary use in the objects of +experience were not shown. Nay, the representation of them is a mere +schema, that always relates to the reproductive imagination, which +calls up the objects of experience, without which they have no +meaning. And so it is with all conceptions without distinction. + +The possibility of experience is, then, that which gives objective +reality to all our a priori cognitions. Now experience depends upon +the synthetical unity of phenomena, that is, upon a synthesis +according to conceptions of the object of phenomena in general, a +synthesis without which experience never could become knowledge, but +would be merely a rhapsody of perceptions, never fitting together into +any connected text, according to rules of a thoroughly united +(possible) consciousness, and therefore never subjected to the +transcendental and necessary unity of apperception. Experience has +therefore for a foundation, a priori principles of its form, that is +to say, general rules of unity in the synthesis of phenomena, the +objective reality of which rules, as necessary conditions even of +the possibility of experience can which rules, as necessary +conditions--even of the possibility of experience--can always be shown +in experience. But apart from this relation, a priori synthetical +propositions are absolutely impossible, because they have no third +term, that is, no pure object, in which the synthetical unity can +exhibit the objective reality of its conceptions. + +Although, then, respecting space, or the forms which productive +imagination describes therein, we do cognize much a priori in +synthetical judgements, and are really in no need of experience for +this purpose, such knowledge would nevertheless amount to nothing +but a busy trifling with a mere chimera, were not space to be +considered as the condition of the phenomena which constitute the +material of external experience. Hence those pure synthetical +judgements do relate, though but mediately, to possible experience, +or rather to the possibility of experience, and upon that alone is +founded the objective validity of their synthesis. + +While then, on the one hand, experience, as empirical synthesis, +is the only possible mode of cognition which gives reality to all +other synthesis; on the other hand, this latter synthesis, as +cognition a priori, possesses truth, that is, accordance with its +object, only in so far as it contains nothing more than what is +necessary to the synthetical unity of experience. + +Accordingly, the supreme principle of all synthetical judgements is: +"Every object is subject to the necessary conditions of the +synthetical unity of the manifold of intuition in a possible +experience." + +A priori synthetical judgements are possible when we apply the +formal conditions of the a priori intuition, the synthesis of the +imagination, and the necessary unity of that synthesis in a +transcendental apperception, to a possible cognition of experience, +and say: "The conditions of the possibility of experience in general +are at the same time conditions of the possibility of the objects of +experience, and have, for that reason, objective validity in an a +priori synthetical judgement." + + + +SECTION III. Systematic Representation of all Synthetical + Principles of the Pure Understanding. + +That principles exist at all is to be ascribed solely to the pure +understanding, which is not only the faculty of rules in regard to +that which happens, but is even the source of principles according +to which everything that can be presented to us as an object is +necessarily subject to rules, because without such rules we never +could attain to cognition of an object. Even the laws of nature, if +they are contemplated as principles of the empirical use of the +understanding, possess also a characteristic of necessity, and we +may therefore at least expect them to be determined upon grounds which +are valid a priori and antecedent to all experience. But all laws of +nature, without distinction, are subject to higher principles of the +understanding, inasmuch as the former are merely applications of the +latter to particular cases of experience. These higher principles +alone therefore give the conception, which contains the necessary +condition, and, as it were, the exponent of a rule; experience, on +the other hand, gives the case which comes under the rule. + +There is no danger of our mistaking merely empirical principles +for principles of the pure understanding, or conversely; for the +character of necessity, according to conceptions which distinguish +the latter, and the absence of this in every empirical proposition, +how extensively valid soever it may be, is a perfect safeguard against +confounding them. There are, however, pure principles a priori, +which nevertheless I should not ascribe to the pure understanding--for +this reason, that they are not derived from pure conceptions, but +(although by the mediation of the understanding) from pure intuitions. +But understanding is the faculty of conceptions. Such principles +mathematical science possesses, but their application to experience, +consequently their objective validity, nay the possibility of such +a priori synthetical cognitions (the deduction thereof) rests entirely +upon the pure understanding. + +On this account, I shall not reckon among my principles those of +mathematics; though I shall include those upon the possibility and +objective validity a priori, of principles of the mathematical +science, which, consequently, are to be looked upon as the principle +of these, and which proceed from conceptions to intuition, and not +from intuition to conceptions. + +In the application of the pure conceptions of the understanding to +possible experience, the employment of their synthesis is either +mathematical or dynamical, for it is directed partly on the +intuition alone, partly on the existence of a phenomenon. But the a +priori conditions of intuition are in relation to a possible +experience absolutely necessary, those of the existence of objects +of a possible empirical intuition are in themselves contingent. +Hence the principles of the mathematical use of the categories will +possess a character of absolute necessity, that is, will be +apodeictic; those, on the other hand, of the dynamical use, the +character of an a priori necessity indeed, but only under the +condition of empirical thought in an experience, therefore only +mediately and indirectly. Consequently they will not possess that +immediate evidence which is peculiar to the former, although their +application to experience does not, for that reason, lose its truth +and certitude. But of this point we shall be better able to judge at +the conclusion of this system of principles. + +The table of the categories is naturally our guide to the table of +principles, because these are nothing else than rules for the +objective employment of the former. Accordingly, all principles of +the pure understanding are: + + 1 + Axioms + of Intuition + + 2 3 + Anticipations Analogies + of Perception of Experience + 4 + Postulates of + Empirical Thought + in general + + +These appellations I have chosen advisedly, in order that we might +not lose sight of the distinctions in respect of the evidence and +the employment of these principles. It will, however, soon appear +that--a fact which concerns both the evidence of these principles, +and the a priori determination of phenomena--according to the categories +of quantity and quality (if we attend merely to the form of these), +the principles of these categories are distinguishable from those of +the two others, in as much as the former are possessed of an +intuitive, but the latter of a merely discursive, though in both +instances a complete, certitude. I shall therefore call the former +mathematical, and the latter dynamical principles.* It must be +observed, however, that by these terms I mean just as little in the +one case the principles of mathematics as those of general +(physical) dynamics in the other. I have here in view merely the +principles of the pure understanding, in their application to the +internal sense (without distinction of the representations given +therein), by means of which the sciences of mathematics and dynamics +become possible. Accordingly, I have named these principles rather +with reference to their application than their content; and I shall +now proceed to consider them in the order in which they stand in the +table. + + +[*Footnote: All combination (conjunctio) is either composition +(compositio) or connection (nexus). The former is the synthesis of a +manifold, the parts of which do not necessarily belong to each other. +For example, the two triangles into which a square is divided by a +diagonal, do not necessarily belong to each other, and of this kind is +the synthesis of the homogeneous in everything that can be +mathematically considered. This synthesis can be divided into those of +aggregation and coalition, the former of which is applied to extensive, +the latter to intensive quantities. The second sort of combination +(nexus) is the synthesis of a manifold, in so far as its parts do +belong necessarily to each other; for example, the accident to a +substance, or the effect to the cause. Consequently it is a synthesis +of that which though heterogeneous, is represented as connected a +priori. This combination--not an arbitrary one--I entitle dynamical +because it concerns the connection of the existence of the manifold. +This, again, may be divided into the physical synthesis, of the +phenomena divided among each other, and the metaphysical synthesis, or +the connection of phenomena a priori in the faculty of cognition.] + + +1. AXIOMS OF INTUITION. + + +The principle of these is: All Intuitions are Extensive Quantities. + + +PROOF. + + +All phenomena contain, as regards their form, an intuition in +space and time, which lies a priori at the foundation of all without +exception. Phenomena, therefore, cannot be apprehended, that is, +received into empirical consciousness otherwise than through the +synthesis of a manifold, through which the representations of a +determinate space or time are generated; that is to say, through the +composition of the homogeneous and the consciousness of the +synthetical unity of this manifold (homogeneous). Now the +consciousness of a homogeneous manifold in intuition, in so far as +thereby the representation of an object is rendered possible, is the +conception of a quantity (quanti). Consequently, even the perception +of an object as phenomenon is possible only through the same +synthetical unity of the manifold of the given sensuous intuition, +through which the unity of the composition of the homogeneous manifold +in the conception of a quantity is cogitated; that is to say, all +phenomena are quantities, and extensive quantities, because as +intuitions in space or time they must be represented by means of the +same synthesis through which space and time themselves are determined. + +An extensive quantity I call that wherein the representation of +the parts renders possible (and therefore necessarily antecedes) the +representation of the whole. I cannot represent to myself any line, +however small, without drawing it in thought, that is, without +generating from a point all its parts one after another, and in this +way alone producing this intuition. Precisely the same is the case +with every, even the smallest, portion of time. I cogitate therein +only the successive progress from one moment to another, and hence, +by means of the different portions of time and the addition of them, +a determinate quantity of time is produced. As the pure intuition in +all phenomena is either time or space, so is every phenomenon in its +character of intuition an extensive quantity, inasmuch as it can +only be cognized in our apprehension by successive synthesis (from +part to part). All phenomena are, accordingly, to be considered as +aggregates, that is, as a collection of previously given parts; +which is not the case with every sort of quantities, but only with +those which are represented and apprehended by us as extensive. + +On this successive synthesis of the productive imagination, in the +generation of figures, is founded the mathematics of extension, or +geometry, with its axioms, which express the conditions of sensuous +intuition a priori, under which alone the schema of a pure +conception of external intuition can exist; for example, "be tween +two points only one straight line is possible," "two straight lines +cannot enclose a space," etc. These are the axioms which properly relate +only to quantities (quanta) as such. + +But, as regards the quantity of a thing (quantitas), that is to say, +the answer to the question: "How large is this or that object?" +although, in respect to this question, we have various propositions +synthetical and immediately certain (indemonstrabilia); we have, in +the proper sense of the term, no axioms. For example, the +propositions: "If equals be added to equals, the wholes are equal"; +"If equals be taken from equals, the remainders are equal"; are +analytical, because I am immediately conscious of the identity of +the production of the one quantity with the production of the other; +whereas axioms must be a priori synthetical propositions. On the other +hand, the self-evident propositions as to the relation of numbers, +are certainly synthetical but not universal, like those of geometry, +and for this reason cannot be called axioms, but numerical formulae. +That 7 + 5 = 12 is not an analytical proposition. For neither in the +representation of seven, nor of five, nor of the composition of the +two numbers, do I cogitate the number twelve. (Whether I cogitate +the number in the addition of both, is not at present the question; +for in the case of an analytical proposition, the only point is +whether I really cogitate the predicate in the representation of the +subject.) But although the proposition is synthetical, it is +nevertheless only a singular proposition. In so far as regard is +here had merely to the synthesis of the homogeneous (the units), it +cannot take place except in one manner, although our use of these +numbers is afterwards general. If I say: "A triangle can be +constructed with three lines, any two of which taken together are +greater than the third," I exercise merely the pure function of the +productive imagination, which may draw the lines longer or shorter +and construct the angles at its pleasure. On the contrary, the number +seven is possible only in one manner, and so is likewise the number +twelve, which results from the synthesis of seven and five. Such +propositions, then, cannot be termed axioms (for in that case we +should have an infinity of these), but numerical formulae. + +This transcendental principle of the mathematics of phenomena +greatly enlarges our a priori cognition. For it is by this principle +alone that pure mathematics is rendered applicable in all its +precision to objects of experience, and without it the validity of +this application would not be so self-evident; on the contrary, +contradictions and confusions have often arisen on this very point. +Phenomena are not things in themselves. Empirical intuition is +possible only through pure intuition (of space and time); +consequently, what geometry affirms of the latter, is indisputably +valid of the former. All evasions, such as the statement that +objects of sense do not conform to the rules of construction in +space (for example, to the rule of the infinite divisibility of +lines or angles), must fall to the ground. For, if these objections +hold good, we deny to space, and with it to all mathematics, objective +validity, and no longer know wherefore, and how far, mathematics can +be applied to phenomena. The synthesis of spaces and times as the +essential form of all intuition, is that which renders possible the +apprehension of a phenomenon, and therefore every external experience, +consequently all cognition of the objects of experience; and +whatever mathematics in its pure use proves of the former, must +necessarily hold good of the latter. All objections are but the +chicaneries of an ill-instructed reason, which erroneously thinks to +liberate the objects of sense from the formal conditions of our +sensibility, and represents these, although mere phenomena, as +things in themselves, presented as such to our understanding. But in +this case, no a priori synthetical cognition of them could be +possible, consequently not through pure conceptions of space and the +science which determines these conceptions, that is to say, +geometry, would itself be impossible. + + + +2. ANTICIPATIONS OF PERCEPTION. + +The principle of these is: In all phenomena the Real, that +which is an object of sensation, has Intensive Quantity, +that is, has a Degree. + + +PROOF. + + +Perception is empirical consciousness, that is to say, a +consciousness which contains an element of sensation. Phenomena as +objects of perception are not pure, that is, merely formal intuitions, +like space and time, for they cannot be perceived in themselves. +[Footnote: They can be perceived only as phenomena, and some part of +them must always belong to the non-ego; whereas pure intuitions are +entirely the products of the mind itself, and as such are coguized +IN THEMSELVES.--Tr] They contain, then, over and above the intuition, +the materials for an object (through which is represented something +existing in space or time), that is to say, they contain the real of +sensation, as a representation merely subjective, which gives us merely +the consciousness that the subject is affected, and which we refer +to some external object. Now, a gradual transition from empirical +consciousness to pure consciousness is possible, inasmuch as the +real in this consciousness entirely vanishes, and there remains a +merely formal consciousness (a priori) of the manifold in time and +space; consequently there is possible a synthesis also of the +production of the quantity of a sensation from its commencement, +that is, from the pure intuition = 0 onwards up to a certain +quantity of the sensation. Now as sensation in itself is not an +objective representation, and in it is to be found neither the +intuition of space nor of time, it cannot possess any extensive +quantity, and yet there does belong to it a quantity (and that by +means of its apprehension, in which empirical consciousness can within +a certain time rise from nothing = 0 up to its given amount), +consequently an intensive quantity. And thus we must ascribe intensive +quantity, that is, a degree of influence on sense to all objects of +perception, in so far as this perception contains sensation. + +All cognition, by means of which I am enabled to cognize and +determine a priori what belongs to empirical cognition, may be +called an anticipation; and without doubt this is the sense in which +Epicurus employed his expression prholepsis. But as there is in +phenomena something which is never cognized a priori, which on this +account constitutes the proper difference between pure and empirical +cognition, that is to say, sensation (as the matter of perception), +it follows, that sensation is just that element in cognition which +cannot be at all anticipated. On the other hand, we might very well +term the pure determinations in space and time, as well in regard to +figure as to quantity, anticipations of phenomena, because they represent +a priori that which may always be given a posteriori in experience. +But suppose that in every sensation, as sensation in general, +without any particular sensation being thought of, there existed +something which could be cognized a priori, this would deserve to be +called anticipation in a special sense--special, because it may seem +surprising to forestall experience, in that which concerns the +matter of experience, and which we can only derive from itself. Yet +such really is the case here. + +Apprehension*, by means of sensation alone, fills only one moment, +that is, if I do not take into consideration a succession of many +sensations. As that in the phenomenon, the apprehension of which is +not a successive synthesis advancing from parts to an entire +representation, sensation has therefore no extensive quantity; the +want of sensation in a moment of time would represent it as empty, +consequently = 0. That which in the empirical intuition corresponds +to sensation is reality (realitas phaenomenon); that which corresponds +to the absence of it, negation = 0. Now every sensation is capable +of a diminution, so that it can decrease, and thus gradually disappear. +Therefore, between reality in a phenomenon and negation, there +exists a continuous concatenation of many possible intermediate +sensations, the difference of which from each other is always +smaller than that between the given sensation and zero, or complete +negation. That is to say, the real in a phenomenon has always a +quantity, which however is not discoverable in apprehension, +inasmuch as apprehension take place by means of mere sensation in +one instant, and not by the successive synthesis of many sensations, +and therefore does not progress from parts to the whole. Consequently, +it has a quantity, but not an extensive quantity. + +[*Footnote: Apprehension is the Kantian word for preception, in the +largest sense in which we employ that term. It is the genus which +includes under i, as species, perception proper and sensation proper--Tr] + +Now that quantity which is apprehended only as unity, and in which +plurality can be represented only by approximation to negation = O, +I term intensive quantity. Consequently, reality in a phenomenon has +intensive quantity, that is, a degree. If we consider this reality +as cause (be it of sensation or of another reality in the +phenomenon, for example, a change), we call the degree of reality in +its character of cause a momentum, for example, the momentum of +weight; and for this reason, that the degree only indicates that +quantity the apprehension of which is not successive, but +instantaneous. This, however, I touch upon only in passing, for with +causality I have at present nothing to do. + +Accordingly, every sensation, consequently every reality in +phenomena, however small it may be, has a degree, that is, an +intensive quantity, which may always be lessened, and between +reality and negation there exists a continuous connection of +possible realities, and possible smaller perceptions. Every colour-- +for example, red--has a degree, which, be it ever so small, is never +the smallest, and so is it always with heat, the momentum of weight, +etc. + +This property of quantities, according to which no part of them is +the smallest possible (no part simple), is called their continuity. +Space and time are quanta continua, because no part of them can be +given, without enclosing it within boundaries (points and moments), +consequently, this given part is itself a space or a time. Space, +therefore, consists only of spaces, and time of times. Points and +moments are only boundaries, that is, the mere places or positions +of their limitation. But places always presuppose intuitions which +are to limit or determine them; and we cannot conceive either space +or time composed of constituent parts which are given before space +or time. Such quantities may also be called flowing, because synthesis +(of the productive imagination) in the production of these +quantities is a progression in time, the continuity of which we are +accustomed to indicate by the expression flowing. + +All phenomena, then, are continuous quantities, in respect both to +intuition and mere perception (sensation, and with it reality). In +the former case they are extensive quantities; in the latter, intensive. +When the synthesis of the manifold of a phenomenon is interrupted, +there results merely an aggregate of several phenomena, and not +properly a phenomenon as a quantity, which is not produced by the mere +continuation of the productive synthesis of a certain kind, but by +the repetition of a synthesis always ceasing. For example, if I call +thirteen dollars a sum or quantity of money, I employ the term quite +correctly, inasmuch as I understand by thirteen dollars the value of +a mark in standard silver, which is, to be sure, a continuous +quantity, in which no part is the smallest, but every part might +constitute a piece of money, which would contain material for still +smaller pieces. If, however, by the words thirteen dollars I +understand so many coins (be their value in silver what it may), it +would be quite erroneous to use the expression a quantity of +dollars; on the contrary, I must call them aggregate, that is, a +number of coins. And as in every number we must have unity as the +foundation, so a phenomenon taken as unity is a quantity, and as +such always a continuous quantity (quantum continuum). + +Now, seeing all phenomena, whether considered as extensive or +intensive, are continuous quantities, the proposition: "All change +(transition of a thing from one state into another) is continuous," +might be proved here easily, and with mathematical evidence, were it +not that the causality of a change lies, entirely beyond the bounds +of a transcendental philosophy, and presupposes empirical principles. +For of the possibility of a cause which changes the condition of things, +that is, which determines them to the contrary to a certain given +state, the understanding gives us a priori no knowledge; not merely +because it has no insight into the possibility of it (for such insight +is absent in several a priori cognitions), but because the notion of +change concerns only certain determinations of phenomena, which +experience alone can acquaint us with, while their cause lies in the +unchangeable. But seeing that we have nothing which we could here +employ but the pure fundamental conceptions of all possible +experience, among which of course nothing empirical can be admitted, +we dare not, without injuring the unity of our system, anticipate +general physical science, which is built upon certain fundamental +experiences. + +Nevertheless, we are in no want of proofs of the great influence +which the principle above developed exercises in the anticipation of +perceptions, and even in supplying the want of them, so far as to +shield us against the false conclusions which otherwise we might +rashly draw. + +If all reality in perception has a degree, between which and +negation there is an endless sequence of ever smaller degrees, and +if, nevertheless, every sense must have a determinate degree of +receptivity for sensations; no perception, and consequently no +experience is possible, which can prove, either immediately or +mediately, an entire absence of all reality in a phenomenon; in +other words, it is impossible ever to draw from experience a proof +of the existence of empty space or of empty time. For in the first +place, an entire absence of reality in a sensuous intuition cannot +of course be an object of perception; secondly, such absence cannot +be deduced from the contemplation of any single phenomenon, and the +difference of the degrees in its reality; nor ought it ever to be +admitted in explanation of any phenomenon. For if even the complete +intuition of a determinate space or time is thoroughly real, that +is, if no part thereof is empty, yet because every reality has its +degree, which, with the extensive quantity of the phenomenon +unchanged, can diminish through endless gradations down to nothing +(the void), there must be infinitely graduated degrees, with which +space or time is filled, and the intensive quantity in different +phenomena may be smaller or greater, although the extensive quantity +of the intuition remains equal and unaltered. + +We shall give an example of this. Almost all natural philosophers, +remarking a great difference in the quantity of the matter of +different kinds in bodies with the same volume (partly on account of +the momentum of gravity or weight, partly on account of the momentum +of resistance to other bodies in motion), conclude unanimously that +this volume (extensive quantity of the phenomenon) must be void in +all bodies, although in different proportion. But who would suspect +that these for the most part mathematical and mechanical inquirers +into nature should ground this conclusion solely on a metaphysical +hypothesis--a sort of hypothesis which they profess to disparage and +avoid? Yet this they do, in assuming that the real in space (I must +not here call it impenetrability or weight, because these are +empirical conceptions) is always identical, and can only be +distinguished according to its extensive quantity, that is, +multiplicity. Now to this presupposition, for which they can have no +ground in experience, and which consequently is merely metaphysical, +I oppose a transcendental demonstration, which it is true will not +explain the difference in the filling up of spaces, but which +nevertheless completely does away with the supposed necessity of the +above-mentioned presupposition that we cannot explain the said +difference otherwise than by the hypothesis of empty spaces. This +demonstration, moreover, has the merit of setting the understanding +at liberty to conceive this distinction in a different manner, if the +explanation of the fact requires any such hypothesis. For we +perceive that although two equal spaces may be completely filled by +matters altogether different, so that in neither of them is there left +a single point wherein matter is not present, nevertheless, every +reality has its degree (of resistance or of weight), which, without +diminution of the extensive quantity, can become less and less ad +infinitum, before it passes into nothingness and disappears. Thus an +expansion which fills a space--for example, caloric, or any other +reality in the phenomenal world--can decrease in its degrees to +infinity, yet without leaving the smallest part of the space empty; +on the contrary, filling it with those lesser degrees as completely +as another phenomenon could with greater. My intention here is by no +means to maintain that this is really the case with the difference +of matters, in regard to their specific gravity; I wish only to prove, +from a principle of the pure understanding, that the nature of our +perceptions makes such a mode of explanation possible, and that it +is erroneous to regard the real in a phenomenon as equal quoad its +degree, and different only quoad its aggregation and extensive +quantity, and this, too, on the pretended authority of an a priori +principle of the understanding. + +Nevertheless, this principle of the anticipation of perception +must somewhat startle an inquirer whom initiation into +transcendental philosophy has rendered cautious. We must naturally +entertain some doubt whether or not the understanding can enounce +any such synthetical proposition as that respecting the degree of +all reality in phenomena, and consequently the possibility of the +internal difference of sensation itself--abstraction being made of +its empirical quality. Thus it is a question not unworthy of solution: +"How the understanding can pronounce synthetically and a priori +respecting phenomena, and thus anticipate these, even in that which +is peculiarly and merely empirical, that, namely, which concerns +sensation itself?" + +The quality of sensation is in all cases merely empirical, and +cannot be represented a priori (for example, colours, taste, etc.). +But the real--that which corresponds to sensation--in opposition to +negation = 0, only represents something the conception of which in +itself contains a being (ein seyn), and signifies nothing but the +synthesis in an empirical consciousness. That is to say, the empirical +consciousness in the internal sense can be raised from 0 to every +higher degree, so that the very same extensive quantity of +intuition, an illuminated surface, for example, excites as great a +sensation as an aggregate of many other surfaces less illuminated. +We can therefore make complete abstraction of the extensive quantity +of a phenomenon, and represent to ourselves in the mere sensation in +a certain momentum, a synthesis of homogeneous ascension from 0 up +to the given empirical consciousness, All sensations therefore as such +are given only a posteriori, but this property thereof, namely, that +they have a degree, can be known a priori. It is worthy of remark, +that in respect to quantities in general, we can cognize a priori only +a single quality, namely, continuity; but in respect to all quality +(the real in phenomena), we cannot cognize a priori anything more than +the intensive quantity thereof, namely, that they have a degree. All +else is left to experience. + + + +3. ANALOGIES OF EXPERIENCE. + +The principle of these is: Experience is possible only +through the representation of a necessary connection of Perceptions. + + +PROOF. + + +Experience is an empirical cognition; that is to say, a cognition +which determines an object by means of perceptions. It is therefore +a synthesis of perceptions, a synthesis which is not itself +contained in perception, but which contains the synthetical unity of +the manifold of perception in a consciousness; and this unity +constitutes the essential of our cognition of objects of the senses, +that is, of experience (not merely of intuition or sensation). Now +in experience our perceptions come together contingently, so that no +character of necessity in their connection appears, or can appear from +the perceptions themselves, because apprehension is only a placing +together of the manifold of empirical intuition, and no representation +of a necessity in the connected existence of the phenomena which +apprehension brings together, is to be discovered therein. But as +experience is a cognition of objects by means of perceptions, it +follows that the relation of the existence of the existence of the +manifold must be represented in experience not as it is put together +in time, but as it is objectively in time. And as time itself cannot +be perceived, the determination of the existence of objects in time +can only take place by means of their connection in time in general, +consequently only by means of a priori connecting conceptions. Now +as these conceptions always possess the character of necessity, +experience is possible only by means of a representation of the +necessary connection of perception. + +The three modi of time are permanence, succession, and +coexistence. Accordingly, there are three rules of all relations of +time in phenomena, according to which the existence of every +phenomenon is determined in respect of the unity of all time, and +these antecede all experience and render it possible. + +The general principle of all three analogies rests on the +necessary unity of apperception in relation to all possible +empirical consciousness (perception) at every time, consequently, as +this unity lies a priori at the foundation of all mental operations, +the principle rests on the synthetical unity of all phenomena +according to their relation in time. For the original apperception +relates to our internal sense (the complex of all representations), +and indeed relates a priori to its form, that is to say, the +relation of the manifold empirical consciousness in time. Now this +manifold must be combined in original apperception according to +relations of time--a necessity imposed by the a priori +transcendental unity of apperception, to which is subjected all that +can belong to my (i.e., my own) cognition, and therefore all that +can become an object for me. This synthetical and a priori +determined unity in relation of perceptions in time is therefore the +rule: "All empirical determinations of time must be subject to rules +of the general determination of time"; and the analogies of +experience, of which we are now about to treat, must be rules of +this nature. + +These principles have this peculiarity, that they do not concern +phenomena, and the synthesis of the empirical intuition thereof, but +merely the existence of phenomena and their relation to each other +in regard to this existence. Now the mode in which we apprehend a +thing in a phenomenon can be determined a priori in such a manner that +the rule of its synthesis can give, that is to say, can produce this +a priori intuition in every empirical example. But the existence of +phenomena cannot be known a priori, and although we could arrive by +this path at a conclusion of the fact of some existence, we could +not cognize that existence determinately, that is to say, we should +be incapable of anticipating in what respect the empirical intuition +of it would be distinguishable from that of others. + +The two principles above mentioned, which I called mathematical, +in consideration of the fact of their authorizing the application of +mathematic phenomena, relate to these phenomena only in regard to +their possibility, and instruct us how phenomena, as far as regards +their intuition or the real in their perception, can be generated +according to the rules of a mathematical synthesis. Consequently, +numerical quantities, and with them the determination of a +phenomenon as a quantity, can be employed in the one case as well as +in the other. Thus, for example, out of 200,000 illuminations by the +moon, I might compose and give a priori, that is construct, the degree +of our sensations of the sun-light.* We may therefore entitle these +two principles constitutive. + +[*Footnote: Kant's meaning is: The two principles enunciated under +the heads of "Axioms of Intuition," and "Anticipations of Perception," +authorize the application to phenomena of determinations of size and +number, that is of mathematic. For exampkle, I may compute the light +of the sun, and say that its quantity is a certain number of times +greater than that of the moon. In the same way, heat is measured by +the comparison of its different effects on water, &c., and on mercury +in a thermometer.--Tr] + +The case is very different with those principles whose province it +is to subject the existence of phenomena to rules a priori. For as +existence does not admit of being constructed, it is clear that they +must only concern the relations of existence and be merely +regulative principles. In this case, therefore, neither axioms nor +anticipations are to be thought of. Thus, if a perception is given +us, in a certain relation of time to other (although undetermined) +perceptions, we cannot then say a priori, what and how great (in +quantity) the other perception necessarily connected with the former +is, but only how it is connected, quoad its existence, in this given +modus of time. Analogies in philosophy mean something very different +from that which they represent in mathematics. In the latter they +are formulae, which enounce the equality of two relations of quantity, +and are always constitutive, so that if two terms of the proportion +are given, the third is also given, that is, can be constructed by +the aid of these formulae. But in philosophy, analogy is not the +equality of two quantitative but of two qualitative relations. In this +case, from three given terms, I can give a priori and cognize the +relation to a fourth member, but not this fourth term itself, although +I certainly possess a rule to guide me in the search for this fourth +term in experience, and a mark to assist me in discovering it. An +analogy of experience is therefore only a rule according to which +unity of experience must arise out of perceptions in respect to +objects (phenomena) not as a constitutive, but merely as a +regulative principle. The same holds good also of the postulates of +empirical thought in general, which relate to the synthesis of mere +intuition (which concerns the form of phenomena), the synthesis of +perception (which concerns the matter of phenomena), and the synthesis +of experience (which concerns the relation of these perceptions). +For they are only regulative principles, and clearly distinguishable +from the mathematical, which are constitutive, not indeed in regard +to the certainty which both possess a priori, but in the mode of evidence +thereof, consequently also in the manner of demonstration. + +But what has been observed of all synthetical propositions, and must +be particularly remarked in this place, is this, that these +analogies possess significance and validity, not as principles of +the transcendental, but only as principles of the empirical use of +the understanding, and their truth can therefore be proved only as +such, and that consequently the phenomena must not be subjoined directly +under the categories, but only under their schemata. For if the +objects to which those principles must be applied were things in +themselves, it would be quite impossible to cognize aught concerning +them synthetically a priori. But they are nothing but phenomena; a +complete knowledge of which--a knowledge to which all principles a +priori must at last relate--is the only possible experience. It +follows that these principles can have nothing else for their aim than +the conditions of the empirical cognition in the unity of synthesis +of phenomena. But this synthesis is cogitated only in the schema of +the pure conception of the understanding, of whose unity, as that of +a synthesis in general, the category contains the function +unrestricted by any sensuous condition. These principles will +therefore authorize us to connect phenomena according to an analogy, +with the logical and universal unity of conceptions, and +consequently to employ the categories in the principles themselves; +but in the application of them to experience, we shall use only +their schemata, as the key to their proper application, instead of +the categories, or rather the latter as restricting conditions, under +the title of "formulae" of the former. + + + +A. FIRST ANALOGY. + +Principle of the Permanence of Substance. + +In all changes of phenomena, substance is permanent, and the +quantum thereof in nature is neither increased nor diminished. + + +PROOF. + + +All phenomena exist in time, wherein alone as substratum, that is, +as the permanent form of the internal intuition, coexistence and +succession can be represented. Consequently time, in which all changes +of phenomena must be cogitated, remains and changes not, because it +is that in which succession and coexistence can be represented only +as determinations thereof. Now, time in itself cannot be an object +of perception. It follows that in objects of perception, that is, in +phenomena, there must be found a substratum which represents time in +general, and in which all change or coexistence can be perceived by +means of the relation of phenomena to it. But the substratum of all +reality, that is, of all that pertains to the existence of things, +is substance; all that pertains to existence can be cogitated only +as a determination of substance. Consequently, the permanent, in +relation to which alone can all relations of time in phenomena be +determined, is substance in the world of phenomena, that is, the +real in phenomena, that which, as the substratum of all change, +remains ever the same. Accordingly, as this cannot change in +existence, its quantity in nature can neither be increased nor +diminished. + +Our apprehension of the manifold in a phenomenon is always +successive, is Consequently always changing. By it alone we could, +therefore, never determine whether this manifold, as an object of +experience, is coexistent or successive, unless it had for a +foundation something fixed and permanent, of the existence of which +all succession and coexistence are nothing but so many modes (modi +of time). Only in the permanent, then, are relations of time +possible (for simultaneity and succession are the only relations in +time); that is to say, the permanent is the substratum of our +empirical representation of time itself, in which alone all +determination of time is possible. Permanence is, in fact, just +another expression for time, as the abiding correlate of all existence +of phenomena, and of all change, and of all coexistence. For change +does not affect time itself, but only the phenomena in time (just as +coexistence cannot be regarded as a modus of time itself, seeing +that in time no parts are coexistent, but all successive). If we +were to attribute succession to time itself, we should be obliged to +cogitate another time, in which this succession would be possible. +It is only by means of the permanent that existence in different parts +of the successive series of time receives a quantity, which we entitle +duration. For in mere succession, existence is perpetually vanishing +and recommencing, and therefore never has even the least quantity. +Without the permanent, then, no relation in time is possible. Now, +time in itself is not an object of perception; consequently the +permanent in phenomena must be regarded as the substratum of all +determination of time, and consequently also as the condition of the +possibility of all synthetical unity of perceptions, that is, of +experience; and all existence and all change in time can only be +regarded as a mode in the existence of that which abides unchangeably. +Therefore, in all phenomena, the permanent is the object in itself, +that is, the substance (phenomenon); but all that changes or can +change belongs only to the mode of the existence of this substance +or substances, consequently to its determinations. + +I find that in all ages not only the philosopher, but even the +common understanding, has preposited this permanence as a substratum +of all change in phenomena; indeed, I am compelled to believe that +they will always accept this as an indubitable fact. Only the +philosopher expresses himself in a more precise and definite manner, +when he says: "In all changes in the world, the substance remains, +and the accidents alone are changeable." But of this decidedly synthetical +proposition, I nowhere meet with even an attempt at proof; nay, it +very rarely has the good fortune to stand, as it deserves to do, at +the head of the pure and entirely a priori laws of nature. In truth, +the statement that substance is permanent, is tautological. For this +very permanence is the ground on which we apply the category of +substance to the phenomenon; and we should have been obliged to +prove that in all phenomena there is something permanent, of the +existence of which the changeable is nothing but a determination. +But because a proof of this nature cannot be dogmatical, that is, +cannot be drawn from conceptions, inasmuch as it concerns a +synthetical proposition a priori, and as philosophers never +reflected that such propositions are valid only in relation to +possible experience, and therefore cannot be proved except by means +of a deduction of the possibility of experience, it is no wonder that +while it has served as the foundation of all experience (for we feel +the need of it in empirical cognition), it has never been supported +by proof. + +A philosopher was asked: "What is the weight of smoke?" He answered: +"Subtract from the weight of the burnt wood the weight of the +remaining ashes, and you will have the weight of the smoke." Thus he +presumed it to be incontrovertible that even in fire the matter +(substance) does not perish, but that only the form of it undergoes +a change. In like manner was the saying: "From nothing comes nothing," +only another inference from the principle or permanence, or rather +of the ever-abiding existence of the true subject in phenomena. For +if that in the phenomenon which we call substance is to be the proper +substratum of all determination of time, it follows that all existence +in past as well as in future time, must be determinable by means of +it alone. Hence we are entitled to apply the term substance to a +phenomenon, only because we suppose its existence in all time, a +notion which the word permanence does not fully express, as it seems +rather to be referable to future time. However, the internal necessity +perpetually to be, is inseparably connected with the necessity +always to have been, and so the expression may stand as it is. +"Gigni de nihilo nihil; in nihilum nil posse reverti,"* are two +propositions which the ancients never parted, and which people +nowadays sometimes mistakenly disjoin, because they imagine that the +propositions apply to objects as things in themselves, and that the +former might be inimical to the dependence (even in respect of its +substance also) of the world upon a supreme cause. But this +apprehension is entirely needless, for the question in this case is +only of phenomena in the sphere of experience, the unity of which +never could be possible, if we admitted the possibility that new +things (in respect of their substance) should arise. For in that case, +we should lose altogether that which alone can represent the unity +of time, to wit, the identity of the substratum, as that through which +alone all change possesses complete and thorough unity. This +permanence is, however, nothing but the manner in which we represent +to ourselves the existence of things in the phenomenal world. + +[*Footnote: Persius, Satirae, iii.83-84.] + +The determinations of a substance, which are only particular modes +of its existence, are called accidents. They are always real, +because they concern the existence of substance (negations are only +determinations, which express the non-existence of something in the +substance). Now, if to this real in the substance we ascribe a +particular existence (for example, to motion as an accident of +matter), this existence is called inherence, in contradistinction to +the existence of substance, which we call subsistence. But hence arise +many misconceptions, and it would be a more accurate and just mode +of expression to designate the accident only as the mode in which +the existence of a substance is positively determined. Meanwhile, by +reason of the conditions of the logical exercise of our understanding, +it is impossible to avoid separating, as it were, that which in the +existence of a substance is subject to change, whilst the substance +remains, and regarding it in relation to that which is properly +permanent and radical. On this account, this category of substance +stands under the title of relation, rather because it is the condition +thereof than because it contains in itself any relation. + +Now, upon this notion of permanence rests the proper notion of the +conception change. Origin and extinction are not changes of that which +originates or becomes extinct. Change is but a mode of existence, +which follows on another mode of existence of the same object; hence +all that changes is permanent, and only the condition thereof changes. +Now since this mutation affects only determinations, which can have +a beginning or an end, we may say, employing an expression which seems +somewhat paradoxical: "Only the permanent (substance) is subject to +change; the mutable suffers no change, but rather alternation, that +is, when certain determinations cease, others begin." + +Change, when, cannot be perceived by us except in substances, and +origin or extinction in an absolute sense, that does not concern +merely a determination of the permanent, cannot be a possible +perception, for it is this very notion of the permanent which +renders possible the representation of a transition from one state +into another, and from non-being to being, which, consequently, can +be empirically cognized only as alternating determinations of that +which is permanent. Grant that a thing absolutely begins to be; we +must then have a point of time in which it was not. But how and by +what can we fix and determine this point of time, unless by that which +already exists? For a void time--preceding--is not an object of +perception; but if we connect this beginning with objects which +existed previously, and which continue to exist till the object in +question in question begins to be, then the latter can only be a +determination of the former as the permanent. The same holds good of +the notion of extinction, for this presupposes the empirical +representation of a time, in which a phenomenon no longer exists. + +Substances (in the world of phenomena) are the substratum of all +determinations of time. The beginning of some, and the ceasing to be +of other substances, would utterly do away with the only condition +of the empirical unity of time; and in that case phenomena would +relate to two different times, in which, side by side, existence would +pass; which is absurd. For there is only one time in which all +different times must be placed, not as coexistent, but as successive. + +Accordingly, permanence is a necessary condition under which alone +phenomena, as things or objects, are determinable in a possible +experience. But as regards the empirical criterion of this necessary +permanence, and with it of the substantiality of phenomena, we shall +find sufficient opportunity to speak in the sequel. + + + +B. SECOND ANALOGY. + +Principle of the Succession of Time According to the Law of Causality. +All changes take place according to the law of the connection of Cause +and Effect. + + +PROOF. + + +(That all phenomena in the succession of time are only changes, that +is, a successive being and non-being of the determinations of +substance, which is permanent; consequently that a being of +substance itself which follows on the non-being thereof, or a +non-being of substance which follows on the being thereof, in other +words, that the origin or extinction of substance itself, is +impossible--all this has been fully established in treating of the +foregoing principle. This principle might have been expressed as +follows: "All alteration (succession) of phenomena is merely +change"; for the changes of substance are not origin or extinction, +because the conception of change presupposes the same subject as +existing with two opposite determinations, and consequently as +permanent. After this premonition, we shall proceed to the proof.) + +I perceive that phenomena succeed one another, that is to say, a +state of things exists at one time, the opposite of which existed in +a former state. In this case, then, I really connect together two +perceptions in time. Now connection is not an operation of mere +sense and intuition, but is the product of a synthetical faculty of +imagination, which determines the internal sense in respect of a +relation of time. But imagination can connect these two states in +two ways, so that either the one or the other may antecede in time; +for time in itself cannot be an object of perception, and what in an +object precedes and what follows cannot be empirically determined in +relation to it. I am only conscious, then, that my imagination +places one state before and the other after; not that the one state +antecedes the other in the object. In other words, the objective +relation of the successive phenomena remains quite undetermined by +means of mere perception. Now in order that this relation may be +cognized as determined, the relation between the two states must be +so cogitated that it is thereby determined as necessary, which of them +must be placed before and which after, and not conversely. But the +conception which carries with it a necessity of synthetical unity, +can be none other than a pure conception of the understanding which +does not lie in mere perception; and in this case it is the conception +of "the relation of cause and effect," the former of which determines +the latter in time, as its necessary consequence, and not as something +which might possibly antecede (or which might in some cases not be +perceived to follow). It follows that it is only because we subject +the sequence of phenomena, and consequently all change, to the law +of causality, that experience itself, that is, empirical cognition +of phenomena, becomes possible; and consequently, that phenomena +themselves, as objects of experience, are possible only by virtue of +this law. + +Our apprehension of the manifold of phenomena is always +successive. The representations of parts succeed one another. +Whether they succeed one another in the object also, is a second point +for reflection, which was not contained in the former. Now we may +certainly give the name of object to everything, even to every +representation, so far as we are conscious thereof; but what this word +may mean in the case of phenomena, not merely in so far as they (as +representations) are objects, but only in so far as they indicate an +object, is a question requiring deeper consideration. In so far as +they, regarded merely as representations, are at the same time objects +of consciousness, they are not to be distinguished from +apprehension, that is, reception into the synthesis of imagination, +and we must therefore say: "The manifold of phenomena is always +produced successively in the mind." If phenomena were things in +themselves, no man would be able to conjecture from the succession +of our representations how this manifold is connected in the object; +for we have to do only with our representations. How things may be +in themselves, without regard to the representations through which +they affect us, is utterly beyond the sphere of our cognition. Now +although phenomena are not things in themselves, and are +nevertheless the only thing given to us to be cognized, it is my +duty to show what sort of connection in time belongs to the manifold +in phenomena themselves, while the representation of this manifold +in apprehension is always successive. For example, the apprehension +of the manifold in the phenomenon of a house which stands before me, +is successive. Now comes the question whether the manifold of this +house is in itself successive--which no one will be at all willing +to grant. But, so soon as I raise my conception of an object to the +transcendental signification thereof, I find that the house is not +a thing in itself, but only a phenomenon, that is, a representation, +the transcendental object of which remains utterly unknown. What then +am I to understand by the question: "How can the manifold be connected +in the phenomenon itself--not considered as a thing in itself, but +merely as a phenomenon?" Here that which lies in my successive apprehension +is regarded as representation, whilst the phenomenon which is given +me, notwithstanding that it is nothing more than a complex of these +representations, is regarded as the object thereof, with which my +conception, drawn from the representations of apprehension, must +harmonize. It is very soon seen that, as accordance of the cognition +with its object constitutes truth, the question now before us can only +relate to the formal conditions of empirical truth; and that the +phenomenon, in opposition to the representations of apprehension, +can only be distinguished therefrom as the object of them, if it is +subject to a rule which distinguishes it from every other +apprehension, and which renders necessary a mode of connection of +the manifold. That in the phenomenon which contains the condition of +this necessary rule of apprehension, is the object. + +Let us now proceed to our task. That something happens, that is to +say, that something or some state exists which before was not, +cannot be empirically perceived, unless a phenomenon precedes, which +does not contain in itself this state. For a reality which should +follow upon a void time, in other words, a beginning, which no state +of things precedes, can just as little be apprehended as the void time +itself. Every apprehension of an event is therefore a perception which +follows upon another perception. But as this is the case with all +synthesis of apprehension, as I have shown above in the example of +a house, my apprehension of an event is not yet sufficiently +distinguished from other apprehensions. But I remark also that if in +a phenomenon which contains an occurrence, I call the antecedent state +of my perception, A, and the following state, B, the perception B +can only follow A in apprehension, and the perception A cannot +follow B, but only precede it. For example, I see a ship float down +the stream of a river. My perception of its place lower down follows +upon my perception of its place higher up the course of the river, +and it is impossible that, in the apprehension of this phenomenon, +the vessel should be perceived first below and afterwards higher up +the stream. Here, therefore, the order in the sequence of perceptions +in apprehension is determined; and by this order apprehension is +regulated. In the former example, my perceptions in the apprehension +of a house might begin at the roof and end at the foundation, or +vice versa; or I might apprehend the manifold in this empirical +intuition, by going from left to right, and from right to left. +Accordingly, in the series of these perceptions, there was no +determined order, which necessitated my beginning at a certain +point, in order empirically to connect the manifold. But this rule +is always to be met with in the perception of that which happens, +and it makes the order of the successive perceptions in the +apprehension of such a phenomenon necessary. + +I must, therefore, in the present case, deduce the subjective +sequence of apprehension from the objective sequence of phenomena, +for otherwise the former is quite undetermined, and one phenomenon +is not distinguishable from another. The former alone proves nothing +as to the connection of the manifold in an object, for it is quite +arbitrary. The latter must consist in the order of the manifold in +a phenomenon, according to which order the apprehension of one thing +(that which happens) follows that of another thing (which precedes), +in conformity with a rule. In this way alone can I be authorized to +say of the phenomenon itself, and not merely of my own apprehension, +that a certain order or sequence is to be found therein. That is, in +other words, I cannot arrange my apprehension otherwise than in this +order. + +In conformity with this rule, then, it is necessary that in that +which antecedes an event there be found the condition of a rule, +according to which in this event follows always and necessarily; but +I cannot reverse this and go back from the event, and determine (by +apprehension) that which antecedes it. For no phenomenon goes back +from the succeeding point of time to the preceding point, although +it does certainly relate to a preceding point of time; from a given +time, on the other hand, there is always a necessary progression to +the determined succeeding time. Therefore, because there certainly +is something that follows, I must of necessity connect it with +something else, which antecedes, and upon which it follows, in +conformity with a rule, that is necessarily, so that the event, as +conditioned, affords certain indication of a condition, and this +condition determines the event. + +Let us suppose that nothing precedes an event, upon which this event +must follow in conformity with a rule. All sequence of perception +would then exist only in apprehension, that is to say, would be merely +subjective, and it could not thereby be objectively determined what +thing ought to precede, and what ought to follow in perception. In +such a case, we should have nothing but a play of representations, +which would possess no application to any object. That is to say, it +would not be possible through perception to distinguish one phenomenon +from another, as regards relations of time; because the succession +in the act of apprehension would always be of the same sort, and +therefore there would be nothing in the phenomenon to determine the +succession, and to render a certain sequence objectively necessary. +And, in this case, I cannot say that two states in a phenomenon follow +one upon the other, but only that one apprehension follows upon +another. But this is merely subjective, and does not determine an +object, and consequently cannot be held to be cognition of an +object--not even in the phenomenal world. + +Accordingly, when we know in experience that something happens, we +always presuppose that something precedes, whereupon it follows in +conformity with a rule. For otherwise I could not say of the object +that it follows; because the mere succession in my apprehension, if +it be not determined by a rule in relation to something preceding, +does not authorize succession in the object. Only, therefore, in +reference to a rule, according to which phenomena are determined in +their sequence, that is, as they happen, by the preceding state, can +I make my subjective synthesis (of apprehension) objective, and it +is only under this presupposition that even the experience of an event +is possible. + +No doubt it appears as if this were in thorough contradiction to all +the notions which people have hitherto entertained in regard to the +procedure of the human understanding. According to these opinions, +it is by means of the perception and comparison of similar +consequences following upon certain antecedent phenomena that the +understanding is led to the discovery of a rule, according to which +certain events always follow certain phenomena, and it is only by this +process that we attain to the conception of cause. Upon such a +basis, it is clear that this conception must be merely empirical, +and the rule which it furnishes us with--"Everything that happens must +have a cause"--would be just as contingent as experience itself. The +universality and necessity of the rule or law would be perfectly +spurious attributes of it. Indeed, it could not possess universal +validity, inasmuch as it would not in this case be a priori, but +founded on deduction. But the same is the case with this law as with +other pure a priori representations (e.g., space and time), which we +can draw in perfect clearness and completeness from experience, only +because we had already placed them therein, and by that means, and +by that alone, had rendered experience possible. Indeed, the logical +clearness of this representation of a rule, determining the series +of events, is possible only when we have made use thereof in +experience. Nevertheless, the recognition of this rule, as a condition +of the synthetical unity of phenomena in time, was the ground of +experience itself and consequently preceded it a priori. + +It is now our duty to show by an example that we never, even in +experience, attribute to an object the notion of succession or +effect (of an event--that is, the happening of something that did +not exist before), and distinguish it from the subjective succession +of apprehension, unless when a rule lies at the foundation, which +compels us to observe this order of perception in preference to any +other, and that, indeed, it is this necessity which first renders +possible the representation of a succession in the object. + +We have representations within us, of which also we can be +conscious. But, however widely extended, however accurate and +thoroughgoing this consciousness may be, these representations are +still nothing more than representations, that is, internal +determinations of the mind in this or that relation of time. Now how +happens it that to these representations we should set an object, or +that, in addition to their subjective reality, as modifications, we +should still further attribute to them a certain unknown objective +reality? It is clear that objective significancy cannot consist in +a relation to another representation (of that which we desire to term +object), for in that case the question again arises: "How does this +other representation go out of itself, and obtain objective +significancy over and above the subjective, which is proper to it, +as a determination of a state of mind?" If we try to discover what +sort of new property the relation to an object gives to our subjective +representations, and what new importance they thereby receive, we +shall find that this relation has no other effect than that of +rendering necessary the connection of our representations in a certain +manner, and of subjecting them to a rule; and that conversely, it is +only because a certain order is necessary in the relations of time +of our representations, that objective significancy is ascribed to +them. + +In the synthesis of phenomena, the manifold of our representations +is always successive. Now hereby is not represented an object, for +by means of this succession, which is common to all apprehension, no +one thing is distinguished from another. But so soon as I perceive +or assume that in this succession there is a relation to a state +antecedent, from which the representation follows in accordance with +a rule, so soon do I represent something as an event, or as a thing +that happens; in other words, I cognize an object to which I must assign +a certain determinate position in time, which cannot be altered, +because of the preceding state in the object. When, therefore, I +perceive that something happens, there is contained in this +representation, in the first place, the fact, that something +antecedes; because, it is only in relation to this that the +phenomenon obtains its proper relation of time, in other words, exists +after an antecedent time, in which it did not exist. But it can +receive its determined place in time only by the presupposition that +something existed in the foregoing state, upon which it follows +inevitably and always, that is, in conformity with a rule. From all +this it is evident that, in the first place, I cannot reverse the +order of succession, and make that which happens precede that upon +which it follows; and that, in the second place, if the antecedent +state be posited, a certain determinate event inevitably and +necessarily follows. Hence it follows that there exists a certain +order in our representations, whereby the present gives a sure +indication of some previously existing state, as a correlate, though +still undetermined, of the existing event which is given--a +correlate which itself relates to the event as its consequence, +conditions it, and connects it necessarily with itself in the series +of time. + +If then it be admitted as a necessary law of sensibility, and +consequently a formal condition of all perception, that the +preceding necessarily determines the succeeding time (inasmuch as I +cannot arrive at the succeeding except through the preceding), it must +likewise be an indispensable law of empirical representation of the +series of time that the phenomena of the past determine all +phenomena in the succeeding time, and that the latter, as events, +cannot take place, except in so far as the former determine their +existence in time, that is to say, establish it according to a rule. +For it is of course only in phenomena that we can empirically +cognize this continuity in the connection of times. + +For all experience and for the possibility of experience, +understanding is indispensable, and the first step which it takes in +this sphere is not to render the representation of objects clear, +but to render the representation of an object in general, possible. +It does this by applying the order of time to phenomena, and their +existence. In other words, it assigns to each phenomenon, as a +consequence, a place in relation to preceding phenomena, determined +a priori in time, without which it could not harmonize with time +itself, which determines a place a priori to all its parts. This +determination of place cannot be derived from the relation of +phenomena to absolute time (for it is not an object of perception); +but, on the contrary, phenomena must reciprocally determine the places +in time of one another, and render these necessary in the order of +time. In other words, whatever follows or happens, must follow in +conformity with a universal rule upon that which was contained in +the foregoing state. Hence arises a series of phenomena, which, by +means of the understanding, produces and renders necessary exactly +the same order and continuous connection in the series of our possible +perceptions, as is found a priori in the form of internal intuition +(time), in which all our perceptions must have place. + +That something happens, then, is a perception which belongs to a +possible experience, which becomes real only because I look upon the +phenomenon as determined in regard to its place in time, +consequently as an object, which can always be found by means of a +rule in the connected series of my perceptions. But this rule of the +determination of a thing according to succession in time is as +follows: "In what precedes may be found the condition, under which +an event always (that is, necessarily) follows." From all this it is +obvious that the principle of cause and effect is the principle of +possible experience, that is, of objective cognition of phenomena, +in regard to their relations in the succession of time. + +The proof of this fundamental proposition rests entirely on the +following momenta of argument. To all empirical cognition belongs +the synthesis of the manifold by the imagination, a synthesis which +is always successive, that is, in which the representations therein +always follow one another. But the order of succession in +imagination is not determined, and the series of successive +representations may be taken retrogressively as well as progressively. +But if this synthesis is a synthesis of apprehension (of the +manifold of a given phenomenon), then the order is determined in the +object, or to speak more accurately, there is therein an order of +successive synthesis which determines an object, and according to +which something necessarily precedes, and when this is posited, +something else necessarily follows. If, then, my perception is to +contain the cognition of an event, that is, of something which +really happens, it must be an empirical judgement, wherein we think +that the succession is determined; that is, it presupposes another +phenomenon, upon which this event follows necessarily, or in +conformity with a rule. If, on the contrary, when I posited the +antecedent, the event did not necessarily follow, I should be +obliged to consider it merely as a subjective play of my +imagination, and if in this I represented to myself anything as +objective, I must look upon it as a mere dream. Thus, the relation +of phenomena (as possible perceptions), according to which that +which happens is, as to its existence, necessarily determined in +time by something which antecedes, in conformity with a rule--in other +words, the relation of cause and effect--is the condition of the +objective validity of our empirical judgements in regard to the +sequence of perceptions, consequently of their empirical truth, and +therefore of experience. The principle of the relation of causality +in the succession of phenomena is therefore valid for all objects of +experience, because it is itself the ground of the possibility of +experience. + +Here, however, a difficulty arises, which must be resolved. The +principle of the connection of causality among phenomena is limited +in our formula to the succession thereof, although in practice we find +that the principle applies also when the phenomena exist together in +the same time, and that cause and effect may be simultaneous. For +example, there is heat in a room, which does not exist in the open +air. I look about for the cause, and find it to be the fire, Now the +fire as the cause is simultaneous with its effect, the heat of the +room. In this case, then, there is no succession as regards time, +between cause and effect, but they are simultaneous; and still the +law holds good. The greater part of operating causes in nature are +simultaneous with their effects, and the succession in time of the +latter is produced only because the cause cannot achieve the total +of its effect in one moment. But at the moment when the effect first +arises, it is always simultaneous with the causality of its cause, +because, if the cause had but a moment before ceased to be, the effect +could not have arisen. Here it must be specially remembered that we +must consider the order of time and not the lapse thereof. The +relation remains, even though no time has elapsed. The time between +the causality of the cause and its immediate effect may entirely +vanish, and the cause and effect be thus simultaneous, but the +relation of the one to the other remains always determinable according +to time. If, for example, I consider a leaden ball, which lies upon +a cushion and makes a hollow in it, as a cause, then it is +simultaneous with the effect. But I distinguish the two through the +relation of time of the dynamical connection of both. For if I lay +the ball upon the cushion, then the hollow follows upon the before +smooth surface; but supposing the cushion has, from some cause or +another, a hollow, there does not thereupon follow a leaden ball. + +Thus, the law of succession of time is in all instances the only +empirical criterion of effect in relation to the causality of the +antecedent cause. The glass is the cause of the rising of the water +above its horizontal surface, although the two phenomena are +contemporaneous. For, as soon as I draw some water with the glass from +a larger vessel, an effect follows thereupon, namely, the change of +the horizontal state which the water had in the large vessel into a +concave, which it assumes in the glass. + +This conception of causality leads us to the conception of action; +that of action, to the conception of force; and through it, to the +conception of substance. As I do not wish this critical essay, the +sole purpose of which is to treat of the sources of our synthetical +cognition a priori, to be crowded with analyses which merely +explain, but do not enlarge the sphere of our conceptions, I reserve +the detailed explanation of the above conceptions for a future +system of pure reason. Such an analysis, indeed, executed with great +particularity, may already be found in well-known works on this +subject. But I cannot at present refrain from making a few remarks +on the empirical criterion of a substance, in so far as it seems to +be more evident and more easily recognized through the conception of +action than through that of the permanence of a phenomenon. + +Where action (consequently activity and force) exists, substance +also must exist, and in it alone must be sought the seat of that +fruitful source of phenomena. Very well. But if we are called upon +to explain what we mean by substance, and wish to avoid the vice of +reasoning in a circle, the answer is by no means so easy. How shall +we conclude immediately from the action to the permanence of that which +acts, this being nevertheless an essential and peculiar criterion of +substance (phenomenon)? But after what has been said above, the +solution of this question becomes easy enough, although by the +common mode of procedure--merely analysing our conceptions--it would +be quite impossible. The conception of action indicates the relation +of the subject of causality to the effect. Now because all effect +consists in that which happens, therefore in the changeable, the +last subject thereof is the permanent, as the substratum of all that +changes, that is, substance. For according to the principle of +causality, actions are always the first ground of all change in +phenomena and, consequently, cannot be a property of a subject which +itself changes, because if this were the case, other actions and +another subject would be necessary to determine this change. From +all this it results that action alone, as an empirical criterion, is +a sufficient proof of the presence of substantiality, without any +necessity on my part of endeavouring to discover the permanence of +substance by a comparison. Besides, by this mode of induction we could +not attain to the completeness which the magnitude and strict +universality of the conception requires. For that the primary +subject of the causality of all arising and passing away, all origin +and extinction, cannot itself (in the sphere of phenomena) arise and +pass away, is a sound and safe conclusion, a conclusion which leads +us to the conception of empirical necessity and permanence in +existence, and consequently to the conception of a substance as +phenomenon. + +When something happens, the mere fact of the occurrence, without +regard to that which occurs, is an object requiring investigation. +The transition from the non-being of a state into the existence of +it, supposing that this state contains no quality which previously +existed in the phenomenon, is a fact of itself demanding inquiry. Such +an event, as has been shown in No. A, does not concern substance (for +substance does not thus originate), but its condition or state. It +is therefore only change, and not origin from nothing. If this +origin be regarded as the effect of a foreign cause, it is termed +creation, which cannot be admitted as an event among phenomena, +because the very possibility of it would annihilate the unity of +experience. If, however, I regard all things not as phenomena, but +as things in themselves and objects of understanding alone, they, +although substances, may be considered as dependent, in respect of +their existence, on a foreign cause. But this would require a very +different meaning in the words, a meaning which could not apply to +phenomena as objects of possible experience. + +How a thing can be changed, how it is possible that upon one state +existing in one point of time, an opposite state should follow in +another point of time--of this we have not the smallest conception +a priori. There is requisite for this the knowledge of real powers, +which can only be given empirically; for example, knowledge of +moving forces, or, in other words, of certain successive phenomena +(as movements) which indicate the presence of such forces. But the +form of every change, the condition under which alone it can take place +as the coming into existence of another state (be the content of the +change, that is, the state which is changed, what it may), and +consequently the succession of the states themselves can very well +be considered a priori, in relation to the law of causality and the +conditions of time.* + +[*Footnote: It must be remarked that I do not speak of the change of +certain relations, but of the change of the state. Thus, when a body +moves in a uniform manner, it does not change its state (of motion); +but only when all motion increases or decreases.] + +When a substance passes from one state, a, into another state, b, +the point of time in which the latter exists is different from, and +subsequent to that in which the former existed. In like manner, the +second state, as reality (in the phenomenon), differs from the +first, in which the reality of the second did not exist, as b from +zero. That is to say, if the state, b, differs from the state, a, only +in respect to quantity, the change is a coming into existence of +b - a, which in the former state did not exist, and in relation to +which that state is = O. + +Now the question arises how a thing passes from one state = a, +into another state = b. Between two moments there is always a +certain time, and between two states existing in these moments there +is always a difference having a certain quantity (for all parts of +phenomena are in their turn quantities). Consequently, every +transition from one state into another is always effected in a time +contained between two moments, of which the first determines the state +which leaves, and the second determines the state into the thing +passes. The thing leaves, and the second determines the state into +which the thing Both moments, then, are limitations of the time of +a change, consequently of the intermediate state between both, and +as such they belong to the total of the change. Now every change has +a cause, which evidences its causality in the whole time during which +the charge takes place. The cause, therefore, does not produce the +change all at once or in one moment, but in a time, so that, as the +time gradually increases from the commencing instant, a, to its +completion at b, in like manner also, the quantity of the reality +(b - a) is generated through the lesser degrees which are contained +between the first and last. All change is therefore possible only +through a continuous action of the causality, which, in so far as it +is uniform, we call a momentum. The change does not consist of these +momenta, but is generated or produced by them as their effect. + +Such is the law of the continuity of all change, the ground of which +is that neither time itself nor any phenomenon in time consists of +parts which are the smallest possible, but that, notwithstanding, +the state of a thing passes in the process of a change through all +these parts, as elements, to its second state. There is no smallest +degree of reality in a phenomenon, just as there is no smallest degree +in the quantity of time; and so the new state of reality grows up +out of the former state, through all the infinite degrees thereof, +the differences of which one from another, taken all together, are +less than the difference between o and a. + +It is not our business to inquire here into the utility of this +principle in the investigation of nature. But how such a +proposition, which appears so greatly to extend our knowledge of +nature, is possible completely a priori, is indeed a question which +deserves investigation, although the first view seems to demonstrate +the truth and reality of the principle, and the question, how it is +possible, may be considered superfluous. For there are so many +groundless pretensions to the enlargement of our knowledge by pure +reason that we must take it as a general rule to be mistrustful of +all such, and without a thoroughgoing and radical deduction, to believe +nothing of the sort even on the clearest dogmatical evidence. + +Every addition to our empirical knowledge, and every advance made in +the exercise of our perception, is nothing more than an extension of +the determination of the internal sense, that is to say, a progression +in time, be objects themselves what they may, phenomena, or pure +intuitions. This progression in time determines everything, and is +itself determined by nothing else. That is to say, the parts of the +progression exist only in time, and by means of the synthesis thereof, +and are not given antecedently to it. For this reason, every +transition in perception to anything which follows upon another in +time, is a determination of time by means of the production of this +perception. And as this determination of time is, always and in all +its parts, a quantity, the perception produced is to be considered +as a quantity which proceeds through all its degrees--no one of +which is the smallest possible--from zero up to its determined degree. +From this we perceive the possibility of cognizing a priori a law of +changes--a law, however, which concerns their form merely. We merely +anticipate our own apprehension, the formal condition of which, +inasmuch as it is itself to be found in the mind antecedently to all +given phenomena, must certainly be capable of being cognized a priori. + +Thus, as time contains the sensuous condition a priori of the +possibility of a continuous progression of that which exists to that +which follows it, the understanding, by virtue of the unity of +apperception, contains the condition a priori of the possibility of +a continuous determination of the position in time of all phenomena, +and this by means of the series of causes and effects, the former of +which necessitate the sequence of the latter, and thereby render +universally and for all time, and by consequence, objectively, valid +the empirical cognition of the relations of time. + + + +C. THIRD ANALOGY. + +Principle of Coexistence, According to the Law of Reciprocity or Community. + +All substances, in so far as they can be perceived in space +at the same time, exist in a state of complete reciprocity of action. + + +PROOF. + + +Things are coexistent, when in empirical intuition the perception of +the one can follow upon the perception of the other, and vice versa-- +which cannot occur in the succession of phenomena, as we have shown +in the explanation of the second principle. Thus I can perceive the +moon and then the earth, or conversely, first the earth and then the +moon; and for the reason that my perceptions of these objects can +reciprocally follow each other, I say, they exist contemporaneously. +Now coexistence is the existence of the manifold in the same time. +But time itself is not an object of perception; and therefore we cannot +conclude from the fact that things are placed in the same time, the +other fact, that the perception of these things can follow each +other reciprocally. The synthesis of the imagination in apprehension +would only present to us each of these perceptions as present in the +subject when the other is not present, and contrariwise; but would +not show that the objects are coexistent, that is to say, that, if +the one exists, the other also exists in the same time, and that this +is necessarily so, in order that the perceptions may be capable of +following each other reciprocally. It follows that a conception of +the understanding or category of the reciprocal sequence of the +determinations of phenomena (existing, as they do, apart from each +other, and yet contemporaneously), is requisite to justify us in +saying that the reciprocal succession of perceptions has its +foundation in the object, and to enable us to represent coexistence +as objective. But that relation of substances in which the one contains +determinations the ground of which is in the other substance, is the +relation of influence. And, when this influence is reciprocal, it is +the relation of community or reciprocity. Consequently the coexistence +of substances in space cannot be cognized in experience otherwise than +under the precondition of their reciprocal action. This is therefore +the condition of the possibility of things themselves as objects of +experience. + +Things are coexistent, in so far as they exist in one and the same +time. But how can we know that they exist in one and the same time? +Only by observing that the order in the synthesis of apprehension of +the manifold is arbitrary and a matter of indifference, that is to +say, that it can proceed from A, through B, C, D, to E, or +contrariwise from E to A. For if they were successive in time (and +in the order, let us suppose, which begins with A), it is quite +impossible for the apprehension in perception to begin with E and go +backwards to A, inasmuch as A belongs to past time and, therefore, +cannot be an object of apprehension. + +Let us assume that in a number of substances considered as phenomena +each is completely isolated, that is, that no one acts upon another. +Then I say that the coexistence of these cannot be an object of +possible perception and that the existence of one cannot, by any +mode of empirical synthesis, lead us to the existence of another. +For we imagine them in this case to be separated by a completely +void space, and thus perception, which proceeds from the one to the +other in time, would indeed determine their existence by means of a +following perception, but would be quite unable to distinguish whether +the one phenomenon follows objectively upon the first, or is +coexistent with it. + +Besides the mere fact of existence, then, there must be something by +means of which A determines the position of B in time and, conversely, +B the position of A; because only under this condition can +substances be empirically represented as existing contemporaneously. +Now that alone determines the position of another thing in time +which is the cause of it or of its determinations. Consequently +every substance (inasmuch as it can have succession predicated of it +only in respect of its determinations) must contain the causality of +certain determinations in another substance, and at the same time +the effects of the causality of the other in itself. That is to say, +substances must stand (mediately or immediately) in dynamical +community with each other, if coexistence is to be cognized in any +possible experience. But, in regard to objects of experience, that +is absolutely necessary without which the experience of these +objects would itself be impossible. Consequently it is absolutely +necessary that all substances in the world of phenomena, in so far +as they are coexistent, stand in a relation of complete community of +reciprocal action to each other. + +The word community has in our language [Footnote: German] two meanings, +and contains the two notions conveyed in the Latin communio and +commercium. We employ it in this place in the latter sense--that of a +dynamical community, without which even the community of place +(communio spatii) could not be empirically cognized. In our experiences +it is easy to observe that it is only the continuous influences in all +parts of space that can conduct our senses from one object to another; +that the light which plays between our eyes and the heavenly bodies +produces a mediating community between them and us, and thereby +evidences their coexistence with us; that we cannot empirically change our +position (perceive this change), unless the existence of matter throughout +the whole of space rendered possible the perception of the positions +we occupy; and that this perception can prove the contemporaneous +existence of these places only through their reciprocal influence, +and thereby also the coexistence of even the most remote objects--although +in this case the proof is only mediate. Without community, every +perception (of a phenomenon in space) is separated from every other +and isolated, and the chain of empirical representations, that is, +of experience, must, with the appearance of a new object, begin +entirely de novo, without the least connection with preceding +representations, and without standing towards these even in the +relation of time. My intention here is by no means to combat the +notion of empty space; for it may exist where our perceptions cannot +exist, inasmuch as they cannot reach thereto, and where, therefore, +no empirical perception of coexistence takes place. But in this case +it is not an object of possible experience. + +The following remarks may be useful in the way of explanation. In +the mind, all phenomena, as contents of a possible experience, must +exist in community (communio) of apperception or consciousness, and +in so far as it is requisite that objects be represented as coexistent +and connected, in so far must they reciprocally determine the position +in time of each other and thereby constitute a whole. If this +subjective community is to rest upon an objective basis, or to be +applied to substances as phenomena, the perception of one substance +must render possible the perception of another, and conversely. For +otherwise succession, which is always found in perceptions as +apprehensions, would be predicated of external objects, and their +representation of their coexistence be thus impossible. But this is +a reciprocal influence, that is to say, a real community +(commercium) of substances, without which therefore the empirical +relation of coexistence would be a notion beyond the reach of our +minds. By virtue of this commercium, phenomena, in so far as they +are apart from, and nevertheless in connection with each other, +constitute a compositum reale. Such composita are possible in many +different ways. The three dynamical relations then, from which all +others spring, are those of inherence, consequence, and composition. + +These, then, are the three analogies of experience. They are nothing +more than principles of the determination of the existence of +phenomena in time, according to the three modi of this +determination; to wit, the relation to time itself as a quantity +(the quantity of existence, that is, duration), the relation in time +as a series or succession, finally, the relation in time as the +complex of all existence (simultaneity). This unity of determination +in regard to time is thoroughly dynamical; that is to say, time is +not considered as that in which experience determines immediately to +every existence its position; for this is impossible, inasmuch as absolute +time is not an object of perception, by means of which phenomena can +be connected with each other. On the contrary, the rule of the +understanding, through which alone the existence of phenomena can +receive synthetical unity as regards relations of time, determines +for every phenomenon its position in time, and consequently a priori, +and with validity for all and every time. + +By nature, in the empirical sense of the word, we understand the +totality of phenomena connected, in respect of their existence, +according to necessary rules, that is, laws. There are therefore +certain laws (which are moreover a priori) which make nature possible; +and all empirical laws can exist only by means of experience, and by +virtue of those primitive laws through which experience itself becomes +possible. The purpose of the analogies is therefore to represent to +us the unity of nature in the connection of all phenomena under certain +exponents, the only business of which is to express the relation of +time (in so far as it contains all existence in itself) to the unity +of apperception, which can exist in synthesis only according to rules. +The combined expression of all is this: "All phenomena exist in one +nature, and must so exist, inasmuch as without this a priori unity, +no unity of experience, and consequently no determination of objects +in experience, is possible." + +As regards the mode of proof which we have employed in treating of +these transcendental laws of nature, and the peculiar character of +we must make one remark, which will at the same time be important as +a guide in every other attempt to demonstrate the truth of +intellectual and likewise synthetical propositions a priori. Had we +endeavoured to prove these analogies dogmatically, that is, from +conceptions; that is to say, had we employed this method in attempting +to show that everything which exists, exists only in that which is +permanent--that every thing or event presupposes the existence of +something in a preceding state, upon which it follows in conformity +with a rule--lastly, that in the manifold, which is coexistent, the +states coexist in connection with each other according to a rule, +all our labour would have been utterly in vain. For more conceptions +of things, analyse them as we may, cannot enable us to conclude from +the existence of one object to the existence of another. What other +course was left for us to pursue? This only, to demonstrate the +possibility of experience as a cognition in which at last all +objects must be capable of being presented to us, if the +representation of them is to possess any objective reality. Now in +this third, this mediating term, the essential form of which +consists in the synthetical unity of the apperception of all +phenomena, we found a priori conditions of the universal and necessary +determination as to time of all existences in the world of +phenomena, without which the empirical determination thereof as to +time would itself be impossible, and we also discovered rules of +synthetical unity a priori, by means of which we could anticipate +experience. For want of this method, and from the fancy that it was +possible to discover a dogmatical proof of the synthetical +propositions which are requisite in the empirical employment of the +understanding, has it happened that a proof of the principle of +sufficient reason has been so often attempted, and always in vain. +The other two analogies nobody has ever thought of, although they have +always been silently employed by the mind,* because the guiding thread +furnished by the categories was wanting, the guide which alone can +enable us to discover every hiatus, both in the system of +conceptions and of principles. + +[*Footnote: The unity of the universe, in which all phenomena to be +connected, is evidently a mere consequence of the admitted principle +of the community of all substances which are coexistent. For were +substances isolated, they could not as parts constitute a whole, and +were their connection (reciprocal action of the manifold) not +necessary from the very fact of coexistence, we could not conclude +from the fact of the latter as a merely ideal relation to the former +as a real one. We have, however, shown in its place that community +is the proper ground of the possibility of an empirical cognition of +coexistence, and that we may therefore properly reason from the latter +to the former as its condition.] + + + +4. THE POSTULATES OF EMPIRICAL THOUGHT. + +1. That which agrees with the formal conditions (intuition and +conception) of experience, is possible. + +2. That which coheres with the material conditions of experience +(sensation), is real. + +3. That whose coherence with the real is determined according to +universal conditions of experience is (exists) necessary. + + +Explanation. + + +The categories of modality possess this peculiarity, that they do +not in the least determine the object, or enlarge the conception to +which they are annexed as predicates, but only express its relation +to the faculty of cognition. Though my conception of a thing is in +itself complete, I am still entitled to ask whether the object of it +is merely possible, or whether it is also real, or, if the latter, +whether it is also necessary. But hereby the object itself is not more +definitely determined in thought, but the question is only in what +relation it, including all its determinations, stands to the +understanding and its employment in experience, to the empirical +faculty of judgement, and to the reason of its application to +experience. + +For this very reason, too, the categories of modality are nothing +more than explanations of the conceptions of possibility, reality, +and necessity, as employed in experience, and at the same time, +restrictions of all the categories to empirical use alone, not +authorizing the transcendental employment of them. For if they are +to have something more than a merely logical significance, and to be +something more than a mere analytical expression of the form of +thought, and to have a relation to things and their possibility, +reality, or necessity, they must concern possible experience and its +synthetical unity, in which alone objects of cognition can be given. + +The postulate of the possibility of things requires also, that the +conception of the things agree with the formal conditions of our +experience in general. But this, that is to say, the objective form +of experience, contains all the kinds of synthesis which are requisite +for the cognition of objects. A conception which contains a +synthesis must be regarded as empty and, without reference to an +object, if its synthesis does not belong to experience--either as +borrowed from it, and in this case it is called an empirical +conception, or such as is the ground and a priori condition of +experience (its form), and in this case it is a pure conception, a +conception which nevertheless belongs to experience, inasmuch as its +object can be found in this alone. For where shall we find the +criterion or character of the possibility of an object which is +cogitated by means of an a priori synthetical conception, if not in +the synthesis which constitutes the form of empirical cognition of +objects? That in such a conception no contradiction exists is indeed +a necessary logical condition, but very far from being sufficient to +establish the objective reality of the conception, that is, the +possibility of such an object as is thought in the conception. Thus, +in the conception of a figure which is contained within two straight +lines, there is no contradiction, for the conceptions of two +straight lines and of their junction contain no negation of a +figure. The impossibility in such a case does not rest upon the +conception in itself, but upon the construction of it in space, that +is to say, upon the conditions of space and its determinations. But +these have themselves objective reality, that is, they apply to +possible things, because they contain a priori the form of +experience in general. + +And now we shall proceed to point out the extensive utility and +influence of this postulate of possibility. When I represent to myself +a thing that is permanent, so that everything in it which changes +belongs merely to its state or condition, from such a conception alone +I never can cognize that such a thing is possible. Or, if I +represent to myself something which is so constituted that, when it +is posited, something else follows always and infallibly, my thought +contains no self-contradiction; but whether such a property as +causality is to be found in any possible thing, my thought alone +affords no means of judging. Finally, I can represent to myself +different things (substances) which are so constituted that the +state or condition of one causes a change in the state of the other, +and reciprocally; but whether such a relation is a property of +things cannot be perceived from these conceptions, which contain a +merely arbitrary synthesis. Only from the fact, therefore, that +these conceptions express a priori the relations of perceptions in +every experience, do we know that they possess objective reality, that +is, transcendental truth; and that independent of experience, though +not independent of all relation to form of an experience in general +and its synthetical unity, in which alone objects can be empirically +cognized. + +But when we fashion to ourselves new conceptions of substances, +forces, action, and reaction, from the material presented to us by +perception, without following the example of experience in their +connection, we create mere chimeras, of the possibility of which we +cannot discover any criterion, because we have not taken experience +for our instructress, though we have borrowed the conceptions from +her. Such fictitious conceptions derive their character of possibility +not, like the categories, a priori, as conceptions on which all +experience depends, but only, a posteriori, as conceptions given by +means of experience itself, and their possibility must either be +cognized a posteriori and empirically, or it cannot be cognized at +all. A substance which is permanently present in space, yet without +filling it (like that tertium quid between matter and the thinking +subject which some have tried to introduce into metaphysics), or a +peculiar fundamental power of the mind of intuiting the future by +anticipation (instead of merely inferring from past and present +events), or, finally, a power of the mind to place itself in community +of thought with other men, however distant they may be--these are +conceptions the possibility of which has no ground to rest upon. For +they are not based upon experience and its known laws; and, without +experience, they are a merely arbitrary conjunction of thoughts, +which, though containing no internal contradiction, has no claim to +objective reality, neither, consequently, to the possibility of such +an object as is thought in these conceptions. As far as concerns +reality, it is self-evident that we cannot cogitate such a possibility +in concreto without the aid of experience; because reality is +concerned only with sensation, as the matter of experience, and not +with the form of thought, with which we can no doubt indulge in +shaping fancies. + +But I pass by everything which derives its possibility from +reality in experience, and I purpose treating here merely of the +possibility of things by means of a priori conceptions. I maintain, +then, that the possibility of things is not derived from such +conceptions per se, but only when considered as formal and objective +conditions of an experience in general. + +It seems, indeed, as if the possibility of a triangle could be +cognized from the conception of it alone (which is certainly +independent of experience); for we can certainly give to the +conception a corresponding object completely a priori, that is to say, +we can construct it. But as a triangle is only the form of an +object, it must remain a mere product of the imagination, and the +possibility of the existence of an object corresponding to it must +remain doubtful, unless we can discover some other ground, unless we +know that the figure can be cogitated under the conditions upon +which all objects of experience rest. Now, the facts that space is +a formal condition a priori of external experience, that the formative +synthesis, by which we construct a triangle in imagination, is the +very same as that we employ in the apprehension of a phenomenon for +the purpose of making an empirical conception of it, are what alone +connect the notion of the possibility of such a thing, with the +conception of it. In the same manner, the possibility of continuous +quantities, indeed of quantities in general, for the conceptions of +them are without exception synthetical, is never evident from the +conceptions in themselves, but only when they are considered as the +formal conditions of the determination of objects in experience. And +where, indeed, should we look for objects to correspond to our +conceptions, if not in experience, by which alone objects are +presented to us? It is, however, true that without antecedent +experience we can cognize and characterize the possibility of +things, relatively to the formal conditions, under which something +is determined in experience as an object, consequently, completely +a priori. But still this is possible only in relation to experience +and within its limits. + +The postulate concerning the cognition of the reality of things +requires perception, consequently conscious sensation, not indeed +immediately, that is, of the object itself, whose existence is to be +cognized, but still that the object have some connection with a real +perception, in accordance with the analogies of experience, which +exhibit all kinds of real connection in experience. + +From the mere conception of a thing it is impossible to conclude its +existence. For, let the conception be ever so complete, and containing +a statement of all the determinations of the thing, the existence of +it has nothing to do with all this, but only with thew question +whether such a thing is given, so that the perception of it can in +every case precede the conception. For the fact that the conception +of it precedes the perception, merely indicates the possibility of +its existence; it is perception which presents matter to the conception, +that is the sole criterion of reality. Prior to the perception of +the thing, however, and therefore comparatively a priori, we are +able to cognize its existence, provided it stands in connection with +some perceptions according to the principles of the empirical +conjunction of these, that is, in conformity with the analogies of +perception. For, in this case, the existence of the supposed thing +is connected with our perception in a possible experience, and we +are able, with the guidance of these analogies, to reason in the +series of possible perceptions from a thing which we do really +perceive to the thing we do not perceive. Thus, we cognize the +existence of a magnetic matter penetrating all bodies from the +perception of the attraction of the steel-filings by the magnet, +although the constitution of our organs renders an immediate +perception of this matter impossible for us. For, according to the +laws of sensibility and the connected context of our perceptions, we +should in an experience come also on an immediate empirical +intuition of this matter, if our senses were more acute--but this +obtuseness has no influence upon and cannot alter the form of possible +experience in general. Our knowledge of the existence of things +reaches as far as our perceptions, and what may be inferred from +them according to empirical laws, extend. If we do not set out from +experience, or do not proceed according to the laws of the empirical +connection of phenomena, our pretensions to discover the existence +of a thing which we do not immediately perceive are vain. Idealism, +however, brings forward powerful objections to these rules for proving +existence mediately. This is, therefore, the proper place for its +refutation. + + + +REFUTATION OF IDEALISM. + +Idealism--I mean material idealism--is the theory which declares the +existence of objects in space without us to be either () doubtful +and indemonstrable, or (2) false and impossible. The first is the +problematical idealism of Descartes, who admits the undoubted +certainty of only one empirical assertion (assertio), to wit, "I +am." The second is the dogmatical idealism of Berkeley, who +maintains that space, together with all the objects of which it is +the inseparable condition, is a thing which is in itself impossible, +and that consequently the objects in space are mere products of the +imagination. The dogmatical theory of idealism is unavoidable, if we +regard space as a property of things in themselves; for in that case +it is, with all to which it serves as condition, a nonentity. But +the foundation for this kind of idealism we have already destroyed +in the transcendental aesthetic. Problematical idealism, which makes +no such assertion, but only alleges our incapacity to prove the +existence of anything besides ourselves by means of immediate +experience, is a theory rational and evidencing a thorough and +philosophical mode of thinking, for it observes the rule not to form +a decisive judgement before sufficient proof be shown. The desired +proof must therefore demonstrate that we have experience of external +things, and not mere fancies. For this purpose, we must prove, that +our internal and, to Descartes, indubitable experience is itself +possible only under the previous assumption of external experience. + + + +THEOREM. + +The simple but empirically determined consciousness of +my own existence proves the existence of external objects in space. + + +PROOF + + +I am conscious of my own existence as determined in time. All +determination in regard to time presupposes the existence of something +permanent in perception. But this permanent something cannot be +something in me, for the very reason that my existence in time is +itself determined by this permanent something. It follows that the +perception of this permanent existence is possible only through a +thing without me and not through the mere representation of a thing +without me. Consequently, the determination of my existence in time +is possible only through the existence of real things external to me. +Now, consciousness in time is necessarily connected with the +consciousness of the possibility of this determination in time. +Hence it follows that consciousness in time is necessarily connected +also with the existence of things without me, inasmuch as the +existence of these things is the condition of determination in time. +That is to say, the consciousness of my own existence is at the same +time an immediate consciousness of the existence of other things +without me. + +Remark I. The reader will observe, that in the foregoing proof the +game which idealism plays is retorted upon itself, and with more +justice. It assumed that the only immediate experience is internal +and that from this we can only infer the existence of external things. +But, as always happens, when we reason from given effects to +determined causes, idealism has reasoned with too much haste and +uncertainty, for it is quite possible that the cause of our +representations may lie in ourselves, and that we ascribe it falsely +to external things. But our proof shows that external experience is +properly immediate,* that only by virtue of it--not, indeed, the +consciousness of our own existence, but certainly the determination +of our existence in time, that is, internal experience--is possible. +It is true, that the representation "I am," which is the expression +of the consciousness which can accompany all my thoughts, is that which +immediately includes the existence of a subject. But in this +representation we cannot find any knowledge of the subject, and +therefore also no empirical knowledge, that is, experience. For +experience contains, in addition to the thought of something existing, +intuition, and in this case it must be internal intuition, that is, +time, in relation to which the subject must be determined. But the +existence of external things is absolutely requisite for this purpose, +so that it follows that internal experience is itself possible only +mediately and through external experience. + +[*Footnote: The immediate consciousness of the existence of external +things is, in the preceding theorem, not presupposed, but proved, by +the possibility of this consciousness understood by us or not. The +question as to the possibility of it would stand thus: "Have we an +internal sense, but no external sense, and is our belief in external +perception a mere delusion?" But it is evident that, in order merely +to fancy to ourselves anything as external, that is, to present it +to the sense in intuition we must already possess an external sense, +and must thereby distinguish immediately the mere receptivity of an +external intuition from the spontaneity which characterizes every +act of imagination. For merely to imagine also an external sense, +would annihilate the faculty of intuition itself which is to be +determined by the imagination.] + +Remark II. Now with this view all empirical use of our faculty of +cognition in the determination of time is in perfect accordance. Its +truth is supported by the fact that it is possible to perceive a +determination of time only by means of a change in external +relations (motion) to the permanent in space (for example, we become +aware of the sun's motion by observing the changes of his relation +to the objects of this earth). But this is not all. We find that we +possess nothing permanent that can correspond and be submitted to +the conception of a substance as intuition, except matter. This idea +of permanence is not itself derived from external experience, but is +an a priori necessary condition of all determination of time, +consequently also of the internal sense in reference to our own +existence, and that through the existence of external things. In the +representation "I," the consciousness of myself is not an intuition, +but a merely intellectual representation produced by the spontaneous +activity of a thinking subject. It follows, that this "I" has not +any predicate of intuition, which, in its character of permanence, +could serve as correlate to the determination of time in the +internal sense--in the same way as impenetrability is the correlate +of matter as an empirical intuition. + +Remark III. From the fact that the existence of external things is +a necessary condition of the possibility of a determined consciousness +of ourselves, it does not follow that every intuitive representation +of external things involves the existence of these things, for their +representations may very well be the mere products of the +imagination (in dreams as well as in madness); though, indeed, these +are themselves created by the reproduction of previous external +perceptions, which, as has been shown, are possible only through the +reality of external objects. The sole aim of our remarks has, however, +been to prove that internal experience in general is possible only +through external experience in general. Whether this or that +supposed experience be purely imaginary must be discovered from its +particular determinations and by comparing these with the criteria +of all real experience. + +Finally, as regards the third postulate, it applies to material +necessity in existence, and not to merely formal and logical necessity +in the connection of conceptions. Now as we cannot cognize completely a +priori the existence of any object of sense, though we can do so +comparatively a priori, that is, relatively to some other previously +given existence--a cognition, however, which can only be of such an +existence as must be contained in the complex of experience, of which +the previously given perception is a part--the necessity of existence +can never be cognized from conceptions, but always, on the contrary, +from its connection with that which is an object of perception. But the +only existence cognized, under the condition of other given phenomena, +as necessary, is the existence of effects from given causes in +conformity with the laws of causality. It is consequently not the +necessity of the existence of things (as substances), but the necessity +of the state of things that we cognize, and that not immediately, but +by means of the existence of other states given in perception, +according to empirical laws of causality. Hence it follows that the +criterion of necessity is to be found only in the law of possible +experience--that everything which happens is determined a priori in the +phenomenon by its cause. Thus we cognize only the necessity of effects +in nature, the causes of which are given us. Moreover, the criterion of +necessity in existence possesses no application beyond the field of +possible experience, and even in this it is not valid of the existence +of things as substances, because these can never be considered as +empirical effects, or as something that happens and has a beginning. +Necessity, therefore, regards only the relations of phenomena according +to the dynamical law of causality, and the possibility grounded +thereon, of reasoning from some given existence (of a cause) a priori +to another existence (of an effect). "Everything that happens is +hypothetically necessary," is a principle which subjects the changes +that take place in the world to a law, that is, to a rule of necessary +existence, without which nature herself could not possibly exist. Hence +the proposition, "Nothing happens by blind chance (in mundo non datur +casus)," is an a priori law of nature. The case is the same with the +proposition, "Necessity in nature is not blind," that is, it is +conditioned, consequently intelligible necessity (non datur fatum). +Both laws subject the play of change to "a nature of things (as +phenomena)," or, which is the same thing, to the unity of the +understanding, and through the understanding alone can changes belong +to an experience, as the synthetical unity of phenomena. Both belong to +the class of dynamical principles. The former is properly a consequence +of the principle of causality--one of the analogies of experience. The +latter belongs to the principles of modality, which to the +determination of causality adds the conception of necessity, which is +itself, however, subject to a rule of the understanding. The principle +of continuity forbids any leap in the series of phenomena regarded as +changes (in mundo non datur saltus); and likewise, in the complex of +all empirical intuitions in space, any break or hiatus between two +phenomena (non datur hiatus)--for we can so express the principle, that +experience can admit nothing which proves the existence of a vacuum, or +which even admits it as a part of an empirical synthesis. For, as +regards a vacuum or void, which we may cogitate as out and beyond the +field of possible experience (the world), such a question cannot come +before the tribunal of mere understanding, which decides only upon +questions that concern the employment of given phenomena for the +construction of empirical cognition. It is rather a problem for ideal +reason, which passes beyond the sphere of a possible experience and +aims at forming a judgement of that which surrounds and circumscribes +it, and the proper place for the consideration of it is the +transcendental dialectic. These four propositions, "In mundo non datur +hiatus, non datur saltus, non datur casus, non datur fatum," as well as +all principles of transcendental origin, we could very easily exhibit +in their proper order, that is, in conformity with the order of the +categories, and assign to each its proper place. But the already +practised reader will do this for himself, or discover the clue to such +an arrangement. But the combined result of all is simply this, to admit +into the empirical synthesis nothing which might cause a break in or be +foreign to the understanding and the continuous connection of all +phenomena, that is, the unity of the conceptions of the understanding. +For in the understanding alone is the unity of experience, in which all +perceptions must have their assigned place, possible. + +Whether the field of possibility be greater than that of reality, and +whether the field of the latter be itself greater than that of +necessity, are interesting enough questions, and quite capable of +synthetic solution, questions, however, which come under the +jurisdiction of reason alone. For they are tantamount to asking whether +all things as phenomena do without exception belong to the complex and +connected whole of a single experience, of which every given perception +is a part which therefore cannot be conjoined with any other +phenomena--or, whether my perceptions can belong to more than one +possible experience? The understanding gives to experience, according +to the subjective and formal conditions, of sensibility as well as of +apperception, the rules which alone make this experience possible. +Other forms of intuition besides those of space and time, other forms +of understanding besides the discursive forms of thought, or of +cognition by means of conceptions, we can neither imagine nor make +intelligible to ourselves; and even if we could, they would still not +belong to experience, which is the only mode of cognition by which +objects are presented to us. Whether other perceptions besides those +which belong to the total of our possible experience, and consequently +whether some other sphere of matter exists, the understanding has no +power to decide, its proper occupation being with the synthesis of that +which is given. Moreover, the poverty of the usual arguments which go +to prove the existence of a vast sphere of possibility, of which all +that is real (every object of experience) is but a small part, is very +remarkable. "All real is possible"; from this follows naturally, +according to the logical laws of conversion, the particular +proposition: "Some possible is real." Now this seems to be equivalent +to: "Much is possible that is not real." No doubt it does seem as if we +ought to consider the sum of the possible to be greater than that of +the real, from the fact that something must be added to the former to +constitute the latter. But this notion of adding to the possible is +absurd. For that which is not in the sum of the possible, and +consequently requires to be added to it, is manifestly impossible. In +addition to accordance with the formal conditions of experience, the +understanding requires a connection with some perception; but that +which is connected with this perception is real, even although it is +not immediately perceived. But that another series of phenomena, in +complete coherence with that which is given in perception, consequently +more than one all-embracing experience is possible, is an inference +which cannot be concluded from the data given us by experience, and +still less without any data at all. That which is possible only under +conditions which are themselves merely possible, is not possible in any +respect. And yet we can find no more certain ground on which to base +the discussion of the question whether the sphere of possibility is +wider than that of experience. + +I have merely mentioned these questions, that in treating of the +conception of the understanding, there might be no omission of +anything that, in the common opinion, belongs to them. In reality, +however, the notion of absolute possibility (possibility which is +valid in every respect) is not a mere conception of the understanding, +which can be employed empirically, but belongs to reason alone, +which passes the bounds of all empirical use of the understanding. +We have, therefore, contented ourselves with a merely critical remark, +leaving the subject to be explained in the sequel. + +Before concluding this fourth section, and at the same time the system +of all principles of the pure understanding, it seems proper to mention +the reasons which induced me to term the principles of modality +postulates. This expression I do not here use in the sense which some +more recent philosophers, contrary to its meaning with mathematicians, +to whom the word properly belongs, attach to it--that of a +proposition, namely, immediately certain, requiring neither deduction +nor proof. For if, in the case of synthetical propositions, however +evident they may be, we accord to them without deduction, and merely on +the strength of their own pretensions, unqualified belief, all critique +of the understanding is entirely lost; and, as there is no want of bold +pretensions, which the common belief (though for the philosopher this +is no credential) does not reject, the understanding lies exposed to +every delusion and conceit, without the power of refusing its assent to +those assertions, which, though illegitimate, demand acceptance as +veritable axioms. When, therefore, to the conception of a thing an a +priori determination is synthetically added, such a proposition must +obtain, if not a proof, at least a deduction of the legitimacy of its +assertion. + +The principles of modality are, however, not objectively +synthetical, for the predicates of possibility, reality, and necessity +do not in the least augment the conception of that of which they are +affirmed, inasmuch as they contribute nothing to the representation +of the object. But as they are, nevertheless, always synthetical, they +are so merely subjectively. That is to say, they have a reflective +power, and apply to the conception of a thing, of which, in other +respects, they affirm nothing, the faculty of cognition in which the +conception originates and has its seat. So that if the conception +merely agree with the formal conditions of experience, its object is +called possible; if it is in connection with perception, and +determined thereby, the object is real; if it is determined +according to conceptions by means of the connection of perceptions, +the object is called necessary. The principles of modality therefore +predicate of a conception nothing more than the procedure of the +faculty of cognition which generated it. Now a postulate in +mathematics is a practical proposition which contains nothing but +the synthesis by which we present an object to ourselves, and +produce the conception of it, for example--"With a given line, to +describe a circle upon a plane, from a given point"; and such a +proposition does not admit of proof, because the procedure, which it +requires, is exactly that by which alone it is possible to generate +the conception of such a figure. With the same right, accordingly, +can we postulate the principles of modality, because they do not +augment* the conception of a thing but merely indicate the manner in +which it is connected with the faculty of cognition. + +[*Footnote: When I think the reality of a thing, I do really think +more than the possibility, but not in the thing; for that can never +contain more in reality than was contained in its complete possibility. +But while the notion of possibility is merely the notion of a position +of thing in relation to the understanding (its empirical use), reality +is the conjunction of the thing with perception.] + + + +GENERAL REMARK ON THE SYSTEM OF PRINCIPLES. + +It is very remarkable that we cannot perceive the possibility of a +thing from the category alone, but must always have an intuition, by +which to make evident the objective reality of the pure conception +of the understanding. Take, for example, the categories of relation. +How (1) a thing can exist only as a subject, and not as a mere +determination of other things, that is, can be substance; or how +(2), because something exists, some other thing must exist, +consequently how a thing can be a cause; or how (3), when several +things exist, from the fact that one of these things exists, some +consequence to the others follows, and reciprocally, and in this way +a community of substances can be possible--are questions whose +solution cannot be obtained from mere conceptions. The very same is +the case with the other categories; for example, how a thing can be +of the same sort with many others, that is, can be a quantity, and +so on. So long as we have not intuition we cannot know whether we do +really think an object by the categories, and where an object can anywhere +be found to cohere with them, and thus the truth is established, that +the categories are not in themselves cognitions, but mere forms of +thought for the construction of cognitions from given intuitions. For +the same reason is it true that from categories alone no synthetical +proposition can be made. For example: "In every existence there is +substance," that is, something that can exist only as a subject and +not as mere predicate; or, "Everything is a quantity"--to construct +propositions such as these, we require something to enable us to go +out beyond the given conception and connect another with it. For the +same reason the attempt to prove a synthetical proposition by means +of mere conceptions, for example: "Everything that exists contingently +has a cause," has never succeeded. We could never get further than +proving that, without this relation to conceptions, we could not +conceive the existence of the contingent, that is, could not a +priori through the understanding cognize the existence of such a +thing; but it does not hence follow that this is also the condition +of the possibility of the thing itself that is said to be contingent. +If, accordingly; we look back to our proof of the principle of +causality, we shall find that we were able to prove it as valid only +of objects of possible experience, and, indeed, only as itself the +principle of the possibility of experience, Consequently of the +cognition of an object given in empirical intuition, and not from mere +conceptions. That, however, the proposition: "Everything that is +contingent must have a cause," is evident to every one merely from +conceptions, is not to be denied. But in this case the conception of +the contingent is cogitated as involving not the category of +modality (as that the non-existence of which can be conceived) but +that of relation (as that which can exist only as the consequence of +something else), and so it is really an identical proposition: "That +which can exist only as a consequence, has a cause." In fact, when +we have to give examples of contingent existence, we always refer to +changes, and not merely to the possibility of conceiving the +opposite.* But change is an event, which, as such, is possible only +through a cause, and considered per se its non-existence is +therefore possible, and we become cognizant of its contingency from +the fact that it can exist only as the effect of a cause. Hence, if +a thing is assumed to be contingent, it is an analytical proposition +to say, it has a cause. + +[*Footnote: We can easily conceive the non-existence of matter; but +the ancients did not thence infer its contingency. But even the +alternation of the existence and non-existence of a given state in +a thing, in which all change consists, by no means proves the +contingency of that state--the ground of proof being the reality of +its opposite. For example, a body is in a state of rest after +motion, but we cannot infer the contingency of the motion from the +fact that the former is the opposite of the latter. For this +opposite is merely a logical and not a real opposite to the other. +If we wish to demonstrate the contingency of the motion, what we ought +to prove is that, instead of the motion which took place in the +preceding point of time, it was possible for the body to have been +then in rest, not, that it is afterwards in rest; for in this case, +both opposites are perfectly consistent with each other.] + +But it is still more remarkable that, to understand the possibility of +things according to the categories and thus to demonstrate the +objective reality of the latter, we require not merely intuitions, but +external intuitions. If, for example, we take the pure conceptions of +relation, we find that (1) for the purpose of presenting to the +conception of substance something permanent in intuition corresponding +thereto and thus of demonstrating the objective reality of this +conception, we require an intuition (of matter) in space, because space +alone is permanent and determines things as such, while time, and with +it all that is in the internal sense, is in a state of continual flow; +(2) in order to represent change as the intuition corresponding to the +conception of causality, we require the representation of motion as +change in space; in fact, it is through it alone that changes, the +possibility of which no pure understanding can perceive, are capable of +being intuited. Change is the connection of determinations +contradictorily opposed to each other in the existence of one and the +same thing. Now, how it is possible that out of a given state one quite +opposite to it in the same thing should follow, reason without an +example can not only not conceive, but cannot even make intelligible +without intuition; and this intuition is the motion of a point in +space; the existence of which in different spaces (as a consequence of +opposite determinations) alone makes the intuition of change possible. +For, in order to make even internal change cognitable, we require to +represent time, as the form of the internal sense, figuratively by a +line, and the internal change by the drawing of that line (motion), and +consequently are obliged to employ external intuition to be able to +represent the successive existence of ourselves in different states. +The proper ground of this fact is that all change to be perceived as +change presupposes something permanent in intuition, while in the +internal sense no permanent intuition is to be found. Lastly, the +objective possibility of the category of community cannot be conceived +by mere reason, and consequently its objective reality cannot be +demonstrated without an intuition, and that external in space. For how +can we conceive the possibility of community, that is, when several +substances exist, that some effect on the existence of the one follows +from the existence of the other, and reciprocally, and therefore that, +because something exists in the latter, something else must exist in +the former, which could not be understood from its own existence alone? +For this is the very essence of community--which is inconceivable as a +property of things which are perfectly isolated. Hence, Leibnitz, in +attributing to the substances of the world--as cogitated by the +understanding alone--a community, required the mediating aid of a +divinity; for, from their existence, such a property seemed to him with +justice inconceivable. But we can very easily conceive the possibility +of community (of substances as phenomena) if we represent them to +ourselves as in space, consequently in external intuition. For external +intuition contains in itself a priori formal external relations, as the +conditions of the possibility of the real relations of action and +reaction, and therefore of the possibility of community. With the same +ease can it be demonstrated, that the possibility of things as +quantities, and consequently the objective reality of the category of +quantity, can be grounded only in external intuition, and that by its +means alone is the notion of quantity appropriated by the internal +sense. But I must avoid prolixity, and leave the task of illustrating +this by examples to the reader's own reflection. + +The above remarks are of the greatest importance, not only for the +confirmation of our previous confutation of idealism, but still more +when the subject of self-cognition by mere internal consciousness +and the determination of our own nature without the aid of external +empirical intuitions is under discussion, for the indication of the +grounds of the possibility of such a cognition. + +The result of the whole of this part of the analytic of principles +is, therefore: "All principles of the pure understanding are nothing +more than a priori principles of the possibility of experience, and +to experience alone do all a priori synthetical propositions apply +and relate"; indeed, their possibility itself rests entirely on this +relation. + + + +CHAPTER III Of the Ground of the Division of all Objects into Phenomena + and Noumena. + +We have now not only traversed the region of the pure +understanding and carefully surveyed every part of it, but we have +also measured it, and assigned to everything therein its proper place. +But this land is an island, and enclosed by nature herself within +unchangeable limits. It is the land of truth (an attractive word), +surrounded by a wide and stormy ocean, the region of illusion, where +many a fog-bank, many an iceberg, seems to the mariner, on his +voyage of discovery, a new country, and, while constantly deluding +him with vain hopes, engages him in dangerous adventures, from which +he never can desist, and which yet he never can bring to a termination. +But before venturing upon this sea, in order to explore it in its +whole extent, and to arrive at a certainty whether anything is to be +discovered there, it will not be without advantage if we cast our eyes +upon the chart of the land that we are about to leave, and to ask +ourselves, firstly, whether we cannot rest perfectly contented with +what it contains, or whether we must not of necessity be contented +with it, if we can find nowhere else a solid foundation to build upon; +and, secondly, by what title we possess this land itself, and how we +hold it secure against all hostile claims? Although, in the course +of our analytic, we have already given sufficient answers to these +questions, yet a summary recapitulation of these solutions may be +useful in strengthening our conviction, by uniting in one point the +momenta of the arguments. + +We have seen that everything which the understanding draws from +itself, without borrowing from experience, it nevertheless possesses +only for the behoof and use of experience. The principles of the +pure understanding, whether constitutive a priori (as the mathematical +principles), or merely regulative (as the dynamical), contain +nothing but the pure schema, as it were, of possible experience. For +experience possesses its unity from the synthetical unity which the +understanding, originally and from itself, imparts to the synthesis +of the imagination in relation to apperception, and in a priori +relation to and agreement with which phenomena, as data for a possible +cognition, must stand. But although these rules of the understanding +are not only a priori true, but the very source of all truth, that +is, of the accordance of our cognition with objects, and on this ground, +that they contain the basis of the possibility of experience, as the +ensemble of all cognition, it seems to us not enough to propound +what is true--we desire also to be told what we want to know. If, +then, we learn nothing more by this critical examination than what +we should have practised in the merely empirical use of the +understanding, without any such subtle inquiry, the presumption is +that the advantage we reap from it is not worth the labour bestowed +upon it. It may certainly be answered that no rash curiosity is more +prejudicial to the enlargement of our knowledge than that which must +know beforehand the utility of this or that piece of information which +we seek, before we have entered on the needful investigations, and +before one could form the least conception of its utility, even though +it were placed before our eyes. But there is one advantage in such +transcendental inquiries which can be made comprehensible to the +dullest and most reluctant learner--this, namely, that the +understanding which is occupied merely with empirical exercise, and +does not reflect on the sources of its own cognition, may exercise +its functions very well and very successfully, but is quite unable +to do one thing, and that of very great importance, to determine, namely, +the bounds that limit its employment, and to know what lies within +or without its own sphere. This purpose can be obtained only by such +profound investigations as we have instituted. But if it cannot +distinguish whether certain questions lie within its horizon or not, +it can never be sure either as to its claims or possessions, but +must lay its account with many humiliating corrections, when it +transgresses, as it unavoidably will, the limits of its own territory, +and loses itself in fanciful opinions and blinding illusions. + +That the understanding, therefore, cannot make of its a priori +principles, or even of its conceptions, other than an empirical use, +is a proposition which leads to the most important results. A +transcendental use is made of a conception in a fundamental +proposition or principle, when it is referred to things in general +and considered as things in themselves; an empirical use, when it is +referred merely to phenomena, that is, to objects of a possible +experience. That the latter use of a conception is the only admissible +one is evident from the reasons following. For every conception are +requisite, firstly, the logical form of a conception (of thought) +general; and, secondly, the possibility of presenting to this an +object to which it may apply. Failing this latter, it has no sense, +and utterly void of content, although it may contain the logical +function for constructing a conception from certain data. Now, +object cannot be given to a conception otherwise than by intuition, +and, even if a pure intuition antecedent to the object is a priori +possible, this pure intuition can itself obtain objective validity +only from empirical intuition, of which it is itself but the form. +All conceptions, therefore, and with them all principles, however high +the degree of their a priori possibility, relate to empirical +intuitions, that is, to data towards a possible experience. Without +this they possess no objective validity, but are mere play of +imagination or of understanding with images or notions. Let us take, +for example, the conceptions of mathematics, and first in its pure +intuitions. "Space has three dimensions"--"Between two points there +can be only one straight line," etc. Although all these principles, +and the representation of the object with which this science +occupies itself, are generated in the mind entirely a priori, they +would nevertheless have no significance if we were not always able +to exhibit their significance in and by means of phenomena +(empirical objects). Hence it is requisite that an abstract conception +be made sensuous, that is, that an object corresponding to it in +intuition be forthcoming, otherwise the conception remains, as we say, +without sense, that is, without meaning. Mathematics fulfils this +requirement by the construction of the figure, which is a phenomenon +evident to the senses. The same science finds support and significance +in number; this in its turn finds it in the fingers, or in counters, +or in lines and points. The conception itself is always produced a +priori, together with the synthetical principles or formulas from such +conceptions; but the proper employment of them, and their +application to objects, can exist nowhere but in experience, the +possibility of which, as regards its form, they contain a priori. + +That this is also the case with all of the categories and the +principles based upon them is evident from the fact that we cannot +render intelligible the possibility of an object corresponding to them +without having recourse to the conditions of sensibility, +consequently, to the form of phenomena, to which, as their only proper +objects, their use must therefore be confined, inasmuch as, if this +condition is removed, all significance, that is, all relation to an +object, disappears, and no example can be found to make it +comprehensible what sort of things we ought to think under such +conceptions. + +The conception of quantity cannot be explained except by saying that +it is the determination of a thing whereby it can be cogitated how +many times one is placed in it. But this "how many times" is based +upon successive repetition, consequently upon time and the synthesis +of the homogeneous therein. Reality, in contradistinction to negation, +can be explained only by cogitating a time which is either filled +therewith or is void. If I leave out the notion of permanence (which +is existence in all time), there remains in the conception of +substance nothing but the logical notion of subject, a notion of which +I endeavour to realize by representing to myself something that can +exist only as a subject. But not only am I perfectly ignorant of any +conditions under which this logical prerogative can belong to a thing, +I can make nothing out of the notion, and draw no inference from it, +because no object to which to apply the conception is determined, +and we consequently do not know whether it has any meaning at all. +In like manner, if I leave out the notion of time, in which +something follows upon some other thing in conformity with a rule, +I can find nothing in the pure category, except that there is a +something of such a sort that from it a conclusion may be drawn as +to the existence of some other thing. But in this case it would not +only be impossible to distinguish between a cause and an effect, +but, as this power to draw conclusions requires conditions of which +I am quite ignorant, the conception is not determined as to the mode +in which it ought to apply to an object. The so-called principle: +"Everything that is contingent has a cause," comes with a gravity +and self-assumed authority that seems to require no support from +without. But, I ask, what is meant by contingent? The answer is that +the non-existence of which is possible. But I should like very well +to know by what means this possibility of non-existence is to be +cognized, if we do not represent to ourselves a succession in the +series of phenomena, and in this succession an existence which follows +a non-existence, or conversely, consequently, change. For to say, that +the non-existence of a thing is not self-contradictory is a lame +appeal to a logical condition, which is no doubt a necessary condition +of the existence of the conception, but is far from being sufficient +for the real objective possibility of non-existence. I can +annihilate in thought every existing substance without +self-contradiction, but I cannot infer from this their objective +contingency in existence, that is to say, the possibility of their +non-existence in itself. As regards the category of community, it +may easily be inferred that, as the pure categories of substance and +causality are incapable of a definition and explanation sufficient +to determine their object without the aid of intuition, the category +of reciprocal causality in the relation of substances to each other +(commercium) is just as little susceptible thereof. Possibility, +existence, and necessity nobody has ever yet been able to explain +without being guilty of manifest tautology, when the definition has +been drawn entirely from the pure understanding. For the +substitution of the logical possibility of the conception--the +condition of which is that it be not self-contradictory, for the +transcendental possibility of things--the condition of which is that +there be an object corresponding to the conception, is a trick which +can only deceive the inexperienced.* + +[*Footnote: In one word, to none of these conceptions belongs a +corresponding object, and consequently their real possibility cannot +be demonstrated, if we take away sensuous intuition--the only intuition +which we possess--and there then remains nothing but the logical +possibility, that is, the fact that the conception or thought is +possible--which, however, is not the question; what we want to know +being, whether it relates to an object and thus possesses any meaning.] + +It follows incontestably, that the pure conceptions of the +understanding are incapable of transcendental, and must always be of +empirical use alone, and that the principles of the pure understanding +relate only to the general conditions of a possible experience, to +objects of the senses, and never to things in general, apart from +the mode in which we intuite them. + +Transcendental analytic has accordingly this important result, to +wit, that the understanding is competent' effect nothing a priori, +except the anticipation of the form of a possible experience in +general, and that, as that which is not phenomenon cannot be an object +of experience, it can never overstep the limits of sensibility, within +which alone objects are presented to us. Its principles are merely +principles of the exposition of phenomena, and the proud name of an +ontology, which professes to present synthetical cognitions a priori +of things in general in a systematic doctrine, must give place to +the modest title of analytic of the pure understanding. + +Thought is the act of referring a given intuition to an object. If +the mode of this intuition is unknown to us, the object is merely +transcendental, and the conception of the understanding is employed +only transcendentally, that is, to produce unity in the thought of +a manifold in general. Now a pure category, in which all conditions +of sensuous intuition--as the only intuition we possess--are +abstracted, does not determine an object, but merely expresses the +thought of an object in general, according to different modes. Now, +to employ a conception, the function of judgement is required, by which +an object is subsumed under the conception, consequently the at +least formal condition, under which something can be given in +intuition. Failing this condition of judgement (schema), subsumption +is impossible; for there is in such a case nothing given, which may +be subsumed under the conception. The merely transcendental use of +the categories is therefore, in fact, no use at all and has no determined, +or even, as regards its form, determinable object. Hence it follows +that the pure category is incompetent to establish a synthetical a +priori principle, and that the principles of the pure understanding +are only of empirical and never of transcendental use, and that beyond +the sphere of possible experience no synthetical a priori principles +are possible. + +It may be advisable, therefore, to express ourselves thus. The +pure categories, apart from the formal conditions of sensibility, have +a merely transcendental meaning, but are nevertheless not of +transcendental use, because this is in itself impossible, inasmuch +as all the conditions of any employment or use of them (in judgements) +are absent, to wit, the formal conditions of the subsumption of an +object under these conceptions. As, therefore, in the character of +pure categories, they must be employed empirically, and cannot be +employed transcendentally, they are of no use at all, when separated +from sensibility, that is, they cannot be applied to an object. They +are merely the pure form of the employment of the understanding in +respect of objects in general and of thought, without its being at +the same time possible to think or to determine any object by their +means. But there lurks at the foundation of this subject an illusion +which it is very difficult to avoid. The categories are not based, +as regards their origin, upon sensibility, like the forms of +intuition, space, and time; they seem, therefore, to be capable of +an application beyond the sphere of sensuous objects. But this is +not the case. They are nothing but mere forms of thought, which +contain only the logical faculty of uniting a priori in +consciousness the manifold given in intuition. Apart, then, from the +only intuition possible for us, they have still less meaning than +the pure sensuous forms, space and time, for through them an object +is at least given, while a mode of connection of the manifold, when +the intuition which alone gives the manifold is wanting, has no meaning +at all. At the same time, when we designate certain objects as +phenomena or sensuous existences, thus distinguishing our mode of +intuiting them from their own nature as things in themselves, it is +evident that by this very distinction we as it were place the +latter, considered in this their own nature, although we do not so +intuite them, in opposition to the former, or, on the other hand, we +do so place other possible things, which are not objects of our +senses, but are cogitated by the understanding alone, and call them +intelligible existences (noumena). Now the question arises whether +the pure conceptions of our understanding do possess significance in +respect of these latter, and may possibly be a mode of cognizing them. + +But we are met at the very commencement with an ambiguity, which may +easily occasion great misapprehension. The understanding, when it +terms an object in a certain relation phenomenon, at the same time +forms out of this relation a representation or notion of an object +in itself, and hence believes that it can form also conceptions of +such objects. Now as the understanding possesses no other +fundamental conceptions besides the categories, it takes for granted +that an object considered as a thing in itself must be capable of +being thought by means of these pure conceptions, and is thereby led +to hold the perfectly undetermined conception of an intelligible +existence, a something out of the sphere of our sensibility, for a +determinate conception of an existence which we can cognize in some +way or other by means of the understanding. + +If, by the term noumenon, we understand a thing so far as it is +not an object of our sensuous intuition, thus making abstraction of +our mode of intuiting it, this is a noumenon in the negative sense +of the word. But if we understand by it an object of a non-sensuous +intuition, we in this case assume a peculiar mode of intuition, an +intellectual intuition, to wit, which does not, however, belong to +us, of the very possibility of which we have no notion--and this is +a noumenon in the positive sense. + +The doctrine of sensibility is also the doctrine of noumena in the +negative sense, that is, of things which the understanding is +obliged to cogitate apart from any relation to our mode of +intuition, consequently not as mere phenomena, but as things in +themselves. But the understanding at the same time comprehends that +it cannot employ its categories for the consideration of things in +themselves, because these possess significance only in relation to +the unity of intuitions in space and time, and that they are competent +to determine this unity by means of general a priori connecting +conceptions only on account of the pure ideality of space and time. +Where this unity of time is not to be met with, as is the case with +noumena, the whole use, indeed the whole meaning of the categories +is entirely lost, for even the possibility of things to correspond +to the categories is in this case incomprehensible. On this point, +I need only refer the reader to what I have said at the commencement +of the General Remark appended to the foregoing chapter. Now, the +possibility of a thing can never be proved from the fact that the +conception of it is not self-contradictory, but only by means of an +intuition corresponding to the conception. If, therefore, we wish to +apply the categories to objects which cannot be regarded as phenomena, +we must have an intuition different from the sensuous, and in this +case the objects would be a noumena in the positive sense of the word. +Now, as such an intuition, that is, an intellectual intuition, is no +part of our faculty of cognition, it is absolutely impossible for +the categories to possess any application beyond the limits of +experience. It may be true that there are intelligible existences to +which our faculty of sensuous intuition has no relation, and cannot +be applied, but our conceptions of the understanding, as mere forms +of thought for our sensuous intuition, do not extend to these. What, +therefore, we call noumenon must be understood by us as such in a +negative sense. + +If I take away from an empirical intuition all thought (by means of +the categories), there remains no cognition of any object; for by +means of mere intuition nothing is cogitated, and, from the +existence of such or such an affection of sensibility in me, it does +not follow that this affection or representation has any relation to +an object without me. But if I take away all intuition, there still +remains the form of thought, that is, the mode of determining an +object for the manifold of a possible intuition. Thus the categories +do in some measure really extend further than sensuous intuition, +inasmuch as they think objects in general, without regard to the +mode (of sensibility) in which these objects are given. But they do +not for this reason apply to and determine a wider sphere of +objects, because we cannot assume that such can be given, without +presupposing the possibility of another than the sensuous mode of +intuition, a supposition we are not justified in making. + +I call a conception problematical which contains in itself no +contradiction, and which is connected with other cognitions as a +limitation of given conceptions, but whose objective reality cannot +be cognized in any manner. The conception of a noumenon, that is, of +a thing which must be cogitated not as an object of sense, but as a +thing in itself (solely through the pure understanding), is not +self-contradictory, for we are not entitled to maintain that +sensibility is the only possible mode of intuition. Nay, further, this +conception is necessary to restrain sensuous intuition within the +bounds of phenomena, and thus to limit the objective validity of +sensuous cognition; for things in themselves, which lie beyond its +province, are called noumena for the very purpose of indicating that +this cognition does not extend its application to all that the +understanding thinks. But, after all, the possibility of such +noumena is quite incomprehensible, and beyond the sphere of phenomena, +all is for us a mere void; that is to say, we possess an understanding +whose province does problematically extend beyond this sphere, but +we do not possess an intuition, indeed, not even the conception of +a possible intuition, by means of which objects beyond the region of +sensibility could be given us, and in reference to which the +understanding might be employed assertorically. The conception of a +noumenon is therefore merely a limitative conception and therefore +only of negative use. But it is not an arbitrary or fictitious notion, +but is connected with the limitation of sensibility, without, however, +being capable of presenting us with any positive datum beyond this +sphere. + +The division of objects into phenomena and noumena, and of the world +into a mundus sensibilis and intelligibilis is therefore quite +inadmissible in a positive sense, although conceptions do certainly +admit of such a division; for the class of noumena have no determinate +object corresponding to them, and cannot therefore possess objective +validity. If we abandon the senses, how can it be made conceivable +that the categories (which are the only conceptions that could serve +as conceptions for noumena) have any sense or meaning at all, inasmuch +as something more than the mere unity of thought, namely, a possible +intuition, is requisite for their application to an object? The +conception of a noumenon, considered as merely problematical, is, +however, not only admissible, but, as a limitative conception of +sensibility, absolutely necessary. But, in this case, a noumenon is +not a particular intelligible object for our understanding; on the +contrary, the kind of understanding to which it could belong is itself +a problem, for we cannot form the most distant conception of the +possibility of an understanding which should cognize an object, not +discursively by means of categories, but intuitively in a non-sensuous +intuition. Our understanding attains in this way a sort of negative +extension. That is to say, it is not limited by, but rather limits, +sensibility, by giving the name of noumena to things, not considered +as phenomena, but as things in themselves. But it at the same time +prescribes limits to itself, for it confesses itself unable to cognize +these by means of the categories, and hence is compelled to cogitate +them merely as an unknown something. + +I find, however, in the writings of modern authors, an entirely +different use of the expressions, mundus sensibilis and +intelligibilis, which quite departs from the meaning of the +ancients--an acceptation in which, indeed, there is to be found no +difficulty, but which at the same time depends on mere verbal +quibbling. According to this meaning, some have chosen to call the +complex of phenomena, in so far as it is intuited, mundus +sensibilis, but in so far as the connection thereof is cogitated +according to general laws of thought, mundus intelligibilis. +Astronomy, in so far as we mean by the word the mere observation of +the starry heaven, may represent the former; a system of astronomy, +such as the Copernican or Newtonian, the latter. But such twisting +of words is a mere sophistical subterfuge, to avoid a difficult +question, by modifying its meaning to suit our own convenience. To +be sure, understanding and reason are employed in the cognition of +phenomena; but the question is, whether these can be applied when +the object is not a phenomenon and in this sense we regard it if it +is cogitated as given to the understanding alone, and not to the +senses. The question therefore is whether, over and above the +empirical use of the understanding, a transcendental use is +possible, which applies to the noumenon as an object. This question +we have answered in the negative. + +When therefore we say, the senses represent objects as they +appear, the understanding as they are, the latter statement must not +be understood in a transcendental, but only in an empirical +signification, that is, as they must be represented in the complete +connection of phenomena, and not according to what they may be, +apart from their relation to possible experience, consequently not +as objects of the pure understanding. For this must ever remain +unknown to us. Nay, it is also quite unknown to us whether any such +transcendental or extraordinary cognition is possible under any +circumstances, at least, whether it is possible by means of our +categories. Understanding and sensibility, with us, can determine +objects only in conjunction. If we separate them, we have intuitions +without conceptions, or conceptions without intuitions; in both cases, +representations, which we cannot apply to any determinate object. + +If, after all our inquiries and explanations, any one still +hesitates to abandon the mere transcendental use of the categories, +let him attempt to construct with them a synthetical proposition. It +would, of course, be unnecessary for this purpose to construct an +analytical proposition, for that does not extend the sphere of the +understanding, but, being concerned only about what is cogitated in +the conception itself, it leaves it quite undecided whether the +conception has any relation to objects, or merely indicates the +unity of thought--complete abstraction being made of the modi in which +an object may be given: in such a proposition, it is sufficient for +the understanding to know what lies in the conception--to what it +applies is to it indifferent. The attempt must therefore be made +with a synthetical and so-called transcendental principle, for +example: "Everything that exists, exists as substance," or, +"Everything that is contingent exists as an effect of some other +thing, viz., of its cause." Now I ask, whence can the understanding +draw these synthetical propositions, when the conceptions contained +therein do not relate to possible experience but to things in +themselves (noumena)? Where is to be found the third term, which is +always requisite PURE site in a synthetical proposition, which may +connect in the same proposition conceptions which have no logical +(analytical) connection with each other? The proposition never will +be demonstrated, nay, more, the possibility of any such pure assertion +never can be shown, without making reference to the empirical use of +the understanding, and thus, ipso facto, completely renouncing pure +and non-sensuous judgement. Thus the conception of pure and merely +intelligible objects is completely void of all principles of its +application, because we cannot imagine any mode in which they might +be given, and the problematical thought which leaves a place open for +them serves only, like a void space, to limit the use of empirical +principles, without containing at the same time any other object of +cognition beyond their sphere. + + + + +APPENDIX. + +Of the Equivocal Nature or Amphiboly of the Conceptions of +Reflection from the Confusion of the Transcendental with +the Empirical use of the Understanding. + +Reflection (reflexio) is not occupied about objects themselves, +for the purpose of directly obtaining conceptions of them, but is that +state of the mind in which we set ourselves to discover the subjective +conditions under which we obtain conceptions. It is the +consciousness of the relation of given representations to the +different sources or faculties of cognition, by which alone their +relation to each other can be rightly determined. The first question +which occurs in considering our representations is to what faculty +of cognition do they belong? To the understanding or to the senses? +Many judgements are admitted to be true from mere habit or +inclination; but, because reflection neither precedes nor follows, +it is held to be a judgement that has its origin in the understanding. +All judgements do not require examination, that is, investigation into +the grounds of their truth. For, when they are immediately certain +(for example: "Between two points there can be only one straight +line"), no better or less mediate test of their truth can be found +than that which they themselves contain and express. But all +judgement, nay, all comparisons require reflection, that is, a +distinction of the faculty of cognition to which the given conceptions +belong. The act whereby I compare my representations with the +faculty of cognition which originates them, and whereby I +distinguish whether they are compared with each other as belonging +to the pure understanding or to sensuous intuition, I term +transcendental reflection. Now, the relations in which conceptions +can stand to each other are those of identity and difference, agreement +and opposition, of the internal and external, finally, of the +determinable and the determining (matter and form). The proper +determination of these relations rests on the question, to what +faculty of cognition they subjectively belong, whether to +sensibility or understanding? For, on the manner in which we solve +this question depends the manner in which we must cogitate these +relations. + +Before constructing any objective judgement, we compare the +conceptions that are to be placed in the judgement, and observe +whether there exists identity (of many representations in one +conception), if a general judgement is to be constructed, or +difference, if a particular; whether there is agreement when +affirmative; and opposition when negative judgements are to be +constructed, and so on. For this reason we ought to call these +conceptions, conceptions of comparison (conceptus comparationis). +But as, when the question is not as to the logical form, but as to +the content of conceptions, that is to say, whether the things +themselves are identical or different, in agreement or opposition, +and so on, the things can have a twofold relation to our faculty of +cognition, to wit, a relation either to sensibility or to the +understanding, and as on this relation depends their relation to +each other, transcendental reflection, that is, the relation of +given representations to one or the other faculty of cognition, can +alone determine this latter relation. Thus we shall not be able to +discover whether the things are identical or different, in agreement +or opposition, etc., from the mere conception of the things by means +of comparison (comparatio), but only by distinguishing the mode of +cognition to which they belong, in other words, by means of +transcendental reflection. We may, therefore, with justice say, that +logical reflection is mere comparison, for in it no account is taken +of the faculty of cognition to which the given conceptions belong, +and they are consequently, as far as regards their origin, to be treated +as homogeneous; while transcendental reflection (which applies to +the objects themselves) contains the ground of the possibility of +objective comparison of representations with each other, and is +therefore very different from the former, because the faculties of +cognition to which they belong are not even the same. Transcendental +reflection is a duty which no one can neglect who wishes to +establish an a priori judgement upon things. We shall now proceed to +fulfil this duty, and thereby throw not a little light on the question +as to the determination of the proper business of the understanding. + +1. Identity and Difference. When an object is presented to us +several times, but always with the same internal determinations +(qualitas et quantitas), it, if an object of pure understanding, is +always the same, not several things, but only one thing (numerica +identitas); but if a phenomenon, we do not concern ourselves with +comparing the conception of the thing with the conception of some +other, but, although they may be in this respect perfectly the same, +the difference of place at the same time is a sufficient ground for +asserting the numerical difference of these objects (of sense). +Thus, in the case of two drops of water, we may make complete +abstraction of all internal difference (quality and quantity), and, +the fact that they are intuited at the same time in different +places, is sufficient to justify us in holding them to be +numerically different. Leibnitz regarded phenomena as things in +themselves, consequently as intelligibilia, that is, objects of pure +understanding (although, on account of the confused nature of their +representations, he gave them the name of phenomena), and in this case +his principle of the indiscernible (principium identatis +indiscernibilium) is not to be impugned. But, as phenomena are objects +of sensibility, and, as the understanding, in respect of them, must +be employed empirically and not purely or transcendentally, plurality +and numerical difference are given by space itself as the condition +of external phenomena. For one part of space, although it may be +perfectly similar and equal to another part, is still without it, +and for this reason alone is different from the latter, which is added +to it in order to make up a greater space. It follows that this must +hold good of all things that are in the different parts of space at +the same time, however similar and equal one may be to another. + +2. Agreement and Opposition. When reality is represented by the pure +understanding (realitas noumenon), opposition between realities is +incogitable--such a relation, that is, that when these realities are +connected in one subject, they annihilate the effects of each other +and may be represented in the formula 3 - 3 = 0. On the other hand, +the real in a phenomenon (realitas phaenomenon) may very well be in +mutual opposition, and, when united in the same subject, the one may +completely or in part annihilate the effect or consequence of the +other; as in the case of two moving forces in the same straight line +drawing or impelling a point in opposite directions, or in the case +of a pleasure counterbalancing a certain amount of pain. + +3. The Internal and External. In an object of the pure +understanding, only that is internal which has no relation (as regards +its existence) to anything different from itself. On the other hand, +the internal determinations of a substantia phaenomenon in space are +nothing but relations, and it is itself nothing more than a complex +of mere relations. Substance in space we are cognizant of only through +forces operative in it, either drawing others towards itself +(attraction), or preventing others from forcing into itself (repulsion +and impenetrability). We know no other properties that make up the +conception of substance phenomenal in space, and which we term matter. +On the other hand, as an object of the pure understanding, every +substance must have internal determination and forces. But what +other internal attributes of such an object can I think than those +which my internal sense presents to me? That, to wit, which in +either itself thought, or something analogous to it. Hence Leibnitz, +who looked upon things as noumena, after denying them everything +like external relation, and therefore also composition or combination, +declared that all substances, even the component parts of matter, were +simple substances with powers of representation, in one word, monads. + +4. Matter and Form. These two conceptions lie at the foundation of +all other reflection, so inseparably are they connected with every +mode of exercising the understanding. The former denotes the +determinable in general, the second its determination, both in a +transcendental sense, abstraction being made of every difference in +that which is given, and of the mode in which it is determined. +Logicians formerly termed the universal, matter, the specific +difference of this or that part of the universal, form. In a judgement +one may call the given conceptions logical matter (for the judgement), +the relation of these to each other (by means of the copula), the form +of the judgement. In an object, the composite parts thereof +(essentialia) are the matter; the mode in which they are connected +in the object, the form. In respect to things in general, unlimited +reality was regarded as the matter of all possibility, the +limitation thereof (negation) as the form, by which one thing is +distinguished from another according to transcendental conceptions. +The understanding demands that something be given (at least in the +conception), in order to be able to determine it in a certain +manner. Hence, in a conception of the pure understanding, the matter +precedes the form, and for this reason Leibnitz first assumed the +existence of things (monads) and of an internal power of +representation in them, in order to found upon this their external +relation and the community their state (that is, of their +representations). Hence, with him, space and time were possible--the +former through the relation of substances, the latter through the +connection of their determinations with each other, as causes and +effects. And so would it really be, if the pure understanding were +capable of an immediate application to objects, and if space and +time were determinations of things in themselves. But being merely +sensuous intuitions, in which we determine all objects solely as +phenomena, the form of intuition (as a subjective property of +sensibility) must antecede all matter (sensations), consequently space +and time must antecede all phenomena and all data of experience, and +rather make experience itself possible. But the intellectual +philosopher could not endure that the form should precede the things +themselves and determine their possibility; an objection perfectly +correct, if we assume that we intuite things as they are, although +with confused representation. But as sensuous intuition is a +peculiar subjective condition, which is a priori at the foundation +of all perception, and the form of which is primitive, the form must +be given per se, and so far from matter (or the things themselves +which appear) lying at the foundation of experience (as we must +conclude, if we judge by mere conceptions), the very possibility of +itself presupposes, on the contrary, a given formal intuition (space +and time). + + + +REMARK ON THE AMPHIBOLY OF THE CONCEPTIONS OF REFLECTION. + +Let me be allowed to term the position which we assign to a +conception either in the sensibility or in the pure understanding, +the transcendental place. In this manner, the appointment of the +position which must be taken by each conception according to the +difference in its use, and the directions for determining this place +to all conceptions according to rules, would be a transcendental +topic, a doctrine which would thoroughly shield us from the +surreptitious devices of the pure understanding and the delusions +which thence arise, as it would always distinguish to what faculty +of cognition each conception properly belonged. Every conception, +every title, under which many cognitions rank together, may be +called a logical place. Upon this is based the logical topic of +Aristotle, of which teachers and rhetoricians could avail +themselves, in order, under certain titles of thought, to observe what +would best suit the matter they had to treat, and thus enable +themselves to quibble and talk with fluency and an appearance of +profundity. + +Transcendental topic, on the contrary, contains nothing more than +the above-mentioned four titles of all comparison and distinction, +which differ from categories in this respect, that they do not +represent the object according to that which constitutes its +conception (quantity, reality), but set forth merely the comparison +of representations, which precedes our conceptions of things. But this +comparison requires a previous reflection, that is, a determination +of the place to which the representations of the things which are +compared belong, whether, to wit, they are cogitated by the pure +understanding, or given by sensibility. + +Conceptions may be logically compared without the trouble of +inquiring to what faculty their objects belong, whether as noumena, +to the understanding, or as phenomena, to sensibility. If, however, +we wish to employ these conceptions in respect of objects, previous +transcendental reflection is necessary. Without this reflection I +should make a very unsafe use of these conceptions, and construct +pretended synthetical propositions which critical reason cannot +acknowledge and which are based solely upon a transcendental +amphiboly, that is, upon a substitution of an object of pure +understanding for a phenomenon. + +For want of this doctrine of transcendental topic, and +consequently deceived by the amphiboly of the conceptions of +reflection, the celebrated Leibnitz constructed an intellectual system +of the world, or rather, believed himself competent to cognize the +internal nature of things, by comparing all objects merely with the +understanding and the abstract formal conceptions of thought. Our +table of the conceptions of reflection gives us the unexpected +advantage of being able to exhibit the distinctive peculiarities of +his system in all its parts, and at the same time of exposing the +fundamental principle of this peculiar mode of thought, which rested +upon naught but a misconception. He compared all things with each +other merely by means of conceptions, and naturally found no other +differences than those by which the understanding distinguishes its +pure conceptions one from another. The conditions of sensuous +intuition, which contain in themselves their own means of distinction, +he did not look upon as primitive, because sensibility was to him +but a confused mode of representation and not any particular source +of representations. A phenomenon was for him the representation of +the thing in itself, although distinguished from cognition by the +understanding only in respect of the logical form--the former with +its usual want of analysis containing, according to him, a certain +mixture of collateral representations in its conception of a thing, +which it is the duty of the understanding to separate and distinguish. +In one word, Leibnitz intellectualized phenomena, just as Locke, in +his system of noogony (if I may be allowed to make use of such +expressions), sensualized the conceptions of the understanding, that +is to say, declared them to be nothing more than empirical or abstract +conceptions of reflection. Instead of seeking in the understanding +and sensibility two different sources of representations, which, +however, can present us with objective judgements of things only in +conjunction, each of these great men recognized but one of these +faculties, which, in their opinion, applied immediately to things in +themselves, the other having no duty but that of confusing or +arranging the representations of the former. + +Accordingly, the objects of sense were compared by Leibnitz as +things in general merely in the understanding. + +1st. He compares them in regard to their identity or difference +--as judged by the understanding. As, therefore, he considered merely +the conceptions of objects, and not their position in intuition, in +which alone objects can be given, and left quite out of sight the +transcendental locale of these conceptions--whether, that is, their +object ought to be classed among phenomena, or among things in +themselves, it was to be expected that he should extend the +application of the principle of indiscernibles, which is valid +solely of conceptions of things in general, to objects of sense +(mundus phaenomenon), and that he should believe that he had thereby +contributed in no small degree to extend our knowledge of nature. In +truth, if I cognize in all its inner determinations a drop of water +as a thing in itself, I cannot look upon one drop as different from +another, if the conception of the one is completely identical with +that of the other. But if it is a phenomenon in space, it has a +place not merely in the understanding (among conceptions), but also +in sensuous external intuition (in space), and in this case, the physical +locale is a matter of indifference in regard to the internal +determinations of things, and one place, B, may contain a thing +which is perfectly similar and equal to another in a place, A, just +as well as if the two things were in every respect different from each +other. Difference of place without any other conditions, makes the +plurality and distinction of objects as phenomena, not only possible +in itself, but even necessary. Consequently, the above so-called law +is not a law of nature. It is merely an analytical rule for the +comparison of things by means of mere conceptions. + +2nd. The principle: "Realities (as simple affirmations) never +logically contradict each other," is a proposition perfectly true +respecting the relation of conceptions, but, whether as regards +nature, or things in themselves (of which we have not the slightest +conception), is without any the least meaning. For real opposition, +in which A - B is = 0, exists everywhere, an opposition, that is, in +which one reality united with another in the same subject +annihilates the effects of the other--a fact which is constantly +brought before our eyes by the different antagonistic actions and +operations in nature, which, nevertheless, as depending on real +forces, must be called realitates phaenomena. General mechanics can +even present us with the empirical condition of this opposition in +an a priori rule, as it directs its attention to the opposition in +the direction of forces--a condition of which the transcendental +conception of reality can tell us nothing. Although M. Leibnitz did +not announce this proposition with precisely the pomp of a new +principle, he yet employed it for the establishment of new +propositions, and his followers introduced it into their +Leibnitzio-Wolfian system of philosophy. According to this +principle, for example, all evils are but consequences of the +limited nature of created beings, that is, negations, because these +are the only opposite of reality. (In the mere conception of a thing +in general this is really the case, but not in things as phenomena.) +In like manner, the upholders of this system deem it not only +possible, but natural also, to connect and unite all reality in one +being, because they acknowledge no other sort of opposition than +that of contradiction (by which the conception itself of a thing is +annihilated), and find themselves unable to conceive an opposition +of reciprocal destruction, so to speak, in which one real cause +destroys the effect of another, and the conditions of whose +representation we meet with only in sensibility. + +3rd. The Leibnitzian monadology has really no better foundation than +on this philosopher's mode of falsely representing the difference of +the internal and external solely in relation to the understanding. +Substances, in general, must have something inward, which is therefore +free from external relations, consequently from that of composition +also. The simple--that which can be represented by a unit--is +therefore the foundation of that which is internal in things in +themselves. The internal state of substances cannot therefore +consist in place, shape, contact, or motion, determinations which +are all external relations, and we can ascribe to them no other than +that whereby we internally determine our faculty of sense itself, that +is to say, the state of representation. Thus, then, were constructed +the monads, which were to form the elements of the universe, the +active force of which consists in representation, the effects of +this force being thus entirely confined to themselves. + +For the same reason, his view of the possible community of +substances could not represent it but as a predetermined harmony, +and by no means as a physical influence. For inasmuch as everything +is occupied only internally, that is, with its own representations, +the state of the representations of one substance could not stand in +active and living connection with that of another, but some third +cause operating on all without exception was necessary to make the +different states correspond with one another. And this did not +happen by means of assistance applied in each particular case (systema +assistentiae), but through the unity of the idea of a cause occupied +and connected with all substances, in which they necessarily +receive, according to the Leibnitzian school, their existence and +permanence, consequently also reciprocal correspondence, according +to universal laws. + +4th. This philosopher's celebrated doctrine of space and time, in +which he intellectualized these forms of sensibility, originated in +the same delusion of transcendental reflection. If I attempt to +represent by the mere understanding, the external relations of things, +I can do so only by employing the conception of their reciprocal +action, and if I wish to connect one state of the same thing with +another state, I must avail myself of the notion of the order of cause +and effect. And thus Leibnitz regarded space as a certain order in +the community of substances, and time as the dynamical sequence of +their states. That which space and time possess proper to themselves +and independent of things, he ascribed to a necessary confusion in +our conceptions of them, whereby that which is a mere form of dynamical +relations is held to be a self-existent intuition, antecedent even +to things themselves. Thus space and time were the intelligible form +of the connection of things (substances and their states) in +themselves. But things were intelligible substances (substantiae +noumena). At the same time, he made these conceptions valid of +phenomena, because he did not allow to sensibility a peculiar mode +of intuition, but sought all, even the empirical representation of +objects, in the understanding, and left to sense naught but the +despicable task of confusing and disarranging the representations of +the former. + +But even if we could frame any synthetical proposition concerning +things in themselves by means of the pure understanding (which is +impossible), it could not apply to phenomena, which do not represent +things in themselves. In such a case I should be obliged in +transcendental reflection to compare my conceptions only under the +conditions of sensibility, and so space and time would not be +determinations of things in themselves, but of phenomena. What +things may be in themselves, I know not and need not know, because +a thing is never presented to me otherwise than as a phenomenon. + +I must adopt the same mode of procedure with the other conceptions +of reflection. Matter is substantia phaenomenon. That in it which is +internal I seek to discover in all parts of space which it occupies, +and in all the functions and operations it performs, and which are +indeed never anything but phenomena of the external sense. I cannot +therefore find anything that is absolutely, but only what is +comparatively internal, and which itself consists of external +relations. The absolutely internal in matter, and as it should be +according to the pure understanding, is a mere chimera, for matter +is not an object for the pure understanding. But the transcendental +object, which is the foundation of the phenomenon which we call +matter, is a mere nescio quid, the nature of which we could not +understand, even though someone were found able to tell us. For we +can understand nothing that does not bring with it something in +intuition corresponding to the expressions employed. If, by the +complaint of being unable to perceive the internal nature of things, +it is meant that we do not comprehend by the pure understanding what +the things which appear to us may be in themselves, it is a silly +and unreasonable complaint; for those who talk thus really desire that +we should be able to cognize, consequently to intuite, things +without senses, and therefore wish that we possessed a faculty of +cognition perfectly different from the human faculty, not merely in +degree, but even as regards intuition and the mode thereof, so that +thus we should not be men, but belong to a class of beings, the +possibility of whose existence, much less their nature and +constitution, we have no means of cognizing. By observation and +analysis of phenomena we penetrate into the interior of nature, and +no one can say what progress this knowledge may make in time. But those +transcendental questions which pass beyond the limits of nature, we +could never answer, even although all nature were laid open to us, +because we have not the power of observing our own mind with any other +intuition than that of our internal sense. For herein lies the mystery +of the origin and source of our faculty of sensibility. Its +application to an object, and the transcendental ground of this +unity of subjective and objective, lie too deeply concealed for us, +who cognize ourselves only through the internal sense, consequently +as phenomena, to be able to discover in our existence anything but +phenomena, the non-sensuous cause of which we at the same time +earnestly desire to penetrate to. + +The great utility of this critique of conclusions arrived at by +the processes of mere reflection consists in its clear demonstration +of the nullity of all conclusions respecting objects which are +compared with each other in the understanding alone, while it at the +same time confirms what we particularly insisted on, namely, that, +although phenomena are not included as things in themselves among +the objects of the pure understanding, they are nevertheless the +only things by which our cognition can possess objective reality, that +is to say, which give us intuitions to correspond with our +conceptions. + +When we reflect in a purely logical manner, we do nothing more +than compare conceptions in our understanding, to discover whether +both have the same content, whether they are self-contradictory or +not, whether anything is contained in either conception, which of +the two is given, and which is merely a mode of thinking that given. +But if I apply these conceptions to an object in general (in the +transcendental sense), without first determining whether it is an +object of sensuous or intellectual intuition, certain limitations +present themselves, which forbid us to pass beyond the conceptions +and render all empirical use of them impossible. And thus these +limitations prove that the representation of an object as a thing in +general is not only insufficient, but, without sensuous +determination and independently of empirical conditions, +self-contradictory; that we must therefore make abstraction of all +objects, as in logic, or, admitting them, must think them under +conditions of sensuous intuition; that, consequently, the intelligible +requires an altogether peculiar intuition, which we do not possess, +and in the absence of which it is for us nothing; while, on the +other hand phenomena cannot be objects in themselves. For, when I +merely think things in general, the difference in their external +relations cannot constitute a difference in the things themselves; +on the contrary, the former presupposes the latter, and if the +conception of one of two things is not internally different from +that of the other, I am merely thinking the same thing in different +relations. Further, by the addition of one affirmation (reality) to +the other, the positive therein is really augmented, and nothing is +abstracted or withdrawn from it; hence the real in things cannot be +in contradiction with or opposition to itself--and so on. + +The true use of the conceptions of reflection in the employment of +the understanding has, as we have shown, been so misconceived by +Leibnitz, one of the most acute philosophers of either ancient or +modern times, that he has been misled into the construction of a +baseless system of intellectual cognition, which professes to +determine its objects without the intervention of the senses. For this +reason, the exposition of the cause of the amphiboly of these +conceptions, as the origin of these false principles, is of great +utility in determining with certainty the proper limits of the +understanding. + +It is right to say whatever is affirmed or denied of the whole of +a conception can be affirmed or denied of any part of it (dictum de +omni et nullo); but it would be absurd so to alter this logical +proposition as to say whatever is not contained in a general +conception is likewise not contained in the particular conceptions +which rank under it; for the latter are particular conceptions, for +the very reason that their content is greater than that which is +cogitated in the general conception. And yet the whole intellectual +system of Leibnitz is based upon this false principle, and with it +must necessarily fall to the ground, together with all the ambiguous +principles in reference to the employment of the understanding which +have thence originated. + +Leibnitz's principle of the identity of indiscernibles or +indistinguishables is really based on the presupposition that, if in +the conception of a thing a certain distinction is not to be found, +it is also not to be met with in things themselves; that, consequently, +all things are completely identical (numero eadem) which are not +distinguishable from each other (as to quality or quantity) in our +conceptions of them. But, as in the mere conception of anything +abstraction has been made of many necessary conditions of intuition, +that of which abstraction has been made is rashly held to be +non-existent, and nothing is attributed to the thing but what is +contained in its conception. + +The conception of a cubic foot of space, however I may think it, +is in itself completely identical. But two cubic feet in space are +nevertheless distinct from each other from the sole fact of their +being in different places (they are numero diversa); and these +places are conditions of intuition, wherein the object of this +conception is given, and which do not belong to the conception, but +to the faculty of sensibility. In like manner, there is in the conception +of a thing no contradiction when a negative is not connected with an +affirmative; and merely affirmative conceptions cannot, in +conjunction, produce any negation. But in sensuous intuition, +wherein reality (take for example, motion) is given, we find +conditions (opposite directions)--of which abstraction has been made +in the conception of motion in general--which render possible a +contradiction or opposition (not indeed of a logical kind)--and +which from pure positives produce zero = 0. We are therefore not +justified in saying that all reality is in perfect agreement and +harmony, because no contradiction is discoverable among its +conceptions.* According to mere conceptions, that which is internal +is the substratum of all relations or external determinations. When, +therefore, I abstract all conditions of intuition, and confine +myself solely to the conception of a thing in general, I can make +abstraction of all external relations, and there must nevertheless +remain a conception of that which indicates no relation, but merely +internal determinations. Now it seems to follow that in everything +(substance) there is something which is absolutely internal and +which antecedes all external determinations, inasmuch as it renders +them possible; and that therefore this substratum is something which +does not contain any external relations and is consequently simple +(for corporeal things are never anything but relations, at least of +their parts external to each other); and, inasmuch as we know of no +other absolutely internal determinations than those of the internal +sense, this substratum is not only simple, but also, analogously +with our internal sense, determined through representations, that is +to say, all things are properly monads, or simple beings endowed +with the power of representation. Now all this would be perfectly +correct, if the conception of a thing were the only necessary +condition of the presentation of objects of external intuition. It +is, on the contrary, manifest that a permanent phenomenon in space +(impenetrable extension) can contain mere relations, and nothing +that is absolutely internal, and yet be the primary substratum of +all external perception. By mere conceptions I cannot think anything +external, without, at the same time, thinking something internal, +for the reason that conceptions of relations presuppose given +things, and without these are impossible. But, as an intuition there +is something (that is, space, which, with all it contains, consists +of purely formal, or, indeed, real relations) which is not found in +the mere conception of a thing in general, and this presents to us +the substratum which could not be cognized through conceptions alone, +I cannot say: because a thing cannot be represented by mere +conceptions without something absolutely internal, there is also, in +the things themselves which are contained under these conceptions, +and in their intuition nothing external to which something absolutely +internal does not serve as the foundation. For, when we have made +abstraction of all the conditions of intuition, there certainly +remains in the mere conception nothing but the internal in general, +through which alone the external is possible. But this necessity, +which is grounded upon abstraction alone, does not obtain in the +case of things themselves, in so far as they are given in intuition +with such determinations as express mere relations, without having +anything internal as their foundation; for they are not things of a +thing of which we can neither for they are not things in themselves, +but only phenomena. What we cognize in matter is nothing but relations +(what we call its internal determinations are but comparatively +internal). But there are some self-subsistent and permanent, through +which a determined object is given. That I, when abstraction is made +of these relations, have nothing more to think, does not destroy the +conception of a thing as phenomenon, nor the conception of an object +in abstracto, but it does away with the possibility of an object +that is determinable according to mere conceptions, that is, of a +noumenon. It is certainly startling to hear that a thing consists +solely of relations; but this thing is simply a phenomenon, and cannot +be cogitated by means of the mere categories: it does itself consist +in the mere relation of something in general to the senses. In the +same way, we cannot cogitate relations of things in abstracto, if we +commence with conceptions alone, in any other manner than that one +is the cause of determinations in the other; for that is itself the +conception of the understanding or category of relation. But, as in +this case we make abstraction of all intuition, we lose altogether +the mode in which the manifold determines to each of its parts its +place, that is, the form of sensibility (space); and yet this mode +antecedes all empirical causality. + + +[*Footnote: If any one wishes here to have recourse to the usual +subterfuge, and to say, that at least realitates noumena cannot be +in opposition to each other, it will be requisite for him to adduce +an example of this pure and non-sensuous reality, that it may be understood +whether the notion represents something or nothing. But an example +cannot be found except in experience, which never presents to us +anything more than phenomena; and thus the proposition means nothing +more than that the conception which contains only affirmatives does +not contain anything negative--a proposition nobody ever doubted.] + + +If by intelligible objects we understand things which can be thought +by means of the pure categories, without the need of the schemata of +sensibility, such objects are impossible. For the condition of the +objective use of all our conceptions of understanding is the mode of +our sensuous intuition, whereby objects are given; and, if we make +abstraction of the latter, the former can have no relation to an +object. And even if we should suppose a different kind of intuition +from our own, still our functions of thought would have no use or +signification in respect thereof. But if we understand by the term, +objects of a non-sensuous intuition, in respect of which our +categories are not valid, and of which we can accordingly have no +knowledge (neither intuition nor conception), in this merely +negative sense noumena must be admitted. For this is no more than +saying that our mode of intuition is not applicable to all things, +but only to objects of our senses, that consequently its objective +validity is limited, and that room is therefore left for another +kind of intuition, and thus also for things that may be objects of +it. But in this sense the conception of a noumenon is problematical, +that is to say, it is the notion of that it that it is possible, nor +that it is impossible, inasmuch as we do not know of any mode of +intuition besides the sensuous, or of any other sort of conceptions +than the categories--a mode of intuition and a kind of conception +neither of which is applicable to a non-sensuous object. We are on +this account incompetent to extend the sphere of our objects of +thought beyond the conditions of our sensibility, and to assume the +existence of objects of pure thought, that is, of noumena, inasmuch +as these have no true positive signification. For it must be confessed +of the categories that they are not of themselves sufficient for the +cognition of things in themselves and, without the data of +sensibility, are mere subjective forms of the unity of the +understanding. Thought is certainly not a product of the senses, and +in so far is not limited by them, but it does not therefore follow +that it may be employed purely and without the intervention of +sensibility, for it would then be without reference to an object. +And we cannot call a noumenon an object of pure thought; for the +representation thereof is but the problematical conception of an +object for a perfectly different intuition and a perfectly different +understanding from ours, both of which are consequently themselves +problematical. The conception of a noumenon is therefore not the +conception of an object, but merely a problematical conception +inseparably connected with the limitation of our sensibility. That +is to say, this conception contains the answer to the question: "Are +there objects quite unconnected with, and independent of, our +intuition?"--a question to which only an indeterminate answer can be +given. That answer is: "Inasmuch as sensuous intuition does not +apply to all things without distinction, there remains room for +other and different objects." The existence of these problematical +objects is therefore not absolutely denied, in the absence of a +determinate conception of them, but, as no category is valid in +respect of them, neither must they be admitted as objects for our +understanding. + +Understanding accordingly limits sensibility, without at the same +time enlarging its own field. While, moreover, it forbids +sensibility to apply its forms and modes to things in themselves and +restricts it to the sphere of phenomena, it cogitates an object in +itself, only, however, as a transcendental object, which is the +cause of a phenomenon (consequently not itself a phenomenon), and +which cannot be thought either as a quantity or as reality, or as +substance (because these conceptions always require sensuous forms +in which to determine an object)--an object, therefore, of which we +are quite unable to say whether it can be met with in ourselves or +out of us, whether it would be annihilated together with sensibility, +or, if this were taken away, would continue to exist. If we wish to +call this object a noumenon, because the representation of it is +non-sensuous, we are at liberty to do so. But as we can apply to it +none of the conceptions of our understanding, the representation is +for us quite void, and is available only for the indication of the +limits of our sensuous intuition, thereby leaving at the same time +an empty space, which we are competent to fill by the aid neither of +possible experience, nor of the pure understanding. + +The critique of the pure understanding, accordingly, does not permit +us to create for ourselves a new field of objects beyond those which +are presented to us as phenomena, and to stray into intelligible +worlds; nay, it does not even allow us to endeavour to form so much +as a conception of them. The specious error which leads to this--and +which is a perfectly excusable one--lies in the fact that the +employment of the understanding, contrary to its proper purpose and +destination, is made transcendental, and objects, that is, possible +intuitions, are made to regulate themselves according to +conceptions, instead of the conceptions arranging themselves according +to the intuitions, on which alone their own objective validity +rests. Now the reason of this again is that apperception, and with +it thought, antecedes all possible determinate arrangement of +representations. Accordingly we think something in general and +determine it on the one hand sensuously, but, on the other, +distinguish the general and in abstracto represented object from +this particular mode of intuiting it. In this case there remains a +mode of determining the object by mere thought, which is really but +a logical form without content, which, however, seems to us to be a +mode of the existence of the object in itself (noumenon), without +regard to intuition which is limited to our senses. + +Before ending this transcendental analytic, we must make an +addition, which, although in itself of no particular importance, seems +to be necessary to the completeness of the system. The highest +conception, with which a transcendental philosophy commonly begins, +is the division into possible and impossible. But as all division +presupposes a divided conception, a still higher one must exist, and +this is the conception of an object in general--problematically +understood and without its being decided whether it is something or +nothing. As the categories are the only conceptions which apply to +objects in general, the distinguishing of an object, whether it is +something or nothing, must proceed according to the order and +direction of the categories. + +1. To the categories of quantity, that is, the conceptions of all, +many, and one, the conception which annihilates all, that is, the +conception of none, is opposed. And thus the object of a conception, +to which no intuition can be found to correspond, is = nothing. That +is, it is a conception without an object (ens rationis), like noumena, +which cannot be considered possible in the sphere of reality, though +they must not therefore be held to be impossible--or like certain +new fundamental forces in matter, the existence of which is +cogitable without contradiction, though, as examples from experience +are not forthcoming, they must not be regarded as possible. + +2. Reality is something; negation is nothing, that is, a +conception of the absence of an object, as cold, a shadow (nihil +privativum). + +3. The mere form of intuition, without substance, is in itself no +object, but the merely formal condition of an object (as +phenomenon), as pure space and pure time. These are certainly +something, as forms of intuition, but are not themselves objects which +are intuited (ens imaginarium). + +4. The object of a conception which is self-contradictory, is +nothing, because the conception is nothing--is impossible, as a figure +composed of two straight lines (nihil negativum). + +The table of this division of the conception of nothing (the +corresponding division of the conception of something does not require +special description) must therefore be arranged as follows: + + + NOTHING + AS + + 1 + As Empty Conception + without object, + ens rationis + 2 3 + Empty object of Empty intuition + a conception, without object, + nihil privativum ens imaginarium + 4 + Empty object + without conception, + nihil negativum + + +We see that the ens rationis is distinguished from the nihil +negativum or pure nothing by the consideration that the former must +not be reckoned among possibilities, because it is a mere fiction- +though not self-contradictory, while the latter is completely +opposed to all possibility, inasmuch as the conception annihilates +itself. Both, however, are empty conceptions. On the other hand, +the nihil privativum and ens imaginarium are empty data for +conceptions. If light be not given to the senses, we cannot +represent to ourselves darkness, and if extended objects are not +perceived, we cannot represent space. Neither the negation, nor the +mere form of intuition can, without something real, be an object. + + + + +TRANSCENDENTAL LOGIC. SECOND DIVISION. + +TRANSCENDENTAL DIALECTIC. INTRODUCTION. + +I. Of Transcendental Illusory Appearance. + +We termed dialectic in general a logic of appearance. This does +not signify a doctrine of probability; for probability is truth, +only cognized upon insufficient grounds, and though the information +it gives us is imperfect, it is not therefore deceitful. Hence it must +not be separated from the analytical part of logic. Still less must +phenomenon and appearance be held to be identical. For truth or +illusory appearance does not reside in the object, in so far as it +is intuited, but in the judgement upon the object, in so far as it +is thought. It is, therefore, quite correct to say that the senses +do not err, not because they always judge correctly, but because +they do not judge at all. Hence truth and error, consequently also, +illusory appearance as the cause of error, are only to be found in +a judgement, that is, in the relation of an object to our understanding. +In a cognition which completely harmonizes with the laws of the +understanding, no error can exist. In a representation of the +senses--as not containing any judgement--there is also no error. But +no power of nature can of itself deviate from its own laws. Hence +neither the understanding per se (without the influence of another +cause), nor the senses per se, would fall into error; the former could +not, because, if it acts only according to its own laws, the effect +(the judgement) must necessarily accord with these laws. But in +accordance with the laws of the understanding consists the formal +element in all truth. In the senses there is no judgement--neither +a true nor a false one. But, as we have no source of cognition besides +these two, it follows that error is caused solely by the unobserved +influence of the sensibility upon the understanding. And thus it +happens that the subjective grounds of a judgement and are +confounded with the objective, and cause them to deviate from their +proper determination,* just as a body in motion would always of itself +proceed in a straight line, but if another impetus gives to it a +different direction, it will then start off into a curvilinear line +of motion. To distinguish the peculiar action of the understanding +from the power which mingles with it, it is necessary to consider an +erroneous judgement as the diagonal between two forces, that determine +the judgement in two different directions, which, as it were, form +an angle, and to resolve this composite operation into the simple ones +of the understanding and the sensibility. In pure a priori +judgements this must be done by means of transcendental reflection, +whereby, as has been already shown, each representation has its +place appointed in the corresponding faculty of cognition, and +consequently the influence of the one faculty upon the other is made +apparent. + +[*Footnote: Sensibility, subjected to the understanding, as the object +upon which the understanding employs its functions, is the source of +real cognitions. But, in so far as it exercises an influence upon the +action of the understanding and determines it to judgement, +sensibility is itself the cause of error.] + +It is not at present our business to treat of empirical illusory +appearance (for example, optical illusion), which occurs in the +empirical application of otherwise correct rules of the understanding, +and in which the judgement is misled by the influence of +imagination. Our purpose is to speak of transcendental illusory +appearance, which influences principles--that are not even applied +to experience, for in this case we should possess a sure test of their +correctness--but which leads us, in disregard of all the warnings of +criticism, completely beyond the empirical employment of the +categories and deludes us with the chimera of an extension of the +sphere of the pure understanding. We shall term those principles the +application of which is confined entirely within the limits of +possible experience, immanent; those, on the other hand, which +transgress these limits, we shall call transcendent principles. But +by these latter I do not understand principles of the transcendental +use or misuse of the categories, which is in reality a mere fault of +the judgement when not under due restraint from criticism, and +therefore not paying sufficient attention to the limits of the +sphere in which the pure understanding is allowed to exercise its +functions; but real principles which exhort us to break down all those +barriers, and to lay claim to a perfectly new field of cognition, +which recognizes no line of demarcation. Thus transcendental and +transcendent are not identical terms. The principles of the pure +understanding, which we have already propounded, ought to be of +empirical and not of transcendental use, that is, they are not +applicable to any object beyond the sphere of experience. A +principle which removes these limits, nay, which authorizes us to +overstep them, is called transcendent. If our criticism can succeed +in exposing the illusion in these pretended principles, those which +are limited in their employment to the sphere of experience may be +called, in opposition to the others, immanent principles of the pure +understanding. + +Logical illusion, which consists merely in the imitation of the form +of reason (the illusion in sophistical syllogisms), arises entirely +from a want of due attention to logical rules. So soon as the +attention is awakened to the case before us, this illusion totally +disappears. Transcendental illusion, on the contrary, does not cease +to exist, even after it has been exposed, and its nothingness +clearly perceived by means of transcendental criticism. Take, for +example, the illusion in the proposition: "The world must have a +beginning in time." The cause of this is as follows. In our reason, +subjectively considered as a faculty of human cognition, there exist +fundamental rules and maxims of its exercise, which have completely +the appearance of objective principles. Now from this cause it happens +that the subjective necessity of a certain connection of our +conceptions, is regarded as an objective necessity of the +determination of things in themselves. This illusion it is +impossible to avoid, just as we cannot avoid perceiving that the sea +appears to be higher at a distance than it is near the shore, +because we see the former by means of higher rays than the latter, +or, which is a still stronger case, as even the astronomer cannot +prevent himself from seeing the moon larger at its rising than some +time afterwards, although he is not deceived by this illusion. + +Transcendental dialectic will therefore content itself with exposing +the illusory appearance in transcendental judgements, and guarding +us against it; but to make it, as in the case of logical illusion, +entirely disappear and cease to be illusion is utterly beyond its +power. For we have here to do with a natural and unavoidable illusion, +which rests upon subjective principles and imposes these upon us as +objective, while logical dialectic, in the detection of sophisms, +has to do merely with an error in the logical consequence of the +propositions, or with an artificially constructed illusion, in +imitation of the natural error. There is, therefore, a natural and +unavoidable dialectic of pure reason--not that in which the bungler, +from want of the requisite knowledge, involves himself, nor that which +the sophist devises for the purpose of misleading, but that which is +an inseparable adjunct of human reason, and which, even after its +illusions have been exposed, does not cease to deceive, and +continually to lead reason into momentary errors, which it becomes +necessary continually to remove. + + + +II. Of Pure Reason as the Seat of Transcendental Illusory Appearance. + +A. OF REASON IN GENERAL. + +All our knowledge begins with sense, proceeds thence to +understanding, and ends with reason, beyond which nothing higher can +be discovered in the human mind for elaborating the matter of +intuition and subjecting it to the highest unity of thought. At this +stage of our inquiry it is my duty to give an explanation of this, +the highest faculty of cognition, and I confess I find myself here +in some difficulty. Of reason, as of the understanding, there is a +merely formal, that is, logical use, in which it makes abstraction +of all content of cognition; but there is also a real use, inasmuch +as it contains in itself the source of certain conceptions and principles, +which it does not borrow either from the senses or the +understanding. The former faculty has been long defined by logicians +as the faculty of mediate conclusion in contradistinction to immediate +conclusions (consequentiae immediatae); but the nature of the +latter, which itself generates conceptions, is not to be understood +from this definition. Now as a division of reason into a logical and +a transcendental faculty presents itself here, it becomes necessary +to seek for a higher conception of this source of cognition which shall +comprehend both conceptions. In this we may expect, according to the +analogy of the conceptions of the understanding, that the logical +conception will give us the key to the transcendental, and that the +table of the functions of the former will present us with the clue +to the conceptions of reason. + +In the former part of our transcendental logic, we defined the +understanding to be the faculty of rules; reason may be +distinguished from understanding as the faculty of principles. + +The term principle is ambiguous, and commonly signifies merely a +cognition that may be employed as a principle, although it is not in +itself, and as regards its proper origin, entitled to the distinction. +Every general proposition, even if derived from experience by the +process of induction, may serve as the major in a syllogism; but it +is not for that reason a principle. Mathematical axioms (for example, +there can be only one straight line between two points) are general +a priori cognitions, and are therefore rightly denominated principles, +relatively to the cases which can be subsumed under them. But I cannot +for this reason say that I cognize this property of a straight line +from principles--I cognize it only in pure intuition. + +Cognition from principles, then, is that cognition in which I +cognize the particular in the general by means of conceptions. Thus +every syllogism is a form of the deduction of a cognition from a +principle. For the major always gives a conception, through which +everything that is subsumed under the condition thereof is cognized +according to a principle. Now as every general cognition may serve +as the major in a syllogism, and the understanding presents us with +such general a priori propositions, they may be termed principles, +in respect of their possible use. + +But if we consider these principles of the pure understanding in +relation to their origin, we shall find them to be anything rather +than cognitions from conceptions. For they would not even be +possible a priori, if we could not rely on the assistance of pure +intuition (in mathematics), or on that of the conditions of a possible +experience. That everything that happens has a cause, cannot be +concluded from the general conception of that which happens; on the +contrary the principle of causality instructs us as to the mode of +obtaining from that which happens a determinate empirical conception. + +Synthetical cognitions from conceptions the understanding cannot +supply, and they alone are entitled to be called principles. At the +same time, all general propositions may be termed comparative +principles. + +It has been a long-cherished wish--that (who knows how late), may +one day, be happily accomplished--that the principles of the endless +variety of civil laws should be investigated and exposed; for in +this way alone can we find the secret of simplifying legislation. +But in this case, laws are nothing more than limitations of our +freedom upon conditions under which it subsists in perfect harmony +with itself; they consequently have for their object that which is +completely our own work, and of which we ourselves may be the cause +by means of these conceptions. But how objects as things in themselves- +how the nature of things is subordinated to principles and is to be +determined, according to conceptions, is a question which it seems +well nigh impossible to answer. Be this, however, as it may--for on +this point our investigation is yet to be made--it is at least +manifest from what we have said that cognition from principles is +something very different from cognition by means of the understanding, +which may indeed precede other cognitions in the form of a +principle, but in itself--in so far as it is synthetical--is neither +based upon mere thought, nor contains a general proposition drawn from +conceptions alone. + +The understanding may be a faculty for the production of unity of +phenomena by virtue of rules; the reason is a faculty for the +production of unity of rules (of the understanding) under +principles. Reason, therefore, never applies directly to experience, +or to any sensuous object; its object is, on the contrary, the +understanding, to the manifold cognition of which it gives a unity +a priori by means of conceptions--a unity which may be called rational +unity, and which is of a nature very different from that of the +unity produced by the understanding. + +The above is the general conception of the faculty of reason, in +so far as it has been possible to make it comprehensible in the +absence of examples. These will be given in the sequel. + + + +B. OF THE LOGICAL USE OF REASON. + +A distinction is commonly made between that which is immediately +cognized and that which is inferred or concluded. That in a figure +which is bounded by three straight lines there are three angles, is +an immediate cognition; but that these angles are together equal to +two right angles, is an inference or conclusion. Now, as we are constantly +employing this mode of thought and have thus become quite accustomed +to it, we no longer remark the above distinction, and, as in the +case of the so-called deceptions of sense, consider as immediately +perceived, what has really been inferred. In every reasoning or +syllogism, there is a fundamental proposition, afterwards a second +drawn from it, and finally the conclusion, which connects the truth +in the first with the truth in the second--and that infallibly. If +the judgement concluded is so contained in the first proposition that +it can be deduced from it without the meditation of a third notion, +the conclusion is called immediate (consequentia immediata); I prefer +the term conclusion of the understanding. But if, in addition to the +fundamental cognition, a second judgement is necessary for the +production of the conclusion, it is called a conclusion of the reason. +In the proposition: All men are mortal, are contained the +propositions: Some men are mortal, Nothing that is not mortal is a +man, and these are therefore immediate conclusions from the first. +On the other hand, the proposition: all the learned are mortal, is +not contained in the main proposition (for the conception of a learned +man does not occur in it), and it can be deduced from the main proposition +only by means of a mediating judgement. + +In every syllogism I first cogitate a rule (the major) by means of +the understanding. In the next place I subsume a cognition under the +condition of the rule (and this is the minor) by means of the +judgement. And finally I determine my cognition by means of the +predicate of the rule (this is the conclusio), consequently, I +determine it a priori by means of the reason. The relations, +therefore, which the major proposition, as the rule, represents +between a cognition and its condition, constitute the different +kinds of syllogisms. These are just threefold--analogously with all +judgements, in so far as they differ in the mode of expressing the +relation of a cognition in the understanding--namely, categorical, +hypothetical, and disjunctive. + +When as often happens, the conclusion is a judgement which may +follow from other given judgements, through which a perfectly +different object is cogitated, I endeavour to discover in the +understanding whether the assertion in this conclusion does not +stand under certain conditions according to a general rule. If I +find such a condition, and if the object mentioned in the conclusion +can be subsumed under the given condition, then this conclusion +follows from a rule which is also valid for other objects of +cognition. From this we see that reason endeavours to subject the +great variety of the cognitions of the understanding to the smallest +possible number of principles (general conditions), and thus to +produce in it the highest unity. + + + +C. OF THE PURE USE OF REASON. + +Can we isolate reason, and, if so, is it in this case a peculiar +source of conceptions and judgements which spring from it alone, and +through which it can be applied to objects; or is it merely a +subordinate faculty, whose duty it is to give a certain form to +given cognitions--a form which is called logical, and through which +the cognitions of the understanding are subordinated to each other, +and lower rules to higher (those, to wit, whose condition comprises +in its sphere the condition of the others), in so far as this can be +done by comparison? This is the question which we have at present to +answer. Manifold variety of rules and unity of principles is a +requirement of reason, for the purpose of bringing the understanding +into complete accordance with itself, just as understanding subjects +the manifold content of intuition to conceptions, and thereby +introduces connection into it. But this principle prescribes no law +to objects, and does not contain any ground of the possibility of +cognizing or of determining them as such, but is merely a subjective +law for the proper arrangement of the content of the understanding. +The purpose of this law is, by a comparison of the conceptions of +the understanding, to reduce them to the smallest possible number, +although, at the same time, it does not justify us in demanding from +objects themselves such a uniformity as might contribute to the +convenience and the enlargement of the sphere of the understanding, +or in expecting that it will itself thus receive from them objective +validity. In one word, the question is: "does reason in itself, that +is, does pure reason contain a priori synthetical principles and +rules, and what are those principles?" + +The formal and logical procedure of reason in syllogisms gives us +sufficient information in regard to the ground on which the +transcendental principle of reason in its pure synthetical cognition +will rest. + +1. Reason, as observed in the syllogistic process, is not applicable +to intuitions, for the purpose of subjecting them to rules--for this +is the province of the understanding with its categories--but to +conceptions and judgements. If pure reason does apply to objects and +the intuition of them, it does so not immediately, but mediately- +through the understanding and its judgements, which have a direct +relation to the senses and their intuition, for the purpose of +determining their objects. The unity of reason is therefore not the +unity of a possible experience, but is essentially different from this +unity, which is that of the understanding. That everything which +happens has a cause, is not a principle cognized and prescribed by +reason. This principle makes the unity of experience possible and +borrows nothing from reason, which, without a reference to possible +experience, could never have produced by means of mere conceptions +any such synthetical unity. + +2. Reason, in its logical use, endeavours to discover the general +condition of its judgement (the conclusion), and a syllogism is itself +nothing but a judgement by means of the subsumption of its condition +under a general rule (the major). Now as this rule may itself be +subjected to the same process of reason, and thus the condition of +the condition be sought (by means of a prosyllogism) as long as the +process can be continued, it is very manifest that the peculiar +principle of reason in its logical use is to find for the +conditioned cognition of the understanding the unconditioned whereby +the unity of the former is completed. + +But this logical maxim cannot be a principle of pure reason, +unless we admit that, if the conditioned is given, the whole series +of conditions subordinated to one another--a series which is consequently +itself unconditioned--is also given, that is, contained in the +object and its connection. + +But this principle of pure reason is evidently synthetical; for, +analytically, the conditioned certainly relates to some condition, +but not to the unconditioned. From this principle also there must +originate different synthetical propositions, of which the pure +understanding is perfectly ignorant, for it has to do only with +objects of a possible experience, the cognition and synthesis of which +is always conditioned. The unconditioned, if it does really exist, +must be especially considered in regard to the determinations which +distinguish it from whatever is conditioned, and will thus afford us +material for many a priori synthetical propositions. + +The principles resulting from this highest principle of pure +reason will, however, be transcendent in relation to phenomena, that +is to say, it will be impossible to make any adequate empirical use +of this principle. It is therefore completely different from all +principles of the understanding, the use made of which is entirely +immanent, their object and purpose being merely the possibility of +experience. Now our duty in the transcendental dialectic is as +follows. To discover whether the principle that the series of +conditions (in the synthesis of phenomena, or of thought in general) +extends to the unconditioned is objectively true, or not; what +consequences result therefrom affecting the empirical use of the +understanding, or rather whether there exists any such objectively +valid proposition of reason, and whether it is not, on the contrary, +a merely logical precept which directs us to ascend perpetually to +still higher conditions, to approach completeness in the series of +them, and thus to introduce into our cognition the highest possible +unity of reason. We must ascertain, I say, whether this requirement +of reason has not been regarded, by a misunderstanding, as a transcendental +principle of pure reason, which postulates a thorough completeness +in the series of conditions in objects themselves. We must show, +moreover, the misconceptions and illusions that intrude into +syllogisms, the major proposition of which pure reason has supplied--a +proposition which has perhaps more of the character of a petitio +than of a postulatum--and that proceed from experience upwards to +its conditions. The solution of these problems is our task in +transcendental dialectic, which we are about to expose even at its +source, that lies deep in human reason. We shall divide it into two +parts, the first of which will treat of the transcendent conceptions +of pure reason, the second of transcendent and dialectical syllogisms. + + + + +BOOK I. + +OF THE CONCEPTIONS OF PURE REASON. + +The conceptions of pure reason--we do not here speak of the +possibility of them--are not obtained by reflection, but by +inference or conclusion. The conceptions of understanding are also +cogitated a priori antecedently to experience, and render it possible; +but they contain nothing but the unity of reflection upon phenomena, +in so far as these must necessarily belong to a possible empirical +consciousness. Through them alone are cognition and the +determination of an object possible. It is from them, accordingly, +that we receive material for reasoning, and antecedently to them we +possess no a priori conceptions of objects from which they might be +deduced, On the other hand, the sole basis of their objective +reality consists in the necessity imposed on them, as containing the +intellectual form of all experience, of restricting their +application and influence to the sphere of experience. + +But the term, conception of reason, or rational conception, itself +indicates that it does not confine itself within the limits of +experience, because its object-matter is a cognition, of which every +empirical cognition is but a part--nay, the whole of possible +experience may be itself but a part of it--a cognition to which no +actual experience ever fully attains, although it does always +pertain to it. The aim of rational conceptions is the comprehension, +as that of the conceptions of understanding is the understanding of +perceptions. If they contain the unconditioned, they relate to that +to which all experience is subordinate, but which is never itself an +object of experience--that towards which reason tends in all its +conclusions from experience, and by the standard of which it estimates +the degree of their empirical use, but which is never itself an +element in an empirical synthesis. If, notwithstanding, such +conceptions possess objective validity, they may be called conceptus +ratiocinati (conceptions legitimately concluded); in cases where +they do not, they have been admitted on account of having the +appearance of being correctly concluded, and may be called conceptus +ratiocinantes (sophistical conceptions). But as this can only be +sufficiently demonstrated in that part of our treatise which relates +to the dialectical conclusions of reason, we shall omit any +consideration of it in this place. As we called the pure conceptions +of the understanding categories, we shall also distinguish those of +pure reason by a new name and call them transcendental ideas. These +terms, however, we must in the first place explain and justify. + + + +SECTION I--Of Ideas in General. + +Despite the great wealth of words which European languages +possess, the thinker finds himself often at a loss for an expression +exactly suited to his conception, for want of which he is unable to +make himself intelligible either to others or to himself. To coin +new words is a pretension to legislation in language which is seldom +successful; and, before recourse is taken to so desperate an +expedient, it is advisable to examine the dead and learned +languages, with the hope and the probability that we may there meet +with some adequate expression of the notion we have in our minds. In +this case, even if the original meaning of the word has become +somewhat uncertain, from carelessness or want of caution on the part +of the authors of it, it is always better to adhere to and confirm +its proper meaning--even although it may be doubtful whether it was +formerly used in exactly this sense--than to make our labour vain by +want of sufficient care to render ourselves intelligible. + +For this reason, when it happens that there exists only a single +word to express a certain conception, and this word, in its usual +acceptation, is thoroughly adequate to the conception, the accurate +distinction of which from related conceptions is of great +importance, we ought not to employ the expression improvidently, or, +for the sake of variety and elegance of style, use it as a synonym +for other cognate words. It is our duty, on the contrary, carefully +to preserve its peculiar signification, as otherwise it easily happens +that when the attention of the reader is no longer particularly +attracted to the expression, and it is lost amid the multitude of +other words of very different import, the thought which it conveyed, +and which it alone conveyed, is lost with it. + +Plato employed the expression idea in a way that plainly showed he +meant by it something which is never derived from the senses, but +which far transcends even the conceptions of the understanding (with +which Aristotle occupied himself), inasmuch as in experience nothing +perfectly corresponding to them could be found. Ideas are, according +to him, archetypes of things themselves, and not merely keys to +possible experiences, like the categories. In his view they flow +from the highest reason, by which they have been imparted to human +reason, which, however, exists no longer in its original state, but +is obliged with great labour to recall by reminiscence--which is called +philosophy--the old but now sadly obscured ideas. I will not here +enter upon any literary investigation of the sense which this +sublime philosopher attached to this expression. I shall content +myself with remarking that it is nothing unusual, in common +conversation as well as in written works, by comparing the thoughts +which an author has delivered upon a subject, to understand him better +than he understood himself inasmuch as he may not have sufficiently +determined his conception, and thus have sometimes spoken, nay even +thought, in opposition to his own opinions. + +Plato perceived very clearly that our faculty of cognition has the +feeling of a much higher vocation than that of merely spelling out +phenomena according to synthetical unity, for the purpose of being +able to read them as experience, and that our reason naturally +raises itself to cognitions far too elevated to admit of the +possibility of an object given by experience corresponding to them- +cognitions which are nevertheless real, and are not mere phantoms of +the brain. + +This philosopher found his ideas especially in all that is +practical,* that is, which rests upon freedom, which in its turn ranks +under cognitions that are the peculiar product of reason. He who would +derive from experience the conceptions of virtue, who would make (as +many have really done) that, which at best can but serve as an +imperfectly illustrative example, a model for or the formation of a +perfectly adequate idea on the subject, would in fact transform virtue +into a nonentity changeable according to time and circumstance and +utterly incapable of being employed as a rule. On the contrary, +every one is conscious that, when any one is held up to him as a model +of virtue, he compares this so-called model with the true original +which he possesses in his own mind and values him according to this +standard. But this standard is the idea of virtue, in relation to +which all possible objects of experience are indeed serviceable as +examples--proofs of the practicability in a certain degree of that +which the conception of virtue demands--but certainly not as +archetypes. That the actions of man will never be in perfect +accordance with all the requirements of the pure ideas of reason, does +not prove the thought to be chimerical. For only through this idea +are all judgements as to moral merit or demerit possible; it +consequently lies at the foundation of every approach to moral +perfection, however far removed from it the obstacles in human nature- +indeterminable as to degree--may keep us. + +[*Footnote: He certainly extended the application of his conception +to speculative cognitions also, provided they were given pure and +completely a priori, nay, even to mathematics, although this science +cannot possess an object otherwhere than in Possible experience. I +cannot follow him in this, and as little can I follow him in his +mystical deduction of these ideas, or in his hypostatization of +them; although, in truth, the elevated and exaggerated language +which he employed in describing them is quite capable of an +interpretation more subdued and more in accordance with fact and the +nature of things.] + +The Platonic Republic has become proverbial as an example--and a +striking one--of imaginary perfection, such as can exist only in the +brain of the idle thinker; and Brucker ridicules the philosopher for +maintaining that a prince can never govern well, unless he is +participant in the ideas. But we should do better to follow up this +thought and, where this admirable thinker leaves us without +assistance, employ new efforts to place it in clearer light, rather +than carelessly fling it aside as useless, under the very miserable +and pernicious pretext of impracticability. A constitution of the +greatest possible human freedom according to laws, by which the +liberty of every individual can consist with the liberty of every +other (not of the greatest possible happiness, for this follows +necessarily from the former), is, to say the least, a necessary +idea, which must be placed at the foundation not only of the first +plan of the constitution of a state, but of all its laws. And, in +this, it not necessary at the outset to take account of the +obstacles which lie in our way--obstacles which perhaps do not +necessarily arise from the character of human nature, but rather +from the previous neglect of true ideas in legislation. For there is +nothing more pernicious and more unworthy of a philosopher, than the +vulgar appeal to a so-called adverse experience, which indeed would +not have existed, if those institutions had been established at the +proper time and in accordance with ideas; while, instead of this, +conceptions, crude for the very reason that they have been drawn +from experience, have marred and frustrated all our better views and +intentions. The more legislation and government are in harmony with +this idea, the more rare do punishments become and thus it is quite +reasonable to maintain, as Plato did, that in a perfect state no +punishments at all would be necessary. Now although a perfect state +may never exist, the idea is not on that account the less just, +which holds up this maximum as the archetype or standard of a +constitution, in order to bring legislative government always nearer +and nearer to the greatest possible perfection. For at what precise +degree human nature must stop in its progress, and how wide must be +the chasm which must necessarily exist between the idea and its +realization, are problems which no one can or ought to determine- +and for this reason, that it is the destination of freedom to overstep +all assigned limits between itself and the idea. + +But not only in that wherein human reason is a real causal agent and +where ideas are operative causes (of actions and their objects), +that is to say, in the region of ethics, but also in regard to +nature herself, Plato saw clear proofs of an origin from ideas. A +plant, and animal, the regular order of nature--probably also the +disposition of the whole universe--give manifest evidence that they +are possible only by means of and according to ideas; that, indeed, +no one creature, under the individual conditions of its existence, +perfectly harmonizes with the idea of the most perfect of its kind- +just as little as man with the idea of humanity, which nevertheless +he bears in his soul as the archetypal standard of his actions; that, +notwithstanding, these ideas are in the highest sense individually, +unchangeably, and completely determined, and are the original causes +of things; and that the totality of connected objects in the +universe is alone fully adequate to that idea. Setting aside the +exaggerations of expression in the writings of this philosopher, the +mental power exhibited in this ascent from the ectypal mode of +regarding the physical world to the architectonic connection thereof +according to ends, that is, ideas, is an effort which deserves +imitation and claims respect. But as regards the principles of ethics, +of legislation, and of religion, spheres in which ideas alone render +experience possible, although they never attain to full expression +therein, he has vindicated for himself a position of peculiar merit, +which is not appreciated only because it is judged by the very +empirical rules, the validity of which as principles is destroyed by +ideas. For as regards nature, experience presents us with rules and +is the source of truth, but in relation to ethical laws experience +is the parent of illusion, and it is in the highest degree reprehensible +to limit or to deduce the laws which dictate what I ought to do, from +what is done. + +We must, however, omit the consideration of these important +subjects, the development of which is in reality the peculiar duty +and dignity of philosophy, and confine ourselves for the present to +the more humble but not less useful task of preparing a firm foundation +for those majestic edifices of moral science. For this foundation +has been hitherto insecure from the many subterranean passages which +reason in its confident but vain search for treasures has made in +all directions. Our present duty is to make ourselves perfectly +acquainted with the transcendental use made of pure reason, its +principles and ideas, that we may be able properly to determine and +value its influence and real worth. But before bringing these +introductory remarks to a close, I beg those who really have +philosophy at heart--and their number is but small--if they shall find +themselves convinced by the considerations following as well as by +those above, to exert themselves to preserve to the expression idea +its original signification, and to take care that it be not lost among +those other expressions by which all sorts of representations are +loosely designated--that the interests of science may not thereby +suffer. We are in no want of words to denominate adequately every mode +of representation, without the necessity of encroaching upon terms +which are proper to others. The following is a graduated list of them. +The genus is representation in general (representatio). Under it +stands representation with consciousness (perceptio). A perception +which relates solely to the subject as a modification of its state, +is a sensation (sensatio), an objective perception is a cognition +(cognitio). A cognition is either an intuition or a conception +(intuitus vel conceptus). The former has an immediate relation to +the object and is singular and individual; the latter has but a +mediate relation, by means of a characteristic mark which may be +common to several things. A conception is either empirical or pure. +A pure conception, in so far as it has its origin in the understanding +alone, and is not the conception of a pure sensuous image, is called +notio. A conception formed from notions, which transcends the +possibility of experience, is an idea, or a conception of reason. To +one who has accustomed himself to these distinctions, it must be quite +intolerable to hear the representation of the colour red called an +idea. It ought not even to be called a notion or conception of +understanding. + + + +SECTION II. Of Transcendental Ideas. + +Transcendental analytic showed us how the mere logical form of our +cognition can contain the origin of pure conceptions a priori, +conceptions which represent objects antecedently to all experience, +or rather, indicate the synthetical unity which alone renders possible +an empirical cognition of objects. The form of judgements--converted +into a conception of the synthesis of intuitions--produced the categories +which direct the employment of the understanding in experience. This +consideration warrants us to expect that the form of syllogisms, +when applied to synthetical unity of intuitions, following the rule +of the categories, will contain the origin of particular a priori +conceptions, which we may call pure conceptions of reason or +transcendental ideas, and which will determine the use of the +understanding in the totality of experience according to principles. + +The function of reason in arguments consists in the universality +of a cognition according to conceptions, and the syllogism itself is +a judgement which is determined a priori in the whole extent of its +condition. The proposition: "Caius is mortal," is one which may be +obtained from experience by the aid of the understanding alone; but +my wish is to find a conception which contains the condition under +which the predicate of this judgement is given--in this case, the +conception of man--and after subsuming under this condition, taken +in its whole extent (all men are mortal), I determine according to +it the cognition of the object thought, and say: "Caius is mortal." + +Hence, in the conclusion of a syllogism we restrict a predicate to +a certain object, after having thought it in the major in its whole +extent under a certain condition. This complete quantity of the extent +in relation to such a condition is called universality +(universalitas). To this corresponds totality (universitas) of +conditions in the synthesis of intuitions. The transcendental +conception of reason is therefore nothing else than the conception +of the totality of the conditions of a given conditioned. Now as the +unconditioned alone renders possible totality of conditions, and, +conversely, the totality of conditions is itself always unconditioned; +a pure rational conception in general can be defined and explained +by means of the conception of the unconditioned, in so far as it +contains a basis for the synthesis of the conditioned. + +To the number of modes of relation which the understanding cogitates +by means of the categories, the number of pure rational conceptions +will correspond. We must therefore seek for, first, an unconditioned +of the categorical synthesis in a subject; secondly, of the +hypothetical synthesis of the members of a series; thirdly, of the +disjunctive synthesis of parts in a system. + +There are exactly the same number of modes of syllogisms, each of +which proceeds through prosyllogisms to the unconditioned--one to +the subject which cannot be employed as predicate, another to the +presupposition which supposes nothing higher than itself, and the +third to an aggregate of the members of the complete division of a +conception. Hence the pure rational conceptions of totality in the +synthesis of conditions have a necessary foundation in the nature of +human reason--at least as modes of elevating the unity of the +understanding to the unconditioned. They may have no valid +application, corresponding to their transcendental employment, in +concreto, and be thus of no greater utility than to direct the +understanding how, while extending them as widely as possible, to +maintain its exercise and application in perfect consistence and +harmony. + +But, while speaking here of the totality of conditions and of the +unconditioned as the common title of all conceptions of reason, we +again light upon an expression which we find it impossible to dispense +with, and which nevertheless, owing to the ambiguity attaching to it +from long abuse, we cannot employ with safety. The word absolute is +one of the few words which, in its original signification, was +perfectly adequate to the conception it was intended to convey--a +conception which no other word in the same language exactly suits, +and the loss--or, which is the same thing, the incautious and loose +employment--of which must be followed by the loss of the conception +itself. And, as it is a conception which occupies much of the +attention of reason, its loss would be greatly to the detriment of +all transcendental philosophy. The word absolute is at present +frequently used to denote that something can be predicated of a +thing considered in itself and intrinsically. In this sense absolutely +possible would signify that which is possible in itself (interne)- +which is, in fact, the least that one can predicate of an object. On +the other hand, it is sometimes employed to indicate that a thing is +valid in all respects--for example, absolute sovereignty. Absolutely +possible would in this sense signify that which is possible in all +relations and in every respect; and this is the most that can be +predicated of the possibility of a thing. Now these significations +do in truth frequently coincide. Thus, for example, that which is +intrinsically impossible, is also impossible in all relations, that +is, absolutely impossible. But in most cases they differ from each +other toto caelo, and I can by no means conclude that, because a thing +is in itself possible, it is also possible in all relations, and +therefore absolutely. Nay, more, I shall in the sequel show that +absolute necessity does not by any means depend on internal necessity, +and that, therefore, it must not be considered as synonymous with +it. Of an opposite which is intrinsically impossible, we may affirm +that it is in all respects impossible, and that, consequently, the +thing itself, of which this is the opposite, is absolutely +necessary; but I cannot reason conversely and say, the opposite of +that which is absolutely necessary is intrinsically impossible, that +is, that the absolute necessity of things is an internal necessity. +For this internal necessity is in certain cases a mere empty word with +which the least conception cannot be connected, while the conception +of the necessity of a thing in all relations possesses very peculiar +determinations. Now as the loss of a conception of great utility in +speculative science cannot be a matter of indifference to the +philosopher, I trust that the proper determination and careful +preservation of the expression on which the conception depends will +likewise be not indifferent to him. + +In this enlarged signification, then, shall I employ the word +absolute, in opposition to that which is valid only in some particular +respect; for the latter is restricted by conditions, the former is +valid without any restriction whatever. + +Now the transcendental conception of reason has for its object +nothing else than absolute totality in the synthesis of conditions +and does not rest satisfied till it has attained to the absolutely, +that is, in all respects and relations, unconditioned. For pure reason +leaves to the understanding everything that immediately relates to +the object of intuition or rather to their synthesis in imagination. +The former restricts itself to the absolute totality in the employment +of the conceptions of the understanding and aims at carrying out the +synthetical unity which is cogitated in the category, even to the +unconditioned. This unity may hence be called the rational unity of +phenomena, as the other, which the category expresses, may be termed +the unity of the understanding. Reason, therefore, has an immediate +relation to the use of the understanding, not indeed in so far as +the latter contains the ground of possible experience (for the +conception of the absolute totality of conditions is not a +conception that can be employed in experience, because no experience +is unconditioned), but solely for the purpose of directing it to a +certain unity, of which the understanding has no conception, and the +aim of which is to collect into an absolute whole all acts of the +understanding. Hence the objective employment of the pure +conceptions of reason is always transcendent, while that of the pure +conceptions of the understanding must, according to their nature, be +always immanent, inasmuch as they are limited to possible experience. + +I understand by idea a necessary conception of reason, to which no +corresponding object can be discovered in the world of sense. +Accordingly, the pure conceptions of reason at present under +consideration are transcendental ideas. They are conceptions of pure +reason, for they regard all empirical cognition as determined by means +of an absolute totality of conditions. They are not mere fictions, +but natural and necessary products of reason, and have hence a necessary +relation to the whole sphere of the exercise of the understanding. +And, finally, they are transcendent, and overstep the limits of all +experiences, in which, consequently, no object can ever be presented +that would be perfectly adequate to a transcendental idea. When we +use the word idea, we say, as regards its object (an object of the +pure understanding), a great deal, but as regards its subject (that +is, in respect of its reality under conditions of experience), exceedingly +little, because the idea, as the conception of a maximum, can never +be completely and adequately presented in concreto. Now, as in the +merely speculative employment of reason the latter is properly the +sole aim, and as in this case the approximation to a conception, which +is never attained in practice, is the same thing as if the conception +were non-existent--it is commonly said of the conception of this kind, +"it is only an idea." So we might very well say, "the absolute +totality of all phenomena is only an idea," for, as we never can +present an adequate representation of it, it remains for us a +problem incapable of solution. On the other hand, as in the +practical use of the understanding we have only to do with action +and practice according to rules, an idea of pure reason can always +be given really in concreto, although only partially, nay, it is the +indispensable condition of all practical employment of reason. The +practice or execution of the idea is always limited and defective, +but nevertheless within indeterminable boundaries, consequently always +under the influence of the conception of an absolute perfection. And +thus the practical idea is always in the highest degree fruitful, +and in relation to real actions indispensably necessary. In the +idea, pure reason possesses even causality and the power of +producing that which its conception contains. Hence we cannot say of +wisdom, in a disparaging way, "it is only an idea." For, for the +very reason that it is the idea of the necessary unity of all possible +aims, it must be for all practical exertions and endeavours the +primitive condition and rule--a rule which, if not constitutive, is +at least limitative. + +Now, although we must say of the transcendental conceptions of +reason, "they are only ideas," we must not, on this account, look upon +them as superfluous and nugatory. For, although no object can be +determined by them, they can be of great utility, unobserved and at +the basis of the edifice of the understanding, as the canon for its +extended and self-consistent exercise--a canon which, indeed, does +not enable it to cognize more in an object than it would cognize by +the help of its own conceptions, but which guides it more securely +in its cognition. Not to mention that they perhaps render possible +a transition from our conceptions of nature and the non-ego to the +practical conceptions, and thus produce for even ethical ideas +keeping, so to speak, and connection with the speculative cognitions +of reason. The explication of all this must be looked for in the +sequel. + +But setting aside, in conformity with our original purpose, the +consideration of the practical ideas, we proceed to contemplate reason +in its speculative use alone, nay, in a still more restricted +sphere, to wit, in the transcendental use; and here must strike into +the same path which we followed in our deduction of the categories. +That is to say, we shall consider the logical form of the cognition +of reason, that we may see whether reason may not be thereby a source +of conceptions which enables us to regard objects in themselves as +determined synthetically a priori, in relation to one or other of +the functions of reason. + +Reason, considered as the faculty of a certain logical form of +cognition, is the faculty of conclusion, that is, of mediate +judgement--by means of the subsumption of the condition of a possible +judgement under the condition of a given judgement. The given judgement +is the general rule (major). The subsumption of the condition of +another possible judgement under the condition of the rule is the +minor. The actual judgement, which enounces the assertion of the rule +in the subsumed case, is the conclusion (conclusio). The rule +predicates something generally under a certain condition. The condition +of the rule is satisfied in some particular case. It follows that what +was valid in general under that condition must also be considered as +valid in the particular case which satisfies this condition. It is very +plain that reason attains to a cognition, by means of acts of the +understanding which constitute a series of conditions. When I arrive at +the proposition, "All bodies are changeable," by beginning with the +more remote cognition (in which the conception of body does not appear, +but which nevertheless contains the condition of that conception), "All +compound is changeable," by proceeding from this to a less remote +cognition, which stands under the condition of the former, "Bodies are +compound," and hence to a third, which at length connects for me the +remote cognition (changeable) with the one before me, "Consequently, +bodies are changeable"--I have arrived at a cognition (conclusion) +through a series of conditions (premisses). Now every series, whose +exponent (of the categorical or hypothetical judgement) is given, can +be continued; consequently the same procedure of reason conducts us to +the ratiocinatio polysyllogistica, which is a series of syllogisms, +that can be continued either on the side of the conditions (per +prosyllogismos) or of the conditioned (per episyllogismos) to an +indefinite extent. + +But we very soon perceive that the chain or series of prosyllogisms, +that is, of deduced cognitions on the side of the grounds or +conditions of a given cognition, in other words, the ascending +series of syllogisms must have a very different relation to the +faculty of reason from that of the descending series, that is, the +progressive procedure of reason on the side of the conditioned by +means of episyllogisms. For, as in the former case the cognition +(conclusio) is given only as conditioned, reason can attain to this +cognition only under the presupposition that all the members of the +series on the side of the conditions are given (totality in the series +of premisses), because only under this supposition is the judgement +we may be considering possible a priori; while on the side of the +conditioned or the inferences, only an incomplete and becoming, and +not a presupposed or given series, consequently only a potential +progression, is cogitated. Hence, when a cognition is contemplated +as conditioned, reason is compelled to consider the series of +conditions in an ascending line as completed and given in their +totality. But if the very same condition is considered at the same +time as the condition of other cognitions, which together constitute +a series of inferences or consequences in a descending line, reason +may preserve a perfect indifference, as to how far this progression +may extend a parte posteriori, and whether the totality of this series +is possible, because it stands in no need of such a series for the +purpose of arriving at the conclusion before it, inasmuch as this +conclusion is sufficiently guaranteed and determined on grounds a +parte priori. It may be the case, that upon the side of the conditions +the series of premisses has a first or highest condition, or it may +not possess this, and so be a parte priori unlimited; but it must, +nevertheless, contain totality of conditions, even admitting that we +never could succeed in completely apprehending it; and the whole +series must be unconditionally true, if the conditioned, which is +considered as an inference resulting from it, is to be held as true. +This is a requirement of reason, which announces its cognition as +determined a priori and as necessary, either in itself--and in this +case it needs no grounds to rest upon--or, if it is deduced, as a +member of a series of grounds, which is itself unconditionally true. + + + +SECTION III. System of Transcendental Ideas. + +We are not at present engaged with a logical dialectic, which +makes complete abstraction of the content of cognition and aims only +at unveiling the illusory appearance in the form of syllogisms. Our +subject is transcendental dialectic, which must contain, completely +a priori, the origin of certain cognitions drawn from pure reason, +and the origin of certain deduced conceptions, the object of which +cannot be given empirically and which therefore lie beyond the +sphere of the faculty of understanding. We have observed, from the +natural relation which the transcendental use of our cognition, in +syllogisms as well as in judgements, must have to the logical, that +there are three kinds of dialectical arguments, corresponding to the +three modes of conclusion, by which reason attains to cognitions on +principles; and that in all it is the business of reason to ascend +from the conditioned synthesis, beyond which the understanding never +proceeds, to the unconditioned which the understanding never can +reach. + +Now the most general relations which can exist in our +representations are: 1st, the relation to the subject; 2nd, the +relation to objects, either as phenomena, or as objects of thought +in general. If we connect this subdivision with the main division, +all the relations of our representations, of which we can form either +a conception or an idea, are threefold: 1. The relation to the +subject; 2. The relation to the manifold of the object as a +phenomenon; 3. The relation to all things in general. + +Now all pure conceptions have to do in general with the +synthetical unity of representations; conceptions of pure reason +(transcendental ideas), on the other hand, with the unconditional +synthetical unity of all conditions. It follows that all +transcendental ideas arrange themselves in three classes, the first +of which contains the absolute (unconditioned) unity of the thinking +subject, the second the absolute unity of the series of the conditions +of a phenomenon, the third the absolute unity of the condition of +all objects of thought in general. + +The thinking subject is the object-matter of Psychology; the sum +total of all phenomena (the world) is the object-matter of +Cosmology; and the thing which contains the highest condition of the +possibility of all that is cogitable (the being of all beings) is +the object-matter of all Theology. Thus pure reason presents us with +the idea of a transcendental doctrine of the soul (psychologia +rationalis), of a transcendental science of the world (cosmologia +rationalis), and finally of a transcendental doctrine of God +(theologia transcendentalis). Understanding cannot originate even +the outline of any of these sciences, even when connected with the +highest logical use of reason, that is, all cogitable syllogisms- +for the purpose of proceeding from one object (phenomenon) to all +others, even to the utmost limits of the empirical synthesis. They +are, on the contrary, pure and genuine products, or problems, of +pure reason. + +What modi of the pure conceptions of reason these transcendental +ideas are will be fully exposed in the following chapter. They +follow the guiding thread of the categories. For pure reason never +relates immediately to objects, but to the conceptions of these +contained in the understanding. In like manner, it will be made +manifest in the detailed explanation of these ideas--how reason, +merely through the synthetical use of the same function which it +employs in a categorical syllogism, necessarily attains to the +conception of the absolute unity of the thinking subject--how the +logical procedure in hypothetical ideas necessarily produces the +idea of the absolutely unconditioned in a series of given +conditions, and finally--how the mere form of the disjunctive +syllogism involves the highest conception of a being of all beings: +a thought which at first sight seems in the highest degree +paradoxical. + +An objective deduction, such as we were able to present in the +case of the categories, is impossible as regards these +transcendental ideas. For they have, in truth, no relation to any +object, in experience, for the very reason that they are only ideas. +But a subjective deduction of them from the nature of our reason is +possible, and has been given in the present chapter. + +It is easy to perceive that the sole aim of pure reason is the +absolute totality of the synthesis on the side of the conditions, +and that it does not concern itself with the absolute completeness +on the Part of the conditioned. For of the former alone does she stand +in need, in order to preposit the whole series of conditions, and thus +present them to the understanding a priori. But if we once have a +completely (and unconditionally) given condition, there is no +further necessity, in proceeding with the series, for a conception +of reason; for the understanding takes of itself every step +downward, from the condition to the conditioned. Thus the +transcendental ideas are available only for ascending in the series +of conditions, till we reach the unconditioned, that is, principles. +As regards descending to the conditioned, on the other hand, we find +that there is a widely extensive logical use which reason makes of +the laws of the understanding, but that a transcendental use thereof +is impossible; and that when we form an idea of the absolute totality +of such a synthesis, for example, of the whole series of all future +changes in the world, this idea is a mere ens rationis, an arbitrary +fiction of thought, and not a necessary presupposition of reason. +For the possibility of the conditioned presupposes the totality of +its conditions, but not of its consequences. Consequently, this conception +is not a transcendental idea--and it is with these alone that we are +at present occupied. + +Finally, it is obvious that there exists among the transcendental +ideas a certain connection and unity, and that pure reason, by means +of them, collects all its cognitions into one system. From the +cognition of self to the cognition of the world, and through these +to the supreme being, the progression is so natural, that it seems +to resemble the logical march of reason from the premisses to the +conclusion.* Now whether there lies unobserved at the foundation of +these ideas an analogy of the same kind as exists between the +logical and transcendental procedure of reason, is another of those +questions, the answer to which we must not expect till we arrive at +a more advanced stage in our inquiries. In this cursory and +preliminary view, we have, meanwhile, reached our aim. For we have +dispelled the ambiguity which attached to the transcendental +conceptions of reason, from their being commonly mixed up with other +conceptions in the systems of philosophers, and not properly +distinguished from the conceptions of the understanding; we have +exposed their origin and, thereby, at the same time their +determinate number, and presented them in a systematic connection, +and have thus marked out and enclosed a definite sphere for pure reason. + + +[*Footnote: The science of Metaphysics has for the proper object of +its inquiries only three grand ideas: GOD, FREEDOM, and IMMORTALITY, +and it aims at showing, that the second conception, conjoined with +the first, must lead to the third, as a necessary conclusion. All the +other subjects with which it occupies itself, are merely means for +the attainment and realization of these ideas. It does not require +these ideas for the construction of a science of nature, but, on the +contrary, for the purpose of passing beyond the sphere of nature. A +complete insight into and comprehension of them would render Theology, +Ethics, and, through the conjunction of both, Religion, solely +dependent on the speculative faculty of reason. In a systematic +representation of these ideas the above-mentioned arrangement--the +synthetical one--would be the most suitable; but in the +investigation which must necessarily precede it, the analytical, which +reverses this arrangement, would be better adapted to our purpose, +as in it we should proceed from that which experience immediately +presents to us--psychology, to cosmology, and thence to theology.] + + + +BOOK II. + +OF THE DIALECTICAL PROCEDURE OF PURE REASON. + +It may be said that the object of a merely transcendental idea is +something of which we have no conception, although the idea may be +a necessary product of reason according to its original laws. For, +in fact, a conception of an object that is adequate to the idea given +by reason, is impossible. For such an object must be capable of +being presented and intuited in a Possible experience. But we should +express our meaning better, and with less risk of being misunderstood, +if we said that we can have no knowledge of an object, which perfectly +corresponds to an idea, although we may possess a problematical +conception thereof. + +Now the transcendental (subjective) reality at least of the pure +conceptions of reason rests upon the fact that we are led to such +ideas by a necessary procedure of reason. There must therefore be +syllogisms which contain no empirical premisses, and by means of which +we conclude from something that we do know, to something of which we +do not even possess a conception, to which we, nevertheless, by an +unavoidable illusion, ascribe objective reality. Such arguments are, +as regards their result, rather to be termed sophisms than syllogisms, +although indeed, as regards their origin, they are very well +entitled to the latter name, inasmuch as they are not fictions or +accidental products of reason, but are necessitated by its very +nature. They are sophisms, not of men, but of pure reason herself, +from which the Wisest cannot free himself. After long labour he may +be able to guard against the error, but he can never be thoroughly +rid of the illusion which continually mocks and misleads him. + +Of these dialectical arguments there are three kinds, +corresponding to the number of the ideas which their conclusions +present. In the argument or syllogism of the first class, I +conclude, from the transcendental conception of the subject contains +no manifold, the absolute unity of the subject itself, of which I +cannot in this manner attain to a conception. This dialectical +argument I shall call the transcendental paralogism. The second +class of sophistical arguments is occupied with the transcendental +conception of the absolute totality of the series of conditions for +a given phenomenon, and I conclude, from the fact that I have always +a self-contradictory conception of the unconditioned synthetical unity +of the series upon one side, the truth of the opposite unity, of which +I have nevertheless no conception. The condition of reason in these +dialectical arguments, I shall term the antinomy of pure reason. +Finally, according to the third kind of sophistical argument, I +conclude, from the totality of the conditions of thinking objects in +general, in so far as they can be given, the absolute synthetical +unity of all conditions of the possibility of things in general; +that is, from things which I do not know in their mere +transcendental conception, I conclude a being of all beings which I +know still less by means of a transcendental conception, and of +whose unconditioned necessity I can form no conception whatever. +This dialectical argument I shall call the ideal of pure reason. + + + +CHAPTER I. Of the Paralogisms of Pure Reason. + +The logical paralogism consists in the falsity of an argument in +respect of its form, be the content what it may. But a +transcendental paralogism has a transcendental foundation, and +concludes falsely, while the form is correct and unexceptionable. In +this manner the paralogism has its foundation in the nature of human +reason, and is the parent of an unavoidable, though not insoluble, +mental illusion. + +We now come to a conception which was not inserted in the general +list of transcendental conceptions, and yet must be reckoned with +them, but at the same time without in the least altering, or +indicating a deficiency in that table. This is the conception, or, +if the term is preferred, the judgement, "I think." But it is +readily perceived that this thought is as it were the vehicle of all +conceptions in general, and consequently of transcendental conceptions +also, and that it is therefore regarded as a transcendental +conception, although it can have no peculiar claim to be so ranked, +inasmuch as its only use is to indicate that all thought is +accompanied by consciousness. At the same time, pure as this +conception is from empirical content (impressions of the senses), it +enables us to distinguish two different kinds of objects. "I," as +thinking, am an object of the internal sense, and am called soul. That +which is an object of the external senses is called body. Thus the +expression, "I," as a thinking being, designates the object-matter +of psychology, which may be called "the rational doctrine of the +soul," inasmuch as in this science I desire to know nothing of the +soul but what, independently of all experience (which determines me +in concreto), may be concluded from this conception "I," in so far +as it appears in all thought. + +Now, the rational doctrine of the soul is really an undertaking of +this kind. For if the smallest empirical element of thought, if any +particular perception of my internal state, were to be introduced +among the grounds of cognition of this science, it would not be a +rational, but an empirical doctrine of the soul. We have thus before +us a pretended science, raised upon the single proposition, "I think," +whose foundation or want of foundation we may very properly, and +agreeably with the nature of a transcendental philosophy, here +examine. It ought not to be objected that in this proposition, which +expresses the perception of one's self, an internal experience is +asserted, and that consequently the rational doctrine of the soul +which is founded upon it, is not pure, but partly founded upon an +empirical principle. For this internal perception is nothing more than +the mere apperception, "I think," which in fact renders all +transcendental conceptions possible, in which we say, "I think +substance, cause, etc." For internal experience in general and its +possibility, or perception in general, and its relation to other +perceptions, unless some particular distinction or determination +thereof is empirically given, cannot be regarded as empirical +cognition, but as cognition of the empirical, and belongs to the +investigation of the possibility of every experience, which is +certainly transcendental. The smallest object of experience (for +example, only pleasure or pain), that should be included in the +general representation of self-consciousness, would immediately change +the rational into an empirical psychology. + +"I think" is therefore the only text of rational psychology, from +which it must develop its whole system. It is manifest that this +thought, when applied to an object (myself), can contain nothing but +transcendental predicates thereof; because the least empirical +predicate would destroy the purity of the science and its independence +of all experience. + +But we shall have to follow here the guidance of the categories- +only, as in the present case a thing, "I," as thinking being, is at +first given, we shall--not indeed change the order of the categories +as it stands in the table--but begin at the category of substance, +by which at the a thing in itself is represented and proceeds +backwards through the series. The topic of the rational doctrine of +the soul, from which everything else it may contain must be deduced, +is accordingly as follows: + + + 1 2 + The Soul is SUBSTANCE As regards its quality + it is SIMPLE + + 3 + As regards the different + times in which it exists, + it is numerically identical, + that is UNITY, not Plurality. + + 4 + It is in relation to possible objects in space* + + +[*Footnote: The reader, who may not so easily perceive the +psychological sense of these expressions, taken here in their +transcendental abstraction, and cannot guess why the latter attribute +of the soul belongs to the category of existence, will find the +expressions sufficiently explained and justified in the sequel. I have, +moreover, to apologize for the Latin terms which have been employed, +instead of their German synonyms, contrary to the rules of correct +writing. But I judged it better to sacrifice elegance to perspicuity.] + +From these elements originate all the conceptions of pure +psychology, by combination alone, without the aid of any other +principle. This substance, merely as an object of the internal +sense, gives the conception of Immateriality; as simple substance, +that of Incorruptibility; its identity, as intellectual substance, +gives the conception of Personality; all these three together, +Spirituality. Its relation to objects in space gives us the conception +of connection (commercium) with bodies. Thus it represents thinking +substance as the principle of life in matter, that is, as a soul +(anima), and as the ground of Animality; and this, limited and +determined by the conception of spirituality, gives us that of +Immortality. + +Now to these conceptions relate four paralogisms of a transcendental +psychology, which is falsely held to be a science of pure reason, +touching the nature of our thinking being. We can, however, lay at +the foundation of this science nothing but the simple and in itself +perfectly contentless representation "I" which cannot even be called +a conception, but merely a consciousness which accompanies all +conceptions. By this "I," or "He," or "It," who or which thinks, +nothing more is represented than a transcendental subject of thought += x, which is cognized only by means of the thoughts that are its +predicates, and of which, apart from these, we cannot form the least +conception. Hence in a perpetual circle, inasmuch as we must always +employ it, in order to frame any judgement respecting it. And this +inconvenience we find it impossible to rid ourselves of, because +consciousness in itself is not so much a representation distinguishing +a particular object, as a form of representation in general, in so +far as it may be termed cognition; for in and by cognition alone do +I think anything. + +It must, however, appear extraordinary at first sight that the +condition under which I think, and which is consequently a property +of my subject, should be held to be likewise valid for every existence +which thinks, and that we can presume to base upon a seemingly +empirical proposition a judgement which is apodeictic and universal, +to wit, that everything which thinks is constituted as the voice of +my consciousness declares it to be, that is, as a self-conscious being. +The cause of this belief is to be found in the fact that we +necessarily attribute to things a priori all the properties which +constitute conditions under which alone we can cogitate them. Now I +cannot obtain the least representation of a thinking being by means +of external experience, but solely through self-consciousness. Such +objects are consequently nothing more than the transference of this +consciousness of mine to other things which can only thus be +represented as thinking beings. The proposition, "I think," is, in +the present case, understood in a problematical sense, not in so far +as it contains a perception of an existence (like the Cartesian "Cogito, +ergo sum"),[Footnote: "I think, therefore I am."] but in regard to +its mere possibility--for the purpose of discovering what properties +may be inferred from so simple a proposition and predicated of the +subject of it. + +If at the foundation of our pure rational cognition of thinking +beings there lay more than the mere Cogito--if we could likewise +call in aid observations on the play of our thoughts, and the thence +derived natural laws of the thinking self, there would arise an +empirical psychology which would be a kind of physiology of the +internal sense and might possibly be capable of explaining the +phenomena of that sense. But it could never be available for +discovering those properties which do not belong to possible +experience (such as the quality of simplicity), nor could it make +any apodeictic enunciation on the nature of thinking beings: it +would therefore not be a rational psychology. + +Now, as the proposition "I think" (in the problematical sense) +contains the form of every judgement in general and is the constant +accompaniment of all the categories, it is manifest that conclusions +are drawn from it only by a transcendental employment of the +understanding. This use of the understanding excludes all empirical +elements; and we cannot, as has been shown above, have any +favourable conception beforehand of its procedure. We shall +therefore follow with a critical eye this proposition through all +the predicaments of pure psychology; but we shall, for brevity's sake, +allow this examination to proceed in an uninterrupted connection. + +Before entering on this task, however, the following general +remark may help to quicken our attention to this mode of argument. +It is not merely through my thinking that I cognize an object, but +only through my determining a given intuition in relation to the unity +of consciousness in which all thinking consists. It follows that I +cognize myself, not through my being conscious of myself as +thinking, but only when I am conscious of the intuition of myself as +determined in relation to the function of thought. All the modi of +self-consciousness in thought are hence not conceptions of objects +(conceptions of the understanding--categories); they are mere +logical functions, which do not present to thought an object to be +cognized, and cannot therefore present my Self as an object. Not the +consciousness of the determining, but only that of the determinable +self, that is, of my internal intuition (in so far as the manifold +contained in it can be connected conformably with the general +condition of the unity of apperception in thought), is the object. + +1. In all judgements I am the determining subject of that relation +which constitutes a judgement. But that the I which thinks, must be +considered as in thought always a subject, and as a thing which cannot +be a predicate to thought, is an apodeictic and identical proposition. +But this proposition does not signify that I, as an object, am, for +myself, a self-subsistent being or substance. This latter statement- +an ambitious one--requires to be supported by data which are not to +be discovered in thought; and are perhaps (in so far as I consider +the thinking self merely as such) not to be discovered in the thinking +self at all. + +2. That the I or Ego of apperception, and consequently in all +thought, is singular or simple, and cannot be resolved into a +plurality of subjects, and therefore indicates a logically simple +subject--this is self-evident from the very conception of an Ego, +and is consequently an analytical proposition. But this is not +tantamount to declaring that the thinking Ego is a simple substance- +for this would be a synthetical proposition. The conception of +substance always relates to intuitions, which with me cannot be +other than sensuous, and which consequently lie completely out of +the sphere of the understanding and its thought: but to this sphere +belongs the affirmation that the Ego is simple in thought. It would +indeed be surprising, if the conception of "substance," which in other +cases requires so much labour to distinguish from the other elements +presented by intuition--so much trouble, too, to discover whether it +can be simple (as in the case of the parts of matter)--should be +presented immediately to me, as if by revelation, in the poorest +mental representation of all. + +3. The proposition of the identity of my Self amidst all the +manifold representations of which I am conscious, is likewise a +proposition lying in the conceptions themselves, and is consequently +analytical. But this identity of the subject, of which I am +conscious in all its representations, does not relate to or concern +the intuition of the subject, by which it is given as an object. +This proposition cannot therefore enounce the identity of the +person, by which is understood the consciousness of the identity of +its own substance as a thinking being in all change and variation of +circumstances. To prove this, we should require not a mere analysis +of the proposition, but synthetical judgements based upon a given +intuition. + +4. I distinguish my own existence, as that of a thinking being, from +that of other things external to me--among which my body also is +reckoned. This is also an analytical proposition, for other things +are exactly those which I think as different or distinguished from +myself. But whether this consciousness of myself is possible without +things external to me; and whether therefore I can exist merely as +a thinking being (without being man)--cannot be known or inferred from +this proposition. + +Thus we have gained nothing as regards the cognition of myself as +object, by the analysis of the consciousness of my Self in thought. +The logical exposition of thought in general is mistaken for a +metaphysical determination of the object. + +Our Critique would be an investigation utterly superfluous, if there +existed a possibility of proving a priori, that all thinking beings +are in themselves simple substances, as such, therefore, possess the +inseparable attribute of personality, and are conscious of their +existence apart from and unconnected with matter. For we should thus +have taken a step beyond the world of sense, and have penetrated +into the sphere of noumena; and in this case the right could not be +denied us of extending our knowledge in this sphere, of establishing +ourselves, and, under a favouring star, appropriating to ourselves +possessions in it. For the proposition: "Every thinking being, as +such, is simple substance," is an a priori synthetical proposition; +because in the first place it goes beyond the conception which is +the subject of it, and adds to the mere notion of a thinking being +the mode of its existence, and in the second place annexes a predicate +(that of simplicity) to the latter conception--a predicate which it +could not have discovered in the sphere of experience. It would follow +that a priori synthetical propositions are possible and legitimate, +not only, as we have maintained, in relation to objects of possible +experience, and as principles of the possibility of this experience +itself, but are applicable to things in themselves--an inference which +makes an end of the whole of this Critique, and obliges us to fall +back on the old mode of metaphysical procedure. But indeed the +danger is not so great, if we look a little closer into the question. + +There lurks in the procedure of rational Psychology a paralogism, +which is represented in the following syllogism: + +That which cannot be cogitated otherwise than as subject, does not +exist otherwise than as subject, and is therefore substance. + +A thinking being, considered merely as such, cannot be cogitated +otherwise than as subject. + +Therefore it exists also as such, that is, as substance. + +In the major we speak of a being that can be cogitated generally and +in every relation, consequently as it may be given in intuition. But +in the minor we speak of the same being only in so far as it regards +itself as subject, relatively to thought and the unity of +consciousness, but not in relation to intuition, by which it is +presented as an object to thought. Thus the conclusion is here arrived +at by a Sophisma figurae dictionis.* + +[*Footnote: Thought is taken in the two premisses in two totally +different senses. In the major it is considered as relating and applying +to objects in general, consequently to objects of intuition also. In the +minor, we understand it as relating merely to self-consciousness. In +this sense, we do not cogitate an object, but merely the relation to the +self-consciousness of the subject, as the form of thought. In the former +premiss we speak of things which cannot be cogitated otherwise than as +subjects. In the second, we do not speak of things, but of thought (all +objects being abstracted), in which the Ego is always the subject of +consciousness. Hence the conclusion cannot be, "I cannot exist otherwise +than as subject"; but only "I can, in cogitating my existence, employ my +Ego only as the subject of the judgement." But this is an identical +proposition, and throws no light on the mode of my existence.] + +That this famous argument is a mere paralogism, will be plain to any +one who will consider the general remark which precedes our exposition +of the principles of the pure understanding, and the section on +noumena. For it was there proved that the conception of a thing, which +can exist per se--only as a subject and never as a predicate, +possesses no objective reality; that is to say, we can never know +whether there exists any object to correspond to the conception; +consequently, the conception is nothing more than a conception, and +from it we derive no proper knowledge. If this conception is to +indicate by the term substance, an object that can be given, if it +is to become a cognition, we must have at the foundation of the +cognition a permanent intuition, as the indispensable condition of +its objective reality. For through intuition alone can an object be +given. But in internal intuition there is nothing permanent, for the +Ego is but the consciousness of my thought. If then, we appeal merely +to thought, we cannot discover the necessary condition of the application +of the conception of substance--that is, of a subject existing per +se--to the subject as a thinking being. And thus the conception of +the simple nature of substance, which is connected with the objective +reality of this conception, is shown to be also invalid, and to be, +in fact, nothing more than the logical qualitative unity of +self-consciousness in thought; whilst we remain perfectly ignorant +whether the subject is composite or not. + + + +Refutation of the Argument of Mendelssohn for the +Substantiality or Permanence of the Soul. + +This acute philosopher easily perceived the insufficiency of the +common argument which attempts to prove that the soul--it being +granted that it is a simple being--cannot perish by dissolution or +decomposition; he saw it is not impossible for it to cease to be by +extinction, or disappearance. He endeavoured to prove in his Phaedo, +that the soul cannot be annihilated, by showing that a simple being +cannot cease to exist. Inasmuch as, he said, a simple existence cannot +diminish, nor gradually lose portions of its being, and thus be by +degrees reduced to nothing (for it possesses no parts, and therefore +no multiplicity), between the moment in which it is, and the moment +in which it is not, no time can be discovered--which is impossible. +But this philosopher did not consider that, granting the soul to possess +this simple nature, which contains no parts external to each other +and consequently no extensive quantity, we cannot refuse to it any +less than to any other being, intensive quantity, that is, a degree +of reality in regard to all its faculties, nay, to all that constitutes +its existence. But this degree of reality can become less and less +through an infinite series of smaller degrees. It follows, +therefore, that this supposed substance--this thing, the permanence +of which is not assured in any other way, may, if not by decomposition, +by gradual loss (remissio) of its powers (consequently by +elanguescence, if I may employ this expression), be changed into +nothing. For consciousness itself has always a degree, which may be +lessened.* Consequently the faculty of being conscious may be +diminished; and so with all other faculties. The permanence of the +soul, therefore, as an object of the internal sense, remains +undemonstrated, nay, even indemonstrable. Its permanence in life is +evident, per se, inasmuch as the thinking being (as man) is to itself, +at the same time, an object of the external senses. But this does +not authorize the rational psychologist to affirm, from mere +conceptions, its permanence beyond life.*[2] + +[*Footnote: Clearness is not, as logicians maintain, the consciousness +of a representation. For a certain degree of consciousness, which may +not, however, be sufficient for recollection, is to be met with in +many dim representations. For without any consciousness at all, we +should not be able to recognize any difference in the obscure +representations we connect; as we really can do with many conceptions, +such as those of right and justice, and those of the musician, who +strikes at once several notes in improvising a piece of music. But +a representation is clear, in which our consciousness is sufficient +for the consciousness of the difference of this representation from +others. If we are only conscious that there is a difference, but are +not conscious of the difference--that is, what the difference is- +the representation must be termed obscure. There is, consequently, +an infinite series of degrees of consciousness down to its entire +disappearance.] + +[*[2]Footnote: There are some who think they have done enough to establish +a new possibility in the mode of the existence of souls, when they +have shown that there is no contradiction in their hypotheses on +this subject. Such are those who affirm the possibility of thought--of +which they have no other knowledge than what they derive from its +use in connecting empirical intuitions presented in this our human +life--after this life has ceased. But it is very easy to embarrass +them by the introduction of counter-possibilities, which rest upon +quite as good a foundation. Such, for example, is the possibility of +the division of a simple substance into several substances; and +conversely, of the coalition of several into one simple substance. +For, although divisibility presupposes composition, it does not +necessarily require a composition of substances, but only of the +degrees (of the several faculties) of one and the same substance. +Now we can cogitate all the powers and faculties of the soul--even +that of consciousness--as diminished by one half, the substance +still remaining. In the same way we can represent to ourselves without +contradiction, this obliterated half as preserved, not in the soul, +but without it; and we can believe that, as in this case every +thing that is real in the soul, and has a degree--consequently its +entire existence--has been halved, a particular substance would +arise out of the soul. For the multiplicity, which has been divided, +formerly existed, but not as a multiplicity of substances, but of +every reality as the quantum of existence in it; and the unity of +substance was merely a mode of existence, which by this division alone +has been transformed into a plurality of subsistence. In the same +manner several simple substances might coalesce into one, without +anything being lost except the plurality of subsistence, inasmuch as +the one substance would contain the degree of reality of all the +former substances. Perhaps, indeed, the simple substances, which +appear under the form of matter, might (not indeed by a mechanical +or chemical influence upon each other, but by an unknown influence, +of which the former would be but the phenomenal appearance), by means +of such a dynamical division of the parent-souls, as intensive +quantities, produce other souls, while the former repaired the loss +thus sustained with new matter of the same sort. I am far from +allowing any value to such chimeras; and the principles of our +analytic have clearly proved that no other than an empirical use of +the categories--that of substance, for example--is possible. But if +the rationalist is bold enough to construct, on the mere authority +of the faculty of thought--without any intuition, whereby an object +is given--a self-subsistent being, merely because the unity of +apperception in thought cannot allow him to believe it a composite +being, instead of declaring, as he ought to do, that he is unable to +explain the possibility of a thinking nature; what ought to hinder +the materialist, with as complete an independence of experience, to +employ the principle of the rationalist in a directly opposite manner-- +still preserving the formal unity required by his opponent?] + +If, now, we take the above propositions--as they must be accepted as +valid for all thinking beings in the system of rational psychology--in +synthetical connection, and proceed, from the category of relation, +with the proposition: "All thinking beings are, as such, substances," +backwards through the series, till the circle is completed; we come at +last to their existence, of which, in this system of rational +psychology, substances are held to be conscious, independently of +external things; nay, it is asserted that, in relation to the +permanence which is a necessary characteristic of substance, they can +of themselves determine external things. It follows that idealism--at +least problematical idealism, is perfectly unavoidable in this +rationalistic system. And, if the existence of outward things is not +held to be requisite to the determination of the existence of a +substance in time, the existence of these outward things at all, is a +gratuitous assumption which remains without the possibility of a proof. + +But if we proceed analytically--the "I think" as a proposition +containing in itself an existence as given, consequently modality +being the principle--and dissect this proposition, in order to +ascertain its content, and discover whether and how this Ego +determines its existence in time and space without the aid of anything +external; the propositions of rationalistic psychology would not begin +with the conception of a thinking being, but with a reality, and the +properties of a thinking being in general would be deduced from the +mode in which this reality is cogitated, after everything empirical +had been abstracted; as is shown in the following table: + + + 1 + I think, + + 2 3 + as Subject, as simple Subject, + + 4 + as identical Subject, + in every state of my thought. + + +Now, inasmuch as it is not determined in this second proposition, +whether I can exist and be cogitated only as subject, and not also +as a predicate of another being, the conception of a subject is here +taken in a merely logical sense; and it remains undetermined, +whether substance is to be cogitated under the conception or not. +But in the third proposition, the absolute unity of apperception- +the simple Ego in the representation to which all connection and +separation, which constitute thought, relate, is of itself +important; even although it presents us with no information about +the constitution or subsistence of the subject. Apperception is +something real, and the simplicity of its nature is given in the +very fact of its possibility. Now in space there is nothing real +that is at the same time simple; for points, which are the only simple +things in space, are merely limits, but not constituent parts of +space. From this follows the impossibility of a definition on the +basis of materialism of the constitution of my Ego as a merely +thinking subject. But, because my existence is considered in the first +proposition as given, for it does not mean, "Every thinking being +exists" (for this would be predicating of them absolute necessity), +but only, "I exist thinking"; the proposition is quite empirical, +and contains the determinability of my existence merely in relation +to my representations in time. But as I require for this purpose +something that is permanent, such as is not given in internal +intuition; the mode of my existence, whether as substance or as +accident, cannot be determined by means of this simple +self-consciousness. Thus, if materialism is inadequate to explain +the mode in which I exist, spiritualism is likewise as insufficient; +and the conclusion is that we are utterly unable to attain to any +knowledge of the constitution of the soul, in so far as relates to +the possibility of its existence apart from external objects. + +And, indeed, how should it be possible, merely by the aid of the +unity of consciousness--which we cognize only for the reason that it +is indispensable to the possibility of experience--to pass the +bounds of experience (our existence in this life); and to extend our +cognition to the nature of all thinking beings by means of the +empirical--but in relation to every sort of intuition, perfectly +undetermined--proposition, "I think"? + +There does not then exist any rational psychology as a doctrine +furnishing any addition to our knowledge of ourselves. It is nothing +more than a discipline, which sets impassable limits to speculative +reason in this region of thought, to prevent it, on the one hand, from +throwing itself into the arms of a soulless materialism, and, on the +other, from losing itself in the mazes of a baseless spiritualism. +It teaches us to consider this refusal of our reason to give any +satisfactory answer to questions which reach beyond the limits of this +our human life, as a hint to abandon fruitless speculation; and to +direct, to a practical use, our knowledge of ourselves--which, +although applicable only to objects of experience, receives its +principles from a higher source, and regulates its procedure as if +our destiny reached far beyond the boundaries of experience and life. + +From all this it is evident that rational psychology has its +origin in a mere misunderstanding. The unity of consciousness, which +lies at the basis of the categories, is considered to be an +intuition of the subject as an object; and the category of substance +is applied to the intuition. But this unity is nothing more than the +unity in thought, by which no object is given; to which therefore +the category of substance--which always presupposes a given intuition- +cannot be applied. Consequently, the subject cannot be cognized. The +subject of the categories cannot, therefore, for the very reason +that it cogitates these, frame any conception of itself as an object +of the categories; for, to cogitate these, it must lay at the +foundation its own pure self-consciousness--the very thing that it +wishes to explain and describe. In like manner, the subject, in +which the representation of time has its basis, cannot determine, +for this very reason, its own existence in time. Now, if the latter +is impossible, the former, as an attempt to determine itself by means +of the categories as a thinking being in general, is no less so.* + +[*Footnote: The "I think" is, as has been already stated, an empirical +proposition, and contains the proposition, "I exist." But I cannot say, +"Everything, which thinks, exists"; for in this case the property of +thought would constitute all beings possessing it, necessary beings. Hence +my existence cannot be considered as an inference from the proposition, +"I think," as Descartes maintained--because in this case the major +premiss, "Everything, which thinks, exists," must precede--but the two +propositions are identical. The proposition, "I think," expresses an +undetermined empirical intuition, that perception (proving consequently +that sensation, which must belong to sensibility, lies at the foundation +of this proposition); but it precedes experience, whose province it is +to determine an object of perception by means of the categories in +relation to time; and existence in this proposition is not a category, +as it does not apply to an undetermined given object, but only to one of +which we have a conception, and about which we wish to know whether it +does or does not exist, out of, and apart from this conception. An +undetermined perception signifies here merely something real that has +been given, only, however, to thought in general--but not as a +phenomenon, nor as a thing in itself (noumenon), but only as something +that really exists, and is designated as such in the proposition, "I +think." For it must be remarked that, when I call the proposition, "I +think," an empirical proposition, I do not thereby mean that the Ego in +the proposition is an empirical representation; on the contrary, it is +purely intellectual, because it belongs to thought in general. But +without some empirical representation, which presents to the mind +material for thought, the mental act, "I think," would not take place; +and the empirical is only the condition of the application or employment +of the pure intellectual faculty.] + +Thus, then, appears the vanity of the hope of establishing a cognition +which is to extend its rule beyond the limits of experience--a +cognition which is one of the highest interests of humanity; and thus is +proved the futility of the attempt of speculative philosophy in this +region of thought. But, in this interest of thought, the severity of +criticism has rendered to reason a not unimportant service, by the +demonstration of the impossibility of making any dogmatical affirmation +concerning an object of experience beyond the boundaries of experience. +She has thus fortified reason against all affirmations of the contrary. +Now, this can be accomplished in only two ways. Either our proposition +must be proved apodeictically; or, if this is unsuccessful, the sources +of this inability must be sought for, and, if these are discovered to +exist in the natural and necessary limitation of our reason, our +opponents must submit to the same law of renunciation and refrain from +advancing claims to dogmatic assertion. + +But the right, say rather the necessity to admit a future life, upon +principles of the practical conjoined with the speculative use of +reason, has lost nothing by this renunciation; for the merely +speculative proof has never had any influence upon the common reason of +men. It stands upon the point of a hair, so that even the schools have +been able to preserve it from falling only by incessantly discussing it +and spinning it like a top; and even in their eyes it has never been +able to present any safe foundation for the erection of a theory. The +proofs which have been current among men, preserve their value +undiminished; nay, rather gain in clearness and unsophisticated power, +by the rejection of the dogmatical assumptions of speculative reason. +For reason is thus confined within her own peculiar province--the +arrangement of ends or aims, which is at the same time the arrangement +of nature; and, as a practical faculty, without limiting itself to the +latter, it is justified in extending the former, and with it our own +existence, beyond the boundaries of experience and life. If we turn our +attention to the analogy of the nature of living beings in this world, +in the consideration of which reason is obliged to accept as a +principle that no organ, no faculty, no appetite is useless, and that +nothing is superfluous, nothing disproportionate to its use, nothing +unsuited to its end; but that, on the contrary, everything is perfectly +conformed to its destination in life--we shall find that man, who alone +is the final end and aim of this order, is still the only animal that +seems to be excepted from it. For his natural gifts--not merely as +regards the talents and motives that may incite him to employ them, but +especially the moral law in him--stretch so far beyond all mere earthly +utility and advantage, that he feels himself bound to prize the mere +consciousness of probity, apart from all advantageous consequences-- +even the shadowy gift of posthumous fame--above everything; and he is +conscious of an inward call to constitute himself, by his conduct in +this world--without regard to mere sublunary interests--the citizen of +a better. This mighty, irresistible proof--accompanied by an +ever-increasing knowledge of the conformability to a purpose in +everything we see around us, by the conviction of the boundless +immensity of creation, by the consciousness of a certain +illimitableness in the possible extension of our knowledge, and by a +desire commensurate therewith--remains to humanity, even after the +theoretical cognition of ourselves has failed to establish the +necessity of an existence after death. + + + +Conclusion of the Solution of the Psychological Paralogism. + +The dialectical illusion in rational psychology arises from our +confounding an idea of reason (of a pure intelligence) with the +conception--in every respect undetermined--of a thinking being in +general. I cogitate myself in behalf of a possible experience, at +the same time making abstraction of all actual experience; and infer +therefrom that I can be conscious of myself apart from experience +and its empirical conditions. I consequently confound the possible +abstraction of my empirically determined existence with the supposed +consciousness of a possible separate existence of my thinking self; +and I believe that I cognize what is substantial in myself as a +transcendental subject, when I have nothing more in thought than the +unity of consciousness, which lies at the basis of all determination +of cognition. + +The task of explaining the community of the soul with the body +does not properly belong to the psychology of which we are here +speaking; because it proposes to prove the personality of the soul +apart from this communion (after death), and is therefore transcendent +in the proper sense of the word, although occupying itself with an +object of experience--only in so far, however, as it ceases to be an +object of experience. But a sufficient answer may be found to the +question in our system. The difficulty which lies in the execution +of this task consists, as is well known, in the presupposed +heterogeneity of the object of the internal sense (the soul) and the +objects of the external senses; inasmuch as the formal condition of +the intuition of the one is time, and of that of the other space also. +But if we consider that both kinds of objects do not differ +internally, but only in so far as the one appears externally to the +other--consequently, that what lies at the basis of phenomena, as a +thing in itself, may not be heterogeneous; this difficulty disappears. +There then remains no other difficulty than is to be found in the +question--how a community of substances is possible; a question +which lies out of the region of psychology, and which the reader, +after what in our analytic has been said of primitive forces and +faculties, will easily judge to be also beyond the region of human +cognition. + + + +GENERAL REMARK + +On the Transition from Rational Psychology to Cosmology. + +The proposition, "I think," or, "I exist thinking," is an +empirical proposition. But such a proposition must be based on +empirical intuition, and the object cogitated as a phenomenon; and +thus our theory appears to maintain that the soul, even in thought, +is merely a phenomenon; and in this way our consciousness itself, in +fact, abuts upon nothing. + +Thought, per se, is merely the purely spontaneous logical function +which operates to connect the manifold of a possible intuition; and +it does not represent the subject of consciousness as a phenomenon--for +this reason alone, that it pays no attention to the question whether +the mode of intuiting it is sensuous or intellectual. I therefore do +not represent myself in thought either as I am, or as I appear to +myself; I merely cogitate myself as an object in general, of the +mode of intuiting which I make abstraction. When I represent myself +as the subject of thought, or as the ground of thought, these modes +of representation are not related to the categories of substance or +of cause; for these are functions of thought applicable only to our +sensuous intuition. The application of these categories to the Ego +would, however, be necessary, if I wished to make myself an object +of knowledge. But I wish to be conscious of myself only as thinking; +in what mode my Self is given in intuition, I do not consider, and +it may be that I, who think, am a phenomenon--although not in so far +as I am a thinking being; but in the consciousness of myself in mere +thought I am a being, though this consciousness does not present to +me any property of this being as material for thought. + +But the proposition, "I think," in so far as it declares, "I exist +thinking," is not the mere representation of a logical function. It +determines the subject (which is in this case an object also) in +relation to existence; and it cannot be given without the aid of the +internal sense, whose intuition presents to us an object, not as a +thing in itself, but always as a phenomenon. In this proposition there +is therefore something more to be found than the mere spontaneity of +thought; there is also the receptivity of intuition, that is, my +thought of myself applied to the empirical intuition of myself. Now, +in this intuition the thinking self must seek the conditions of the +employment of its logical functions as categories of substance, cause, +and so forth; not merely for the purpose of distinguishing itself as +an object in itself by means of the representation "I," but also for +the purpose of determining the mode of its existence, that is, of +cognizing itself as noumenon. But this is impossible, for the internal +empirical intuition is sensuous, and presents us with nothing but +phenomenal data, which do not assist the object of pure +consciousness in its attempt to cognize itself as a separate +existence, but are useful only as contributions to experience. + +But, let it be granted that we could discover, not in experience, but +in certain firmly-established a priori laws of the use of pure reason-- +laws relating to our existence, authority to consider ourselves as +legislating a priori in relation to our own existence and as +determining this existence; we should, on this supposition, find +ourselves possessed of a spontaneity, by which our actual existence +would be determinable, without the aid of the conditions of empirical +intuition. We should also become aware that in the consciousness of +our existence there was an a priori content, which would serve to +determine our own existence--an existence only sensuously +determinable--relatively, however, to a certain internal faculty +in relation to an intelligible world. + +But this would not give the least help to the attempts of rational +psychology. For this wonderful faculty, which the consciousness of +the moral law in me reveals, would present me with a principle of the +determination of my own existence which is purely intellectual--but +by what predicates? By none other than those which are given in +sensuous intuition. Thus I should find myself in the same position +in rational psychology which I formerly occupied, that is to say, I +should find myself still in need of sensuous intuitions, in order to +give significance to my conceptions of substance and cause, by means +of which alone I can possess a knowledge of myself: but these +intuitions can never raise me above the sphere of experience. I should +be justified, however, in applying these conceptions, in regard to +their practical use, which is always directed to objects of +experience--in conformity with their analogical significance when +employed theoretically--to freedom and its subject. At the same +time, I should understand by them merely the logical functions of +subject and predicate, of principle and consequence, in conformity +with which all actions are so determined, that they are capable of +being explained along with the laws of nature, conformably to the +categories of substance and cause, although they originate from a very +different principle. We have made these observations for the purpose +of guarding against misunderstanding, to which the doctrine of our +intuition of self as a phenomenon is exposed. We shall have occasion +to perceive their utility in the sequel. + + + +CHAPTER II. The Antinomy of Pure Reason. + +We showed in the introduction to this part of our work, that all +transcendental illusion of pure reason arose from dialectical +arguments, the schema of which logic gives us in its three formal +species of syllogisms--just as the categories find their logical +schema in the four functions of all judgements. The first kind of +these sophistical arguments related to the unconditioned unity of +the subjective conditions of all representations in general (of the +subject or soul), in correspondence with the categorical syllogisms, +the major of which, as the principle, enounces the relation of a +predicate to a subject. The second kind of dialectical argument will +therefore be concerned, following the analogy with hypothetical +syllogisms, with the unconditioned unity of the objective conditions +in the phenomenon; and, in this way, the theme of the third kind to +be treated of in the following chapter will be the unconditioned unity +of the objective conditions of the possibility of objects in general. + +But it is worthy of remark that the transcendental paralogism +produced in the mind only a one-third illusion, in regard to the +idea of the subject of our thought; and the conceptions of reason gave +no ground to maintain the contrary proposition. The advantage is +completely on the side of Pneumatism; although this theory itself +passes into naught, in the crucible of pure reason. + +Very different is the case when we apply reason to the objective +synthesis of phenomena. Here, certainly, reason establishes, with much +plausibility, its principle of unconditioned unity; but it very soon +falls into such contradictions that it is compelled, in relation to +cosmology, to renounce its pretensions. + +For here a new phenomenon of human reason meets us--a perfectly +natural antithetic, which does not require to be sought for by +subtle sophistry, but into which reason of itself unavoidably falls. +It is thereby preserved, to be sure, from the slumber of a fancied +conviction--which a merely one-sided illusion produces; but it is at +the same time compelled, either, on the one hand, to abandon itself +to a despairing scepticism, or, on the other, to assume a dogmatical +confidence and obstinate persistence in certain assertions, without +granting a fair hearing to the other side of the question. Either is +the death of a sound philosophy, although the former might perhaps +deserve the title of the euthanasia of pure reason. + +Before entering this region of discord and confusion, which the +conflict of the laws of pure reason (antinomy) produces, we shall +present the reader with some considerations, in explanation and +justification of the method we intend to follow in our treatment of +this subject. I term all transcendental ideas, in so far as they +relate to the absolute totality in the synthesis of phenomena, +cosmical conceptions; partly on account of this unconditioned +totality, on which the conception of the world-whole is based--a +conception, which is itself an idea--partly because they relate solely +to the synthesis of phenomena--the empirical synthesis; while, on +the other hand, the absolute totality in the synthesis of the +conditions of all possible things gives rise to an ideal of pure +reason, which is quite distinct from the cosmical conception, although +it stands in relation with it. Hence, as the paralogisms of pure +reason laid the foundation for a dialectical psychology, the +antinomy of pure reason will present us with the transcendental +principles of a pretended pure (rational) cosmology--not, however, +to declare it valid and to appropriate it, but--as the very term of +a conflict of reason sufficiently indicates, to present it as an +idea which cannot be reconciled with phenomena and experience. + + + +SECTION I. System of Cosmological Ideas. + +That We may be able to enumerate with systematic precision these +ideas according to a principle, we must remark, in the first place, +that it is from the understanding alone that pure and transcendental +conceptions take their origin; that the reason does not properly +give birth to any conception, but only frees the conception of the +understanding from the unavoidable limitation of a possible +experience, and thus endeavours to raise it above the empirical, +though it must still be in connection with it. This happens from the +fact that, for a given conditioned, reason demands absolute totality +on the side of the conditions (to which the understanding submits +all phenomena), and thus makes of the category a transcendental +idea. This it does that it may be able to give absolute completeness +to the empirical synthesis, by continuing it to the unconditioned +(which is not to be found in experience, but only in the idea). Reason +requires this according to the principle: If the conditioned is +given the whole of the conditions, and consequently the absolutely +unconditioned, is also given, whereby alone the former was possible. +First, then, the transcendental ideas are properly nothing but +categories elevated to the unconditioned; and they may be arranged +in a table according to the titles of the latter. But, secondly, all +the categories are not available for this purpose, but only those in +which the synthesis constitutes a series--of conditions subordinated +to, not co-ordinated with, each other. Absolute totality is required +of reason only in so far as concerns the ascending series of the +conditions of a conditioned; not, consequently, when the question +relates to the descending series of consequences, or to the +aggregate of the co-ordinated conditions of these consequences. For, +in relation to a given conditioned, conditions are presupposed and +considered to be given along with it. On the other hand, as the +consequences do not render possible their conditions, but rather +presuppose them--in the consideration of the procession of +consequences (or in the descent from the given condition to the +conditioned), we may be quite unconcerned whether the series ceases +or not; and their totality is not a necessary demand of reason. + +Thus we cogitate--and necessarily--a given time completely elapsed +up to a given moment, although that time is not determinable by us. +But as regards time future, which is not the condition of arriving +at the present, in order to conceive it; it is quite indifferent +whether we consider future time as ceasing at some point, or as +prolonging itself to infinity. Take, for example, the series m, n, +o, in which n is given as conditioned in relation to m, but at the +same time as the condition of o, and let the series proceed upwards +from the conditioned n to m (l, k, i, etc.), and also downwards from +the condition n to the conditioned o (p, q, r, etc.)--I must +presuppose the former series, to be able to consider n as given, and +n is according to reason (the totality of conditions) possible only +by means of that series. But its possibility does not rest on the +following series o, p, q, r, which for this reason cannot be +regarded as given, but only as capable of being given (dabilis). + +I shall term the synthesis of the series on the side of the +conditions--from that nearest to the given phenomenon up to the more +remote--regressive; that which proceeds on the side of the +conditioned, from the immediate consequence to the more remote, I +shall call the progressive synthesis. The former proceeds in +antecedentia, the latter in consequentia. The cosmological ideas are +therefore occupied with the totality of the regressive synthesis, +and proceed in antecedentia, not in consequentia. When the latter +takes place, it is an arbitrary and not a necessary problem of pure +reason; for we require, for the complete understanding of what is +given in a phenomenon, not the consequences which succeed, but the +grounds or principles which precede. + +In order to construct the table of ideas in correspondence with +the table of categories, we take first the two primitive quanta of +all our intuitions, time and space. Time is in itself a series (and +the formal condition of all series), and hence, in relation to a given +present, we must distinguish a priori in it the antecedentia as +conditions (time past) from the consequentia (time future). +Consequently, the transcendental idea of the absolute totality of +the series of the conditions of a given conditioned, relates merely +to all past time. According to the idea of reason, the whole past time, +as the condition of the given moment, is necessarily cogitated as +given. But, as regards space, there exists in it no distinction +between progressus and regressus; for it is an aggregate and not a +series--its parts existing together at the same time. I can consider +a given point of time in relation to past time only as conditioned, +because this given moment comes into existence only through the past +time rather through the passing of the preceding time. But as the +parts of space are not subordinated, but co-ordinated to each other, +one part cannot be the condition of the possibility of the other; +and space is not in itself, like time, a series. But the synthesis +of the manifold parts of space--(the syntheses whereby we apprehend +space)--is nevertheless successive; it takes place, therefore, in +time, and contains a series. And as in this series of aggregated +spaces (for example, the feet in a rood), beginning with a given +portion of space, those which continue to be annexed form the +condition of the limits of the former--the measurement of a space must +also be regarded as a synthesis of the series of the conditions of +a given conditioned. It differs, however, in this respect from that +of time, that the side of the conditioned is not in itself +distinguishable from the side of the condition; and, consequently, +regressus and progressus in space seem to be identical. But, +inasmuch as one part of space is not given, but only limited, by and +through another, we must also consider every limited space as +conditioned, in so far as it presupposes some other space as the +condition of its limitation, and so on. As regards limitation, +therefore, our procedure in space is also a regressus, and the +transcendental idea of the absolute totality of the synthesis in a +series of conditions applies to space also; and I am entitled to +demand the absolute totality of the phenomenal synthesis in space as +well as in time. Whether my demand can be satisfied is a question to +be answered in the sequel. + +Secondly, the real in space--that is, matter--is conditioned. Its +internal conditions are its parts, and the parts of parts its remote +conditions; so that in this case we find a regressive synthesis, the +absolute totality of which is a demand of reason. But this cannot be +obtained otherwise than by a complete division of parts, whereby the +real in matter becomes either nothing or that which is not matter, +that is to say, the simple. Consequently we find here also a series +of conditions and a progress to the unconditioned. + +Thirdly, as regards the categories of a real relation between +phenomena, the category of substance and its accidents is not suitable +for the formation of a transcendental idea; that is to say, reason has +no ground, in regard to it, to proceed regressively with conditions. +For accidents (in so far as they inhere in a substance) are +co-ordinated with each other, and do not constitute a series. And, in +relation to substance, they are not properly subordinated to it, but +are the mode of existence of the substance itself. The conception of +the substantial might nevertheless seem to be an idea of the +transcendental reason. But, as this signifies nothing more than the +conception of an object in general, which subsists in so far as we +cogitate in it merely a transcendental subject without any predicates; +and as the question here is of an unconditioned in the series of +phenomena--it is clear that the substantial can form no member thereof. +The same holds good of substances in community, which are mere +aggregates and do not form a series. For they are not subordinated to +each other as conditions of the possibility of each other; which, +however, may be affirmed of spaces, the limits of which are never +determined in themselves, but always by some other space. It is, +therefore, only in the category of causality that we can find a series +of causes to a given effect, and in which we ascend from the latter, as +the conditioned, to the former as the conditions, and thus answer the +question of reason. + +Fourthly, the conceptions of the possible, the actual, and the +necessary do not conduct us to any series--excepting only in so far +as the contingent in existence must always be regarded as conditioned, +and as indicating, according to a law of the understanding, a +condition, under which it is necessary to rise to a higher, till in +the totality of the series, reason arrives at unconditioned necessity. + +There are, accordingly, only four cosmological ideas, corresponding +with the four titles of the categories. For we can select only such as +necessarily furnish us with a series in the synthesis of the manifold. + + 1 + The absolute Completeness + of the + COMPOSITION + of the given totality of all phenomena. + + 2 + The absolute Completeness + of the + DIVISION + of given totality in a phenomenon. + + 3 + The absolute Completeness + of the + ORIGINATION + of a phenomenon. + + 4 + The absolute Completeness + of the DEPENDENCE of the EXISTENCE + of what is changeable in a phenomenon. + + +We must here remark, in the first place, that the idea of absolute +totality relates to nothing but the exposition of phenomena, and +therefore not to the pure conception of a totality of things. +Phenomena are here, therefore, regarded as given, and reason +requires the absolute completeness of the conditions of their +possibility, in so far as these conditions constitute a series- +consequently an absolutely (that is, in every respect) complete +synthesis, whereby a phenomenon can be explained according to the laws +of the understanding. + +Secondly, it is properly the unconditioned alone that reason seeks +in this serially and regressively conducted synthesis of conditions. +It wishes, to speak in another way, to attain to completeness in the +series of premisses, so as to render it unnecessary to presuppose +others. This unconditioned is always contained in the absolute +totality of the series, when we endeavour to form a representation +of it in thought. But this absolutely complete synthesis is itself +but an idea; for it is impossible, at least before hand, to know whether +any such synthesis is possible in the case of phenomena. When we +represent all existence in thought by means of pure conceptions of +the understanding, without any conditions of sensuous intuition, we +may say with justice that for a given conditioned the whole series +of conditions subordinated to each other is also given; for the former +is only given through the latter. But we find in the case of phenomena +a particular limitation of the mode in which conditions are given, +that is, through the successive synthesis of the manifold of +intuition, which must be complete in the regress. Now whether this +completeness is sensuously possible, is a problem. But the idea of +it lies in the reason--be it possible or impossible to connect with +the idea adequate empirical conceptions. Therefore, as in the absolute +totality of the regressive synthesis of the manifold in a phenomenon +(following the guidance of the categories, which represent it as a +series of conditions to a given conditioned) the unconditioned is +necessarily contained--it being still left unascertained whether and +how this totality exists; reason sets out from the idea of totality, +although its proper and final aim is the unconditioned--of the whole +series, or of a part thereof. + +This unconditioned may be cogitated--either as existing only in +the entire series, all the members of which therefore would be without +exception conditioned and only the totality absolutely +unconditioned--and in this case the regressus is called infinite; or +the absolutely unconditioned is only a part of the series, to which +the other members are subordinated, but which Is not itself +submitted to any other condition.* In the former case the series is +a parte priori unlimited (without beginning), that is, infinite, and +nevertheless completely given. But the regress in it is never +completed, and can only be called potentially infinite. In the +second case there exists a first in the series. This first is +called, in relation to past time, the beginning of the world; in +relation to space, the limit of the world; in relation to the parts +of a given limited whole, the simple; in relation to causes, absolute +spontaneity (liberty); and in relation to the existence of +changeable things, absolute physical necessity. + +[*Footnote: The absolute totality of the series of conditions to a +given conditioned is always unconditioned; because beyond it there +exist no other conditions, on which it might depend. But the absolute +totality of such a series is only an idea, or rather a problematical +conception, the possibility of which must be investigated- +particularly in relation to the mode in which the unconditioned, as +the transcendental idea which is the real subject of inquiry, may be +contained therein.] + +We possess two expressions, world and nature, which are generally +interchanged. The first denotes the mathematical total of all +phenomena and the totality of their synthesis--in its progress by +means of composition, as well as by division. And the world is +termed nature,* when it is regarded as a dynamical whole--when our +attention is not directed to the aggregation in space and time, for +the purpose of cogitating it as a quantity, but to the unity in the +existence of phenomena. In this case the condition of that which +happens is called a cause; the unconditioned causality of the cause +in a phenomenon is termed liberty; the conditioned cause is called +in a more limited sense a natural cause. The conditioned in existence +is termed contingent, and the unconditioned necessary. The +unconditioned necessity of phenomena may be called natural necessity. + +[*Footnote: Nature, understood adjective (formaliter), signifies the +complex of the determinations of a thing, connected according to an +internal principle of causality. On the other hand, we understand by +nature, substantive (materialiter), the sum total of phenomena, in +so far as they, by virtue of an internal principle of causality, are +connected with each other throughout. In the former sense we speak +of the nature of liquid matter, of fire, etc., and employ the word +only adjective; while, if speaking of the objects of nature, we have +in our minds the idea of a subsisting whole.] + +The ideas which we are at present engaged in discussing I have +called cosmological ideas; partly because by the term world is +understood the entire content of all phenomena, and our ideas are +directed solely to the unconditioned among phenomena; partly also, +because world, in the transcendental sense, signifies the absolute +totality of the content of existing things, and we are directing our +attention only to the completeness of the synthesis--although, +properly, only in regression. In regard to the fact that these ideas +are all transcendent, and, although they do not transcend phenomena +as regards their mode, but are concerned solely with the world of sense +(and not with noumena), nevertheless carry their synthesis to a degree +far above all possible experience--it still seems to me that we can, +with perfect propriety, designate them cosmical conceptions. As +regards the distinction between the mathematically and the dynamically +unconditioned which is the aim of the regression of the synthesis, +I should call the two former, in a more limited signification, +cosmical conceptions, the remaining two transcendent physical +conceptions. This distinction does not at present seem to be of +particular importance, but we shall afterwards find it to be of some +value. + + + +SECTION II. Antithetic of Pure Reason. + +Thetic is the term applied to every collection of dogmatical +propositions. By antithetic I do not understand dogmatical +assertions of the opposite, but the self-contradiction of seemingly +dogmatical cognitions (thesis cum antithesis), in none of which we +can discover any decided superiority. Antithetic is not, therefore, +occupied with one-sided statements, but is engaged in considering +the contradictory nature of the general cognitions of reason and its +causes. Transcendental antithetic is an investigation into the +antinomy of pure reason, its causes and result. If we employ our +reason not merely in the application of the principles of the +understanding to objects of experience, but venture with it beyond +these boundaries, there arise certain sophistical propositions or +theorems. These assertions have the following peculiarities: They +can find neither confirmation nor confutation in experience; and +each is in itself not only self-consistent, but possesses conditions +of its necessity in the very nature of reason--only that, unluckily, +there exist just as valid and necessary grounds for maintaining the +contrary proposition. + +The questions which naturally arise in the consideration of this +dialectic of pure reason, are therefore: 1st. In what propositions +is pure reason unavoidably subject to an antinomy? 2nd. What are the +causes of this antinomy? 3rd. Whether and in what way can reason +free itself from this self-contradiction? + +A dialectical proposition or theorem of pure reason must, +according to what has been said, be distinguishable from all +sophistical propositions, by the fact that it is not an answer to an +arbitrary question, which may be raised at the mere pleasure of any +person, but to one which human reason must necessarily encounter in +its progress. In the second place, a dialectical proposition, with +its opposite, does not carry the appearance of a merely artificial +illusion, which disappears as soon as it is investigated, but a +natural and unavoidable illusion, which, even when we are no longer +deceived by it, continues to mock us and, although rendered +harmless, can never be completely removed. + +This dialectical doctrine will not relate to the unity of +understanding in empirical conceptions, but to the unity of reason +in pure ideas. The conditions of this doctrine are--inasmuch as it +must, as a synthesis according to rules, be conformable to the +understanding, and at the same time as the absolute unity of the +synthesis, to the reason--that, if it is adequate to the unity of +reason, it is too great for the understanding, if according with the +understanding, it is too small for the reason. Hence arises a mutual +opposition, which cannot be avoided, do what we will. + +These sophistical assertions of dialectic open, as it were, a +battle-field, where that side obtains the victory which has been +permitted to make the attack, and he is compelled to yield who has +been unfortunately obliged to stand on the defensive. And hence, +champions of ability, whether on the right or on the wrong side, are +certain to carry away the crown of victory, if they only take care +to have the right to make the last attack, and are not obliged to +sustain another onset from their opponent. We can easily believe +that this arena has been often trampled by the feet of combatants, +that many victories have been obtained on both sides, but that the +last victory, decisive of the affair between the contending parties, +was won by him who fought for the right, only if his adversary was +forbidden to continue the tourney. As impartial umpires, we must lay +aside entirely the consideration whether the combatants are fighting +for the right or for the wrong side, for the true or for the false, +and allow the combat to be first decided. Perhaps, after they have +wearied more than injured each other, they will discover the +nothingness of their cause of quarrel and part good friends. + +This method of watching, or rather of originating, a conflict of +assertions, not for the purpose of finally deciding in favour of +either side, but to discover whether the object of the struggle is +not a mere illusion, which each strives in vain to reach, but which +would be no gain even when reached--this procedure, I say, may be +termed the sceptical method. It is thoroughly distinct from +scepticism--the principle of a technical and scientific ignorance, +which undermines the foundations of all knowledge, in order, if +possible, to destroy our belief and confidence therein. For the +sceptical method aims at certainty, by endeavouring to discover in +a conflict of this kind, conducted honestly and intelligently on both +sides, the point of misunderstanding; just as wise legislators derive, +from the embarrassment of judges in lawsuits, information in regard +to the defective and ill-defined parts of their statutes. The antinomy +which reveals itself in the application of laws, is for our limited +wisdom the best criterion of legislation. For the attention of reason, +which in abstract speculation does not easily become conscious of +its errors, is thus roused to the momenta in the determination of +its principles. + +But this sceptical method is essentially peculiar to +transcendental philosophy, and can perhaps be dispensed with in +every other field of investigation. In mathematics its use would be +absurd; because in it no false assertions can long remain hidden, +inasmuch as its demonstrations must always proceed under the +guidance of pure intuition, and by means of an always evident +synthesis. In experimental philosophy, doubt and delay may be very +useful; but no misunderstanding is possible, which cannot be easily +removed; and in experience means of solving the difficulty and putting +an end to the dissension must at last be found, whether sooner or +later. Moral philosophy can always exhibit its principles, with +their practical consequences, in concreto--at least in possible +experiences, and thus escape the mistakes and ambiguities of +abstraction. But transcendental propositions, which lay claim to +insight beyond the region of possible experience, cannot, on the one +hand, exhibit their abstract synthesis in any a priori intuition, nor, +on the other, expose a lurking error by the help of experience. +Transcendental reason, therefore, presents us with no other +criterion than that of an attempt to reconcile such assertions, and +for this purpose to permit a free and unrestrained conflict between +them. And this we now proceed to arrange.* + + +[*Footnote: The antinomies stand in the order of the four +transcendental ideas above detailed.] + + + +FIRST CONFLICT OF THE TRANSCENDENTAL IDEAS. + +THESIS. + +The world has a beginning in time, and is also limited in +regard to space. + + +PROOF. + +Granted that the world has no beginning in time; up to every given +moment of time, an eternity must have elapsed, and therewith passed +away an infinite series of successive conditions or states of things +in the world. Now the infinity of a series consists in the fact that +it never can be completed by means of a successive synthesis. It +follows that an infinite series already elapsed is impossible and +that, consequently, a beginning of the world is a necessary +condition of its existence. And this was the first thing to be proved. + +As regards the second, let us take the opposite for granted. In this +case, the world must be an infinite given total of coexistent +things. Now we cannot cogitate the dimensions of a quantity, which +is not given within certain limits of an intuition,* in any other +way than by means of the synthesis of its parts, and the total of such +a quantity only by means of a completed synthesis, or the repeated +addition of unity to itself. Accordingly, to cogitate the world, which +fills all spaces, as a whole, the successive synthesis of the parts +of an infinite world must be looked upon as completed, that is to say, +an infinite time must be regarded as having elapsed in the enumeration +of all co-existing things; which is impossible. For this reason an +infinite aggregate of actual things cannot be considered as a given +whole, consequently, not as a contemporaneously given whole. The world +is consequently, as regards extension in space, not infinite, but +enclosed in limits. And this was the second thing to be proved. + +[*Footnote: We may consider an undetermined quantity as a whole, when +it is enclosed within limits, although we cannot construct or ascertain +its totality by measurement, that is, by the successive synthesis of +its parts. For its limits of themselves determine its completeness +as a whole.] + + +ANTITHESIS. + +The world has no beginning, and no limits in space, but is, in +relation both to time and space, infinite. + + +PROOF. + +For let it be granted that it has a beginning. A beginning is an +existence which is preceded by a time in which the thing does not +exist. On the above supposition, it follows that there must have +been a time in which the world did not exist, that is, a void time. +But in a void time the origination of a thing is impossible; because +no part of any such time contains a distinctive condition of being, +in preference to that of non-being (whether the supposed thing +originate of itself, or by means of some other cause). Consequently, +many series of things may have a beginning in the world, but the world +itself cannot have a beginning, and is, therefore, in relation to past +time, infinite. + +As regards the second statement, let us first take the opposite +for granted--that the world is finite and limited in space; it follows +that it must exist in a void space, which is not limited. We should +therefore meet not only with a relation of things in space, but also +a relation of things to space. Now, as the world is an absolute whole, +out of and beyond which no object of intuition, and consequently no +correlate to which can be discovered, this relation of the world to +a void space is merely a relation to no object. But such a relation, +and consequently the limitation of the world by void space, is +nothing. Consequently, the world, as regards space, is not limited, +that is, it is infinite in regard to extension.* + + +[*Footnote: Space is merely the form of external intuition (formal +intuition), and not a real object which can be externally perceived. +Space, prior to all things which determine it (fill or limit it), +or, rather, which present an empirical intuition conformable to it, +is, under the title of absolute space, nothing but the mere +possibility of external phenomena, in so far as they either exist in +themselves, or can annex themselves to given intuitions. Empirical +intuition is therefore not a composition of phenomena and space (of +perception and empty intuition). The one is not the correlate of the +other in a synthesis, but they are vitally connected in the same +empirical intuition, as matter and form. If we wish to set one of +these two apart from the other--space from phenomena--there arise +all sorts of empty determinations of external intuition, which are +very far from being possible perceptions. For example, motion or +rest of the world in an infinite empty space, or a determination of +the mutual relation of both, cannot possibly be perceived, and is +therefore merely the predicate of a notional entity.] + + + +OBSERVATIONS ON THE FIRST ANTINOMY. + +ON THE THESIS. + +In bringing forward these conflicting arguments, I have not been +on the search for sophisms, for the purpose of availing myself of +special pleading, which takes advantage of the carelessness of the +opposite party, appeals to a misunderstood statute, and erects its +unrighteous claims upon an unfair interpretation. Both proofs +originate fairly from the nature of the case, and the advantage +presented by the mistakes of the dogmatists of both parties has been +completely set aside. + +The thesis might also have been unfairly demonstrated, by the +introduction of an erroneous conception of the infinity of a given +quantity. A quantity is infinite, if a greater than itself cannot +possibly exist. The quantity is measured by the number of given units- +which are taken as a standard--contained in it. Now no number can be +the greatest, because one or more units can always be added. It +follows that an infinite given quantity, consequently an infinite +world (both as regards time and extension) is impossible. It is, +therefore, limited in both respects. In this manner I might have +conducted my proof; but the conception given in it does not agree with +the true conception of an infinite whole. In this there is no +representation of its quantity, it is not said how large it is; +consequently its conception is not the conception of a maximum. We +cogitate in it merely its relation to an arbitrarily assumed unit, +in relation to which it is greater than any number. Now, just as the +unit which is taken is greater or smaller, the infinite will be +greater or smaller; but the infinity, which consists merely in the +relation to this given unit, must remain always the same, although +the absolute quantity of the whole is not thereby cognized. + +The true (transcendental) conception of infinity is: that the +successive synthesis of unity in the measurement of a given quantum +can never be completed.* Hence it follows, without possibility of +mistake, that an eternity of actual successive states up to a given +(the present) moment cannot have elapsed, and that the world must +therefore have a beginning. + +[*Footnote: The quantum in this sense contains a congeries of given +units, which is greater than any number--and this is the mathematical +conception of the infinite.] + +In regard to the second part of the thesis, the difficulty as to +an infinite and yet elapsed series disappears; for the manifold of +a world infinite in extension is contemporaneously given. But, in +order to cogitate the total of this manifold, as we cannot have the +aid of limits constituting by themselves this total in intuition, we +are obliged to give some account of our conception, which in this case +cannot proceed from the whole to the determined quantity of the parts, +but must demonstrate the possibility of a whole by means of a +successive synthesis of the parts. But as this synthesis must +constitute a series that cannot be completed, it is impossible for +us to cogitate prior to it, and consequently not by means of it, a +totality. For the conception of totality itself is in the present case +the representation of a completed synthesis of the parts; and this +completion, and consequently its conception, is impossible. + + + +ON THE ANTITHESIS. + +The proof in favour of the infinity of the cosmical succession and +the cosmical content is based upon the consideration that, in the +opposite case, a void time and a void space must constitute the limits +of the world. Now I am not unaware, that there are some ways of +escaping this conclusion. It may, for example, be alleged, that a +limit to the world, as regards both space and time, is quite possible, +without at the same time holding the existence of an absolute time +before the beginning of the world, or an absolute space extending +beyond the actual world--which is impossible. I am quite well +satisfied with the latter part of this opinion of the philosophers +of the Leibnitzian school. Space is merely the form of external +intuition, but not a real object which can itself be externally +intuited; it is not a correlate of phenomena, it is the form of +phenomena itself. Space, therefore, cannot be regarded as absolutely +and in itself something determinative of the existence of things, +because it is not itself an object, but only the form of possible +objects. Consequently, things, as phenomena, determine space; that +is to say, they render it possible that, of all the possible +predicates of space (size and relation), certain may belong to +reality. But we cannot affirm the converse, that space, as something +self-subsistent, can determine real things in regard to size or shape, +for it is in itself not a real thing. Space (filled or void)* may +therefore be limited by phenomena, but phenomena cannot be limited +by an empty space without them. This is true of time also. All this +being granted, it is nevertheless indisputable, that we must assume +these two nonentities, void space without and void time before the +world, if we assume the existence of cosmical limits, relatively to +space or time. + +[*Footnote: It is evident that what is meant here is, that empty space, +in so far as it is limited by phenomena--space, that is, within the +world--does not at least contradict transcendental principles, and +may therefore, as regards them, be admitted, although its possibility +cannot on that account be affirmed.] + +For, as regards the subterfuge adopted by those who endeavour to +evade the consequence--that, if the world is limited as to space and +time, the infinite void must determine the existence of actual +things in regard to their dimensions--it arises solely from the fact +that instead of a sensuous world, an intelligible world--of which +nothing is known--is cogitated; instead of a real beginning (an +existence, which is preceded by a period in which nothing exists), +an existence which presupposes no other condition than that of time; +and, instead of limits of extension, boundaries of the universe. But +the question relates to the mundus phaenomenon, and its quantity; +and in this case we cannot make abstraction of the conditions of +sensibility, without doing away with the essential reality of this +world itself. The world of sense, if it is limited, must necessarily +lie in the infinite void. If this, and with it space as the a priori +condition of the possibility of phenomena, is left out of view, the +whole world of sense disappears. In our problem is this alone +considered as given. The mundus intelligibilis is nothing but the +general conception of a world, in which abstraction has been made of +all conditions of intuition, and in relation to which no synthetical +proposition--either affirmative or negative--is possible. + + + +SECOND CONFLICT OF TRANSCENDENTAL IDEAS. + +THESIS. + +Every composite substance in the world consists of simple parts; and +there exists nothing that is not either itself simple, or composed +of simple parts. + + +PROOF. + +For, grant that composite substances do not consist of simple parts; +in this case, if all combination or composition were annihilated in +thought, no composite part, and (as, by the supposition, there do +not exist simple parts) no simple part would exist. Consequently, no +substance; consequently, nothing would exist. Either, then, it is +impossible to annihilate composition in thought; or, after such +annihilation, there must remain something that subsists without +composition, that is, something that is simple. But in the former case +the composite could not itself consist of substances, because with +substances composition is merely a contingent relation, apart from +which they must still exist as self-subsistent beings. Now, as this +case contradicts the supposition, the second must contain the truth- +that the substantial composite in the world consists of simple parts. + +It follows, as an immediate inference, that the things in the +world are all, without exception, simple beings--that composition is +merely an external condition pertaining to them--and that, although +we never can separate and isolate the elementary substances from the +state of composition, reason must cogitate these as the primary +subjects of all composition, and consequently, as prior thereto--and +as simple substances. + + +ANTITHESIS. + +No composite thing in the world consists of simple parts; and +there does not exist in the world any simple substance. + + +PROOF. + +Let it be supposed that a composite thing (as substance) consists of +simple parts. Inasmuch as all external relation, consequently all +composition of substances, is possible only in space; the space, +occupied by that which is composite, must consist of the same number +of parts as is contained in the composite. But space does not +consist of simple parts, but of spaces. Therefore, every part of the +composite must occupy a space. But the absolutely primary parts of +what is composite are simple. It follows that what is simple +occupies a space. Now, as everything real that occupies a space, +contains a manifold the parts of which are external to each other, +and is consequently composite--and a real composite, not of accidents +(for these cannot exist external to each other apart from substance), +but of substances--it follows that the simple must be a substantial +composite, which is self-contradictory. + +The second proposition of the antithesis--that there exists in the +world nothing that is simple--is here equivalent to the following: +The existence of the absolutely simple cannot be demonstrated from +any experience or perception either external or internal; and the +absolutely simple is a mere idea, the objective reality of which +cannot be demonstrated in any possible experience; it is consequently, +in the exposition of phenomena, without application and object. For, +let us take for granted that an object may be found in experience +for this transcendental idea; the empirical intuition of such an +object must then be recognized to contain absolutely no manifold +with its parts external to each other, and connected into unity. +Now, as we cannot reason from the non-consciousness of such a manifold +to the impossibility of its existence in the intuition of an object, +and as the proof of this impossibility is necessary for the +establishment and proof of absolute simplicity; it follows that this +simplicity cannot be inferred from any perception whatever. As, +therefore, an absolutely simple object cannot be given in any +experience, and the world of sense must be considered as the sum total +of all possible experiences: nothing simple exists in the world. + +This second proposition in the antithesis has a more extended aim +than the first. The first merely banishes the simple from the +intuition of the composite; while the second drives it entirely out +of nature. Hence we were unable to demonstrate it from the conception +of a given object of external intuition (of the composite), but we +were obliged to prove it from the relation of a given object to a +possible experience in general. + + + +OBSERVATIONS ON THE SECOND ANTINOMY. + +THESIS. + +When I speak of a whole, which necessarily consists of simple parts, +I understand thereby only a substantial whole, as the true +composite; that is to say, I understand that contingent unity of the +manifold which is given as perfectly isolated (at least in thought), +placed in reciprocal connection, and thus constituted a unity. Space +ought not to be called a compositum but a totum, for its parts are +possible in the whole, and not the whole by means of the parts. It +might perhaps be called a compositum ideale, but not a compositum +reale. But this is of no importance. As space is not a composite of +substances (and not even of real accidents), if I abstract all +composition therein--nothing, not even a point, remains; for a point +is possible only as the limit of a space--consequently of a composite. +Space and time, therefore, do not consist of simple parts. That +which belongs only to the condition or state of a substance, even +although it possesses a quantity (motion or change, for example), +likewise does not consist of simple parts. That is to say, a certain +degree of change does not originate from the addition of many simple +changes. Our inference of the simple from the composite is valid +only of self-subsisting things. But the accidents of a state are not +self-subsistent. The proof, then, for the necessity of the simple, +as the component part of all that is substantial and composite, may +prove a failure, and the whole case of this thesis be lost, if we +carry the proposition too far, and wish to make it valid of everything +that is composite without distinction--as indeed has really now and +then happened. Besides, I am here speaking only of the simple, in so +far as it is necessarily given in the composite--the latter being +capable of solution into the former as its component parts. The proper +signification of the word monas (as employed by Leibnitz) ought to +relate to the simple, given immediately as simple substance (for +example, in consciousness), and not as an element of the composite. +As an clement, the term atomus would be more appropriate. And as I +wish to prove the existence of simple substances, only in relation +to, and as the elements of, the composite, I might term the antithesis +of the second Antinomy, transcendental Atomistic. But as this word +has long been employed to designate a particular theory of corporeal +phenomena (moleculae), and thus presupposes a basis of empirical +conceptions, I prefer calling it the dialectical principle of +Monadology. + + +ANTITHESIS. + +Against the assertion of the infinite subdivisibility of matter +whose ground of proof is purely mathematical, objections have been +alleged by the Monadists. These objections lay themselves open, at +first sight, to suspicion, from the fact that they do not recognize +the clearest mathematical proofs as propositions relating to the +constitution of space, in so far as it is really the formal +condition of the possibility of all matter, but regard them merely +as inferences from abstract but arbitrary conceptions, which cannot +have any application to real things. Just as if it were possible to +imagine another mode of intuition than that given in the primitive +intuition of space; and just as if its a priori determinations did +not apply to everything, the existence of which is possible, from the +fact alone of its filling space. If we listen to them, we shall find +ourselves required to cogitate, in addition to the mathematical point, +which is simple--not, however, a part, but a mere limit of space- +physical points, which are indeed likewise simple, but possess the +peculiar property, as parts of space, of filling it merely by their +aggregation. I shall not repeat here the common and clear +refutations of this absurdity, which are to be found everywhere in +numbers: every one knows that it is impossible to undermine the +evidence of mathematics by mere discursive conceptions; I shall only +remark that, if in this case philosophy endeavours to gain an +advantage over mathematics by sophistical artifices, it is because +it forgets that the discussion relates solely to Phenomena and their +conditions. It is not sufficient to find the conception of the +simple for the pure conception of the composite, but we must +discover for the intuition of the composite (matter), the intuition +of the simple. Now this, according to the laws of sensibility, and +consequently in the case of objects of sense, is utterly impossible. +In the case of a whole composed of substances, which is cogitated +solely by the pure understanding, it may be necessary to be in +possession of the simple before composition is possible. But this does +not hold good of the Totum substantiale phaenomenon, which, as an +empirical intuition in space, possesses the necessary property of +containing no simple part, for the very reason that no part of space +is simple. Meanwhile, the Monadists have been subtle enough to +escape from this difficulty, by presupposing intuition and the +dynamical relation of substances as the condition of the possibility +of space, instead of regarding space as the condition of the +possibility of the objects of external intuition, that is, of +bodies. Now we have a conception of bodies only as phenomena, and, +as such, they necessarily presuppose space as the condition of all +external phenomena. The evasion is therefore in vain; as, indeed, we +have sufficiently shown in our Aesthetic. If bodies were things in +themselves, the proof of the Monadists would be unexceptionable. + +The second dialectical assertion possesses the peculiarity of having +opposed to it a dogmatical proposition, which, among all such +sophistical statements, is the only one that undertakes to prove in +the case of an object of experience, that which is properly a +transcendental idea--the absolute simplicity of substance. The +proposition is that the object of the internal sense, the thinking +Ego, is an absolute simple substance. Without at present entering upon +this subject--as it has been considered at length in a former chapter- +I shall merely remark that, if something is cogitated merely as an +object, without the addition of any synthetical determination of its +intuition--as happens in the case of the bare representation, I--it +is certain that no manifold and no composition can be perceived in +such a representation. As, moreover, the predicates whereby I cogitate +this object are merely intuitions of the internal sense, there cannot +be discovered in them anything to prove the existence of a manifold +whose parts are external to each other, and, consequently, nothing +to prove the existence of real composition. Consciousness, therefore, +is so constituted that, inasmuch as the thinking subject is at the +same time its own object, it cannot divide itself--although it can +divide its inhering determinations. For every object in relation to +itself is absolute unity. Nevertheless, if the subject is regarded +externally, as an object of intuition, it must, in its character of +phenomenon, possess the property of composition. And it must always +be regarded in this manner, if we wish to know whether there is or +is not contained in it a manifold whose parts are external to each +other. + + + +THIRD CONFLICT OF THE TRANSCENDENTAL IDEAS. + +THESIS. + +Causality according to the laws of nature, is not the only causality +operating to originate the phenomena of the world. A causality of +freedom is also necessary to account fully for these phenomena. + + +PROOF. + +Let it be supposed, that there is no other kind of causality than +that according to the laws of nature. Consequently, everything that +happens presupposes a previous condition, which it follows with +absolute certainty, in conformity with a rule. But this previous +condition must itself be something that has happened (that has +arisen in time, as it did not exist before), for, if it has always +been in existence, its consequence or effect would not thus +originate for the first time, but would likewise have always +existed. The causality, therefore, of a cause, whereby something +happens, is itself a thing that has happened. Now this again +presupposes, in conformity with the law of nature, a previous +condition and its causality, and this another anterior to the +former, and so on. If, then, everything happens solely in accordance +with the laws of nature, there cannot be any real first beginning of +things, but only a subaltern or comparative beginning. There cannot, +therefore, be a completeness of series on the side of the causes which +originate the one from the other. But the law of nature is that +nothing can happen without a sufficient a priori determined cause. +The proposition therefore--if all causality is possible only in accordance +with the laws of nature--is, when stated in this unlimited and general +manner, self-contradictory. It follows that this cannot be the only +kind of causality. + +From what has been said, it follows that a causality must be +admitted, by means of which something happens, without its cause being +determined according to necessary laws by some other cause +preceding. That is to say, there must exist an absolute spontaneity +of cause, which of itself originates a series of phenomena which proceeds +according to natural laws--consequently transcendental freedom, +without which even in the course of nature the succession of phenomena +on the side of causes is never complete. + + +ANTITHESIS. + +There is no such thing as freedom, but everything in the world +happens solely according to the laws of nature. + + +PROOF. + +Granted, that there does exist freedom in the transcendental +sense, as a peculiar kind of causality, operating to produce events +in the world--a faculty, that is to say, of originating a state, and +consequently a series of consequences from that state. In this case, +not only the series originated by this spontaneity, but the +determination of this spontaneity itself to the production of the +series, that is to say, the causality itself must have an absolute +commencement, such that nothing can precede to determine this action +according to unvarying laws. But every beginning of action presupposes +in the acting cause a state of inaction; and a dynamically primal +beginning of action presupposes a state, which has no connection--as +regards causality--with the preceding state of the cause--which does +not, that is, in any wise result from it. Transcendental freedom is +therefore opposed to the natural law of cause and effect, and such +a conjunction of successive states in effective causes is destructive +of the possibility of unity in experience and for that reason not to +be found in experience--is consequently a mere fiction of thought. + +We have, therefore, nothing but nature to which we must look for +connection and order in cosmical events. Freedom--independence of +the laws of nature--is certainly a deliverance from restraint, but +it is also a relinquishing of the guidance of law and rule. For it +cannot be alleged that, instead of the laws of nature, laws of freedom +may be introduced into the causality of the course of nature. For, +if freedom were determined according to laws, it would be no longer +freedom, but merely nature. Nature, therefore, and transcendental +freedom are distinguishable as conformity to law and lawlessness. +The former imposes upon understanding the difficulty of seeking the +origin of events ever higher and higher in the series of causes, +inasmuch as causality is always conditioned thereby; while it +compensates this labour by the guarantee of a unity complete and in +conformity with law. The latter, on the contrary, holds out to the +understanding the promise of a point of rest in the chain of causes, +by conducting it to an unconditioned causality, which professes to +have the power of spontaneous origination, but which, in its own utter +blindness, deprives it of the guidance of rules, by which alone a +completely connected experience is possible. + + + +OBSERVATIONS ON THE THIRD ANTINOMY. + +ON THE THESIS. + +The transcendental idea of freedom is far from constituting the +entire content of the psychological conception so termed, which is +for the most part empirical. It merely presents us with the conception +of spontaneity of action, as the proper ground for imputing freedom +to the cause of a certain class of objects. It is, however, the true +stumbling-stone to philosophy, which meets with unconquerable +difficulties in the way of its admitting this kind of unconditioned +causality. That element in the question of the freedom of the will, +which has for so long a time placed speculative reason in such +perplexity, is properly only transcendental, and concerns the +question, whether there must be held to exist a faculty of spontaneous +origination of a series of successive things or states. How such a +faculty is possible is not a necessary inquiry; for in the case of +natural causality itself, we are obliged to content ourselves with +the a priori knowledge that such a causality must be presupposed, although +we are quite incapable of comprehending how the being of one thing +is possible through the being of another, but must for this +information look entirely to experience. Now we have demonstrated this +necessity of a free first beginning of a series of phenomena, only +in so far as it is required for the comprehension of an origin of +the world, all following states being regarded as a succession +according to laws of nature alone. But, as there has thus been +proved the existence of a faculty which can of itself originate a +series in time--although we are unable to explain how it can exist--we +feel ourselves authorized to admit, even in the midst of the natural +course of events, a beginning, as regards causality, of different +successions of phenomena, and at the same time to attribute to all +substances a faculty of free action. But we ought in this case not +to allow ourselves to fall into a common misunderstanding, and to +suppose that, because a successive series in the world can only have +a comparatively first beginning--another state or condition of things +always preceding--an absolutely first beginning of a series in the +course of nature is impossible. For we are not speaking here of an +absolutely first beginning in relation to time, but as regards +causality alone. When, for example, I, completely of my own free will, +and independently of the necessarily determinative influence of +natural causes, rise from my chair, there commences with this event, +including its material consequences in infinitum, an absolutely new +series; although, in relation to time, this event is merely the +continuation of a preceding series. For this resolution and act of +mine do not form part of the succession of effects in nature, and +are not mere continuations of it; on the contrary, the determining +causes of nature cease to operate in reference to this event, which +certainly succeeds the acts of nature, but does not proceed from them. +For these reasons, the action of a free agent must be termed, in +regard to causality, if not in relation to time, an absolutely +primal beginning of a series of phenomena. + +The justification of this need of reason to rest upon a free act +as the first beginning of the series of natural causes is evident from +the fact, that all philosophers of antiquity (with the exception of +the Epicurean school) felt themselves obliged, when constructing a +theory of the motions of the universe, to accept a prime mover, that +is, a freely acting cause, which spontaneously and prior to all +other causes evolved this series of states. They always felt the +need of going beyond mere nature, for the purpose of making a first +beginning comprehensible. + + + +ON THE ANTITHESIS. + +The assertor of the all-sufficiency of nature in regard to causality +(transcendental Physiocracy), in opposition to the doctrine of +freedom, would defend his view of the question somewhat in the +following manner. He would say, in answer to the sophistical arguments +of the opposite party: If you do not accept a mathematical first, in +relation to time, you have no need to seek a dynamical first, in +regard to causality. Who compelled you to imagine an absolutely primal +condition of the world, and therewith an absolute beginning of the +gradually progressing successions of phenomena--and, as some +foundation for this fancy of yours, to set bounds to unlimited nature? +Inasmuch as the substances in the world have always existed--at +least the unity of experience renders such a supposition quite +necessary--there is no difficulty in believing also, that the +changes in the conditions of these substances have always existed; +and, consequently, that a first beginning, mathematical or +dynamical, is by no means required. The possibility of such an +infinite derivation, without any initial member from which all the +others result, is certainly quite incomprehensible. But, if you are +rash enough to deny the enigmatical secrets of nature for this reason, +you will find yourselves obliged to deny also the existence of many +fundamental properties of natural objects (such as fundamental +forces), which you can just as little comprehend; and even the +possibility of so simple a conception as that of change must present +to you insuperable difficulties. For if experience did not teach you +that it was real, you never could conceive a priori the possibility +of this ceaseless sequence of being and non-being. + +But if the existence of a transcendental faculty of freedom is +granted--a faculty of originating changes in the world--this faculty +must at least exist out of and apart from the world; although it is +certainly a bold assumption, that, over and above the complete content +of all possible intuitions, there still exists an object which +cannot be presented in any possible perception. But, to attribute to +substances in the world itself such a faculty, is quite +inadmissible; for, in this case; the connection of phenomena +reciprocally determining and determined according to general laws, +which is termed nature, and along with it the criteria of empirical +truth, which enable us to distinguish experience from mere visionary +dreaming, would almost entirely disappear. In proximity with such a +lawless faculty of freedom, a system of nature is hardly cogitable; +for the laws of the latter would be continually subject to the +intrusive influences of the former, and the course of phenomena, which +would otherwise proceed regularly and uniformly, would become +thereby confused and disconnected. + + + +FOURTH CONFLICT OF THE TRANSCENDENTAL IDEAS. + +THESIS. + +There exists either in, or in connection with the world--either as +a part of it, or as the cause of it--an absolutely necessary being. + + +PROOF. + +The world of sense, as the sum total of all phenomena, contains a +series of changes. For, without such a series, the mental +representation of the series of time itself, as the condition of the +possibility of the sensuous world, could not be presented to us.* +But every change stands under its condition, which precedes it in time +and renders it necessary. Now the existence of a given condition +presupposes a complete series of conditions up to the absolutely +unconditioned, which alone is absolutely necessary. It follows that +something that is absolutely necessary must exist, if change exists +as its consequence. But this necessary thing itself belongs to the +sensuous world. For suppose it to exist out of and apart from it, +the series of cosmical changes would receive from it a beginning, +and yet this necessary cause would not itself belong to the world of +sense. But this is impossible. For, as the beginning of a series in +time is determined only by that which precedes it in time, the supreme +condition of the beginning of a series of changes must exist in the +time in which this series itself did not exist; for a beginning +supposes a time preceding, in which the thing that begins to be was +not in existence. The causality of the necessary cause of changes, +and consequently the cause itself, must for these reasons belong to +time--and to phenomena, time being possible only as the form of +phenomena. Consequently, it cannot be cogitated as separated from +the world of sense--the sum total of all phenomena. There is, +therefore, contained in the world, something that is absolutely +necessary--whether it be the whole cosmical series itself, or only +a part of it. + +[*Footnote: Objectively, time, as the formal condition of the possibility +of change, precedes all changes; but subjectively, and in +consciousness, the representation of time, like every other, is +given solely by occasion of perception.] + + +ANTITHESIS. + +An absolutely necessary being does not exist, either in the world, +or out of it--as its cause. + + +PROOF. + +Grant that either the world itself is necessary, or that there is +contained in it a necessary existence. Two cases are possible. +First, there must either be in the series of cosmical changes a +beginning, which is unconditionally necessary, and therefore uncaused- +which is at variance with the dynamical law of the determination of +all phenomena in time; or, secondly, the series itself is without +beginning, and, although contingent and conditioned in all its +parts, is nevertheless absolutely necessary and unconditioned as a +whole--which is self-contradictory. For the existence of an +aggregate cannot be necessary, if no single part of it possesses +necessary existence. + +Grant, on the other band, that an absolutely necessary cause +exists out of and apart from the world. This cause, as the highest +member in the series of the causes of cosmical changes, must originate +or begin* the existence of the latter and their series. In this case +it must also begin to act, and its causality would therefore belong +to time, and consequently to the sum total of phenomena, that is, to +the world. It follows that the cause cannot be out of the world; which +is contradictory to the hypothesis. Therefore, neither in the world, +nor out of it (but in causal connection with it), does there exist +any absolutely necessary being. + +[*Footnote: The word begin is taken in two senses. The first is active-- +the cause being regarded as beginning a series of conditions as its +effect (infit). The second is passive--the causality in the cause itself +beginning to operate (fit). I reason here from the first to the second.] + + + +OBSERVATIONS ON THE FOURTH ANTINOMY. + +ON THE THESIS. + +To demonstrate the existence of a necessary being, I cannot be +permitted in this place to employ any other than the cosmological +argument, which ascends from the conditioned in phenomena to the +unconditioned in conception--the unconditioned being considered the +necessary condition of the absolute totality of the series. The proof, +from the mere idea of a supreme being, belongs to another principle +of reason and requires separate discussion. + +The pure cosmological proof demonstrates the existence of a +necessary being, but at the same time leaves it quite unsettled, +whether this being is the world itself, or quite distinct from it. +To establish the truth of the latter view, principles are requisite, +which are not cosmological and do not proceed in the series of +phenomena. We should require to introduce into our proof conceptions +of contingent beings--regarded merely as objects of the understanding, +and also a principle which enables us to connect these, by means of +mere conceptions, with a necessary being. But the proper place for +all such arguments is a transcendent philosophy, which has unhappily +not yet been established. + +But, if we begin our proof cosmologically, by laying at the +foundation of it the series of phenomena, and the regress in it +according to empirical laws of causality, we are not at liberty to +break off from this mode of demonstration and to pass over to +something which is not itself a member of the series. The condition +must be taken in exactly the same signification as the relation of +the conditioned to its condition in the series has been taken, for +the series must conduct us in an unbroken regress to this supreme +condition. But if this relation is sensuous, and belongs to the +possible empirical employment of understanding, the supreme +condition or cause must close the regressive series according to the +laws of sensibility and consequently, must belong to the series of +time. It follows that this necessary existence must be regarded as +the highest member of the cosmical series. + +Certain philosophers have, nevertheless, allowed themselves the +liberty of making such a saltus (metabasis eis allo gonos). From the +changes in the world they have concluded their empirical +contingency, that is, their dependence on empirically-determined +causes, and they thus admitted an ascending series of empirical +conditions: and in this they are quite right. But as they could not +find in this series any primal beginning or any highest member, they +passed suddenly from the empirical conception of contingency to the +pure category, which presents us with a series--not sensuous, but +intellectual--whose completeness does certainly rest upon the +existence of an absolutely necessary cause. Nay, more, this +intellectual series is not tied to any sensuous conditions; and is +therefore free from the condition of time, which requires it +spontaneously to begin its causality in time. But such a procedure +is perfectly inadmissible, as will be made plain from what follows. + +In the pure sense of the categories, that is contingent the +contradictory opposite of which is possible. Now we cannot reason from +empirical contingency to intellectual. The opposite of that which is +changed--the opposite of its state--is actual at another time, and +is therefore possible. Consequently, it is not the contradictory +opposite of the former state. To be that, it is necessary that, in +the same time in which the preceding state existed, its opposite could +have existed in its place; but such a cognition is not given us in +the mere phenomenon of change. A body that was in motion = A, comes +into a state of rest = non-A. Now it cannot be concluded from the fact +that a state opposite to the state A follows it, that the contradictory +opposite of A is possible; and that A is therefore contingent. To +prove this, we should require to know that the state of rest could +have existed in the very same time in which the motion took place. +Now we know nothing more than that the state of rest was actual in +the time that followed the state of motion; consequently, that it was +also possible. But motion at one time, and rest at another time, are +not contradictorily opposed to each other. It follows from what has +been said that the succession of opposite determinations, that is, +change, does not demonstrate the fact of contingency as represented +in the conceptions of the pure understanding; and that it cannot, +therefore, conduct us to the fact of the existence of a necessary +being. Change proves merely empirical contingency, that is to say, +that the new state could not have existed without a cause, which +belongs to the preceding time. This cause--even although it is +regarded as absolutely necessary--must be presented to us in time, +and must belong to the series of phenomena. + + +ON THE ANTITHESIS. + +The difficulties which meet us, in our attempt to rise through the +series of phenomena to the existence of an absolutely necessary +supreme cause, must not originate from our inability to establish +the truth of our mere conceptions of the necessary existence of a +thing. That is to say, our objections not be ontological, but must +be directed against the causal connection with a series of phenomena +of a condition which is itself unconditioned. In one word, they must +be cosmological and relate to empirical laws. We must show that the +regress in the series of causes (in the world of sense) cannot +conclude with an empirically unconditioned condition, and that the +cosmological argument from the contingency of the cosmical state--a +contingency alleged to arise from change--does not justify us in +accepting a first cause, that is, a prime originator of the cosmical +series. + +The reader will observe in this antinomy a very remarkable contrast. +The very same grounds of proof which established in the thesis the +existence of a supreme being, demonstrated in the antithesis--and with +equal strictness--the non-existence of such a being. We found, +first, that a necessary being exists, because the whole time past +contains the series of all conditions, and with it, therefore, the +unconditioned (the necessary); secondly, that there does not exist +any necessary being, for the same reason, that the whole time past +contains the series of all conditions--which are themselves, +therefore, in the aggregate, conditioned. The cause of this seeming +incongruity is as follows. We attend, in the first argument, solely +to the absolute totality of the series of conditions, the one of which +determines the other in time, and thus arrive at a necessary +unconditioned. In the second, we consider, on the contrary, the +contingency of everything that is determined in the series of time- +for every event is preceded by a time, in which the condition itself +must be determined as conditioned--and thus everything that is +unconditioned or absolutely necessary disappears. In both, the mode +of proof is quite in accordance with the common procedure of human +reason, which often falls into discord with itself, from considering +an object from two different points of view. Herr von Mairan +regarded the controversy between two celebrated astronomers, which +arose from a similar difficulty as to the choice of a proper +standpoint, as a phenomenon of sufficient importance to warrant a +separate treatise on the subject. The one concluded: the moon revolves +on its own axis, because it constantly presents the same side to the +earth; the other declared that the moon does not revolve on its own +axis, for the same reason. Both conclusions were perfectly correct, +according to the point of view from which the motions of the moon were +considered. + + + +SECTION III. Of the Interest of Reason in these Self-contradictions. + +We have thus completely before us the dialectical procedure of the +cosmological ideas. No possible experience can present us with an +object adequate to them in extent. Nay, more, reason itself cannot +cogitate them as according with the general laws of experience. And +yet they are not arbitrary fictions of thought. On the contrary, +reason, in its uninterrupted progress in the empirical synthesis, is +necessarily conducted to them, when it endeavours to free from all +conditions and to comprehend in its unconditioned totality that +which can only be determined conditionally in accordance with the laws +of experience. These dialectical propositions are so many attempts +to solve four natural and unavoidable problems of reason. There are +neither more, nor can there be less, than this number, because there +are no other series of synthetical hypotheses, limiting a priori the +empirical synthesis. + +The brilliant claims of reason striving to extend its dominion +beyond the limits of experience, have been represented above only in +dry formulae, which contain merely the grounds of its pretensions. +They have, besides, in conformity with the character of a +transcendental philosophy, been freed from every empirical element; +although the full splendour of the promises they hold out, and the +anticipations they excite, manifests itself only when in connection +with empirical cognitions. In the application of them, however, and +in the advancing enlargement of the employment of reason, while +struggling to rise from the region of experience and to soar to +those sublime ideas, philosophy discovers a value and a dignity, +which, if it could but make good its assertions, would raise it far +above all other departments of human knowledge--professing, as it +does, to present a sure foundation for our highest hopes and the +ultimate aims of all the exertions of reason. The questions: whether +the world has a beginning and a limit to its extension in space; +whether there exists anywhere, or perhaps, in my own thinking Self, +an indivisible and indestructible unity--or whether nothing but what +is divisible and transitory exists; whether I am a free agent, or, +like other beings, am bound in the chains of nature and fate; whether, +finally, there is a supreme cause of the world, or all our thought +and speculation must end with nature and the order of external things--are +questions for the solution of which the mathematician would +willingly exchange his whole science; for in it there is no +satisfaction for the highest aspirations and most ardent desires of +humanity. Nay, it may even be said that the true value of mathematics- +that pride of human reason--consists in this: that she guides reason +to the knowledge of nature--in her greater as well as in her less +manifestations--in her beautiful order and regularity--guides her, +moreover, to an insight into the wonderful unity of the moving +forces in the operations of nature, far beyond the expectations of +a philosophy building only on experience; and that she thus encourages +philosophy to extend the province of reason beyond all experience, +and at the same time provides it with the most excellent materials +for supporting its investigations, in so far as their nature admits, +by adequate and accordant intuitions. + +Unfortunately for speculation--but perhaps fortunately for the +practical interests of humanity--reason, in the midst of her highest +anticipations, finds herself hemmed in by a press of opposite and +contradictory conclusions, from which neither her honour nor her +safety will permit her to draw back. Nor can she regard these +conflicting trains of reasoning with indifference as mere passages +at arms, still less can she command peace; for in the subject of the +conflict she has a deep interest. There is no other course left open +to her than to reflect with herself upon the origin of this disunion +in reason--whether it may not arise from a mere misunderstanding. +After such an inquiry, arrogant claims would have to be given up on +both sides; but the sovereignty of reason over understanding and sense +would be based upon a sure foundation. + +We shall at present defer this radical inquiry and, in the meantime, +consider for a little what side in the controversy we should most +willingly take, if we were obliged to become partisans at all. As, +in this case, we leave out of sight altogether the logical criterion +of truth, and merely consult our own interest in reference to the +question, these considerations, although inadequate to settle the +question of right in either party, will enable us to comprehend how +those who have taken part in the struggle, adopt the one view rather +than the other--no special insight into the subject, however, having +influenced their choice. They will, at the same time, explain to us +many other things by the way--for example, the fiery zeal on the one +side and the cold maintenance of their cause on the other; why the +one party has met with the warmest approbations, and the other has +always been repulsed by irreconcilable prejudices. + +There is one thing, however, that determines the proper point of +view, from which alone this preliminary inquiry can be instituted +and carried on with the proper completeness--and that is the +comparison of the principles from which both sides, thesis and +antithesis, proceed. My readers would remark in the propositions of +the antithesis a complete uniformity in the mode of thought and a +perfect unity of principle. Its principle was that of pure empiricism, +not only in the explication of the phenomena in the world, but also +in the solution of the transcendental ideas, even of that of the universe +itself. The affirmations of the thesis, on the contrary, were based, +in addition to the empirical mode of explanation employed in the +series of phenomena, on intellectual propositions; and its +principles were in so far not simple. I shall term the thesis, in view +of its essential characteristic, the dogmatism of pure reason. + +On the side of Dogmatism, or of the thesis, therefore, in the +determination of the cosmological ideas, we find: + +1. A practical interest, which must be very dear to every +right-thinking man. That the word has a beginning--that the nature +of my thinking self is simple, and therefore indestructible--that I +am a free agent, and raised above the compulsion of nature and her +laws--and, finally, that the entire order of things, which form the +world, is dependent upon a Supreme Being, from whom the whole receives +unity and connection--these are so many foundation-stones of +morality and religion. The antithesis deprives us of all these +supports--or, at least, seems so to deprive us. + +2. A speculative interest of reason manifests itself on this side. +For, if we take the transcendental ideas and employ them in the manner +which the thesis directs, we can exhibit completely a priori the +entire chain of conditions, and understand the derivation of the +conditioned--beginning from the unconditioned. This the antithesis +does not do; and for this reason does not meet with so welcome a +reception. For it can give no answer to our question respecting the +conditions of its synthesis--except such as must be supplemented by +another question, and so on to infinity. According to it, we must rise +from a given beginning to one still higher; every part conducts us +to a still smaller one; every event is preceded by another event which +is its cause; and the conditions of existence rest always upon other +and still higher conditions, and find neither end nor basis in some +self-subsistent thing as the primal being. + +3. This side has also the advantage of popularity; and this +constitutes no small part of its claim to favour. The common +understanding does not find the least difficulty in the idea of the +unconditioned beginning of all synthesis--accustomed, as it is, rather +to follow our consequences than to seek for a proper basis for +cognition. In the conception of an absolute first, moreover--the +possibility of which it does not inquire into--it is highly +gratified to find a firmly-established point of departure for its +attempts at theory; while in the restless and continuous ascent from +the conditioned to the condition, always with one foot in the air, +it can find no satisfaction. + +On the side of the antithesis, or Empiricism, in the determination +of the cosmological ideas: + +1. We cannot discover any such practical interest arising from +pure principles of reason as morality and religion present. On the +contrary, pure empiricism seems to empty them of all their power and +influence. If there does not exist a Supreme Being distinct from the +world--if the world is without beginning, consequently without a +Creator--if our wills are not free, and the soul is divisible and +subject to corruption just like matter--the ideas and principles of +morality lose all validity and fall with the transcendental ideas +which constituted their theoretical support. + +2. But empiricism, in compensation, holds out to reason, in its +speculative interests, certain important advantages, far exceeding +any that the dogmatist can promise us. For, when employed by the +empiricist, understanding is always upon its proper ground of +investigation--the field of possible experience, the laws of which +it can explore, and thus extend its cognition securely and with +clear intelligence without being stopped by limits in any direction. +Here can it and ought it to find and present to intuition its proper +object--not only in itself, but in all its relations; or, if it employ +conceptions, upon this ground it can always present the +corresponding images in clear and unmistakable intuitions. It is quite +unnecessary for it to renounce the guidance of nature, to attach +itself to ideas, the objects of which it cannot know; because, as mere +intellectual entities, they cannot be presented in any intuition. On +the contrary, it is not even permitted to abandon its proper +occupation, under the pretence that it has been brought to a +conclusion (for it never can be), and to pass into the region of +idealizing reason and transcendent conceptions, which it is not +required to observe and explore the laws of nature, but merely to +think and to imagine--secure from being contradicted by facts, because +they have not been called as witnesses, but passed by, or perhaps +subordinated to the so-called higher interests and considerations of +pure reason. + +Hence the empiricist will never allow himself to accept any epoch of +nature for the first--the absolutely primal state; he will not believe +that there can be limits to his outlook into her wide domains, nor +pass from the objects of nature, which he can satisfactorily explain +by means of observation and mathematical thought--which he can +determine synthetically in intuition, to those which neither sense +nor imagination can ever present in concreto; he will not concede the +existence of a faculty in nature, operating independently of the +laws of nature--a concession which would introduce uncertainty into +the procedure of the understanding, which is guided by necessary +laws to the observation of phenomena; nor, finally, will he permit +himself to seek a cause beyond nature, inasmuch as we know nothing +but it, and from it alone receive an objective basis for all our +conceptions and instruction in the unvarying laws of things. + +In truth, if the empirical philosopher had no other purpose in the +establishment of his antithesis than to check the presumption of a +reason which mistakes its true destination, which boasts of its +insight and its knowledge, just where all insight and knowledge +cease to exist, and regards that which is valid only in relation to +a practical interest, as an advancement of the speculative interests +of the mind (in order, when it is convenient for itself, to break +the thread of our physical investigations, and, under pretence of +extending our cognition, connect them with transcendental ideas, by +means of which we really know only that we know nothing)--if, I say, +the empiricist rested satisfied with this benefit, the principle +advanced by him would be a maxim recommending moderation in the +pretensions of reason and modesty in its affirmations, and at the same +time would direct us to the right mode of extending the province of +the understanding, by the help of the only true teacher, experience. +In obedience to this advice, intellectual hypotheses and faith would +not be called in aid of our practical interests; nor should we +introduce them under the pompous titles of science and insight. For +speculative cognition cannot find an objective basis any other where +than in experience; and, when we overstep its limits our synthesis, +which requires ever new cognitions independent of experience, has no +substratum of intuition upon which to build. + +But if--as often happens--empiricism, in relation to ideas, +becomes itself dogmatic and boldly denies that which is above the +sphere of its phenomenal cognition, it falls itself into the error +of intemperance--an error which is here all the more reprehensible, +as thereby the practical interest of reason receives an irreparable +injury. + +And this constitutes the opposition between Epicureanism* and +Platonism. + +[*Footnote: It is, however, still a matter of doubt whether Epicurus +ever propounded these principles as directions for the objective employment +of the understanding. If, indeed, they were nothing more than maxims +for the speculative exercise of reason, he gives evidence therein a +more genuine philosophic spirit than any of the philosophers of +antiquity. That, in the explanation of phenomena, we must proceed as +if the field of inquiry had neither limits in space nor commencement +in time; that we must be satisfied with the teaching of experience +in reference to the material of which the world is posed; that we must +not look for any other mode of the origination of events than that +which is determined by the unalterable laws of nature; and finally, +that we not employ the hypothesis of a cause distinct from the world +to account for a phenomenon or for the world itself--are principles +for the extension of speculative philosophy, and the discovery of +the true sources of the principles of morals, which, however little +conformed to in the present day, are undoubtedly correct. At the +same time, any one desirous of ignoring, in mere speculation, these +dogmatical propositions, need not for that reason be accused of +denying them.] + +Both Epicurus and Plato assert more in their systems than they know. +The former encourages and advances science--although to the +prejudice of the practical; the latter presents us with excellent +principles for the investigation of the practical, but, in relation +to everything regarding which we can attain to speculative cognition, +permits reason to append idealistic explanations of natural phenomena, +to the great injury of physical investigation. + +3. In regard to the third motive for the preliminary choice of a +party in this war of assertions, it seems very extraordinary that +empiricism should be utterly unpopular. We should be inclined to +believe that the common understanding would receive it with +pleasure--promising as it does to satisfy it without passing the +bounds of experience and its connected order; while transcendental +dogmatism obliges it to rise to conceptions which far surpass the +intelligence and ability of the most practised thinkers. But in +this, in truth, is to be found its real motive. For the common +understanding thus finds itself in a situation where not even the most +learned can have the advantage of it. If it understands little or +nothing about these transcendental conceptions, no one can boast of +understanding any more; and although it may not express itself in so +scholastically correct a manner as others, it can busy itself with +reasoning and arguments without end, wandering among mere ideas, about +which one can always be very eloquent, because we know nothing about +them; while, in the observation and investigation of nature, it +would be forced to remain dumb and to confess its utter ignorance. +Thus indolence and vanity form of themselves strong recommendations +of these principles. Besides, although it is a hard thing for a +philosopher to assume a principle, of which he can give to himself +no reasonable account, and still more to employ conceptions, the +objective reality of which cannot be established, nothing is more +usual with the common understanding. It wants something which will +allow it to go to work with confidence. The difficulty of even +comprehending a supposition does not disquiet it, because--not knowing +what comprehending means--it never even thinks of the supposition it +may be adopting as a principle; and regards as known that with which +it has become familiar from constant use. And, at last, all +speculative interests disappear before the practical interests which +it holds dear; and it fancies that it understands and knows what its +necessities and hopes incite it to assume or to believe. Thus the +empiricism of transcendentally idealizing reason is robbed of all +popularity; and, however prejudicial it may be to the highest +practical principles, there is no fear that it will ever pass the +limits of the schools, or acquire any favour or influence in society +or with the multitude. + +Human reason is by nature architectonic. That is to say, it +regards all cognitions as parts of a possible system, and hence +accepts only such principles as at least do not incapacitate a +cognition to which we may have attained from being placed along with +others in a general system. But the propositions of the antithesis +are of a character which renders the completion of an edifice of +cognitions impossible. According to these, beyond one state or epoch +of the world there is always to be found one more ancient; in every +part always other parts themselves divisible; preceding every event +another, the origin of which must itself be sought still higher; and +everything in existence is conditioned, and still not dependent on +an unconditioned and primal existence. As, therefore, the antithesis +will not concede the existence of a first beginning which might be +available as a foundation, a complete edifice of cognition, in the +presence of such hypothesis, is utterly impossible. Thus the +architectonic interest of reason, which requires a unity--not +empirical, but a priori and rational--forms a natural recommendation +for the assertions of the thesis in our antinomy. + +But if any one could free himself entirely from all considerations +of interest, and weigh without partiality the assertions of reason, +attending only to their content, irrespective of the consequences +which follow from them; such a person, on the supposition that he knew +no other way out of the confusion than to settle the truth of one or +other of the conflicting doctrines, would live in a state of continual +hesitation. Today, he would feel convinced that the human will is +free; to-morrow, considering the indissoluble chain of nature, he +would look on freedom as a mere illusion and declare nature to be +all-in-all. But, if he were called to action, the play of the merely +speculative reason would disappear like the shapes of a dream, and +practical interest would dictate his choice of principles. But, as +it well befits a reflective and inquiring being to devote certain +periods of time to the examination of its own reason--to divest itself +of all partiality, and frankly to communicate its observations for +the judgement and opinion of others; so no one can be blamed for, much +less prevented from, placing both parties on their trial, with +permission to end themselves, free from intimidation, before +intimidation, before a sworn jury of equal condition with +themselves--the condition of weak and fallible men. + + + +SECTION IV. Of the necessity imposed upon Pure Reason of + presenting a Solution of its Transcendental Problems. + +To avow an ability to solve all problems and to answer all questions +would be a profession certain to convict any philosopher of +extravagant boasting and self-conceit, and at once to destroy the +confidence that might otherwise have been reposed in him. There are, +however, sciences so constituted that every question arising within +their sphere must necessarily be capable of receiving an answer from +the knowledge already possessed, for the answer must be received +from the same sources whence the question arose. In such sciences it +is not allowable to excuse ourselves on the plea of necessary and +unavoidable ignorance; a solution is absolutely requisite. The rule +of right and wrong must help us to the knowledge of what is right or +wrong in all possible cases; otherwise, the idea of obligation or duty +would be utterly null, for we cannot have any obligation to that which +we cannot know. On the other hand, in our investigations of the +phenomena of nature, much must remain uncertain, and many questions +continue insoluble; because what we know of nature is far from being +sufficient to explain all the phenomena that are presented to our +observation. Now the question is: Whether there is in +transcendental philosophy any question, relating to an object +presented to pure reason, which is unanswerable by this reason; and +whether we must regard the subject of the question as quite uncertain, +so far as our knowledge extends, and must give it a place among +those subjects, of which we have just so much conception as is +sufficient to enable us to raise a question--faculty or materials +failing us, however, when we attempt an answer. + +Now I maintain that, among all speculative cognition, the +peculiarity of transcendental philosophy is that there is no question, +relating to an object presented to pure reason, which is insoluble +by this reason; and that the profession of unavoidable ignorance- +the problem being alleged to be beyond the reach of our faculties- +cannot free us from the obligation to present a complete and +satisfactory answer. For the very conception which enables us to raise +the question must give us the power of answering it; inasmuch as the +object, as in the case of right and wrong, is not to be discovered +out of the conception. + +But, in transcendental philosophy, it is only the cosmological +questions to which we can demand a satisfactory answer in relation +to the constitution of their object; and the philosopher is not +permitted to avail himself of the pretext of necessary ignorance and +impenetrable obscurity. These questions relate solely to the +cosmological ideas. For the object must be given in experience, and +the question relates to the adequateness of the object to an idea. +If the object is transcendental and therefore itself unknown; if the +question, for example, is whether the object--the something, the +phenomenon of which (internal--in ourselves) is thought--that is to +say, the soul, is in itself a simple being; or whether there is a +cause of all things, which is absolutely necessary--in such cases we +are seeking for our idea an object, of which we may confess that it +is unknown to us, though we must not on that account assert that it +is impossible.* The cosmological ideas alone posses the peculiarity +that we can presuppose the object of them and the empirical +synthesis requisite for the conception of that object to be given; +and the question, which arises from these ideas, relates merely to +the progress of this synthesis, in so far as it must contain absolute +totality--which, however, is not empirical, as it cannot be given in +any experience. Now, as the question here is solely in regard to a +thing as the object of a possible experience and not as a thing in +itself, the answer to the transcendental cosmological question need +not be sought out of the idea, for the question does not regard an +object in itself. The question in relation to a possible experience +is not, "What can be given in an experience in concreto" but "what +is contained in the idea, to which the empirical synthesis must +approximate." The question must therefore be capable of solution +from the idea alone. For the idea is a creation of reason itself, +which therefore cannot disclaim the obligation to answer or refer us +to the unknown object. + +[*Footnote: The question, "What is the constitution of a transcendental +object?" is unanswerable--we are unable to say what it is; but we +can perceive that the question itself is nothing; because it does +not relate to any object that can be presented to us. For this reason, +we must consider all the questions raised in transcendental psychology +as answerable and as really answered; for they relate to the +transcendental subject of all internal phenomena, which is not +itself phenomenon and consequently not given as an object, in which, +moreover, none of the categories--and it is to them that the +question is properly directed--find any conditions of its application. +Here, therefore, is a case where no answer is the only proper +answer. For a question regarding the constitution of a something which +cannot be cogitated by any determined predicate, being completely +beyond the sphere of objects and experience, is perfectly null and +void.] + +It is not so extraordinary, as it at first sight appears, that a +science should demand and expect satisfactory answers to all the +questions that may arise within its own sphere (questiones +domesticae), although, up to a certain time, these answers may not +have been discovered. There are, in addition to transcendental +philosophy, only two pure sciences of reason; the one with a +speculative, the other with a practical content--pure mathematics +and pure ethics. Has any one ever heard it alleged that, from our +complete and necessary ignorance of the conditions, it is uncertain +what exact relation the diameter of a circle bears to the circle in +rational or irrational numbers? By the former the sum cannot be +given exactly, by the latter only approximately; and therefore we +decide that the impossibility of a solution of the question is +evident. Lambert presented us with a demonstration of this. In the +general principles of morals there can be nothing uncertain, for the +propositions are either utterly without meaning, or must originate +solely in our rational conceptions. On the other hand, there must be +in physical science an infinite number of conjectures, which can never +become certainties; because the phenomena of nature are not given as +objects dependent on our conceptions. The key to the solution of +such questions cannot, therefore, be found in our conceptions, or in +pure thought, but must lie without us and for that reason is in many +cases not to be discovered; and consequently a satisfactory +explanation cannot be expected. The questions of transcendental +analytic, which relate to the deduction of our pure cognition, are +not to be regarded as of the same kind as those mentioned above; for +we are not at present treating of the certainty of judgements in relation +to the origin of our conceptions, but only of that certainty in +relation to objects. + +We cannot, therefore, escape the responsibility of at least a +critical solution of the questions of reason, by complaints of the +limited nature of our faculties, and the seemingly humble confession +that it is beyond the power of our reason to decide, whether the world +has existed from all eternity or had a beginning--whether it is +infinitely extended, or enclosed within certain limits--whether +anything in the world is simple, or whether everything must be capable +of infinite divisibility--whether freedom can originate phenomena, +or whether everything is absolutely dependent on the laws and order +of nature--and, finally, whether there exists a being that is +completely unconditioned and necessary, or whether the existence of +everything is conditioned and consequently dependent on something +external to itself, and therefore in its own nature contingent. For +all these questions relate to an object, which can be given nowhere +else than in thought. This object is the absolutely unconditioned +totality of the synthesis of phenomena. If the conceptions in our +minds do not assist us to some certain result in regard to these +problems, we must not defend ourselves on the plea that the object +itself remains hidden from and unknown to us. For no such thing or +object can be given--it is not to be found out of the idea in our +minds. We must seek the cause of our failure in our idea itself, which +is an insoluble problem and in regard to which we obstinately assume +that there exists a real object corresponding and adequate to it. A +clear explanation of the dialectic which lies in our conception, +will very soon enable us to come to a satisfactory decision in +regard to such a question. + +The pretext that we are unable to arrive at certainty in regard to +these problems may be met with this question, which requires at +least a plain answer: "From what source do the ideas originate, the +solution of which involves you in such difficulties? Are you seeking +for an explanation of certain phenomena; and do you expect these ideas +to give you the principles or the rules of this explanation?" Let it +be granted, that all nature was laid open before you; that nothing +was hid from your senses and your consciousness. Still, you could not +cognize in concreto the object of your ideas in any experience. For +what is demanded is not only this full and complete intuition, but +also a complete synthesis and the consciousness of its absolute +totality; and this is not possible by means of any empirical +cognition. It follows that your question--your idea--is by no means +necessary for the explanation of any phenomenon; and the idea cannot +have been in any sense given by the object itself. For such an +object can never be presented to us, because it cannot be given by +any possible experience. Whatever perceptions you may attain to, you +are still surrounded by conditions--in space, or in time--and you cannot +discover anything unconditioned; nor can you decide whether this +unconditioned is to be placed in an absolute beginning of the +synthesis, or in an absolute totality of the series without beginning. +A whole, in the empirical signification of the term, is always +merely comparative. The absolute whole of quantity (the universe), +of division, of derivation, of the condition of existence, with the +question--whether it is to be produced by finite or infinite +synthesis, no possible experience can instruct us concerning. You will +not, for example, be able to explain the phenomena of a body in the +least degree better, whether you believe it to consist of simple, or +of composite parts; for a simple phenomenon--and just as little an +infinite series of composition--can never be presented to your +perception. Phenomena require and admit of explanation, only in so +far as the conditions of that explanation are given in perception; +but the sum total of that which is given in phenomena, considered as +an absolute whole, is itself a perception--and we cannot therefore +seek for explanations of this whole beyond itself, in other perceptions. +The explanation of this whole is the proper object of the +transcendental problems of pure reason. + +Although, therefore, the solution of these problems is +unattainable through experience, we must not permit ourselves to say +that it is uncertain how the object of our inquiries is constituted. +For the object is in our own mind and cannot be discovered in +experience; and we have only to take care that our thoughts are +consistent with each other, and to avoid falling into the amphiboly +of regarding our idea as a representation of an object empirically +given, and therefore to be cognized according to the laws of experience. +A dogmatical solution is therefore not only unsatisfactory but +impossible. The critical solution, which may be a perfectly certain +one, does not consider the question objectively, but proceeds by +inquiring into the basis of the cognition upon which the question +rests. + + + +SECTION V. Sceptical Exposition of the Cosmological Problems + presented in the four Transcendental Ideas. + +We should be quite willing to desist from the demand of a dogmatical +answer to our questions, if we understood beforehand that, be the +answer what it may, it would only serve to increase our ignorance, +to throw us from one incomprehensibility into another, from one +obscurity into another still greater, and perhaps lead us into +irreconcilable contradictions. If a dogmatical affirmative or negative +answer is demanded, is it at all prudent to set aside the probable +grounds of a solution which lie before us and to take into +consideration what advantage we shall gain, if the answer is to favour +the one side or the other? If it happens that in both cases the answer +is mere nonsense, we have in this an irresistible summons to institute +a critical investigation of the question, for the purpose of +discovering whether it is based on a groundless presupposition and +relates to an idea, the falsity of which would be more easily +exposed in its application and consequences than in the mere +representation of its content. This is the great utility of the +sceptical mode of treating the questions addressed by pure reason to +itself. By this method we easily rid ourselves of the confusions of +dogmatism, and establish in its place a temperate criticism, which, +as a genuine cathartic, will successfully remove the presumptuous notions +of philosophy and their consequence--the vain pretension to +universal science. + +If, then, I could understand the nature of a cosmological idea and +perceive, before I entered on the discussion of the subject at all, +that, whatever side of the question regarding the unconditioned of +the regressive synthesis of phenomena it favoured--it must either be +too great or too small for every conception of the understanding--I +would be able to comprehend how the idea, which relates to an object +of experience--an experience which must be adequate to and in +accordance with a possible conception of the understanding--must be +completely void and without significance, inasmuch as its object is +inadequate, consider it as we may. And this is actually the case +with all cosmological conceptions, which, for the reason above +mentioned, involve reason, so long as it remains attached to them, +in an unavoidable antinomy. For suppose: + +First, that the world has no beginning--in this case it is too large +for our conception; for this conception, which consists in a +successive regress, cannot overtake the whole eternity that has +elapsed. Grant that it has a beginning, it is then too small for the +conception of the understanding. For, as a beginning presupposes a +time preceding, it cannot be unconditioned; and the law of the +empirical employment of the understanding imposes the necessity of +looking for a higher condition of time; and the world is, therefore, +evidently too small for this law. + +The same is the case with the double answer to the question +regarding the extent, in space, of the world. For, if it is infinite +and unlimited, it must be too large for every possible empirical +conception. If it is finite and limited, we have a right to ask: "What +determines these limits?" Void space is not a self-subsistent +correlate of things, and cannot be a final condition--and still less +an empirical condition, forming a part of a possible experience. For +how can we have any experience or perception of an absolute void? +But the absolute totality of the empirical synthesis requires that +the unconditioned be an empirical conception. Consequently, a finite +world is too small for our conception. + +Secondly, if every phenomenon (matter) in space consists of an +infinite number of parts, the regress of the division is always too +great for our conception; and if the division of space must cease with +some member of the division (the simple), it is too small for the idea +of the unconditioned. For the member at which we have discontinued +our division still admits a regress to many more parts contained in +the object. + +Thirdly, suppose that every event in the world happens in accordance +with the laws of nature; the causality of a cause must itself be an +event and necessitates a regress to a still higher cause, and +consequently the unceasing prolongation of the series of conditions +a parte priori. Operative nature is therefore too large for every +conception we can form in the synthesis of cosmical events. + +If we admit the existence of spontaneously produced events, that is, +of free agency, we are driven, in our search for sufficient reasons, +on an unavoidable law of nature and are compelled to appeal to the +empirical law of causality, and we find that any such totality of +connection in our synthesis is too small for our necessary empirical +conception. + +Fourthly, if we assume the existence of an absolutely necessary +being--whether it be the world or something in the world, or the cause +of the world--we must place it in a time at an infinite distance +from any given moment; for, otherwise, it must be dependent on some +other and higher existence. Such an existence is, in this case, too +large for our empirical conception, and unattainable by the +continued regress of any synthesis. + +But if we believe that everything in the world--be it condition or +conditioned--is contingent; every given existence is too small for +our conception. For in this case we are compelled to seek for some +other existence upon which the former depends. + +We have said that in all these cases the cosmological idea is either +too great or too small for the empirical regress in a synthesis, and +consequently for every possible conception of the understanding. Why +did we not express ourselves in a manner exactly the reverse of this +and, instead of accusing the cosmological idea of over stepping or +of falling short of its true aim, possible experience, say that, in +the first case, the empirical conception is always too small for the +idea, and in the second too great, and thus attach the blame of +these contradictions to the empirical regress? The reason is this. +Possible experience can alone give reality to our conceptions; without +it a conception is merely an idea, without truth or relation to an +object. Hence a possible empirical conception must be the standard +by which we are to judge whether an idea is anything more than an idea +and fiction of thought, or whether it relates to an object in the +world. If we say of a thing that in relation to some other thing it +is too large or too small, the former is considered as existing for +the sake of the latter, and requiring to be adapted to it. Among the +trivial subjects of discussion in the old schools of dialectics was +this question: "If a ball cannot pass through a hole, shall we say +that the ball is too large or the hole too small?" In this case it +is indifferent what expression we employ; for we do not know which +exists for the sake of the other. On the other hand, we cannot say: +"The man is too long for his coat"; but: "The coat is too short for +the man." + +We are thus led to the well-founded suspicion that the +cosmological ideas, and all the conflicting sophistical assertions +connected with them, are based upon a false and fictitious +conception of the mode in which the object of these ideas is presented +to us; and this suspicion will probably direct us how to expose the +illusion that has so long led us astray from the truth. + + + +SECTION VI. Transcendental Idealism as the Key to the + Solution of Pure Cosmological Dialectic. + +In the transcendental aesthetic we proved that everything intuited +in space and time, all objects of a possible experience, are nothing +but phenomena, that is, mere representations; and that these, as +presented to us--as extended bodies, or as series of changes--have +no self-subsistent existence apart from human thought. This doctrine +I call Transcendental Idealism.* The realist in the transcendental +sense regards these modifications of our sensibility, these mere +representations, as things subsisting in themselves. + +[*Footnote: I have elsewhere termed this theory formal idealism, to +distinguish it from material idealism, which doubts or denies the +existence of external things. To avoid ambiguity, it seems advisable +in many cases to employ this term instead of that mentioned in the text.] + +It would be unjust to accuse us of holding the long-decried theory +of empirical idealism, which, while admitting the reality of space, +denies, or at least doubts, the existence of bodies extended in it, +and thus leaves us without a sufficient criterion of reality and +illusion. The supporters of this theory find no difficulty in +admitting the reality of the phenomena of the internal sense in +time; nay, they go the length of maintaining that this internal +experience is of itself a sufficient proof of the real existence of +its object as a thing in itself. + +Transcendental idealism allows that the objects of external +intuition--as intuited in space, and all changes in time--as +represented by the internal sense, are real. For, as space is the form +of that intuition which we call external, and, without objects in +space, no empirical representation could be given us, we can and ought +to regard extended bodies in it as real. The case is the same with +representations in time. But time and space, with all phenomena +therein, are not in themselves things. They are nothing but +representations and cannot exist out of and apart from the mind. +Nay, the sensuous internal intuition of the mind (as the object of +consciousness), the determination of which is represented by the +succession of different states in time, is not the real, proper +self, as it exists in itself--not the transcendental subject--but only +a phenomenon, which is presented to the sensibility of this, to us, +unknown being. This internal phenomenon cannot be admitted to be a +self-subsisting thing; for its condition is time, and time cannot be +the condition of a thing in itself. But the empirical truth of +phenomena in space and time is guaranteed beyond the possibility of +doubt, and sufficiently distinguished from the illusion of dreams or +fancy--although both have a proper and thorough connection in an +experience according to empirical laws. The objects of experience then +are not things in themselves, but are given only in experience, and +have no existence apart from and independently of experience. That +there may be inhabitants in the moon, although no one has ever +observed them, must certainly be admitted; but this assertion means +only, that we may in the possible progress of experience discover them +at some future time. For that which stands in connection with a +perception according to the laws of the progress of experience is +real. They are therefore really existent, if they stand in empirical +connection with my actual or real consciousness, although they are +not in themselves real, that is, apart from the progress of experience. + +There is nothing actually given--we can be conscious of nothing as +real, except a perception and the empirical progression from it to +other possible perceptions. For phenomena, as mere representations, +are real only in perception; and perception is, in fact, nothing but +the reality of an empirical representation, that is, a phenomenon. +To call a phenomenon a real thing prior to perception means either +that we must meet with this phenomenon in the progress of +experience, or it means nothing at all. For I can say only of a +thing in itself that it exists without relation to the senses and +experience. But we are speaking here merely of phenomena in space +and time, both of which are determinations of sensibility, and not +of things in themselves. It follows that phenomena are not things in +themselves, but are mere representations, which if not given in us--in +perception--are non-existent. + +The faculty of sensuous intuition is properly a receptivity--a +capacity of being affected in a certain manner by representations, +the relation of which to each other is a pure intuition of space and +time--the pure forms of sensibility. These representations, in so far +as they are connected and determinable in this relation (in space and +time) according to laws of the unity of experience, are called +objects. The non-sensuous cause of these representations is completely +unknown to us and hence cannot be intuited as an object. For such an +object could not be represented either in space or in time; and +without these conditions intuition or representation is impossible. +We may, at the same time, term the non-sensuous cause of phenomena +the transcendental object--but merely as a mental correlate to +sensibility, considered as a receptivity. To this transcendental +object we may attribute the whole connection and extent of our +possible perceptions, and say that it is given and exists in itself +prior to all experience. But the phenomena, corresponding to it, are +not given as things in themselves, but in experience alone. For they +are mere representations, receiving from perceptions alone +significance and relation to a real object, under the condition that +this or that perception--indicating an object--is in complete +connection with all others in accordance with the rules of the unity +of experience. Thus we can say: "The things that really existed in +past time are given in the transcendental object of experience." But +these are to me real objects, only in so far as I can represent to +my own mind, that a regressive series of possible perceptions- +following the indications of history, or the footsteps of cause and +effect--in accordance with empirical laws--that, in one word, the +course of the world conducts us to an elapsed series of time as the +condition of the present time. This series in past time is represented +as real, not in itself, but only in connection with a possible +experience. Thus, when I say that certain events occurred in past +time, I merely assert the possibility of prolonging the chain of +experience, from the present perception, upwards to the conditions +that determine it according to time. + +If I represent to myself all objects existing in all space and time, +I do not thereby place these in space and time prior to all +experience; on the contrary, such a representation is nothing more +than the notion of a possible experience, in its absolute +completeness. In experience alone are those objects, which are nothing +but representations, given. But, when I say they existed prior to my +experience, this means only that I must begin with the perception +present to me and follow the track indicated until I discover them +in some part or region of experience. The cause of the empirical +condition of this progression--and consequently at what member therein +I must stop, and at what point in the regress I am to find this +member--is transcendental, and hence necessarily incognizable. But +with this we have not to do; our concern is only with the law of +progression in experience, in which objects, that is, phenomena, are +given. It is a matter of indifference, whether I say, "I may in the +progress of experience discover stars, at a hundred times greater +distance than the most distant of those now visible," or, "Stars at +this distance may be met in space, although no one has, or ever will +discover them." For, if they are given as things in themselves, +without any relation to possible experience, they are for me +non-existent, consequently, are not objects, for they are not +contained in the regressive series of experience. But, if these +phenomena must be employed in the construction or support of the +cosmological idea of an absolute whole, and when we are discussing +a question that oversteps the limits of possible experience, the +proper distinction of the different theories of the reality of +sensuous objects is of great importance, in order to avoid the +illusion which must necessarily arise from the misinterpretation of +our empirical conceptions. + + + +SECTION VII. Critical Solution of the Cosmological Problem. + +The antinomy of pure reason is based upon the following +dialectical argument: "If that which is conditioned is given, the +whole series of its conditions is also given; but sensuous objects +are given as conditioned; consequently..." This syllogism, the major +of which seems so natural and evident, introduces as many cosmological +ideas as there are different kinds of conditions in the synthesis of +phenomena, in so far as these conditions constitute a series. These +ideas require absolute totality in the series, and thus place reason +in inextricable embarrassment. Before proceeding to expose the fallacy +in this dialectical argument, it will be necessary to have a correct +understanding of certain conceptions that appear in it. + +In the first place, the following proposition is evident, and +indubitably certain: "If the conditioned is given, a regress in the +series of all its conditions is thereby imperatively required." For +the very conception of a conditioned is a conception of something +related to a condition, and, if this condition is itself +conditioned, to another condition--and so on through all the members +of the series. This proposition is, therefore, analytical and has +nothing to fear from transcendental criticism. It is a logical +postulate of reason: to pursue, as far as possible, the connection +of a conception with its conditions. + +If, in the second place, both the conditioned and the condition +are things in themselves, and if the former is given, not only is +the regress to the latter requisite, but the latter is really given +with the former. Now, as this is true of all the members of the +series, the entire series of conditions, and with them the +unconditioned, is at the same time given in the very fact of the +conditioned, the existence of which is possible only in and through +that series, being given. In this case, the synthesis of the +conditioned with its condition, is a synthesis of the understanding +merely, which represents things as they are, without regarding whether +and how we can cognize them. But if I have to do with phenomena, +which, in their character of mere representations, are not given, if +I do not attain to a cognition of them (in other words, to themselves, +for they are nothing more than empirical cognitions), I am not +entitled to say: "If the conditioned is given, all its conditions +(as phenomena) are also given." I cannot, therefore, from the fact +of a conditioned being given, infer the absolute totality of the +series of its conditions. For phenomena are nothing but an empirical +synthesis in apprehension or perception, and are therefore given +only in it. Now, in speaking of phenomena it does not follow that, +if the conditioned is given, the synthesis which constitutes its +empirical condition is also thereby given and presupposed; such a +synthesis can be established only by an actual regress in the series +of conditions. But we are entitled to say in this case that a +regress to the conditions of a conditioned, in other words, that a +continuous empirical synthesis is enjoined; that, if the conditions +are not given, they are at least required; and that we are certain +to discover the conditions in this regress. + +We can now see that the major, in the above cosmological +syllogism, takes the conditioned in the transcendental signification +which it has in the pure category, while the minor speaks of it in +the empirical signification which it has in the category as applied +to phenomena. There is, therefore, a dialectical fallacy in the +syllogism--a sophisma figurae dictionis. But this fallacy is not a +consciously devised one, but a perfectly natural illusion of the +common reason of man. For, when a thing is given as conditioned, we +presuppose in the major its conditions and their series, +unperceived, as it were, and unseen; because this is nothing more than +the logical requirement of complete and satisfactory premisses for +a given conclusion. In this case, time is altogether left out in the +connection of the conditioned with the condition; they are supposed +to be given in themselves, and contemporaneously. It is, moreover, +just as natural to regard phenomena (in the minor) as things in +themselves and as objects presented to the pure understanding, as in +the major, in which complete abstraction was made of all conditions +of intuition. But it is under these conditions alone that objects are +given. Now we overlooked a remarkable distinction between the +conceptions. The synthesis of the conditioned with its condition, +and the complete series of the latter (in the major) are not limited +by time, and do not contain the conception of succession. On the +contrary, the empirical synthesis and the series of conditions in +the phenomenal world--subsumed in the minor--are necessarily +successive and given in time alone. It follows that I cannot +presuppose in the minor, as I did in the major, the absolute +totality of the synthesis and of the series therein represented; for +in the major all the members of the series are given as things in +themselves--without any limitations or conditions of time, while in +the minor they are possible only in and through a successive +regress, which cannot exist, except it be actually carried into +execution in the world of phenomena. + +After this proof of the viciousness of the argument commonly +employed in maintaining cosmological assertions, both parties may +now be justly dismissed, as advancing claims without grounds or title. +But the process has not been ended by convincing them that one or both +were in the wrong and had maintained an assertion which was without +valid grounds of proof. Nothing seems to be clearer than that, if +one maintains: "The world has a beginning," and another: "The world +has no beginning," one of the two must be right. But it is likewise +clear that, if the evidence on both sides is equal, it is impossible +to discover on what side the truth lies; and the controversy +continues, although the parties have been recommended to peace +before the tribunal of reason. There remains, then, no other means +of settling the question than to convince the parties, who refute each +other with such conclusiveness and ability, that they are disputing +about nothing, and that a transcendental illusion has been mocking +them with visions of reality where there is none. The mode of +adjusting a dispute which cannot be decided upon its own merits, we +shall now proceed to lay before our readers. + +Zeno of Elea, a subtle dialectician, was severely reprimanded by +Plato as a sophist, who, merely from the base motive of exhibiting +his skill in discussion, maintained and subverted the same proposition +by arguments as powerful and convincing on the one side as on the +other. He maintained, for example, that God (who was probably +nothing more, in his view, than the world) is neither finite nor +infinite, neither in motion nor in rest, neither similar nor +dissimilar to any other thing. It seemed to those philosophers who +criticized his mode of discussion that his purpose was to deny +completely both of two self-contradictory propositions--which is +absurd. But I cannot believe that there is any justice in this +accusation. The first of these propositions I shall presently consider +in a more detailed manner. With regard to the others, if by the word +of God he understood merely the Universe, his meaning must have +been--that it cannot be permanently present in one place--that is, +at rest--nor be capable of changing its place--that is, of moving- +because all places are in the universe, and the universe itself is, +therefore, in no place. Again, if the universe contains in itself +everything that exists, it cannot be similar or dissimilar to any +other thing, because there is, in fact, no other thing with which it +can be compared. If two opposite judgements presuppose a contingent +impossible, or arbitrary condition, both--in spite of their opposition +(which is, however, not properly or really a contradiction)--fall +away; because the condition, which ensured the validity of both, has +itself disappeared. + +If we say: "Everybody has either a good or a bad smell," we have +omitted a third possible judgement--it has no smell at all; and thus +both conflicting statements may be false. If we say: "It is either +good-smelling or not good-smelling (vel suaveolens vel +non-suaveolens)," both judgements are contradictorily opposed; and +the contradictory opposite of the former judgement--some bodies are +not good-smelling--embraces also those bodies which have no smell at +all. In the preceding pair of opposed judgements (per disparata), +the contingent condition of the conception of body (smell) attached +to both conflicting statements, instead of having been omitted in the +latter, which is consequently not the contradictory opposite of the +former. + +If, accordingly, we say: "The world is either infinite in extension, +or it is not infinite (non est infinitus)"; and if the former +proposition is false, its contradictory opposite--the world is not +infinite--must be true. And thus I should deny the existence of an +infinite, without, however affirming the existence of a finite +world. But if we construct our proposition thus: "The world is +either infinite or finite (non-infinite)," both statements may be +false. For, in this case, we consider the world as per se determined +in regard to quantity, and while, in the one judgement, we deny its +infinite and consequently, perhaps, its independent existence; in +the other, we append to the world, regarded as a thing in itself, a +certain determination--that of finitude; and the latter may be false +as well as the former, if the world is not given as a thing in itself, +and thus neither as finite nor as infinite in quantity. This kind of +opposition I may be allowed to term dialectical; that of +contradictories may be called analytical opposition. Thus then, of +two dialectically opposed judgements both may be false, from the fact, +that the one is not a mere contradictory of the other, but actually +enounces more than is requisite for a full and complete contradiction. + +When we regard the two propositions--"The world is infinite in +quantity," and, "The world is finite in quantity," as contradictory +opposites, we are assuming that the world--the complete series of +phenomena--is a thing in itself. For it remains as a permanent +quantity, whether I deny the infinite or the finite regress in the +series of its phenomena. But if we dismiss this assumption--this +transcendental illusion--and deny that it is a thing in itself, the +contradictory opposition is metamorphosed into a merely dialectical +one; and the world, as not existing in itself--independently of the +regressive series of my representations--exists in like manner neither +as a whole which is infinite nor as a whole which is finite in itself. +The universe exists for me only in the empirical regress of the series +of phenomena and not per se. If, then, it is always conditioned, it +is never completely or as a whole; and it is, therefore, not an +unconditioned whole and does not exist as such, either with an +infinite, or with a finite quantity. + +What we have here said of the first cosmological idea--that of the +absolute totality of quantity in phenomena--applies also to the +others. The series of conditions is discoverable only in the +regressive synthesis itself, and not in the phenomenon considered as +a thing in itself--given prior to all regress. Hence I am compelled +to say: "The aggregate of parts in a given phenomenon is in itself +neither finite nor infinite; and these parts are given only in the +regressive synthesis of decomposition--a synthesis which is never +given in absolute completeness, either as finite, or as infinite." +The same is the case with the series of subordinated causes, or of +the conditioned up to the unconditioned and necessary existence, which +can never be regarded as in itself, ind in its totality, either as +finite or as infinite; because, as a series of subordinate +representations, it subsists only in the dynamical regress and +cannot be regarded as existing previously to this regress, or as a +self-subsistent series of things. + +Thus the antinomy of pure reason in its cosmological ideas +disappears. For the above demonstration has established the fact +that it is merely the product of a dialectical and illusory +opposition, which arises from the application of the idea of +absolute totality--admissible only as a condition of things in +themselves--to phenomena, which exist only in our representations, +and--when constituting a series--in a successive regress. This +antinomy of reason may, however, be really profitable to our +speculative interests, not in the way of contributing any dogmatical +addition, but as presenting to us another material support in our +critical investigations. For it furnishes us with an indirect proof +of the transcendental ideality of phenomena, if our minds were not +completely satisfied with the direct proof set forth in the +Trancendental Aesthetic. The proof would proceed in the following +dilemma. If the world is a whole existing in itself, it must be either +finite or infinite. But it is neither finite nor infinite--as has been +shown, on the one side, by the thesis, on the other, by the +antithesis. Therefore the world--the content of all phenomena--is +not a whole existing in itself. It follows that phenomena are nothing, +apart from our representations. And this is what we mean by +transcendental ideality. + +This remark is of some importance. It enables us to see that the +proofs of the fourfold antinomy are not mere sophistries--are not +fallacious, but grounded on the nature of reason, and valid--under +the supposition that phenomena are things in themselves. The opposition +of the judgements which follow makes it evident that a fallacy lay +in the initial supposition, and thus helps us to discover the true +constitution of objects of sense. This transcendental dialectic does +not favour scepticism, although it presents us with a triumphant +demonstration of the advantages of the sceptical method, the great +utility of which is apparent in the antinomy, where the arguments of +reason were allowed to confront each other in undiminished force. +And although the result of these conflicts of reason is not what we +expected--although we have obtained no positive dogmatical addition +to metaphysical science--we have still reaped a great advantage in +the correction of our judgements on these subjects of thought. + + + +SECTION VIII. Regulative Principle of Pure Reason in relation + to the Cosmological Ideas. + +The cosmological principle of totality could not give us any certain +knowledge in regard to the maximum in the series of conditions in +the world of sense, considered as a thing in itself. The actual +regress in the series is the only means of approaching this maximum. +This principle of pure reason, therefore, may still be considered as +valid--not as an axiom enabling us to cogitate totality in the +object as actual, but as a problem for the understanding, which +requires it to institute and to continue, in conformity with the +idea of totality in the mind, the regress in the series of the +conditions of a given conditioned. For in the world of sense, that +is, in space and time, every condition which we discover in our +investigation of phenomena is itself conditioned; because sensuous +objects are not things in themselves (in which case an absolutely +unconditioned might be reached in the progress of cognition), but +are merely empirical representations the conditions of which must +always be found in intuition. The principle of reason is therefore +properly a mere rule--prescribing a regress in the series of +conditions for given phenomena, and prohibiting any pause or rest on +an absolutely unconditioned. It is, therefore, not a principle of +the possibility of experience or of the empirical cognition of +sensuous objects--consequently not a principle of the understanding; +for every experience is confined within certain proper limits +determined by the given intuition. Still less is it a constitutive +principle of reason authorizing us to extend our conception of the +sensuous world beyond all possible experience. It is merely a +principle for the enlargement and extension of experience as far as +is possible for human faculties. It forbids us to consider any +empirical limits as absolute. It is, hence, a principle of reason, +which, as a rule, dictates how we ought to proceed in our empirical +regress, but is unable to anticipate or indicate prior to the +empirical regress what is given in the object itself. I have termed +it for this reason a regulative principle of reason; while the +principle of the absolute totality of the series of conditions, as +existing in itself and given in the object, is a constitutive +cosmological principle. This distinction will at once demonstrate +the falsehood of the constitutive principle, and prevent us from +attributing (by a transcendental subreptio) objective reality to an +idea, which is valid only as a rule. + +In order to understand the proper meaning of this rule of pure +reason, we must notice first that it cannot tell us what the object +is, but only how the empirical regress is to be proceeded with in +order to attain to the complete conception of the object. If it gave +us any information in respect to the former statement, it would be +a constitutive principle--a principle impossible from the nature of +pure reason. It will not therefore enable us to establish any such +conclusions as: "The series of conditions for a given conditioned is +in itself finite," or, "It is infinite." For, in this case, we +should be cogitating in the mere idea of absolute totality, an +object which is not and cannot be given in experience; inasmuch as +we should be attributing a reality objective and independent of the +empirical synthesis, to a series of phenomena. This idea of reason +cannot then be regarded as valid--except as a rule for the +regressive synthesis in the series of conditions, according to which +we must proceed from the conditioned, through all intermediate and +subordinate conditions, up to the unconditioned; although this goal +is unattained and unattainable. For the absolutely unconditioned cannot +be discovered in the sphere of experience. + +We now proceed to determine clearly our notion of a synthesis +which can never be complete. There are two terms commonly employed +for this purpose. These terms are regarded as expressions of different +and distinguishable notions, although the ground of the distinction +has never been clearly exposed. The term employed by the mathematicians +is progressus in infinitum. The philosophers prefer the expression +progressus in indefinitum. Without detaining the reader with an +examination of the reasons for such a distinction, or with remarks +on the right or wrong use of the terms, I shall endeavour clearly to +determine these conceptions, so far as is necessary for the purpose +in this Critique. + +We may, with propriety, say of a straight line, that it may be +produced to infinity. In this case the distinction between a +progressus in infinitum and a progressus in indefinitum is a mere +piece of subtlety. For, although when we say, "Produce a straight +line," it is more correct to say in indefinitum than in infinitum; +because the former means, "Produce it as far as you please," the +second, "You must not cease to produce it"; the expression in +infinitum is, when we are speaking of the power to do it, perfectly +correct, for we can always make it longer if we please--on to +infinity. And this remark holds good in all cases, when we speak of +a progressus, that is, an advancement from the condition to the +conditioned; this possible advancement always proceeds to infinity. +We may proceed from a given pair in the descending line of generation +from father to son, and cogitate a never-ending line of descendants +from it. For in such a case reason does not demand absolute totality +in the series, because it does not presuppose it as a condition and +as given (datum), but merely as conditioned, and as capable of being +given (dabile). + +Very different is the case with the problem: "How far the regress, +which ascends from the given conditioned to the conditions, must +extend"; whether I can say: "It is a regress in infinitum," or only +"in indefinitum"; and whether, for example, setting out from the human +beings at present alive in the world, I may ascend in the series of +their ancestors, in infinitum--mr whether all that can be said is, +that so far as I have proceeded, I have discovered no empirical ground +for considering the series limited, so that I am justified, and +indeed, compelled to search for ancestors still further back, although +I am not obliged by the idea of reason to presuppose them. + +My answer to this question is: "If the series is given in +empirical intuition as a whole, the regress in the series of its +internal conditions proceeds in infinitum; but, if only one member +of the series is given, from which the regress is to proceed to +absolute totality, the regress is possible only in indefinitum." For +example, the division of a portion of matter given within certain +limits--of a body, that is--proceeds in infinitum. For, as the +condition of this whole is its part, and the condition of the part +a part of the part, and so on, and as in this regress of decomposition +an unconditioned indivisible member of the series of conditions is +not to be found; there are no reasons or grounds in experience for +stopping in the division, but, on the contrary, the more remote +members of the division are actually and empirically given prior to +this division. That is to say, the division proceeds to infinity. On +the other hand, the series of ancestors of any given human being is +not given, in its absolute totality, in any experience, and yet the +regress proceeds from every genealogical member of this series to +one still higher, and does not meet with any empirical limit +presenting an absolutely unconditioned member of the series. But as +the members of such a series are not contained in the empirical +intuition of the whole, prior to the regress, this regress does not +proceed to infinity, but only in indefinitum, that is, we are called +upon to discover other and higher members, which are themselves always +conditioned. + +In neither case--the regressus in infinitum, nor the regressus in +indefinitum, is the series of conditions to be considered as +actually infinite in the object itself. This might be true of things +in themselves, but it cannot be asserted of phenomena, which, as +conditions of each other, are only given in the empirical regress +itself. Hence, the question no longer is, "What is the quantity of +this series of conditions in itself--is it finite or infinite?" for +it is nothing in itself; but, "How is the empirical regress to be +commenced, and how far ought we to proceed with it?" And here a signal +distinction in the application of this rule becomes apparent. If the +whole is given empirically, it is possible to recede in the series +of its internal conditions to infinity. But if the whole is not given, +and can only be given by and through the empirical regress, I can only +say: "It is possible to infinity, to proceed to still higher +conditions in the series." In the first case, I am justified in +asserting that more members are empirically given in the object than +I attain to in the regress (of decomposition). In the second case, +I am justified only in saying, that I can always proceed further in +the regress, because no member of the series is given as absolutely +conditioned, and thus a higher member is possible, and an inquiry with +regard to it is necessary. In the one case it is necessary to find +other members of the series, in the other it is necessary to inquire +for others, inasmuch as experience presents no absolute limitation +of the regress. For, either you do not possess a perception which +absolutely limits your empirical regress, and in this case the regress +cannot be regarded as complete; or, you do possess such a limitative +perception, in which case it is not a part of your series (for that +which limits must be distinct from that which is limited by it), and +it is incumbent you to continue your regress up to this condition, +and so on. + +These remarks will be placed in their proper light by their +application in the following section. + + + +SECTION IX. Of the Empirical Use of the Regulative Principle + of Reason with regard to the Cosmological Ideas. + +We have shown that no transcendental use can be made either of the +conceptions of reason or of understanding. We have shown, likewise, +that the demand of absolute totality in the series of conditions in +the world of sense arises from a transcendental employment of +reason, resting on the opinion that phenomena are to be regarded as +things in themselves. It follows that we are not required to answer +the question respecting the absolute quantity of a series--whether +it is in itself limited or unlimited. We are only called upon to +determine how far we must proceed in the empirical regress from +condition to condition, in order to discover, in conformity with the +rule of reason, a full and correct answer to the questions proposed +by reason itself. + +This principle of reason is hence valid only as a rule for the +extension of a possible experience--its invalidity as a principle +constitutive of phenomena in themselves having been sufficiently +demonstrated. And thus, too, the antinomial conflict of reason with +itself is completely put an end to; inasmuch as we have not only +presented a critical solution of the fallacy lurking in the opposite +statements of reason, but have shown the true meaning of the ideas +which gave rise to these statements. The dialectical principle of +reason has, therefore, been changed into a doctrinal principle. But +in fact, if this principle, in the subjective signification which we +have shown to be its only true sense, may be guaranteed as a principle +of the unceasing extension of the employment of our understanding, +its influence and value are just as great as if it were an axiom for +the a priori determination of objects. For such an axiom could not +exert a stronger influence on the extension and rectification of our +knowledge, otherwise than by procuring for the principles of the +understanding the most widely expanded employment in the field of +experience. + + + +I. Solution of the Cosmological Idea of the Totality of the + Composition of Phenomena in the Universe. + +Here, as well as in the case of the other cosmological problems, the +ground of the regulative principle of reason is the proposition that +in our empirical regress no experience of an absolute limit, and +consequently no experience of a condition, which is itself +absolutely unconditioned, is discoverable. And the truth of this +proposition itself rests upon the consideration that such an +experience must represent to us phenomena as limited by nothing or +the mere void, on which our continued regress by means of perception +must abut--which is impossible. + +Now this proposition, which declares that every condition attained +in the empirical regress must itself be considered empirically +conditioned, contains the rule in terminis, which requires me, to +whatever extent I may have proceeded in the ascending series, always +to look for some higher member in the series--whether this member is +to become known to me through experience, or not. + +Nothing further is necessary, then, for the solution of the first +cosmological problem, than to decide, whether, in the regress to the +unconditioned quantity of the universe (as regards space and time), +this never limited ascent ought to be called a regressus in +infinitum or indefinitum. + +The general representation which we form in our minds of the +series of all past states or conditions of the world, or of all the +things which at present exist in it, is itself nothing more than a +possible empirical regress, which is cogitated--although in an +undetermined manner--in the mind, and which gives rise to the +conception of a series of conditions for a given object.* Now I have +a conception of the universe, but not an intuition--that is, not an +intuition of it as a whole. Thus I cannot infer the magnitude of the +regress from the quantity or magnitude of the world, and determine +the former by means of the latter; on the contrary, I must first of +all form a conception of the quantity or magnitude of the world from +the magnitude of the empirical regress. But of this regress I know +nothing more than that I ought to proceed from every given member of +the series of conditions to one still higher. But the quantity of the +universe is not thereby determined, and we cannot affirm that this +regress proceeds in infinitum. Such an affirmation would anticipate +the members of the series which have not yet been reached, and +represent the number of them as beyond the grasp of any empirical +synthesis; it would consequently determine the cosmical quantity prior +to the regress (although only in a negative manner)--which is +impossible. For the world is not given in its totality in any +intuition: consequently, its quantity cannot be given prior to the +regress. It follows that we are unable to make any declaration +respecting the cosmical quantity in itself--not even that the +regress in it is a regress in infinitum; we must only endeavour to +attain to a conception of the quantity of the universe, in +conformity with the rule which determines the empirical regress in +it. But this rule merely requires us never to admit an absolute limit +to our series--how far soever we may have proceeded in it, but always, +on the contrary, to subordinate every phenomenon to some other as its +condition, and consequently to proceed to this higher phenomenon. Such +a regress is, therefore, the regressus in indefinitum, which, as not +determining a quantity in the object, is clearly distinguishable +from the regressus in infinitum. + +[*Footnote: The cosmical series can neither be greater nor smaller +than the possible empirical regress, upon which its conception is based. +And as this regress cannot be a determinate infinite regress, still +less a determinate finite (absolutely limited), it is evident that +we cannot regard the world as either finite or infinite, because the +regress, which gives us the representation of the world, is neither +finite nor infinite.] + +It follows from what we have said that we are not justified in +declaring the world to be infinite in space, or as regards past +time. For this conception of an infinite given quantity is +empirical; but we cannot apply the conception of an infinite +quantity to the world as an object of the senses. I cannot say, "The +regress from a given perception to everything limited either in +space or time, proceeds in infinitum," for this presupposes an +infinite cosmical quantity; neither can I say, "It is finite," for +an absolute limit is likewise impossible in experience. It follows +that I am not entitled to make any assertion at all respecting the +whole object of experience--the world of sense; I must limit my +declarations to the rule according to which experience or empirical +knowledge is to be attained. + +To the question, therefore, respecting the cosmical quantity, the +first and negative answer is: "The world has no beginning in time, +and no absolute limit in space." + +For, in the contrary case, it would be limited by a void time on the +one hand, and by a void space on the other. Now, since the world, as +a phenomenon, cannot be thus limited in itself for a phenomenon is +not a thing in itself; it must be possible for us to have a perception +of this limitation by a void time and a void space. But such a +perception--such an experience is impossible; because it has no +content. Consequently, an absolute cosmical limit is empirically, +and therefore absolutely, impossible.* + +[*Footnote: The reader will remark that the proof presented above is +very different from the dogmatical demonstration given in the antithesis +of the first antinomy. In that demonstration, it was taken for granted +that the world is a thing in itself--given in its totality prior to +all regress, and a determined position in space and time was denied +to it--if it was not considered as occupying all time and all space. +Hence our conclusion differed from that given above; for we inferred +in the antithesis the actual infinity of the world.] + +From this follows the affirmative answer: "The regress in the series +of phenomena--as a determination of the cosmical quantity, proceeds +in indefinitum." This is equivalent to saying: "The world of sense +has no absolute quantity, but the empirical regress (through which +alone the world of sense is presented to us on the side of its conditions) +rests upon a rule, which requires it to proceed from every member of +the series, as conditioned, to one still more remote (whether +through personal experience, or by means of history, or the chain of +cause and effect), and not to cease at any point in this extension +of the possible empirical employment of the understanding." And this +is the proper and only use which reason can make of its principles. + +The above rule does not prescribe an unceasing regress in one kind +of phenomena. It does not, for example, forbid us, in our ascent +from an individual human being through the line of his ancestors, to +expect that we shall discover at some point of the regress a +primeval pair, or to admit, in the series of heavenly bodies, a sun +at the farthest possible distance from some centre. All that it demands +is a perpetual progress from phenomena to phenomena, even although +an actual perception is not presented by them (as in the case of our +perceptions being so weak as that we are unable to become conscious +of them), since they, nevertheless, belong to possible experience. + +Every beginning is in time, and all limits to extension are in +space. But space and time are in the world of sense. Consequently +phenomena in the world are conditionally limited, but the world itself +is not limited, either conditionally or unconditionally. + +For this reason, and because neither the world nor the cosmical +series of conditions to a given conditioned can be completely given, +our conception of the cosmical quantity is given only in and through +the regress and not prior to it--in a collective intuition. But the +regress itself is really nothing more than the determining of the +cosmical quantity, and cannot therefore give us any determined +conception of it--still less a conception of a quantity which is, in +relation to a certain standard, infinite. The regress does not, +therefore, proceed to infinity (an infinity given), but only to an +indefinite extent, for or the of presenting to us a quantity--realized +only in and through the regress itself. + + + +II. Solution of the Cosmological Idea of the Totality of + the Division of a Whole given in Intuition. + +When I divide a whole which is given in intuition, I proceed from +a conditioned to its conditions. The division of the parts of the +whole (subdivisio or decompositio) is a regress in the series of these +conditions. The absolute totality of this series would be actually +attained and given to the mind, if the regress could arrive at +simple parts. But if all the parts in a continuous decomposition are +themselves divisible, the division, that is to say, the regress, +proceeds from the conditioned to its conditions in infinitum; +because the conditions (the parts) are themselves contained in the +conditioned, and, as the latter is given in a limited intuition, the +former are all given along with it. This regress cannot, therefore, +be called a regressus in indefinitum, as happened in the case of the +preceding cosmological idea, the regress in which proceeded from the +conditioned to the conditions not given contemporaneously and along +with it, but discoverable only through the empirical regress. We are +not, however, entitled to affirm of a whole of this kind, which is +divisible in infinitum, that it consists of an infinite number of +parts. For, although all the parts are contained in the intuition of +the whole, the whole division is not contained therein. The division +is contained only in the progressing decomposition--in the regress +itself, which is the condition of the possibility and actuality of +the series. Now, as this regress is infinite, all the members (parts) +to which it attains must be contained in the given whole as an aggregate. +But the complete series of division is not contained therein. For this +series, being infinite in succession and always incomplete, cannot +represent an infinite number of members, and still less a +composition of these members into a whole. + +To apply this remark to space. Every limited part of space presented +to intuition is a whole, the parts of which are always spaces--to +whatever extent subdivided. Every limited space is hence divisible +to infinity. + +Let us again apply the remark to an external phenomenon enclosed +in limits, that is, a body. The divisibility of a body rests upon +the divisibility of space, which is the condition of the possibility +of the body as an extended whole. A body is consequently divisible +to infinity, though it does not, for that reason, consist of an +infinite number of parts. + +It certainly seems that, as a body must be cogitated as substance in +space, the law of divisibility would not be applicable to it as +substance. For we may and ought to grant, in the case of space, that +division or decomposition, to any extent, never can utterly annihilate +composition (that is to say, the smallest part of space must still +consist of spaces); otherwise space would entirely cease to exist- +which is impossible. But, the assertion on the other band that when +all composition in matter is annihilated in thought, nothing +remains, does not seem to harmonize with the conception of +substance, which must be properly the subject of all composition and +must remain, even after the conjunction of its attributes in space- +which constituted a body--is annihilated in thought. But this is not +the case with substance in the phenomenal world, which is not a +thing in itself cogitated by the pure category. Phenomenal substance +is not an absolute subject; it is merely a permanent sensuous image, +and nothing more than an intuition, in which the unconditioned is +not to be found. + +But, although this rule of progress to infinity is legitimate and +applicable to the subdivision of a phenomenon, as a mere occupation +or filling of space, it is not applicable to a whole consisting of +a number of distinct parts and constituting a quantum discretum--that +is to say, an organized body. It cannot be admitted that every part +in an organized whole is itself organized, and that, in analysing it +to infinity, we must always meet with organized parts; although we +may allow that the parts of the matter which we decompose in infinitum, +may be organized. For the infinity of the division of a phenomenon +in space rests altogether on the fact that the divisibility of a +phenomenon is given only in and through this infinity, that is, an +undetermined number of parts is given, while the parts themselves +are given and determined only in and through the subdivision; in a +word, the infinity of the division necessarily presupposes that the +whole is not already divided in se. Hence our division determines a +number of parts in the whole--a number which extends just as far as +the actual regress in the division; while, on the other hand, the very +notion of a body organized to infinity represents the whole as already +and in itself divided. We expect, therefore, to find in it a +determinate, but at the same time, infinite, number of parts--which +is self-contradictory. For we should thus have a whole containing a +series of members which could not be completed in any regress--which +is infinite, and at the same time complete in an organized +composite. Infinite divisibility is applicable only to a quantum +continuum, and is based entirely on the infinite divisibility of +space, But in a quantum discretum the multitude of parts or units is +always determined, and hence always equal to some number. To what +extent a body may be organized, experience alone can inform us; and +although, so far as our experience of this or that body has +extended, we may not have discovered any inorganic part, such parts +must exist in possible experience. But how far the transcendental +division of a phenomenon must extend, we cannot know from +experience--it is a question which experience cannot answer; it is +answered only by the principle of reason which forbids us to +consider the empirical regress, in the analysis of extended body, as +ever absolutely complete. + + + +Concluding Remark on the Solution of the Transcendental +Mathematical Ideas--and Introductory to the +Solution of the Dynamical Ideas. + +We presented the antinomy of pure reason in a tabular form, and we +endeavoured to show the ground of this self-contradiction on the +part of reason, and the only means of bringing it to a conclusion-- +namely, by declaring both contradictory statements to be false. We +represented in these antinomies the conditions of phenomena as +belonging to the conditioned according to relations of space and time- +which is the usual supposition of the common understanding. In this +respect, all dialectical representations of totality, in the series +of conditions to a given conditioned, were perfectly homogeneous. The +condition was always a member of the series along with the +conditioned, and thus the homogeneity of the whole series was assured. +In this case the regress could never be cogitated as complete; or, +if this was the case, a member really conditioned was falsely regarded +as a primal member, consequently as unconditioned. In such an +antinomy, therefore, we did not consider the object, that is, the +conditioned, but the series of conditions belonging to the object, +and the magnitude of that series. And thus arose the difficulty--a +difficulty not to be settled by any decision regarding the claims of +the two parties, but simply by cutting the knot--by declaring the +series proposed by reason to be either too long or too short for the +understanding, which could in neither case make its conceptions +adequate with the ideas. + +But we have overlooked, up to this point, an essential difference +existing between the conceptions of the understanding which reason +endeavours to raise to the rank of ideas--two of these indicating a +mathematical, and two a dynamical synthesis of phenomena. Hitherto, +it was necessary to signalize this distinction; for, just as in our +general representation of all transcendental ideas, we considered them +under phenomenal conditions, so, in the two mathematical ideas, our +discussion is concerned solely with an object in the world of +phenomena. But as we are now about to proceed to the consideration +of the dynamical conceptions of the understanding, and their +adequateness with ideas, we must not lose sight of this distinction. +We shall find that it opens up to us an entirely new view of the +conflict in which reason is involved. For, while in the first two +antinomies, both parties were dismissed, on the ground of having +advanced statements based upon false hypothesis; in the present case +the hope appears of discovering a hypothesis which may be consistent +with the demands of reason, and, the judge completing the statement +of the grounds of claim, which both parties had left in an unsatisfactory +state, the question may be settled on its own merits, not by +dismissing the claimants, but by a comparison of the arguments on both +sides. If we consider merely their extension, and whether they are +adequate with ideas, the series of conditions may be regarded as all +homogeneous. But the conception of the understanding which lies at +the basis of these ideas, contains either a synthesis of the homogeneous +(presupposed in every quantity--in its composition as well as in its +division) or of the heterogeneous, which is the case in the +dynamical synthesis of cause and effect, as well as of the necessary +and the contingent. + +Thus it happens that in the mathematical series of phenomena no +other than a sensuous condition is admissible--a condition which is +itself a member of the series; while the dynamical series of +sensuous conditions admits a heterogeneous condition, which is not +a member of the series, but, as purely intelligible, lies out of and +beyond it. And thus reason is satisfied, and an unconditioned placed +at the head of the series of phenomena, without introducing +confusion into or discontinuing it, contrary to the principles of +the understanding. + +Now, from the fact that the dynamical ideas admit a condition of +phenomena which does not form a part of the series of phenomena, +arises a result which we should not have expected from an antinomy. +In former cases, the result was that both contradictory dialectical +statements were declared to be false. In the present case, we find +the conditioned in the dynamical series connected with an empirically +unconditioned, but non-sensuous condition; and thus satisfaction is +done to the understanding on the one hand and to the reason on the +other.* While, moreover, the dialectical arguments for unconditioned +totality in mere phenomena fall to the ground, both propositions of +reason may be shown to be true in their proper signification. This +could not happen in the case of the cosmological ideas which +demanded a mathematically unconditioned unity; for no condition +could be placed at the head of the series of phenomena, except one +which was itself a phenomenon and consequently a member of the series. + +[*Footnote: For the understanding cannot admit among phenomena a condition +which is itself empirically unconditioned. But if it is possible to +cogitate an intelligible condition--one which is not a member of the +series of phenomena--for a conditioned phenomenon, without breaking +the series of empirical conditions, such a condition may be admissible +as empirically unconditioned, and the empirical regress continue +regular, unceasing, and intact.] + + + +III. Solution of the Cosmological Idea of the Totality of + the Deduction of Cosmical Events from their Causes. + +There are only two modes of causality cogitable--the causality of +nature or of freedom. The first is the conjunction of a particular +state with another preceding it in the world of sense, the former +following the latter by virtue of a law. Now, as the causality of +phenomena is subject to conditions of time, and the preceding state, +if it had always existed, could not have produced an effect which +would make its first appearance at a particular time, the causality +of a cause must itself be an effect--must itself have begun to be, +and therefore, according to the principle of the understanding, itself +requires a cause. + +We must understand, on the contrary, by the term freedom, in the +cosmological sense, a faculty of the spontaneous origination of a +state; the causality of which, therefore, is not subordinated to +another cause determining it in time. Freedom is in this sense a +pure transcendental idea, which, in the first place, contains no +empirical element; the object of which, in the second place, cannot +be given or determined in any experience, because it is a universal +law of the very possibility of experience, that everything which happens +must have a cause, that consequently the causality of a cause, being +itself something that has happened, must also have a cause. In this +view of the case, the whole field of experience, how far soever it +may extend, contains nothing that is not subject to the laws of nature. +But, as we cannot by this means attain to an absolute totality of +conditions in reference to the series of causes and effects, reason +creates the idea of a spontaneity, which can begin to act of itself, +and without any external cause determining it to action, according +to the natural law of causality. + +It is especially remarkable that the practical conception of freedom +is based upon the transcendental idea, and that the question of the +possibility of the former is difficult only as it involves the +consideration of the truth of the latter. Freedom, in the practical +sense, is the independence of the will of coercion by sensuous +impulses. A will is sensuous, in so far as it is pathologically +affected (by sensuous impulses); it is termed animal (arbitrium +brutum), when it is pathologically necessitated. The human will is +certainly an arbitrium sensitivum, not brutum, but liberum; because +sensuousness does not necessitate its action, a faculty existing in +man of self-determination, independently of all sensuous coercion. + +It is plain that, if all causality in the world of sense were +natural--and natural only--every event would be determined by +another according to necessary laws, and that, consequently, +phenomena, in so far as they determine the will, must necessitate +every action as a natural effect from themselves; and thus all +practical freedom would fall to the ground with the transcendental +idea. For the latter presupposes that although a certain thing has +not happened, it ought to have happened, and that, consequently, its +phenomenal cause was not so powerful and determinative as to exclude +the causality of our will--a causality capable of producing effects +independently of and even in opposition to the power of natural +causes, and capable, consequently, of spontaneously originating a +series of events. + +Here, too, we find it to be the case, as we generally found in the +self-contradictions and perplexities of a reason which strives to pass +the bounds of possible experience, that the problem is properly not +physiological, but transcendental. The question of the possibility +of freedom does indeed concern psychology; but, as it rests upon +dialectical arguments of pure reason, its solution must engage the +attention of transcendental philosophy. Before attempting this +solution, a task which transcendental philosophy cannot decline, it +will be advisable to make a remark with regard to its procedure in +the settlement of the question. + +If phenomena were things in themselves, and time and space forms +of the existence of things, condition and conditioned would always +be members of the same series; and thus would arise in the present +case the antinomy common to all transcendental ideas--that their +series is either too great or too small for the understanding. The +dynamical ideas, which we are about to discuss in this and the +following section, possess the peculiarity of relating to an object, +not considered as a quantity, but as an existence; and thus, in the +discussion of the present question, we may make abstraction of the +quantity of the series of conditions, and consider merely the +dynamical relation of the condition to the conditioned. The +question, then, suggests itself, whether freedom is possible; and, +if it is, whether it can consist with the universality of the +natural law of causality; and, consequently, whether we enounce a +proper disjunctive proposition when we say: "Every effect must have +its origin either in nature or in freedom," or whether both cannot +exist together in the same event in different relations. The principle +of an unbroken connection between all events in the phenomenal +world, in accordance with the unchangeable laws of nature, is a +well-established principle of transcendental analytic which admits +of no exception. The question, therefore, is: "Whether an effect, +determined according to the laws of nature, can at the same time be +produced by a free agent, or whether freedom and nature mutually +exclude each other?" And here, the common but fallacious hypothesis +of the absolute reality of phenomena manifests its injurious influence +in embarrassing the procedure of reason. For if phenomena are things +in themselves, freedom is impossible. In this case, nature is the +complete and all-sufficient cause of every event; and condition and +conditioned, cause and effect are contained in the same series, and +necessitated by the same law. If, on the contrary, phenomena are +held to be, as they are in fact, nothing more than mere +representations, connected with each other in accordance with +empirical laws, they must have a ground which is not phenomenal. But +the causality of such an intelligible cause is not determined or +determinable by phenomena; although its effects, as phenomena, must +be determined by other phenomenal existences. This cause and its +causality exist therefore out of and apart from the series of +phenomena; while its effects do exist and are discoverable in the +series of empirical conditions. Such an effect may therefore be +considered to be free in relation to its intelligible cause, and +necessary in relation to the phenomena from which it is a necessary +consequence--a distinction which, stated in this perfectly general +and abstract manner, must appear in the highest degree subtle and obscure. +The sequel will explain. It is sufficient, at present, to remark that, +as the complete and unbroken connection of phenomena is an unalterable +law of nature, freedom is impossible--on the supposition that +phenomena are absolutely real. Hence those philosophers who adhere +to the common opinion on this subject can never succeed in reconciling +the ideas of nature and freedom. + + + +Possibility of Freedom in Harmony with the Universal Law +of Natural Necessity. + +That element in a sensuous object which is not itself sensuous, I +may be allowed to term intelligible. If, accordingly, an object +which must be regarded as a sensuous phenomenon possesses a faculty +which is not an object of sensuous intuition, but by means of which +it is capable of being the cause of phenomena, the causality of an +object or existence of this kind may be regarded from two different +points of view. It may be considered to be intelligible, as regards +its action--the action of a thing which is a thing in itself, and +sensuous, as regards its effects--the effects of a phenomenon +belonging to the sensuous world. We should accordingly, have to form +both an empirical and an intellectual conception of the causality of +such a faculty or power--both, however, having reference to the same +effect. This twofold manner of cogitating a power residing in a +sensuous object does not run counter to any of the conceptions which +we ought to form of the world of phenomena or of a possible +experience. Phenomena--not being things in themselves--must have a +transcendental object as a foundation, which determines them as mere +representations; and there seems to be no reason why we should not +ascribe to this transcendental object, in addition to the property +of self-phenomenization, a causality whose effects are to be met +with in the world of phenomena, although it is not itself a +phenomenon. But every effective cause must possess a character, that +is to say, a law of its causality, without which it would cease to +be a cause. In the above case, then, every sensuous object would +possess an empirical character, which guaranteed that its actions, +as phenomena, stand in complete and harmonious connection, conformably +to unvarying natural laws, with all other phenomena, and can be +deduced from these, as conditions, and that they do thus, in +connection with these, constitute a series in the order of nature. +This sensuous object must, in the second place, possess an +intelligible character, which guarantees it to be the cause of those +actions, as phenomena, although it is not itself a phenomenon nor +subordinate to the conditions of the world of sense. The former may +be termed the character of the thing as a phenomenon, the latter the +character of the thing as a thing in itself. + +Now this active subject would, in its character of intelligible +subject, be subordinate to no conditions of time, for time is only +a condition of phenomena, and not of things in themselves. No action +would begin or cease to be in this subject; it would consequently be +free from the law of all determination of time--the law of change, +namely, that everything which happens must have a cause in the +phenomena of a preceding state. In one word, the causality of the +subject, in so far as it is intelligible, would not form part of the +series of empirical conditions which determine and necessitate an +event in the world of sense. Again, this intelligible character of +a thing cannot be immediately cognized, because we can perceive +nothing but phenomena, but it must be capable of being cogitated in +harmony with the empirical character; for we always find ourselves +compelled to place, in thought, a transcendental object at the basis +of phenomena although we can never know what this object is in itself. + +In virtue of its empirical character, this subject would at the same +time be subordinate to all the empirical laws of causality, and, as +a phenomenon and member of the sensuous world, its effects would +have to be accounted for by a reference to preceding phenomena. +Eternal phenomena must be capable of influencing it; and its +actions, in accordance with natural laws, must explain to us how its +empirical character, that is, the law of its causality, is to be +cognized in and by means of experience. In a word, all requisites +for a complete and necessary determination of these actions must be +presented to us by experience. + +In virtue of its intelligible character, on the other hand (although +we possess only a general conception of this character), the subject +must be regarded as free from all sensuous influences, and from all +phenomenal determination. Moreover, as nothing happens in this +subject--for it is a noumenon, and there does not consequently exist +in it any change, demanding the dynamical determination of time, and +for the same reason no connection with phenomena as causes--this +active existence must in its actions be free from and independent of +natural necessity, for or necessity exists only in the world of +phenomena. It would be quite correct to say that it originates or +begins its effects in the world of sense from itself, although the +action productive of these effects does not begin in itself. We should +not be in this case affirming that these sensuous effects began to +exist of themselves, because they are always determined by prior +empirical conditions--by virtue of the empirical character, which is +the phenomenon of the intelligible character--and are possible only +as constituting a continuation of the series of natural causes. And +thus nature and freedom, each in the complete and absolute +signification of these terms, can exist, without contradiction or +disagreement, in the same action. + + + +Exposition of the Cosmological Idea of Freedom in Harmony +with the Universal Law of Natural Necessity. + +I have thought it advisable to lay before the reader at first merely +a sketch of the solution of this transcendental problem, in order to +enable him to form with greater ease a clear conception of the +course which reason must adopt in the solution. I shall now proceed +to exhibit the several momenta of this solution, and to consider them +in their order. + +The natural law that everything which happens must have a cause, +that the causality of this cause, that is, the action of the cause +(which cannot always have existed, but must be itself an event, for +it precedes in time some effect which it has originated), must have +itself a phenomenal cause, by which it is determined and, and, +consequently, all events are empirically determined in an order of +nature--this law, I say, which lies at the foundation of the +possibility of experience, and of a connected system of phenomena or +nature is a law of the understanding, from which no departure, and +to which no exception, can be admitted. For to except even a single +phenomenon from its operation is to exclude it from the sphere of +possible experience and thus to admit it to be a mere fiction of +thought or phantom of the brain. + +Thus we are obliged to acknowledge the existence of a chain of +causes, in which, however, absolute totality cannot be found. But we +need not detain ourselves with this question, for it has already +been sufficiently answered in our discussion of the antinomies into +which reason falls, when it attempts to reach the unconditioned in +the series of phenomena. If we permit ourselves to be deceived by the +illusion of transcendental idealism, we shall find that neither nature +nor freedom exists. Now the question is: "Whether, admitting the +existence of natural necessity in the world of phenomena, it is +possible to consider an effect as at the same time an effect of nature +and an effect of freedom--or, whether these two modes of causality +are contradictory and incompatible?" + +No phenomenal cause can absolutely and of itself begin a series. +Every action, in so far as it is productive of an event, is itself +an event or occurrence, and presupposes another preceding state, in +which its cause existed. Thus everything that happens is but a +continuation of a series, and an absolute beginning is impossible in +the sensuous world. The actions of natural causes are, accordingly, +themselves effects, and presuppose causes preceding them in time. A +primal action which forms an absolute beginning, is beyond the +causal power of phenomena. + +Now, is it absolutely necessary that, granting that all effects +are phenomena, the causality of the cause of these effects must also +be a phenomenon and belong to the empirical world? Is it not rather +possible that, although every effect in the phenomenal world must be +connected with an empirical cause, according to the universal law of +nature, this empirical causality may be itself the effect of a +non-empirical and intelligible causality--its connection with +natural causes remaining nevertheless intact? Such a causality would +be considered, in reference to phenomena, as the primal action of a +cause, which is in so far, therefore, not phenomenal, but, by reason +of this faculty or power, intelligible; although it must, at the +same time, as a link in the chain of nature, be regarded as +belonging to the sensuous world. + +A belief in the reciprocal causality of phenomena is necessary, if +we are required to look for and to present the natural conditions of +natural events, that is to say, their causes. This being admitted as +unexceptionably valid, the requirements of the understanding, which +recognizes nothing but nature in the region of phenomena, are +satisfied, and our physical explanations of physical phenomena may +proceed in their regular course, without hindrance and without +opposition. But it is no stumbling-block in the way, even assuming +the idea to be a pure fiction, to admit that there are some natural +causes in the possession of a faculty which is not empirical, but +intelligible, inasmuch as it is not determined to action by +empirical conditions, but purely and solely upon grounds brought +forward by the understanding--this action being still, when the +cause is phenomenized, in perfect accordance with the laws of +empirical causality. Thus the acting subject, as a causal +phenomenon, would continue to preserve a complete connection with +nature and natural conditions; and the phenomenon only of the +subject (with all its phenomenal causality) would contain certain +conditions, which, if we ascend from the empirical to the +transcendental object, must necessarily be regarded as intelligible. +For, if we attend, in our inquiries with regard to causes in the world +of phenomena, to the directions of nature alone, we need not trouble +ourselves about the relation in which the transcendental subject, +which is completely unknown to us, stands to these phenomena and their +connection in nature. The intelligible ground of phenomena in this +subject does not concern empirical questions. It has to do only with +pure thought; and, although the effects of this thought and action +of the pure understanding are discoverable in phenomena, these +phenomena must nevertheless be capable of a full and complete +explanation, upon purely physical grounds and in accordance with +natural laws. And in this case we attend solely to their empirical +and omit all consideration of their intelligible character (which is +the transcendental cause of the former) as completely unknown, except +in so far as it is exhibited by the latter as its empirical symbol. +Now let us apply this to experience. Man is a phenomenon of the sensuous +world and, at the same time, therefore, a natural cause, the causality +of which must be regulated by empirical laws. As such, he must possess +an empirical character, like all other natural phenomena. We remark +this empirical character in his actions, which reveal the presence +of certain powers and faculties. If we consider inanimate or merely +animal nature, we can discover no reason for ascribing to ourselves +any other than a faculty which is determined in a purely sensuous +manner. But man, to whom nature reveals herself only through sense, +cognizes himself not only by his senses, but also through pure +apperception; and this in actions and internal determinations, which +he cannot regard as sensuous impressions. He is thus to himself, on +the one hand, a phenomenon, but on the other hand, in respect of +certain faculties, a purely intelligible object--intelligible, because +its action cannot be ascribed to sensuous receptivity. These faculties +are understanding and reason. The latter, especially, is in a peculiar +manner distinct from all empirically-conditioned faculties, for it +employs ideas alone in the consideration of its objects, and by +means of these determines the understanding, which then proceeds to +make an empirical use of its own conceptions, which, like the ideas +of reason, are pure and non-empirical. + +That reason possesses the faculty of causality, or that at least +we are compelled so to represent it, is evident from the +imperatives, which in the sphere of the practical we impose on many +of our executive powers. The words I ought express a species of +necessity, and imply a connection with grounds which nature does not +and cannot present to the mind of man. Understanding knows nothing +in nature but that which is, or has been, or will be. It would be +absurd to say that anything in nature ought to be other than it is +in the relations of time in which it stands; indeed, the ought, when +we consider merely the course of nature, has neither application nor +meaning. The question, "What ought to happen in the sphere of nature?" +is just as absurd as the question, "What ought to be the properties +of a circle?" All that we are entitled to ask is, "What takes place +in nature?" or, in the latter case, "What are the properties of a +circle?" + +But the idea of an ought or of duty indicates a possible action, the +ground of which is a pure conception; while the ground of a merely +natural action is, on the contrary, always a phenomenon. This action +must certainly be possible under physical conditions, if it is +prescribed by the moral imperative ought; but these physical or +natural conditions do not concern the determination of the will +itself, they relate to its effects alone, and the consequences of +the effect in the world of phenomena. Whatever number of motives +nature may present to my will, whatever sensuous impulses--the moral +ought it is beyond their power to produce. They may produce a +volition, which, so far from being necessary, is always conditioned--a +volition to which the ought enunciated by reason, sets an aim and a +standard, gives permission or prohibition. Be the object what it +may, purely sensuous--as pleasure, or presented by pure reason--as +good, reason will not yield to grounds which have an empirical origin. +Reason will not follow the order of things presented by experience, +but, with perfect spontaneity, rearranges them according to ideas, +with which it compels empirical conditions to agree. It declares, in +the name of these ideas, certain actions to be necessary which +nevertheless have not taken place and which perhaps never will take +place; and yet presupposes that it possesses the faculty of +causality in relation to these actions. For, in the absence of this +supposition, it could not expect its ideas to produce certain +effects in the world of experience. + +Now, let us stop here and admit it to be at least possible that +reason does stand in a really causal relation to phenomena. In this +case it must--pure reason as it is--exhibit an empirical character. +For every cause supposes a rule, according to which certain +phenomena follow as effects from the cause, and every rule requires +uniformity in these effects; and this is the proper ground of the +conception of a cause--as a faculty or power. Now this conception +(of a cause) may be termed the empirical character of reason; and this +character is a permanent one, while the effects produced appear, in +conformity with the various conditions which accompany and partly +limit them, in various forms. + +Thus the volition of every man has an empirical character, which +is nothing more than the causality of his reason, in so far as its +effects in the phenomenal world manifest the presence of a rule, +according to which we are enabled to examine, in their several kinds +and degrees, the actions of this causality and the rational grounds +for these actions, and in this way to decide upon the subjective +principles of the volition. Now we learn what this empirical character +is only from phenomenal effects, and from the rule of these which is +presented by experience; and for this reason all the actions of man +in the world of phenomena are determined by his empirical character, +and the co-operative causes of nature. If, then, we could +investigate all the phenomena of human volition to their lowest +foundation in the mind, there would be no action which we could not +anticipate with certainty, and recognize to be absolutely necessary +from its preceding conditions. So far as relates to this empirical +character, therefore, there can be no freedom; and it is only in the +light of this character that we can consider the human will, when we +confine ourselves to simple observation and, as is the case in +anthropology, institute a physiological investigation of the motive +causes of human actions. + +But when we consider the same actions in relation to reason--not for +the purpose of explaining their origin, that is, in relation to +speculative reason, but to practical reason, as the producing cause +of these actions--we shall discover a rule and an order very different +from those of nature and experience. For the declaration of this +mental faculty may be that what has and could not but take place in +the course of nature, ought not to have taken place. Sometimes, too, +we discover, or believe that we discover, that the ideas of reason +did actually stand in a causal relation to certain actions of man; +and that these actions have taken place because they were determined, +not by empirical causes, but by the act of the will upon grounds of +reason. + +Now, granting that reason stands in a causal relation to +phenomena; can an action of reason be called free, when we know +that, sensuously, in its empirical character, it is completely +determined and absolutely necessary? But this empirical character is +itself determined by the intelligible character. The latter we +cannot cognize; we can only indicate it by means of phenomena, which +enable us to have an immediate cognition only of the empirical +character.* An action, then, in so far as it is to be ascribed to an +intelligible cause, does not result from it in accordance with +empirical laws. That is to say, not the conditions of pure reason, +but only their effects in the internal sense, precede the act. Pure +reason, as a purely intelligible faculty, is not subject to the +conditions of time. The causality of reason in its intelligible +character does not begin to be; it does not make its appearance at +a certain time, for the purpose of producing an effect. If this were +not the case, the causality of reason would be subservient to the +natural law of phenomena, which determines them according to time, +and as a series of causes and effects in time; it would consequently +cease to be freedom and become a part of nature. We are therefore +justified in saying: "If reason stands in a causal relation to +phenomena, it is a faculty which originates the sensuous condition +of an empirical series of effects." For the condition, which resides +in the reason, is non-sensuous, and therefore cannot be originated, +or begin to be. And thus we find--what we could not discover in any +empirical series--a condition of a successive series of events +itself empirically unconditioned. For, in the present case, the +condition stands out of and beyond the series of phenomena--it is +intelligible, and it consequently cannot be subjected to any +sensuous condition, or to any time-determination by a preceding cause. + +[*Footnote: The real morality of actions--their merit or demerit, and +even that of our own conduct, is completely unknown to us. Our estimates +can relate only to their empirical character. How much is the result +of the action of free will, how much is to be ascribed to nature and +to blameless error, or to a happy constitution of temperament (merito +fortunae), no one can discover, nor, for this reason, determine with +perfect justice.] + +But, in another respect, the same cause belongs also to the series +of phenomena. Man is himself a phenomenon. His will has an empirical +character, which is the empirical cause of all his actions. There is +no condition--determining man and his volition in conformity with this +character--which does not itself form part of the series of effects +in nature, and is subject to their law--the law according to which +an empirically undetermined cause of an event in time cannot exist. +For this reason no given action can have an absolute and spontaneous +origination, all actions being phenomena, and belonging to the world +of experience. But it cannot be said of reason, that the state in +which it determines the will is always preceded by some other state +determining it. For reason is not a phenomenon, and therefore not +subject to sensuous conditions; and, consequently, even in relation +to its causality, the sequence or conditions of time do not influence +reason, nor can the dynamical law of nature, which determines the +sequence of time according to certain rules, be applied to it. + +Reason is consequently the permanent condition of all actions of the +human will. Each of these is determined in the empirical character +of the man, even before it has taken place. The intelligible +character, of which the former is but the sensuous schema, knows no +before or after; and every action, irrespective of the time-relation +in which it stands with other phenomena, is the immediate effect of +the intelligible character of pure reason, which, consequently, enjoys +freedom of action, and is not dynamically determined either by +internal or external preceding conditions. This freedom must not be +described, in a merely negative manner, as independence of empirical +conditions, for in this case the faculty of reason would cease to be +a cause of phenomena; but it must be regarded, positively, as a +faculty which can spontaneously originate a series of events. At the +same time, it must not be supposed that any beginning can take place +in reason; on the contrary, reason, as the unconditioned condition +of all action of the will, admits of no time-conditions, although +its effect does really begin in a series of phenomena--a beginning +which is not, however, absolutely primal. + +I shall illustrate this regulative principle of reason by an +example, from its employment in the world of experience; proved it +cannot be by any amount of experience, or by any number of facts, +for such arguments cannot establish the truth of transcendental +propositions. Let us take a voluntary action--for example, a +falsehood--by means of which a man has introduced a certain degree +of confusion into the social life of humanity, which is judged +according to the motives from which it originated, and the blame of +which and of the evil consequences arising from it, is imputed to +the offender. We at first proceed to examine the empirical character +of the offence, and for this purpose we endeavour to penetrate to +the sources of that character, such as a defective education, bad +company, a shameless and wicked disposition, frivolity, and want of +reflection--not forgetting also the occasioning causes which prevailed +at the moment of the transgression. In this the procedure is exactly +the same as that pursued in the investigation of the series of +causes which determine a given physical effect. Now, although we +believe the action to have been determined by all these circumstances, +we do not the less blame the offender. We do not blame him for his +unhappy disposition, nor for the circumstances which influenced him, +nay, not even for his former course of life; for we presuppose that +all these considerations may be set aside, that the series of +preceding conditions may be regarded as having never existed, and that +the action may be considered as completely unconditioned in relation +to any state preceding, just as if the agent commenced with it an +entirely new series of effects. Our blame of the offender is +grounded upon a law of reason, which requires us to regard this +faculty as a cause, which could have and ought to have otherwise +determined the behaviour of the culprit, independently of all +empirical conditions. This causality of reason we do not regard as +a co-operating agency, but as complete in itself. It matters not whether +the sensuous impulses favoured or opposed the action of this +causality, the offence is estimated according to its intelligible +character--the offender is decidedly worthy of blame, the moment he +utters a falsehood. It follows that we regard reason, in spite of +the empirical conditions of the act, as completely free, and +therefore, therefore, as in the present case, culpable. + +The above judgement is complete evidence that we are accustomed to +think that reason is not affected by sensuous conditions, that in it +no change takes place--although its phenomena, in other words, the +mode in which it appears in its effects, are subject to change--that +in it no preceding state determines the following, and, +consequently, that it does not form a member of the series of sensuous +conditions which necessitate phenomena according to natural laws. +Reason is present and the same in all human actions and at all +times; but it does not itself exist in time, and therefore does not +enter upon any state in which it did not formerly exist. It is, +relatively to new states or conditions, determining, but not +determinable. Hence we cannot ask: "Why did not reason determine +itself in a different manner?" The question ought to be thus stated: +"Why did not reason employ its power of causality to determine certain +phenomena in a different manner?" But this is a question which admits +of no answer. For a different intelligible character would have +exhibited a different empirical character; and, when we say that, in +spite of the course which his whole former life has taken, the +offender could have refrained from uttering the falsehood, this +means merely that the act was subject to the power and authority- +permissive or prohibitive--of reason. Now, reason is not subject in +its causality to any conditions of phenomena or of time; and a +difference in time may produce a difference in the relation of +phenomena to each other--for these are not things and therefore not +causes in themselves--but it cannot produce any difference in the +relation in which the action stands to the faculty of reason. + +Thus, then, in our investigation into free actions and the causal +power which produced them, we arrive at an intelligible cause, +beyond which, however, we cannot go; although we can recognize that +it is free, that is, independent of all sensuous conditions, and that, +in this way, it may be the sensuously unconditioned condition of +phenomena. But for what reason the intelligible character generates +such and such phenomena and exhibits such and such an empirical +character under certain circumstances, it is beyond the power of our +reason to decide. The question is as much above the power and the +sphere of reason as the following would be: "Why does the +transcendental object of our external sensuous intuition allow of no +other form than that of intuition in space?" But the problem, which +we were called upon to solve, does not require us to entertain any +such questions. The problem was merely this--whether freedom and natural +necessity can exist without opposition in the same action. To this +question we have given a sufficient answer; for we have shown that, +as the former stands in a relation to a different kind of condition +from those of the latter, the law of the one does not affect the law +of the other and that, consequently, both can exist together in +independence of and without interference with each other. + +The reader must be careful to remark that my intention in the +above remarks has not been to prove the actual existence of freedom, +as a faculty in which resides the cause of certain sensuous phenomena. +For, not to mention that such an argument would not have a +transcendental character, nor have been limited to the discussion of +pure conceptions--all attempts at inferring from experience what +cannot be cogitated in accordance with its laws, must ever be +unsuccessful. Nay, more, I have not even aimed at demonstrating the +possibility of freedom; for this too would have been a vain endeavour, +inasmuch as it is beyond the power of the mind to cognize the +possibility of a reality or of a causal power by the aid of mere a +priori conceptions. Freedom has been considered in the foregoing +remarks only as a transcendental idea, by means of which reason aims +at originating a series of conditions in the world of phenomena with +the help of that which is sensuously unconditioned, involving +itself, however, in an antinomy with the laws which itself +prescribes for the conduct of the understanding. That this antinomy +is based upon a mere illusion, and that nature and freedom are at least +not opposed--this was the only thing in our power to prove, and the +question which it was our task to solve. + + + +IV. Solution of the Cosmological Idea of the Totality of + the Dependence of Phenomenal Existences. + +In the preceding remarks, we considered the changes in the world +of sense as constituting a dynamical series, in which each member is +subordinated to another--as its cause. Our present purpose is to avail +ourselves of this series of states or conditions as a guide to an +existence which may be the highest condition of all changeable +phenomena, that is, to a necessary being. Our endeavour to reach, +not the unconditioned causality, but the unconditioned existence, of +substance. The series before us is therefore a series of +conceptions, and not of intuitions (in which the one intuition is +the condition of the other). + +But it is evident that, as all phenomena are subject to change and +conditioned in their existence, the series of dependent existences +cannot embrace an unconditioned member, the existence of which would +be absolutely necessary. It follows that, if phenomena were things +in themselves, and--as an immediate consequence from this supposition- +condition and conditioned belonged to the same series of phenomena, +the existence of a necessary being, as the condition of the +existence of sensuous phenomena, would be perfectly impossible. + +An important distinction, however, exists between the dynamical +and the mathematical regress. The latter is engaged solely with the +combination of parts into a whole, or with the division of a whole +into its parts; and therefore are the conditions of its series parts +of the series, and to be consequently regarded as homogeneous, and +for this reason, as consisting, without exception, of phenomena. If +the former regress, on the contrary, the aim of which is not to +establish the possibility of an unconditioned whole consisting of +given parts, or of an unconditioned part of a given whole, but to +demonstrate the possibility of the deduction of a certain state from +its cause, or of the contingent existence of substance from that which +exists necessarily, it is not requisite that the condition should form +part of an empirical series along with the conditioned. + +In the case of the apparent antinomy with which we are at present +dealing, there exists a way of escape from the difficulty; for it is +not impossible that both of the contradictory statements may be true +in different relations. All sensuous phenomena may be contingent, +and consequently possess only an empirically conditioned existence, +and yet there may also exist a non-empirical condition of the whole +series, or, in other words, a necessary being. For this necessary +being, as an intelligible condition, would not form a member--not even +the highest member--of the series; the whole world of sense would be +left in its empirically determined existence uninterfered with and +uninfluenced. This would also form a ground of distinction between +the modes of solution employed for the third and fourth antinomies. +For, while in the consideration of freedom in the former antinomy, +the thing itself--the cause (substantia phaenomenon)--was regarded +as belonging to the series of conditions, and only its causality to +the intelligible world--we are obliged in the present case to cogitate +this necessary being as purely intelligible and as existing entirely +apart from the world of sense (as an ens extramundanum); for otherwise +it would be subject to the phenomenal law of contingency and +dependence. + +In relation to the present problem, therefore, the regulative +principle of reason is that everything in the sensuous world possesses +an empirically conditioned existence--that no property of the sensuous +world possesses unconditioned necessity--that we are bound to +expect, and, so far as is possible, to seek for the empirical +condition of every member in the series of conditions--and that +there is no sufficient reason to justify us in deducing any +existence from a condition which lies out of and beyond the +empirical series, or in regarding any existence as independent and +self-subsistent; although this should not prevent us from +recognizing the possibility of the whole series being based upon a +being which is intelligible, and for this reason free from all +empirical conditions. + +But it has been far from my intention, in these remarks, to prove +the existence of this unconditioned and necessary being, or even to +evidence the possibility of a purely intelligible condition of the +existence or all sensuous phenomena. As bounds were set to reason, +to prevent it from leaving the guiding thread of empirical +conditions and losing itself in transcendent theories which are +incapable of concrete presentation; so it was my purpose, on the other +band, to set bounds to the law of the purely empirical +understanding, and to protest against any attempts on its part at +deciding on the possibility of things, or declaring the existence of +the intelligible to be impossible, merely on the ground that it is +not available for the explanation and exposition of phenomena. It has +been shown, at the same time, that the contingency of all the phenomena +of nature and their empirical conditions is quite consistent with +the arbitrary hypothesis of a necessary, although purely +intelligible condition, that no real contradiction exists between them +and that, consequently, both may be true. The existence of such an +absolutely necessary being may be impossible; but this can never be +demonstrated from the universal contingency and dependence of sensuous +phenomena, nor from the principle which forbids us to discontinue +the series at some member of it, or to seek for its cause in some +sphere of existence beyond the world of nature. Reason goes its way +in the empirical world, and follows, too, its peculiar path in the +sphere of the transcendental. + +The sensuous world contains nothing but phenomena, which are mere +representations, and always sensuously conditioned; things in +themselves are not, and cannot be, objects to us. It is not to be +wondered at, therefore, that we are not justified in leaping from some +member of an empirical series beyond the world of sense, as if +empirical representations were things in themselves, existing apart +from their transcendental ground in the human mind, and the cause of +whose existence may be sought out of the empirical series. This +would certainly be the case with contingent things; but it cannot be +with mere representations of things, the contingency of which is +itself merely a phenomenon and can relate to no other regress than +that which determines phenomena, that is, the empirical. But to +cogitate an intelligible ground of phenomena, as free, moreover, +from the contingency of the latter, conflicts neither with the +unlimited nature of the empirical regress, nor with the complete +contingency of phenomena. And the demonstration of this was the only +thing necessary for the solution of this apparent antinomy. For if +the condition of every conditioned--as regards its existence--is sensuous, +and for this reason a part of the same series, it must be itself +conditioned, as was shown in the antithesis of the fourth antinomy. +The embarrassments into which a reason, which postulates the +unconditioned, necessarily falls, must, therefore, continue to +exist; or the unconditioned must be placed in the sphere of the +intelligible. In this way, its necessity does not require, nor does +it even permit, the presence of an empirical condition: and it is, +consequently, unconditionally necessary. + +The empirical employment of reason is not affected by the assumption +of a purely intelligible being; it continues its operations on the +principle of the contingency of all phenomena, proceeding from +empirical conditions to still higher and higher conditions, themselves +empirical. Just as little does this regulative principle exclude the +assumption of an intelligible cause, when the question regards +merely the pure employment of reason--in relation to ends or aims. +For, in this case, an intelligible cause signifies merely the +transcendental and to us unknown ground of the possibility of sensuous +phenomena, and its existence, necessary and independent of all +sensuous conditions, is not inconsistent with the contingency of +phenomena, or with the unlimited possibility of regress which exists +in the series of empirical conditions. + + + +Concluding Remarks on the Antinomy of Pure Reason. + +So long as the object of our rational conceptions is the totality of +conditions in the world of phenomena, and the satisfaction, from +this source, of the requirements of reason, so long are our ideas +transcendental and cosmological. But when we set the unconditioned- +which is the aim of all our inquiries--in a sphere which lies out of +the world of sense and possible experience, our ideas become +transcendent. They are then not merely serviceable towards the +completion of the exercise of reason (which remains an idea, never +executed, but always to be pursued); they detach themselves completely +from experience and construct for themselves objects, the material +of which has not been presented by experience, and the objective +reality of which is not based upon the completion of the empirical +series, but upon pure a priori conceptions. The intelligible object +of these transcendent ideas may be conceded, as a transcendental +object. But we cannot cogitate it as a thing determinable by certain +distinct predicates relating to its internal nature, for it has no +connection with empirical conceptions; nor are we justified in +affirming the existence of any such object. It is, consequently, a +mere product of the mind alone. Of all the cosmological ideas, +however, it is that occasioning the fourth antinomy which compels us +to venture upon this step. For the existence of phenomena, always +conditioned and never self-subsistent, requires us to look for an +object different from phenomena--an intelligible object, with which +all contingency must cease. But, as we have allowed ourselves to +assume the existence of a self-subsistent reality out of the field +of experience, and are therefore obliged to regard phenomena as merely +a contingent mode of representing intelligible objects employed by +beings which are themselves intelligences--no other course remains +for us than to follow analogy and employ the same mode in forming +some conception of intelligible things, of which we have not the least +knowledge, which nature taught us to use in the formation of empirical +conceptions. Experience made us acquainted with the contingent. But +we are at present engaged in the discussion of things which are not +objects of experience; and must, therefore, deduce our knowledge of +them from that which is necessary absolutely and in itself, that is, +from pure conceptions. Hence the first step which we take out of the +world of sense obliges us to begin our system of new cognition with +the investigation of a necessary being, and to deduce from our +conceptions of it all our conceptions of intelligible things. This +we propose to attempt in the following chapter. + + + + +CHAPTER III. The Ideal of Pure Reason. + +SECTION I. Of the Ideal in General. + +We have seen that pure conceptions do not present objects to the +mind, except under sensuous conditions; because the conditions of +objective reality do not exist in these conceptions, which contain, +in fact, nothing but the mere form of thought. They may, however, when +applied to phenomena, be presented in concreto; for it is phenomena +that present to them the materials for the formation of empirical +conceptions, which are nothing more than concrete forms of the +conceptions of the understanding. But ideas are still further +removed from objective reality than categories; for no phenomenon +can ever present them to the human mind in concreto. They contain a +certain perfection, attainable by no possible empirical cognition; +and they give to reason a systematic unity, to which the unity of +experience attempts to approximate, but can never completely attain. + +But still further removed than the idea from objective reality is +the Ideal, by which term I understand the idea, not in concreto, but +in individuo--as an individual thing, determinable or determined by +the idea alone. The idea of humanity in its complete perfection +supposes not only the advancement of all the powers and faculties, +which constitute our conception of human nature, to a complete +attainment of their final aims, but also everything which is requisite +for the complete determination of the idea; for of all contradictory +predicates, only one can conform with the idea of the perfect man. +What I have termed an ideal was in Plato's philosophy an idea of the +divine mind--an individual object present to its pure intuition, the +most perfect of every kind of possible beings, and the archetype of +all phenomenal existences. + +Without rising to these speculative heights, we are bound to confess +that human reason contains not only ideas, but ideals, which +possess, not, like those of Plato, creative, but certainly practical +power--as regulative principles, and form the basis of the +perfectibility of certain actions. Moral conceptions are not perfectly +pure conceptions of reason, because an empirical element--of +pleasure or pain--lies at the foundation of them. In relation, +however, to the principle, whereby reason sets bounds to a freedom +which is in itself without law, and consequently when we attend merely +to their form, they may be considered as pure conceptions of reason. +Virtue and wisdom in their perfect purity are ideas. But the wise +man of the Stoics is an ideal, that is to say, a human being +existing only in thought and in complete conformity with the idea of +wisdom. As the idea provides a rule, so the ideal serves as an +archetype for the perfect and complete determination of the copy. Thus +the conduct of this wise and divine man serves us as a standard of +action, with which we may compare and judge ourselves, which may +help us to reform ourselves, although the perfection it demands can +never be attained by us. Although we cannot concede objective +reality to these ideals, they are not to be considered as chimeras; +on the contrary, they provide reason with a standard, which enables +it to estimate, by comparison, the degree of incompleteness in the +objects presented to it. But to aim at realizing the ideal in an example +in the world of experience--to describe, for instance, the character +of the perfectly wise man in a romance--is impracticable. Nay more, +there is something absurd in the attempt; and the result must be little +edifying, as the natural limitations, which are continually breaking +in upon the perfection and completeness of the idea, destroy the +illusion in the story and throw an air of suspicion even on what is +good in the idea, which hence appears fictitious and unreal. + +Such is the constitution of the ideal of reason, which is always +based upon determinate conceptions, and serves as a rule and a model +for limitation or of criticism. Very different is the nature of the +ideals of the imagination. Of these it is impossible to present an +intelligible conception; they are a kind of monogram, drawn +according to no determinate rule, and forming rather a vague +picture--the production of many diverse experiences--than a +determinate image. Such are the ideals which painters and +physiognomists profess to have in their minds, and which can serve +neither as a model for production nor as a standard for +appreciation. They may be termed, though improperly, sensuous +ideals, as they are declared to be models of certain possible +empirical intuitions. They cannot, however, furnish rules or standards +for explanation or examination. + +In its ideals, reason aims at complete and perfect determination +according to a priori rules; and hence it cogitates an object, which +must be completely determinable in conformity with principles, +although all empirical conditions are absent, and the conception of +the object is on this account transcendent. + + + +SECTION II. Of the Transcendental Ideal (Prototypon Trancendentale). + +Every conception is, in relation to that which is not contained in +it, undetermined and subject to the principle of determinability. This +principle is that, of every two contradictorily opposed predicates, +only one can belong to a conception. It is a purely logical principle, +itself based upon the principle of contradiction; inasmuch as it makes +complete abstraction of the content and attends merely to the +logical form of the cognition. + +But again, everything, as regards its possibility, is also subject +to the principle of complete determination, according to which one +of all the possible contradictory predicates of things must belong +to it. This principle is not based merely upon that of +contradiction; for, in addition to the relation between two +contradictory predicates, it regards everything as standing in a +relation to the sum of possibilities, as the sum total of all +predicates of things, and, while presupposing this sum as an a +priori condition, presents to the mind everything as receiving the +possibility of its individual existence from the relation it bears +to, and the share it possesses in, the aforesaid sum of possibilities.* +The principle of complete determination relates the content and not +to the logical form. It is the principle of the synthesis of all the +predicates which are required to constitute the complete conception +of a thing, and not a mere principle analytical representation, which +enounces that one of two contradictory predicates must belong to a +conception. It contains, moreover, a transcendental presupposition-- +that, namely, of the material for all possibility, which must +contain a priori the data for this or that particular possibility. + +[*Footnote: Thus this principle declares everything to possess a +relation to a common correlate--the sum-total of possibility, which, if +discovered to exist in the idea of one individual thing, would +establish the affinity of all possible things, from the identity of the +ground of their complete determination. The determinability of every +conception is subordinate to the universality (Allgemeinheit, +universalitas) of the principle of excluded middle; the determination +of a thing to the totality (Allheit, universitas) of all possible +predicates.] + +The proposition, everything which exists is completely determined, +means not only that one of every pair of given contradictory +attributes, but that one of all possible attributes, is always +predicable of the thing; in it the predicates are not merely +compared logically with each other, but the thing itself is +transcendentally compared with the sum-total of all possible +predicates. The proposition is equivalent to saying: "To attain to +a complete knowledge of a thing, it is necessary to possess a +knowledge of everything that is possible, and to determine it +thereby in a positive or negative manner." The conception of +complete determination is consequently a conception which cannot be +presented in its totality in concreto, and is therefore based upon +an idea, which has its seat in the reason--the faculty which +prescribes to the understanding the laws of its harmonious and perfect +exercise. + +Now, although this idea of the sum-total of all possibility, in so +far as it forms the condition of the complete determination of +everything, is itself undetermined in relation to the predicates which +may constitute this sum-total, and we cogitate in it merely the +sum-total of all possible predicates--we nevertheless find, upon +closer examination, that this idea, as a primitive conception of the +mind, excludes a large number of predicates--those deduced and those +irreconcilable with others, and that it is evolved as a conception +completely determined a priori. Thus it becomes the conception of an +individual object, which is completely determined by and through the +mere idea, and must consequently be termed an ideal of pure reason. + +When we consider all possible predicates, not merely logically, +but transcendentally, that is to say, with reference to the content +which may be cogitated as existing in them a priori, we shall find +that some indicate a being, others merely a non-being. The logical +negation expressed in the word not does not properly belong to a +conception, but only to the relation of one conception to another in +a judgement, and is consequently quite insufficient to present to the +mind the content of a conception. The expression not mortal does not +indicate that a non-being is cogitated in the object; it does not +concern the content at all. A transcendental negation, on the +contrary, indicates non-being in itself, and is opposed to +transcendental affirmation, the conception of which of itself +expresses a being. Hence this affirmation indicates a reality, because +in and through it objects are considered to be something--to be +things; while the opposite negation, on the other band, indicates a +mere want, or privation, or absence, and, where such negations alone +are attached to a representation, the non-existence of anything +corresponding to the representation. + +Now a negation cannot be cogitated as determined, without cogitating +at the same time the opposite affirmation. The man born blind has +not the least notion of darkness, because he has none of light; the +vagabond knows nothing of poverty, because he has never known what +it is to be in comfort;* the ignorant man has no conception of his +ignorance, because he has no conception of knowledge. All +conceptions of negatives are accordingly derived or deduced +conceptions; and realities contain the data, and, so to speak, the +material or transcendental content of the possibility and complete +determination of all things. + +[*Footnote: The investigations and calculations of astronomers have +taught us much that is wonderful; but the most important lesson we +have received from them is the discovery of the abyss of our ignorance +in relation to the universe--an ignorance the magnitude of which reason, +without the information thus derived, could never have conceived. This +discovery of our deficiencies must produce a great change in the +determination of the aims of human reason.] + +If, therefore, a transcendental substratum lies at the foundation of +the complete determination of things--a substratum which is to form +the fund from which all possible predicates of things are to be +supplied, this substratum cannot be anything else than the idea of +a sum-total of reality (omnitudo realitatis). In this view, negations +are nothing but limitations--a term which could not, with propriety, +be applied to them, if the unlimited (the all) did not form the true +basis of our conception. + +This conception of a sum-total of reality is the conception of a +thing in itself, regarded as completely determined; and the conception +of an ens realissimum is the conception of an individual being, +inasmuch as it is determined by that predicate of all possible +contradictory predicates, which indicates and belongs to being. It +is, therefore, a transcendental ideal which forms the basis of the +complete determination of everything that exists, and is the highest +material condition of its possibility--a condition on which must +rest the cogitation of all objects with respect to their content. Nay, +more, this ideal is the only proper ideal of which the human mind is +capable; because in this case alone a general conception of a thing +is completely determined by and through itself, and cognized as the +representation of an individuum. + +The logical determination of a conception is based upon a +disjunctive syllogism, the major of which contains the logical +division of the extent of a general conception, the minor limits +this extent to a certain part, while the conclusion determines the +conception by this part. The general conception of a reality cannot +be divided a priori, because, without the aid of experience, we cannot +know any determinate kinds of reality, standing under the former as +the genus. The transcendental principle of the complete +determination of all things is therefore merely the representation +of the sum-total of all reality; it is not a conception which is the +genus of all predicates under itself, but one which comprehends them +all within itself. The complete determination of a thing is +consequently based upon the limitation of this total of reality, so +much being predicated of the thing, while all that remains over is +excluded--a procedure which is in exact agreement with that of the +disjunctive syllogism and the determination of the objects in the +conclusion by one of the members of the division. It follows that +reason, in laying the transcendental ideal at the foundation of its +determination of all possible things, takes a course in exact +analogy with that which it pursues in disjunctive syllogisms--a +proposition which formed the basis of the systematic division of all +transcendental ideas, according to which they are produced in complete +parallelism with the three modes of syllogistic reasoning employed +by the human mind. + +It is self-evident that reason, in cogitating the necessary complete +determination of things, does not presuppose the existence of a +being corresponding to its ideal, but merely the idea of the ideal- +for the purpose of deducing from the unconditional totality of +complete determination, The ideal is therefore the prototype of all +things, which, as defective copies (ectypa), receive from it the +material of their possibility, and approximate to it more or less, +though it is impossible that they can ever attain to its perfection. + +The possibility of things must therefore be regarded as derived- +except that of the thing which contains in itself all reality, which +must be considered to be primitive and original. For all negations- +and they are the only predicates by means of which all other things +can be distinguished from the ens realissimum--are mere limitations +of a greater and a higher--nay, the highest reality; and they +consequently presuppose this reality, and are, as regards their +content, derived from it. The manifold nature of things is only an +infinitely various mode of limiting the conception of the highest +reality, which is their common substratum; just as all figures are +possible only as different modes of limiting infinite space. The +object of the ideal of reason--an object existing only in reason +itself--is also termed the primal being (ens originarium); as having +no existence superior to him, the supreme being (ens summum); and as +being the condition of all other beings, which rank under it, the +being of all beings (ens entium). But none of these terms indicate +the objective relation of an actually existing object to other things, +but merely that of an idea to conceptions; and all our investigations +into this subject still leave us in perfect uncertainty with regard +to the existence of this being. + +A primal being cannot be said to consist of many other beings with +an existence which is derivative, for the latter presuppose the +former, and therefore cannot be constitutive parts of it. It follows +that the ideal of the primal being must be cogitated as simple. + +The deduction of the possibility of all other things from this +primal being cannot, strictly speaking, be considered as a limitation, +or as a kind of division of its reality; for this would be regarding +the primal being as a mere aggregate--which has been shown to be +impossible, although it was so represented in our first rough +sketch. The highest reality must be regarded rather as the ground than +as the sum-total of the possibility of all things, and the manifold +nature of things be based, not upon the limitation of the primal being +itself, but upon the complete series of effects which flow from it. +And thus all our powers of sense, as well as all phenomenal reality, +phenomenal reality, may be with propriety regarded as belonging to +this series of effects, while they could not have formed parts of +the idea, considered as an aggregate. Pursuing this track, and +hypostatizing this idea, we shall find ourselves authorized to +determine our notion of the Supreme Being by means of the mere +conception of a highest reality, as one, simple, all-sufficient, +eternal, and so on--in one word, to determine it in its +unconditioned completeness by the aid of every possible predicate. +The conception of such a being is the conception of God in its +transcendental sense, and thus the ideal of pure reason is the +object-matter of a transcendental theology. + +But, by such an employment of the transcendental idea, we should +be over stepping the limits of its validity and purpose. For reason +placed it, as the conception of all reality, at the basis of the +complete determination of things, without requiring that this +conception be regarded as the conception of an objective existence. +Such an existence would be purely fictitious, and the hypostatizing +of the content of the idea into an ideal, as an individual being, is +a step perfectly unauthorized. Nay, more, we are not even called upon +to assume the possibility of such an hypothesis, as none of the +deductions drawn from such an ideal would affect the complete +determination of things in general--for the sake of which alone is +the idea necessary. + +It is not sufficient to circumscribe the procedure and the dialectic +of reason; we must also endeavour to discover the sources of this +dialectic, that we may have it in our power to give a rational +explanation of this illusion, as a phenomenon of the human mind. For +the ideal, of which we are at present speaking, is based, not upon +an arbitrary, but upon a natural, idea. The question hence arises: +How happens it that reason regards the possibility of all things as +deduced from a single possibility, that, to wit, of the highest +reality, and presupposes this as existing in an individual and +primal being? + +The answer is ready; it is at once presented by the procedure of +transcendental analytic. The possibility of sensuous objects is a +relation of these objects to thought, in which something (the +empirical form) may be cogitated a priori; while that which +constitutes the matter--the reality of the phenomenon (that element +which corresponds to sensation)--must be given from without, as +otherwise it could not even be cogitated by, nor could its possibility +be presentable to the mind. Now, a sensuous object is completely +determined, when it has been compared with all phenomenal +predicates, and represented by means of these either positively or +negatively. But, as that which constitutes the thing itself--the +real in a phenomenon, must be given, and that, in which the real of +all phenomena is given, is experience, one, sole, and all-embracing- +the material of the possibility of all sensuous objects must be +presupposed as given in a whole, and it is upon the limitation of this +whole that the possibility of all empirical objects, their distinction +from each other and their complete determination, are based. Now, no +other objects are presented to us besides sensuous objects, and +these can be given only in connection with a possible experience; it +follows that a thing is not an object to us, unless it presupposes +the whole or sum-total of empirical reality as the condition of its +possibility. Now, a natural illusion leads us to consider this +principle, which is valid only of sensuous objects, as valid with +regard to things in general. And thus we are induced to hold the +empirical principle of our conceptions of the possibility of things, +as phenomena, by leaving out this limitative condition, to be a +transcendental principle of the possibility of things in general. + +We proceed afterwards to hypostatize this idea of the sum-total of +all reality, by changing the distributive unity of the empirical +exercise of the understanding into the collective unity of an +empirical whole--a dialectical illusion, and by cogitating this +whole or sum of experience as an individual thing, containing in +itself all empirical reality. This individual thing or being is +then, by means of the above-mentioned transcendental subreption, +substituted for our notion of a thing which stands at the head of +the possibility of all things, the real conditions of whose complete +determination it presents.* + +[*Footnote: This ideal of the ens realissimum--although merely a mental +representation--is first objectivized, that is, has an objective +existence attributed to it, then hypostatized, and finally, by the +natural progress of reason to the completion of unity, personified, +as we shall show presently. For the regulative unity of experience +is not based upon phenomena themselves, but upon the connection of +the variety of phenomena by the understanding in a consciousness, and +thus the unity of the supreme reality and the complete determinability +of all things, seem to reside in a supreme understanding, and, +consequently, in a conscious intelligence.] + + + +SECTION III. Of the Arguments employed by Speculative Reason in + Proof of the Existence of a Supreme Being. + +Notwithstanding the pressing necessity which reason feels, to form +some presupposition that shall serve the understanding as a proper +basis for the complete determination of its conceptions, the +idealistic and factitious nature of such a presupposition is too +evident to allow reason for a moment to persuade itself into a +belief of the objective existence of a mere creation of its own +thought. But there are other considerations which compel reason to +seek out some resting place in the regress from the conditioned to +the unconditioned, which is not given as an actual existence from the +mere conception of it, although it alone can give completeness to the +series of conditions. And this is the natural course of every human +reason, even of the most uneducated, although the path at first +entered it does not always continue to follow. It does not begin +from conceptions, but from common experience, and requires a basis +in actual existence. But this basis is insecure, unless it rests +upon the immovable rock of the absolutely necessary. And this +foundation is itself unworthy of trust, if it leave under and above +it empty space, if it do not fill all, and leave no room for a why +or a wherefore, if it be not, in one word, infinite in its reality. + +If we admit the existence of some one thing, whatever it may be, +we must also admit that there is something which exists necessarily. +For what is contingent exists only under the condition of some other +thing, which is its cause; and from this we must go on to conclude +the existence of a cause which is not contingent, and which consequently +exists necessarily and unconditionally. Such is the argument by +which reason justifies its advances towards a primal being. + +Now reason looks round for the conception of a being that may be +admitted, without inconsistency, to be worthy of the attribute of +absolute necessity, not for the purpose of inferring a priori, from +the conception of such a being, its objective existence (for if reason +allowed itself to take this course, it would not require a basis in +given and actual existence, but merely the support of pure +conceptions), but for the purpose of discovering, among all our +conceptions of possible things, that conception which possesses no +element inconsistent with the idea of absolute necessity. For that +there must be some absolutely necessary existence, it regards as a +truth already established. Now, if it can remove every existence +incapable of supporting the attribute of absolute necessity, excepting +one--this must be the absolutely necessary being, whether its +necessity is comprehensible by us, that is, deducible from the +conception of it alone, or not. + +Now that, the conception of which contains a therefore to every +wherefore, which is not defective in any respect whatever, which is +all-sufficient as a condition, seems to be the being of which we can +justly predicate absolute necessity--for this reason, that, possessing +the conditions of all that is possible, it does not and cannot +itself require any condition. And thus it satisfies, in one respect +at least, the requirements of the conception of absolute necessity. +In this view, it is superior to all other conceptions, which, as +deficient and incomplete, do not possess the characteristic of +independence of all higher conditions. It is true that we cannot infer +from this that what does not contain in itself the supreme and +complete condition--the condition of all other things--must possess +only a conditioned existence; but as little can we assert the +contrary, for this supposed being does not possess the only +characteristic which can enable reason to cognize by means of an a +priori conception the unconditioned and necessary nature of its +existence. + +The conception of an ens realissimum is that which best agrees +with the conception of an unconditioned and necessary being. The +former conception does not satisfy all the requirements of the latter; +but we have no choice, we are obliged to adhere to it, for we find +that we cannot do without the existence of a necessary being; and even +although we admit it, we find it out of our power to discover in the +whole sphere of possibility any being that can advance well-grounded +claims to such a distinction. + +The following is, therefore, the natural course of human reason. +It begins by persuading itself of the existence of some necessary +being. In this being it recognizes the characteristics of +unconditioned existence. It then seeks the conception of that which +is independent of all conditions, and finds it in that which is itself +the sufficient condition of all other things--in other words, in +that which contains all reality. But the unlimited all is an +absolute unity, and is conceived by the mind as a being one and +supreme; and thus reason concludes that the Supreme Being, as the +primal basis of all things, possesses an existence which is absolutely +necessary. + +This conception must be regarded as in some degree satisfactory, +if we admit the existence of a necessary being, and consider that +there exists a necessity for a definite and final answer to these +questions. In such a case, we cannot make a better choice, or rather +we have no choice at all, but feel ourselves obliged to declare in +favour of the absolute unity of complete reality, as the highest +source of the possibility of things. But if there exists no motive +for coming to a definite conclusion, and we may leave the question +unanswered till we have fully weighed both sides--in other words, when +we are merely called upon to decide how much we happen to know about +the question, and how much we merely flatter ourselves that we know- +the above conclusion does not appear to be so great advantage, but, +on the contrary, seems defective in the grounds upon which it is +supported. + +For, admitting the truth of all that has been said, that, namely, +the inference from a given existence (my own, for example) to the +existence of an unconditioned and necessary being is valid and +unassailable; that, in the second place, we must consider a being +which contains all reality, and consequently all the conditions of +other things, to be absolutely unconditioned; and admitting too, +that we have thus discovered the conception of a thing to which may +be attributed, without inconsistency, absolute necessity--it does not +follow from all this that the conception of a limited being, in +which the supreme reality does not reside, is therefore incompatible +with the idea of absolute necessity. For, although I do not discover +the element of the unconditioned in the conception of such a being--an +element which is manifestly existent in the sum-total of all +conditions--I am not entitled to conclude that its existence is +therefore conditioned; just as I am not entitled to affirm, in a +hypothetical syllogism, that where a certain condition does not +exist (in the present, completeness, as far as pure conceptions are +concerned), the conditioned does not exist either. On the contrary, +we are free to consider all limited beings as likewise unconditionally +necessary, although we are unable to infer this from the general +conception which we have of them. Thus conducted, this argument is +incapable of giving us the least notion of the properties of a +necessary being, and must be in every respect without result. + +This argument continues, however, to possess a weight and an +authority, which, in spite of its objective insufficiency, it has +never been divested of. For, granting that certain responsibilities +lie upon us, which, as based on the ideas of reason, deserve to be +respected and submitted to, although they are incapable of a real or +practical application to our nature, or, in other words, would be +responsibilities without motives, except upon the supposition of a +Supreme Being to give effect and influence to the practical laws: in +such a case we should be bound to obey our conceptions, which, +although objectively insufficient, do, according to the standard of +reason, preponderate over and are superior to any claims that may be +advanced from any other quarter. The equilibrium of doubt would in +this case be destroyed by a practical addition; indeed, Reason would +be compelled to condemn herself, if she refused to comply with the +demands of the judgement, no superior to which we know--however +defective her understanding of the grounds of these demands might be. + +This argument, although in fact transcendental, inasmuch as it rests +upon the intrinsic insufficiency of the contingent, is so simple and +natural, that the commonest understanding can appreciate its value. +We see things around us change, arise, and pass away; they, or their +condition, must therefore have a cause. The same demand must again +be made of the cause itself--as a datum of experience. Now it is +natural that we should place the highest causality just where we place +supreme causality, in that being, which contains the conditions of +all possible effects, and the conception of which is so simple as that +of an all-embracing reality. This highest cause, then, we regard as +absolutely necessary, because we find it absolutely necessary to +rise to it, and do not discover any reason for proceeding beyond it. +Thus, among all nations, through the darkest polytheism glimmer some +faint sparks of monotheism, to which these idolaters have been led, +not from reflection and profound thought, but by the study and natural +progress of the common understanding. + +There are only three modes of proving the existence of a Deity, on +the grounds of speculative reason. + +All the paths conducting to this end begin either from determinate +experience and the peculiar constitution of the world of sense, and +rise, according to the laws of causality, from it to the highest cause +existing apart from the world--or from a purely indeterminate +experience, that is, some empirical existence--or abstraction is +made of all experience, and the existence of a supreme cause is +concluded from a priori conceptions alone. The first is the +physico-theological argument, the second the cosmological, the third +the ontological. More there are not, and more there cannot be. + +I shall show it is as unsuccessful on the one path--the empirical- +as on the other--the transcendental, and that it stretches its wings +in vain, to soar beyond the world of sense by the mere might of +speculative thought. As regards the order in which we must discuss +those arguments, it will be exactly the reverse of that in which +reason, in the progress of its development, attains to them--the order +in which they are placed above. For it will be made manifest to the +reader that, although experience presents the occasion and the +starting-point, it is the transcendental idea of reason which guides +it in its pilgrimage and is the goal of all its struggles. I shall +therefore begin with an examination of the transcendental argument, +and afterwards inquire what additional strength has accrued to this +mode of proof from the addition of the empirical element. + + + +SECTION IV. Of the Impossibility of an Ontological Proof of + the Existence of God. + +It is evident from what has been said that the conception of an +absolutely necessary being is a mere idea, the objective reality of +which is far from being established by the mere fact that it is a need +of reason. On the contrary, this idea serves merely to indicate a +certain unattainable perfection, and rather limits the operations +than, by the presentation of new objects, extends the sphere of the +understanding. But a strange anomaly meets us at the very threshold; +for the inference from a given existence in general to an absolutely +necessary existence seems to be correct and unavoidable, while the +conditions of the understanding refuse to aid us in forming any +conception of such a being. + +Philosophers have always talked of an absolutely necessary being, +and have nevertheless declined to take the trouble of conceiving +whether--and how--a being of this nature is even cogitable, not to +mention that its existence is actually demonstrable. A verbal +definition of the conception is certainly easy enough: it is something +the non-existence of which is impossible. But does this definition +throw any light upon the conditions which render it impossible to +cogitate the non-existence of a thing--conditions which we wish to +ascertain, that we may discover whether we think anything in the +conception of such a being or not? For the mere fact that I throw +away, by means of the word unconditioned, all the conditions which +the understanding habitually requires in order to regard anything as +necessary, is very far from making clear whether by means of the +conception of the unconditionally necessary I think of something, or +really of nothing at all. + +Nay, more, this chance-conception, now become so current, many +have endeavoured to explain by examples which seemed to render any +inquiries regarding its intelligibility quite needless. Every +geometrical proposition--a triangle has three angles--it was said, +is absolutely necessary; and thus people talked of an object which +lay out of the sphere of our understanding as if it were perfectly +plain what the conception of such a being meant. + +All the examples adduced have been drawn, without exception, from +judgements, and not from things. But the unconditioned necessity of +a judgement does not form the absolute necessity of a thing. On the +contrary, the absolute necessity of a judgement is only a +conditioned necessity of a thing, or of the predicate in a +judgement. The proposition above-mentioned does not enounce that three +angles necessarily exist, but, upon condition that a triangle +exists, three angles must necessarily exist--in it. And thus this +logical necessity has been the source of the greatest delusions. +Having formed an a priori conception of a thing, the content of +which was made to embrace existence, we believed ourselves safe in +concluding that, because existence belongs necessarily to the object +of the conception (that is, under the condition of my positing this +thing as given), the existence of the thing is also posited +necessarily, and that it is therefore absolutely necessary--merely +because its existence has been cogitated in the conception. + +If, in an identical judgement, I annihilate the predicate in +thought, and retain the subject, a contradiction is the result; and +hence I say, the former belongs necessarily to the latter. But if I +suppress both subject and predicate in thought, no contradiction +arises; for there is nothing at all, and therefore no means of forming +a contradiction. To suppose the existence of a triangle and not that +of its three angles, is self-contradictory; but to suppose the +non-existence of both triangle and angles is perfectly admissible. +And so is it with the conception of an absolutely necessary being. +Annihilate its existence in thought, and you annihilate the thing +itself with all its predicates; how then can there be any room for +contradiction? Externally, there is nothing to give rise to a +contradiction, for a thing cannot be necessary externally; nor +internally, for, by the annihilation or suppression of the thing +itself, its internal properties are also annihilated. God is +omnipotent--that is a necessary judgement. His omnipotence cannot be +denied, if the existence of a Deity is posited--the existence, that +is, of an infinite being, the two conceptions being identical. But +when you say, God does not exist, neither omnipotence nor any other +predicate is affirmed; they must all disappear with the subject, and +in this judgement there cannot exist the least self-contradiction. + +You have thus seen that when the predicate of a judgement is +annihilated in thought along with the subject, no internal +contradiction can arise, be the predicate what it may. There is no +possibility of evading the conclusion--you find yourselves compelled +to declare: There are certain subjects which cannot be annihilated +in thought. But this is nothing more than saying: There exist subjects +which are absolutely necessary--the very hypothesis which you are +called upon to establish. For I find myself unable to form the +slightest conception of a thing which when annihilated in thought with +all its predicates, leaves behind a contradiction; and contradiction +is the only criterion of impossibility in the sphere of pure a +priori conceptions. + +Against these general considerations, the justice of which no one +can dispute, one argument is adduced, which is regarded as +furnishing a satisfactory demonstration from the fact. It is +affirmed that there is one and only one conception, in which the +non-being or annihilation of the object is self-contradictory, and +this is the conception of an ens realissimum. It possesses, you say, +all reality, and you feel yourselves justified in admitting the +possibility of such a being. (This I am willing to grant for the +present, although the existence of a conception which is not +self-contradictory is far from being sufficient to prove the +possibility of an object.)* Now the notion of all reality embraces +in it that of existence; the notion of existence lies, therefore, in +the conception of this possible thing. If this thing is annihilated +in thought, the internal possibility of the thing is also annihilated, +which is self-contradictory. + +[*Footnote: A conception is always possible, if it is not +self-contradictory. This is the logical criterion of possibility, +distinguishing the object of such a conception from the nihil negativum. +But it may be, notwithstanding, an empty conception, unless the objective +reality of this synthesis, but which it is generated, is demonstrated; +and a proof of this kind must be based upon principles of possible +experience, and not upon the principle of analysis or contradiction. +This remark may be serviceable as a warning against concluding, from +the possibility of a conception--which is logical--the possibility +of a thing--which is real.] + +I answer: It is absurd to introduce--under whatever term +disguised--into the conception of a thing, which is to be cogitated +solely in reference to its possibility, the conception of its +existence. If this is admitted, you will have apparently gained the +day, but in reality have enounced nothing but a mere tautology. I ask, +is the proposition, this or that thing (which I am admitting to be +possible) exists, an analytical or a synthetical proposition? If the +former, there is no addition made to the subject of your thought by +the affirmation of its existence; but then the conception in your +minds is identical with the thing itself, or you have supposed the +existence of a thing to be possible, and then inferred its existence +from its internal possibility--which is but a miserable tautology. +The word reality in the conception of the thing, and the word existence +in the conception of the predicate, will not help you out of the +difficulty. For, supposing you were to term all positing of a thing +reality, you have thereby posited the thing with all its predicates +in the conception of the subject and assumed its actual existence, +and this you merely repeat in the predicate. But if you confess, as +every reasonable person must, that every existential proposition is +synthetical, how can it be maintained that the predicate of +existence cannot be denied without contradiction?--a property which +is the characteristic of analytical propositions, alone. + +I should have a reasonable hope of putting an end for ever to this +sophistical mode of argumentation, by a strict definition of the +conception of existence, did not my own experience teach me that the +illusion arising from our confounding a logical with a real +predicate (a predicate which aids in the determination of a thing) +resists almost all the endeavours of explanation and illustration. +A logical predicate may be what you please, even the subject may be +predicated of itself; for logic pays no regard to the content of a +judgement. But the determination of a conception is a predicate, which +adds to and enlarges the conception. It must not, therefore, be +contained in the conception. + +Being is evidently not a real predicate, that is, a conception of +something which is added to the conception of some other thing. It +is merely the positing of a thing, or of certain determinations in +it. Logically, it is merely the copula of a judgement. The proposition, +God is omnipotent, contains two conceptions, which have a certain +object or content; the word is, is no additional predicate--it +merely indicates the relation of the predicate to the subject. Now, +if I take the subject (God) with all its predicates (omnipotence being +one), and say: God is, or, There is a God, I add no new predicate to +the conception of God, I merely posit or affirm the existence of the +subject with all its predicates--I posit the object in relation to +my conception. The content of both is the same; and there is no +addition made to the conception, which expresses merely the +possibility of the object, by my cogitating the object--in the +expression, it is--as absolutely given or existing. Thus the real +contains no more than the possible. A hundred real dollars contain +no more than a hundred possible dollars. For, as the latter indicate +the conception, and the former the object, on the supposition that +the content of the former was greater than that of the latter, my +conception would not be an expression of the whole object, and would +consequently be an inadequate conception of it. But in reckoning my +wealth there may be said to be more in a hundred real dollars than +in a hundred possible dollars--that is, in the mere conception of +them. For the real object--the dollars--is not analytically +contained in my conception, but forms a synthetical addition to my +conception (which is merely a determination of my mental state), +although this objective reality--this existence--apart from my +conceptions, does not in the least degree increase the aforesaid +hundred dollars. + +By whatever and by whatever number of predicates--even to the +complete determination of it--I may cogitate a thing, I do not in +the least augment the object of my conception by the addition of the +statement: This thing exists. Otherwise, not exactly the same, but +something more than what was cogitated in my conception, would +exist, and I could not affirm that the exact object of my conception +had real existence. If I cogitate a thing as containing all modes of +reality except one, the mode of reality which is absent is not added +to the conception of the thing by the affirmation that the thing +exists; on the contrary, the thing exists--if it exist at all--with +the same defect as that cogitated in its conception; otherwise not +that which was cogitated, but something different, exists. Now, if +I cogitate a being as the highest reality, without defect or +imperfection, the question still remains--whether this being exists +or not? For, although no element is wanting in the possible real +content of my conception, there is a defect in its relation to my +mental state, that is, I am ignorant whether the cognition of the +object indicated by the conception is possible a posteriori. And +here the cause of the present difficulty becomes apparent. If the +question regarded an object of sense merely, it would be impossible +for me to confound the conception with the existence of a thing. For +the conception merely enables me to cogitate an object as according +with the general conditions of experience; while the existence of +the object permits me to cogitate it as contained in the sphere of +actual experience. At the same time, this connection with the world +of experience does not in the least augment the conception, although +a possible perception has been added to the experience of the mind. +But if we cogitate existence by the pure category alone, it is not +to be wondered at, that we should find ourselves unable to present +any criterion sufficient to distinguish it from mere possibility. + +Whatever be the content of our conception of an object, it is +necessary to go beyond it, if we wish to predicate existence of the +object. In the case of sensuous objects, this is attained by their +connection according to empirical laws with some one of my +perceptions; but there is no means of cognizing the existence of +objects of pure thought, because it must be cognized completely a +priori. But all our knowledge of existence (be it immediately by +perception, or by inferences connecting some object with a perception) +belongs entirely to the sphere of experience--which is in perfect +unity with itself; and although an existence out of this sphere cannot +be absolutely declared to be impossible, it is a hypothesis the +truth of which we have no means of ascertaining. + +The notion of a Supreme Being is in many respects a highly useful +idea; but for the very reason that it is an idea, it is incapable of +enlarging our cognition with regard to the existence of things. It +is not even sufficient to instruct us as to the possibility of a being +which we do not know to exist. The analytical criterion of +possibility, which consists in the absence of contradiction in +propositions, cannot be denied it. But the connection of real +properties in a thing is a synthesis of the possibility of which an +a priori judgement cannot be formed, because these realities are not +presented to us specifically; and even if this were to happen, a +judgement would still be impossible, because the criterion of the +possibility of synthetical cognitions must be sought for in the +world of experience, to which the object of an idea cannot belong. +And thus the celebrated Leibnitz has utterly failed in his attempt +to establish upon a priori grounds the possibility of this sublime +ideal being. + +The celebrated ontological or Cartesian argument for the existence +of a Supreme Being is therefore insufficient; and we may as well +hope to increase our stock of knowledge by the aid of mere ideas, as +the merchant to augment his wealth by the addition of noughts to his +cash account. + + + +SECTION V. Of the Impossibility of a Cosmological Proof + of the Existence of God. + +It was by no means a natural course of proceeding, but, on the +contrary, an invention entirely due to the subtlety of the schools, +to attempt to draw from a mere idea a proof of the existence of an +object corresponding to it. Such a course would never have been pursued, +were it not for that need of reason which requires it to suppose the +existence of a necessary being as a basis for the empirical regress, +and that, as this necessity must be unconditioned and a priori, reason +is bound to discover a conception which shall satisfy, if possible, +this requirement, and enable us to attain to the a priori cognition +of such a being. This conception was thought to be found in the idea +of an ens realissimum, and thus this idea was employed for the attainment +of a better defined knowledge of a necessary being, of the existence +of which we were convinced, or persuaded, on other grounds. Thus +reason was seduced from her natural courage; and, instead of +concluding with the conception of an ens realissimum, an attempt was +made to begin with it, for the purpose of inferring from it that +idea of a necessary existence which it was in fact called in to +complete. Thus arose that unfortunate ontological argument, which +neither satisfies the healthy common sense of humanity, nor sustains +the scientific examination of the philosopher. + +The cosmological proof, which we are about to examine, retains the +connection between absolute necessity and the highest reality; but, +instead of reasoning from this highest reality to a necessary +existence, like the preceding argument, it concludes from the given +unconditioned necessity of some being its unlimited reality. The track +it pursues, whether rational or sophistical, is at least natural, +and not only goes far to persuade the common understanding, but +shows itself deserving of respect from the speculative intellect; +while it contains, at the same time, the outlines of all the arguments +employed in natural theology--arguments which always have been, and +still will be, in use and authority. These, however adorned, and hid +under whatever embellishments of rhetoric and sentiment, are at bottom +identical with the arguments we are at present to discuss. This proof, +termed by Leibnitz the argumentum a contingentia mundi, I shall now +lay before the reader, and subject to a strict examination. + +It is framed in the following manner: If something exists, an +absolutely necessary being must likewise exist. Now I, at least, +exist. Consequently, there exists an absolutely necessary being. The +minor contains an experience, the major reasons from a general +experience to the existence of a necessary being.* Thus this +argument really begins at experience, and is not completely a +priori, or ontological. The object of all possible experience being +the world, it is called the cosmological proof. It contains no +reference to any peculiar property of sensuous objects, by which +this world of sense might be distinguished from other possible worlds; +and in this respect it differs from the physico-theological proof, +which is based upon the consideration of the peculiar constitution +of our sensuous world. + +[*Footnote: This inference is too well known to require more detailed +discussion. It is based upon the spurious transcendental law of +causality, that everything which is contingent has a cause, which, +if itself contingent, must also have a cause; and so on, till the +series of subordinated causes must end with an absolutely necessary +cause, without which it would not possess completeness.] + +The proof proceeds thus: A necessary being can be determined only in +one way, that is, it can be determined by only one of all possible +opposed predicates; consequently, it must be completely determined +in and by its conception. But there is only a single conception of +a thing possible, which completely determines the thing a priori: that +is, the conception of the ens realissimum. It follows that the +conception of the ens realissimum is the only conception by and in +which we can cogitate a necessary being. Consequently, a Supreme Being +necessarily exists. + +In this cosmological argument are assembled so many sophistical +propositions that speculative reason seems to have exerted in it all +her dialectical skill to produce a transcendental illusion of the most +extreme character. We shall postpone an investigation of this argument +for the present, and confine ourselves to exposing the stratagem by +which it imposes upon us an old argument in a new dress, and appeals +to the agreement of two witnesses, the one with the credentials of +pure reason, and the other with those of empiricism; while, in fact, +it is only the former who has changed his dress and voice, for the +purpose of passing himself off for an additional witness. That it +may possess a secure foundation, it bases its conclusions upon +experience, and thus appears to be completely distinct from the +ontological argument, which places its confidence entirely in pure +a priori conceptions. But this experience merely aids reason in making +one step--to the existence of a necessary being. What the properties +of this being are cannot be learned from experience; and therefore +reason abandons it altogether, and pursues its inquiries in the sphere +of pure conception, for the purpose of discovering what the properties +of an absolutely necessary being ought to be, that is, what among +all possible things contain the conditions (requisita) of absolute +necessity. Reason believes that it has discovered these requisites +in the conception of an ens realissimum--and in it alone, and hence +concludes: The ens realissimum is an absolutely necessary being. But +it is evident that reason has here presupposed that the conception +of an ens realissimum is perfectly adequate to the conception of a +being of absolute necessity, that is, that we may infer the +existence of the latter from that of the former--a proposition which +formed the basis of the ontological argument, and which is now +employed in the support of the cosmological argument, contrary to +the wish and professions of its inventors. For the existence of an +absolutely necessary being is given in conceptions alone. But if I +say: "The conception of the ens realissimum is a conception of this +kind, and in fact the only conception which is adequate to our idea +of a necessary being," I am obliged to admit, that the latter may be +inferred from the former. Thus it is properly the ontological argument +which figures in the cosmological, and constitutes the whole +strength of the latter; while the spurious basis of experience has +been of no further use than to conduct us to the conception of +absolute necessity, being utterly insufficient to demonstrate the +presence of this attribute in any determinate existence or thing. +For when we propose to ourselves an aim of this character, we must +abandon the sphere of experience, and rise to that of pure +conceptions, which we examine with the purpose of discovering +whether any one contains the conditions of the possibility of an +absolutely necessary being. But if the possibility of such a being +is thus demonstrated, its existence is also proved; for we may then +assert that, of all possible beings there is one which possesses the +attribute of necessity--in other words, this being possesses an +absolutely necessary existence. + +All illusions in an argument are more easily detected when they +are presented in the formal manner employed by the schools, which we +now proceed to do. + +If the proposition: "Every absolutely necessary being is likewise an +ens realissimum," is correct (and it is this which constitutes the +nervus probandi of the cosmological argument), it must, like all +affirmative judgements, be capable of conversion--the conversio per +accidens, at least. It follows, then, that some entia realissima are +absolutely necessary beings. But no ens realissimum is in any +respect different from another, and what is valid of some is valid +of all. In this present case, therefore, I may employ simple +conversion, and say: "Every ens realissimum is a necessary being." +But as this proposition is determined a priori by the conceptions +contained in it, the mere conception of an ens realissimum must +possess the additional attribute of absolute necessity. But this is +exactly what was maintained in the ontological argument, and not +recognized by the cosmological, although it formed the real ground +of its disguised and illusory reasoning. + +Thus the second mode employed by speculative reason of demonstrating +the existence of a Supreme Being, is not only, like the first, +illusory and inadequate, but possesses the additional blemish of an +ignoratio elenchi--professing to conduct us by a new road to the +desired goal, but bringing us back, after a short circuit, to the +old path which we had deserted at its call. + +I mentioned above that this cosmological argument contains a perfect +nest of dialectical assumptions, which transcendental criticism does +not find it difficult to expose and to dissipate. I shall merely +enumerate these, leaving it to the reader, who must by this time be +well practised in such matters, to investigate the fallacies +residing therein. + +The following fallacies, for example, are discoverable in this +mode of proof: 1. The transcendental principle: "Everything that is +contingent must have a cause"--a principle without significance, +except in the sensuous world. For the purely intellectual conception +of the contingent cannot produce any synthetical proposition, like +that of causality, which is itself without significance or +distinguishing characteristic except in the phenomenal world. But in +the present case it is employed to help us beyond the limits of its +sphere. 2. "From the impossibility of an infinite ascending series +of causes in the world of sense a first cause is inferred"; a +conclusion which the principles of the employment of reason do not +justify even in the sphere of experience, and still less when an +attempt is made to pass the limits of this sphere. 3. Reason allows +itself to be satisfied upon insufficient grounds, with regard to the +completion of this series. It removes all conditions (without which, +however, no conception of Necessity can take place); and, as after +this it is beyond our power to form any other conceptions, it +accepts this as a completion of the conception it wishes to form of +the series. 4. The logical possibility of a conception of the total +of reality (the criterion of this possibility being the absence of +contradiction) is confounded with the transcendental, which requires +a principle of the practicability of such a synthesis--a principle +which again refers us to the world of experience. And so on. + +The aim of the cosmological argument is to avoid the necessity of +proving the existence of a necessary being priori from mere +conceptions--a proof which must be ontological, and of which we feel +ourselves quite incapable. With this purpose, we reason from an actual +existence--an experience in general, to an absolutely necessary +condition of that existence. It is in this case unnecessary to +demonstrate its possibility. For after having proved that it exists, +the question regarding its possibility is superfluous. Now, when we +wish to define more strictly the nature of this necessary being, we +do not look out for some being the conception of which would enable +us to comprehend the necessity of its being--for if we could do this, +an empirical presupposition would be unnecessary; no, we try to +discover merely the negative condition (conditio sine qua non), +without which a being would not be absolutely necessary. Now this +would be perfectly admissible in every sort of reasoning, from a +consequence to its principle; but in the present case it unfortunately +happens that the condition of absolute necessity can be discovered +in but a single being, the conception of which must consequently +contain all that is requisite for demonstrating the presence of +absolute necessity, and thus entitle me to infer this absolute +necessity a priori. That is, it must be possible to reason conversely, +and say: The thing, to which the conception of the highest reality +belongs, is absolutely necessary. But if I cannot reason thus--and +I cannot, unless I believe in the sufficiency of the ontological +argument--I find insurmountable obstacles in my new path, and am +really no farther than the point from which I set out. The +conception of a Supreme Being satisfies all questions a priori +regarding the internal determinations of a thing, and is for this +reason an ideal without equal or parallel, the general conception of +it indicating it as at the same time an ens individuum among all +possible things. But the conception does not satisfy the question +regarding its existence--which was the purpose of all our inquiries; +and, although the existence of a necessary being were admitted, we +should find it impossible to answer the question: What of all things +in the world must be regarded as such? + +It is certainly allowable to admit the existence of an +all-sufficient being--a cause of all possible effects--for the purpose +of enabling reason to introduce unity into its mode and grounds of +explanation with regard to phenomena. But to assert that such a +being necessarily exists, is no longer the modest enunciation of an +admissible hypothesis, but the boldest declaration of an apodeictic +certainty; for the cognition of that which is absolutely necessary +must itself possess that character. + +The aim of the transcendental ideal formed by the mind is either +to discover a conception which shall harmonize with the idea of +absolute necessity, or a conception which shall contain that idea. +If the one is possible, so is the other; for reason recognizes that +alone as absolutely necessary which is necessary from its +conception. But both attempts are equally beyond our power--we find +it impossible to satisfy the understanding upon this point, and as +impossible to induce it to remain at rest in relation to this +incapacity. + +Unconditioned necessity, which, as the ultimate support and stay +of all existing things, is an indispensable requirement of the mind, +is an abyss on the verge of which human reason trembles in dismay. +Even the idea of eternity, terrible and sublime as it is, as +depicted by Haller, does not produce upon the mental vision such a +feeling of awe and terror; for, although it measures the duration of +things, it does not support them. We cannot bear, nor can we rid +ourselves of the thought that a being, which we regard as the greatest +of all possible existences, should say to himself: I am from +eternity to eternity; beside me there is nothing, except that which +exists by my will; whence then am I? Here all sinks away from under +us; and the greatest, as the smallest, perfection, hovers without stay +or footing in presence of the speculative reason, which finds it as +easy to part with the one as with the other. + +Many physical powers, which evidence their existence by their +effects, are perfectly inscrutable in their nature; they elude all +our powers of observation. The transcendental object which forms the +basis of phenomena, and, in connection with it, the reason why our +sensibility possesses this rather than that particular kind of +conditions, are and must ever remain hidden from our mental vision; +the fact is there, the reason of the fact we cannot see. But an +ideal of pure reason cannot be termed mysterious or inscrutable, +because the only credential of its reality is the need of it felt by +reason, for the purpose of giving completeness to the world of +synthetical unity. An ideal is not even given as a cogitable object, +and therefore cannot be inscrutable; on the contrary, it must, as a +mere idea, be based on the constitution of reason itself, and on +this account must be capable of explanation and solution. For the very +essence of reason consists in its ability to give an account, of all +our conceptions, opinions, and assertions--upon objective, or, when +they happen to be illusory and fallacious, upon subjective grounds. + + + +Detection and Explanation of the Dialectical Illusion in +all Transcendental Arguments for the Existence of a +Necessary Being. + +Both of the above arguments are transcendental; in other words, they +do not proceed upon empirical principles. For, although the +cosmological argument professed to lay a basis of experience for its +edifice of reasoning, it did not ground its procedure upon the +peculiar constitution of experience, but upon pure principles of +reason--in relation to an existence given by empirical +consciousness; utterly abandoning its guidance, however, for the +purpose of supporting its assertions entirely upon pure conceptions. +Now what is the cause, in these transcendental arguments, of the +dialectical, but natural, illusion, which connects the conceptions +of necessity and supreme reality, and hypostatizes that which cannot +be anything but an idea? What is the cause of this unavoidable step +on the part of reason, of admitting that some one among all existing +things must be necessary, while it falls back from the assertion of +the existence of such a being as from an abyss? And how does reason +proceed to explain this anomaly to itself, and from the wavering +condition of a timid and reluctant approbation--always again +withdrawn--arrive at a calm and settled insight into its cause? + +It is something very remarkable that, on the supposition that +something exists, I cannot avoid the inference that something exists +necessarily. Upon this perfectly natural--but not on that account +reliable--inference does the cosmological argument rest. But, let me +form any conception whatever of a thing, I find that I cannot cogitate +the existence of the thing as absolutely necessary, and that nothing +prevents me--be the thing or being what it may--from cogitating its +non-existence. I may thus be obliged to admit that all existing things +have a necessary basis, while I cannot cogitate any single or +individual thing as necessary. In other words, I can never complete +the regress through the conditions of existence, without admitting +the existence of a necessary being; but, on the other hand, I cannot +make a commencement from this being. + +If I must cogitate something as existing necessarily as the basis of +existing things, and yet am not permitted to cogitate any individual +thing as in itself necessary, the inevitable inference is that +necessity and contingency are not properties of things themselves- +otherwise an internal contradiction would result; that consequently +neither of these principles are objective, but merely subjective +principles of reason--the one requiring us to seek for a necessary +ground for everything that exists, that is, to be satisfied with no +other explanation than that which is complete a priori, the other +forbidding us ever to hope for the attainment of this completeness, +that is, to regard no member of the empirical world as +unconditioned. In this mode of viewing them, both principles, in their +purely heuristic and regulative character, and as concerning merely +the formal interest of reason, are quite consistent with each other. +The one says: "You must philosophize upon nature," as if there existed +a necessary primal basis of all existing things, solely for the +purpose of introducing systematic unity into your knowledge, by +pursuing an idea of this character--a foundation which is +arbitrarily admitted to be ultimate; while the other warns you to +consider no individual determination, concerning the existence of +things, as such an ultimate foundation, that is, as absolutely +necessary, but to keep the way always open for further progress in +the deduction, and to treat every determination as determined by some +other. But if all that we perceive must be regarded as conditionally +necessary, it is impossible that anything which is empirically given +should be absolutely necessary. + +It follows from this that you must accept the absolutely necessary +as out of and beyond the world, inasmuch as it is useful only as a +principle of the highest possible unity in experience, and you +cannot discover any such necessary existence in the would, the +second rule requiring you to regard all empirical causes of unity as +themselves deduced. + +The philosophers of antiquity regarded all the forms of nature as +contingent; while matter was considered by them, in accordance with +the judgement of the common reason of mankind, as primal and +necessary. But if they had regarded matter, not relatively--as the +substratum of phenomena, but absolutely and in itself--as an +independent existence, this idea of absolute necessity would have +immediately disappeared. For there is nothing absolutely connecting +reason with such an existence; on the contrary, it can annihilate it +in thought, always and without self-contradiction. But in thought +alone lay the idea of absolute necessity. A regulative principle must, +therefore, have been at the foundation of this opinion. In fact, +extension and impenetrability--which together constitute our +conception of matter--form the supreme empirical principle of the +unity of phenomena, and this principle, in so far as it is empirically +unconditioned, possesses the property of a regulative principle. +But, as every determination of matter which constitutes what is real +in it--and consequently impenetrability--is an effect, which must have +a cause, and is for this reason always derived, the notion of matter +cannot harmonize with the idea of a necessary being, in its +character of the principle of all derived unity. For every one of +its real properties, being derived, must be only conditionally +necessary, and can therefore be annihilated in thought; and thus the +whole existence of matter can be so annihilated or suppressed. If this +were not the case, we should have found in the world of phenomena +the highest ground or condition of unity--which is impossible, +according to the second regulative principle. It follows that +matter, and, in general, all that forms part of the world of sense, +cannot be a necessary primal being, nor even a principle of +empirical unity, but that this being or principle must have its +place assigned without the world. And, in this way, we can proceed +in perfect confidence to deduce the phenomena of the world and their +existence from other phenomena, just as if there existed no +necessary being; and we can at the same time, strive without ceasing +towards the attainment of completeness for our deduction, just as if +such a being--the supreme condition of all existences--were +presupposed by the mind. + +These remarks will have made it evident to the reader that the ideal +of the Supreme Being, far from being an enouncement of the existence +of a being in itself necessary, is nothing more than a regulative +principle of reason, requiring us to regard all connection existing +between phenomena as if it had its origin from an all-sufficient +necessary cause, and basing upon this the rule of a systematic and +necessary unity in the explanation of phenomena. We cannot, at the +same time, avoid regarding, by a transcendental subreptio, this formal +principle as constitutive, and hypostatizing this unity. Precisely +similar is the case with our notion of space. Space is the primal +condition of all forms, which are properly just so many different +limitations of it; and thus, although it is merely a principle of +sensibility, we cannot help regarding it as an absolutely necessary +and self-subsistent thing--as an object given a priori in itself. In +the same way, it is quite natural that, as the systematic unity of +nature cannot be established as a principle for the empirical +employment of reason, unless it is based upon the idea of an ens +realissimum, as the supreme cause, we should regard this idea as a +real object, and this object, in its character of supreme condition, +as absolutely necessary, and that in this way a regulative should be +transformed into a constitutive principle. This interchange becomes +evident when I regard this supreme being, which, relatively to the +world, was absolutely (unconditionally) necessary, as a thing per +se. In this case, I find it impossible to represent this necessity +in or by any conception, and it exists merely in my own mind, as the +formal condition of thought, but not as a material and hypostatic +condition of existence. + + + +SECTION VI. Of the Impossibility of a Physico-Theological Proof. + +If, then, neither a pure conception nor the general experience of an +existing being can provide a sufficient basis for the proof of the +existence of the Deity, we can make the attempt by the only other +mode--that of grounding our argument upon a determinate experience +of the phenomena of the present world, their constitution and +disposition, and discover whether we can thus attain to a sound +conviction of the existence of a Supreme Being. This argument we shall +term the physico-theological argument. If it is shown to be +insufficient, speculative reason cannot present us with any +satisfactory proof of the existence of a being corresponding to our +transcendental idea. + +It is evident from the remarks that have been made in the +preceding sections, that an answer to this question will be far from +being difficult or unconvincing. For how can any experience be +adequate with an idea? The very essence of an idea consists in the +fact that no experience can ever be discovered congruent or adequate +with it. The transcendental idea of a necessary and all-sufficient +being is so immeasurably great, so high above all that is empirical, +which is always conditioned, that we hope in vain to find materials +in the sphere of experience sufficiently ample for our conception, +and in vain seek the unconditioned among things that are conditioned, +while examples, nay, even guidance is denied us by the laws of empirical +synthesis. + +If the Supreme Being forms a link in the chain of empirical +conditions, it must be a member of the empirical series, and, like +the lower members which it precedes, have its origin in some higher +member of the series. If, on the other hand, we disengage it from the +chain, and cogitate it as an intelligible being, apart from the series +of natural causes--how shall reason bridge the abyss that separates +the latter from the former? All laws respecting the regress from +effects to causes, all synthetical additions to our knowledge relate +solely to possible experience and the objects of the sensuous world, +and, apart from them, are without significance. + +The world around us opens before our view so magnificent a spectacle +of order, variety, beauty, and conformity to ends, that whether we +pursue our observations into the infinity of space in the one +direction, or into its illimitable divisions in the other, whether +we regard the world in its greatest or its least manifestations- +even after we have attained to the highest summit of knowledge which +our weak minds can reach, we find that language in the presence of +wonders so inconceivable has lost its force, and number its power to +reckon, nay, even thought fails to conceive adequately, and our +conception of the whole dissolves into an astonishment without power +of expression--all the more eloquent that it is dumb. Everywhere +around us we observe a chain of causes and effects, of means and ends, +of death and birth; and, as nothing has entered of itself into the +condition in which we find it, we are constantly referred to some +other thing, which itself suggests the same inquiry regarding its +cause, and thus the universe must sink into the abyss of +nothingness, unless we admit that, besides this infinite chain of +contingencies, there exists something that is primal and +self-subsistent--something which, as the cause of this phenomenal +world, secures its continuance and preservation. + +This highest cause--what magnitude shall we attribute to it? Of +the content of the world we are ignorant; still less can we estimate +its magnitude by comparison with the sphere of the possible. But +this supreme cause being a necessity of the human mind, what is +there to prevent us from attributing to it such a degree of perfection +as to place it above the sphere of all that is possible? This we can +easily do, although only by the aid of the faint outline of an +abstract conception, by representing this being to ourselves as +containing in itself, as an individual substance, all possible +perfection--a conception which satisfies that requirement of reason +which demands parsimony in principles, which is free from +self-contradiction, which even contributes to the extension of the +employment of reason in experience, by means of the guidance +afforded by this idea to order and system, and which in no respect +conflicts with any law of experience. + +This argument always deserves to be mentioned with respect. It is +the oldest, the clearest, and that most in conformity with the +common reason of humanity. It animates the study of nature, as it +itself derives its existence and draws ever new strength from that +source. It introduces aims and ends into a sphere in which our +observation could not of itself have discovered them, and extends +our knowledge of nature, by directing our attention to a unity, the +principle of which lies beyond nature. This knowledge of nature +again reacts upon this idea--its cause; and thus our belief in a +divine author of the universe rises to the power of an irresistible +conviction. + +For these reasons it would be utterly hopeless to attempt to rob +this argument of the authority it has always enjoyed. The mind, +unceasingly elevated by these considerations, which, although +empirical, are so remarkably powerful, and continually adding to their +force, will not suffer itself to be depressed by the doubts +suggested by subtle speculation; it tears itself out of this state +of uncertainty, the moment it casts a look upon the wondrous forms +of nature and the majesty of the universe, and rises from height to +height, from condition to condition, till it has elevated itself to +the supreme and unconditioned author of all. + +But although we have nothing to object to the reasonableness and +utility of this procedure, but have rather to commend and encourage +it, we cannot approve of the claims which this argument advances to +demonstrative certainty and to a reception upon its own merits, +apart from favour or support by other arguments. Nor can it injure +the cause of morality to endeavour to lower the tone of the arrogant +sophist, and to teach him that modesty and moderation which are the +properties of a belief that brings calm and content into the mind, +without prescribing to it an unworthy subjection. I maintain, then, +that the physico-theological argument is insufficient of itself to +prove the existence of a Supreme Being, that it must entrust this to +the ontological argument--to which it serves merely as an +introduction, and that, consequently, this argument contains the +only possible ground of proof (possessed by speculative reason) for +the existence of this being. + +The chief momenta in the physico-theological argument are as follow: +1. We observe in the world manifest signs of an arrangement full of +purpose, executed with great wisdom, and argument in whole of a +content indescribably various, and of an extent without limits. 2. +This arrangement of means and ends is entirely foreign to the things +existing in the world--it belongs to them merely as a contingent +attribute; in other words, the nature of different things could not +of itself, whatever means were employed, harmoniously tend towards +certain purposes, were they not chosen and directed for these purposes +by a rational and disposing principle, in accordance with certain +fundamental ideas. 3. There exists, therefore, a sublime and wise +cause (or several), which is not merely a blind, all-powerful +nature, producing the beings and events which fill the world in +unconscious fecundity, but a free and intelligent cause of the +world. 4. The unity of this cause may be inferred from the unity of +the reciprocal relation existing between the parts of the world, as +portions of an artistic edifice--an inference which all our +observation favours, and all principles of analogy support. + +In the above argument, it is inferred from the analogy of certain +products of nature with those of human art, when it compels Nature +to bend herself to its purposes, as in the case of a house, a ship, +or a watch, that the same kind of causality--namely, understanding +and will--resides in nature. It is also declared that the internal +possibility of this freely-acting nature (which is the source of all +art, and perhaps also of human reason) is derivable from another and +superhuman art--a conclusion which would perhaps be found incapable +of standing the test of subtle transcendental criticism. But to neither +of these opinions shall we at present object. We shall only remark +that it must be confessed that, if we are to discuss the subject of +cause at all, we cannot proceed more securely than with the guidance +of the analogy subsisting between nature and such products of +design--these being the only products whose causes and modes of +organization are completely known to us. Reason would be unable to +satisfy her own requirements, if she passed from a causality which +she does know, to obscure and indemonstrable principles of explanation +which she does not know. + +According to the physico-theological argument, the connection and +harmony existing in the world evidence the contingency of the form +merely, but not of the matter, that is, of the substance of the world. +To establish the truth of the latter opinion, it would be necessary +to prove that all things would be in themselves incapable of this harmony +and order, unless they were, even as regards their substance, the +product of a supreme wisdom. But this would require very different +grounds of proof from those presented by the analogy with human art. +This proof can at most, therefore, demonstrate the existence of an +architect of the world, whose efforts are limited by the +capabilities of the material with which he works, but not of a creator +of the world, to whom all things are subject. Thus this argument is +utterly insufficient for the task before us--a demonstration of the +existence of an all-sufficient being. If we wish to prove the +contingency of matter, we must have recourse to a transcendental +argument, which the physico-theological was constructed expressly to +avoid. + +We infer, from the order and design visible in the universe, as a +disposition of a thoroughly contingent character, the existence of +a cause proportionate thereto. The conception of this cause must contain +certain determinate qualities, and it must therefore be regarded as +the conception of a being which possesses all power, wisdom, and so +on, in one word, all perfection--the conception, that is, of an +all-sufficient being. For the predicates of very great, astonishing, +or immeasurable power and excellence, give us no determinate +conception of the thing, nor do they inform us what the thing may be +in itself. They merely indicate the relation existing between the +magnitude of the object and the observer, who compares it with himself +and with his own power of comprehension, and are mere expressions of +praise and reverence, by which the object is either magnified, or +the observing subject depreciated in relation to the object. Where +we have to do with the magnitude (of the perfection) of a thing, we +can discover no determinate conception, except that which +comprehends all possible perfection or completeness, and it is only +the total (omnitudo) of reality which is completely determined in +and through its conception alone. + +Now it cannot be expected that any one will be bold enough to +declare that he has a perfect insight into the relation which the +magnitude of the world he contemplates bears (in its extent as well +as in its content) to omnipotence, into that of the order and design +in the world to the highest wisdom, and that of the unity of the world +to the absolute unity of a Supreme Being. Physico-theology is therefore +incapable of presenting a determinate conception of a supreme cause +of the world, and is therefore insufficient as a principle of theology--a +theology which is itself to be the basis of religion. + +The attainment of absolute totality is completely impossible on +the path of empiricism. And yet this is the path pursued in the +physico-theological argument. What means shall we employ to bridge +the abyss? + +After elevating ourselves to admiration of the magnitude of the +power, wisdom, and other attributes of the author of the world, and +finding we can advance no further, we leave the argument on +empirical grounds, and proceed to infer the contingency of the world +from the order and conformity to aims that are observable in it. +From this contingency we infer, by the help of transcendental +conceptions alone, the existence of something absolutely necessary; +and, still advancing, proceed from the conception of the absolute +necessity of the first cause to the completely determined or +determining conception thereof--the conception of an all-embracing +reality. Thus the physico-theological, failing in its undertaking, +recurs in its embarrassment to the cosmological argument; and, as this +is merely the ontological argument in disguise, it executes its design +solely by the aid of pure reason, although it at first professed to +have no connection with this faculty and to base its entire +procedure upon experience alone. + +The physico-theologians have therefore no reason to regard with such +contempt the transcendental mode of argument, and to look down upon +it, with the conceit of clear-sighted observers of nature, as the +brain-cobweb of obscure speculatists. For, if they reflect upon and +examine their own arguments, they will find that, after following +for some time the path of nature and experience, and discovering +themselves no nearer their object, they suddenly leave this path and +pass into the region of pure possibility, where they hope to reach +upon the wings of ideas what had eluded all their empirical +investigations. Gaining, as they think, a firm footing after this +immense leap, they extend their determinate conception--into the +possession of which they have come, they know not how--over the +whole sphere of creation, and explain their ideal, which is entirely +a product of pure reason, by illustrations drawn from experience--though +in a degree miserably unworthy of the grandeur of the object, while +they refuse to acknowledge that they have arrived at this cognition +or hypothesis by a very different road from that of experience. + +Thus the physico-theological is based upon the cosmological, and +this upon the ontological proof of the existence of a Supreme Being; +and as besides these three there is no other path open to +speculative reason, the ontological proof, on the ground of pure +conceptions of reason, is the only possible one, if any proof of a +proposition so far transcending the empirical exercise of the +understanding is possible at all. + + + +SECTION VII. Critique of all Theology based upon Speculative + Principles of Reason. + +If by the term theology I understand the cognition of a primal +being, that cognition is based either upon reason alone (theologia +rationalis) or upon revelation (theologia revelata). The former +cogitates its object either by means of pure transcendental +conceptions, as an ens originarium, realissimum, ens entium, and is +termed transcendental theology; or, by means of a conception derived +from the nature of our own mind, as a supreme intelligence, and must +then be entitled natural theology. The person who believes in a +transcendental theology alone, is termed a deist; he who +acknowledges the possibility of a natural theology also, a theist. +The former admits that we can cognize by pure reason alone the existence +of a Supreme Being, but at the same time maintains that our conception +of this being is purely transcendental, and that all we can say of +it is that it possesses all reality, without being able to define it +more closely. The second asserts that reason is capable of +presenting us, from the analogy with nature, with a more definite +conception of this being, and that its operations, as the cause of +all things, are the results of intelligence and free will. The former +regards the Supreme Being as the cause of the world--whether by the +necessity of his nature, or as a free agent, is left undetermined; +the latter considers this being as the author of the world. + +Transcendental theology aims either at inferring the existence of +a Supreme Being from a general experience, without any closer +reference to the world to which this experience belongs, and in this +case it is called cosmotheology; or it endeavours to cognize the +existence of such a being, through mere conceptions, without the aid +of experience, and is then termed ontotheology. + +Natural theology infers the attributes and the existence of an +author of the world, from the constitution of, the order and unity +observable in, the world, in which two modes of causality must be +admitted to exist--those of nature and freedom. Thus it rises from +this world to a supreme intelligence, either as the principle of all +natural, or of all moral order and perfection. In the former case it +is termed physico-theology, in the latter, ethical or moral-theology.* + +[*Footnote: Not theological ethics; for this science contains ethical +laws, which presuppose the existence of a Supreme Governor of the world; +while moral-theology, on the contrary, is the expression of a +conviction of the existence of a Supreme Being, founded upon ethical +laws.] + +As we are wont to understand by the term God not merely an eternal +nature, the operations of which are insensate and blind, but a Supreme +Being, who is the free and intelligent author of all things, and as +it is this latter view alone that can be of interest to humanity, we +might, in strict rigour, deny to the deist any belief in God at all, +and regard him merely as a maintainer of the existence of a primal +being or thing--the supreme cause of all other things. But, as no +one ought to be blamed, merely because he does not feel himself +justified in maintaining a certain opinion, as if he altogether denied +its truth and asserted the opposite, it is more correct--as it is less +harsh--to say, the deist believes in a God, the theist in a living +God (summa intelligentia). We shall now proceed to investigate the +sources of all these attempts of reason to establish the existence +of a Supreme Being. + +It may be sufficient in this place to define theoretical knowledge +or cognition as knowledge of that which is, and practical knowledge +as knowledge of that which ought to be. In this view, the theoretical +employment of reason is that by which I cognize a priori (as +necessary) that something is, while the practical is that by which +I cognize a priori what ought to happen. Now, if it is an indubitably +certain, though at the same time an entirely conditioned truth, that +something is, or ought to happen, either a certain determinate +condition of this truth is absolutely necessary, or such a condition +may be arbitrarily presupposed. In the former case the condition is +postulated (per thesin), in the latter supposed (per hypothesin). +There are certain practical laws--those of morality--which are +absolutely necessary. Now, if these laws necessarily presuppose the +existence of some being, as the condition of the possibility of +their obligatory power, this being must be postulated, because the +conditioned, from which we reason to this determinate condition, is +itself cognized a priori as absolutely necessary. We shall at some +future time show that the moral laws not merely presuppose the +existence of a Supreme Being, but also, as themselves absolutely +necessary in a different relation, demand or postulate it--although +only from a practical point of view. The discussion of this argument +we postpone for the present. + +When the question relates merely to that which is, not to that which +ought to be, the conditioned which is presented in experience is +always cogitated as contingent. For this reason its condition cannot +be regarded as absolutely necessary, but merely as relatively +necessary, or rather as needful; the condition is in itself and a +priori a mere arbitrary presupposition in aid of the cognition, by +reason, of the conditioned. If, then, we are to possess a +theoretical cognition of the absolute necessity of a thing, we +cannot attain to this cognition otherwise than a priori by means of +conceptions; while it is impossible in this way to cognize the +existence of a cause which bears any relation to an existence given +in experience. + +Theoretical cognition is speculative when it relates to an object or +certain conceptions of an object which is not given and cannot be +discovered by means of experience. It is opposed to the cognition of +nature, which concerns only those objects or predicates which can be +presented in a possible experience. + +The principle that everything which happens (the empirically +contingent) must have a cause, is a principle of the cognition of +nature, but not of speculative cognition. For, if we change it into +an abstract principle, and deprive it of its reference to experience +and the empirical, we shall find that it cannot with justice be +regarded any longer as a synthetical proposition, and that it is +impossible to discover any mode of transition from that which exists +to something entirely different--termed cause. Nay, more, the +conception of a cause likewise that of the contingent--loses, in +this speculative mode of employing it, all significance, for its +objective reality and meaning are comprehensible from experience +alone. + +When from the existence of the universe and the things in it the +existence of a cause of the universe is inferred, reason is proceeding +not in the natural, but in the speculative method. For the principle +of the former enounces, not that things themselves or substances, +but only that which happens or their states--as empirically +contingent, have a cause: the assertion that the existence of +substance itself is contingent is not justified by experience, it is +the assertion of a reason employing its principles in a speculative +manner. If, again, I infer from the form of the universe, from the +way in which all things are connected and act and react upon each other, +the existence of a cause entirely distinct from the universe--this +would again be a judgement of purely speculative reason; because the +object in this case--the cause--can never be an object of possible +experience. In both these cases the principle of causality, which is +valid only in the field of experience--useless and even meaningless +beyond this region, would be diverted from its proper destination. + +Now I maintain that all attempts of reason to establish a theology +by the aid of speculation alone are fruitless, that the principles +of reason as applied to nature do not conduct us to any theological +truths, and, consequently, that a rational theology can have no +existence, unless it is founded upon the laws of morality. For all +synthetical principles of the understanding are valid only as immanent +in experience; while the cognition of a Supreme Being necessitates +their being employed transcendentally, and of this the understanding +is quite incapable. If the empirical law of causality is to conduct +us to a Supreme Being, this being must belong to the chain of empirical +objects--in which case it would be, like all phenomena, itself +conditioned. If the possibility of passing the limits of experience +be admitted, by means of the dynamical law of the relation of an effect +to its cause, what kind of conception shall we obtain by this +procedure? Certainly not the conception of a Supreme Being, because +experience never presents us with the greatest of all possible +effects, and it is only an effect of this character that could witness +to the existence of a corresponding cause. If, for the purpose of +fully satisfying the requirements of Reason, we recognize her right +to assert the existence of a perfect and absolutely necessary being, +this can be admitted only from favour, and cannot be regarded as the +result or irresistible demonstration. The physico-theological proof +may add weight to others--if other proofs there are--by connecting +speculation with experience; but in itself it rather prepares the mind +for theological cognition, and gives it a right and natural direction, +than establishes a sure foundation for theology. + +It is now perfectly evident that transcendental questions admit only +of transcendental answers--those presented a priori by pure +conceptions without the least empirical admixture. But the question +in the present case is evidently synthetical--it aims at the extension +of our cognition beyond the bounds of experience--it requires an +assurance respecting the existence of a being corresponding with the +idea in our minds, to which no experience can ever be adequate. Now +it has been abundantly proved that all a priori synthetical cognition +is possible only as the expression of the formal conditions of a +possible experience; and that the validity of all principles depends +upon their immanence in the field of experience, that is, their +relation to objects of empirical cognition or phenomena. Thus all +transcendental procedure in reference to speculative theology is +without result. + +If any one prefers doubting the conclusiveness of the proofs of +our analytic to losing the persuasion of the validity of these old +and time honoured arguments, he at least cannot decline answering the +question--how he can pass the limits of all possible experience by +the help of mere ideas. If he talks of new arguments, or of improvements +upon old arguments, I request him to spare me. There is certainly no +great choice in this sphere of discussion, as all speculative +arguments must at last look for support to the ontological, and I +have, therefore, very little to fear from the argumentative +fecundity of the dogmatical defenders of a non-sensuous reason. +Without looking upon myself as a remarkably combative person, I +shall not decline the challenge to detect the fallacy and destroy +the pretensions of every attempt of speculative theology. And yet +the hope of better fortune never deserts those who are accustomed to +the dogmatical mode of procedure. I shall, therefore, restrict +myself to the simple and equitable demand that such reasoners will +demonstrate, from the nature of the human mind as well as from that +of the other sources of knowledge, how we are to proceed to extend +our cognition completely a priori, and to carry it to that point where +experience abandons us, and no means exist of guaranteeing the +objective reality of our conceptions. In whatever way the +understanding may have attained to a conception, the existence of +the object of the conception cannot be discovered in it by analysis, +because the cognition of the existence of the object depends upon +the object's being posited and given in itself apart from the +conception. But it is utterly impossible to go beyond our +conception, without the aid of experience--which presents to the +mind nothing but phenomena, or to attain by the help of mere +conceptions to a conviction of the existence of new kinds of objects +or supernatural beings. + +But although pure speculative reason is far from sufficient to +demonstrate the existence of a Supreme Being, it is of the highest +utility in correcting our conception of this being--on the supposition +that we can attain to the cognition of it by some other means--in +making it consistent with itself and with all other conceptions of +intelligible objects, clearing it from all that is incompatible with +the conception of an ens summun, and eliminating from it all +limitations or admixtures of empirical elements. + +Transcendental theology is still therefore, notwithstanding its +objective insufficiency, of importance in a negative respect; it is +useful as a test of the procedure of reason when engaged with pure +ideas, no other than a transcendental standard being in this case +admissible. For if, from a practical point of view, the hypothesis +of a Supreme and All-sufficient Being is to maintain its validity +without opposition, it must be of the highest importance to define +this conception in a correct and rigorous manner--as the +transcendental conception of a necessary being, to eliminate all +phenomenal elements (anthropomorphism in its most extended +signification), and at the same time to overflow all contradictory +assertions--be they atheistic, deistic, or anthropomorphic. This is +of course very easy; as the same arguments which demonstrated the +inability of human reason to affirm the existence of a Supreme Being +must be alike sufficient to prove the invalidity of its denial. For +it is impossible to gain from the pure speculation of reason +demonstration that there exists no Supreme Being, as the ground of +all that exists, or that this being possesses none of those properties +which we regard as analogical with the dynamical qualities of a +thinking being, or that, as the anthropomorphists would have us +believe, it is subject to all the limitations which sensibility +imposes upon those intelligences which exist in the world of +experience. + +A Supreme Being is, therefore, for the speculative reason, a mere +ideal, though a faultless one--a conception which perfects and +crowns the system of human cognition, but the objective reality of +which can neither be proved nor disproved by pure reason. If this +defect is ever supplied by a moral theology, the problematic +transcendental theology which has preceded, will have been at least +serviceable as demonstrating the mental necessity existing for the +conception, by the complete determination of it which it has +furnished, and the ceaseless testing of the conclusions of a reason +often deceived by sense, and not always in harmony with its own ideas. +The attributes of necessity, infinitude, unity, existence apart from +the world (and not as a world soul), eternity (free from conditions +of time), omnipresence (free from conditions of space), omnipotence, +and others, are pure transcendental predicates; and thus the +accurate conception of a Supreme Being, which every theology requires, +is furnished by transcendental theology alone. + + + +APPENDIX. + +Of the Regulative Employment of the Ideas of Pure Reason. + +The result of all the dialectical attempts of pure reason not only +confirms the truth of what we have already proved in our +Transcendental Analytic, namely, that all inferences which would +lead us beyond the limits of experience are fallacious and groundless, +but it at the same time teaches us this important lesson, that human +reason has a natural inclination to overstep these limits, and that +transcendental ideas are as much the natural property of the reason +as categories are of the understanding. There exists this difference, +however, that while the categories never mislead us, outward objects +being always in perfect harmony therewith, ideas are the parents of +irresistible illusions, the severest and most subtle criticism being +required to save us from the fallacies which they induce. + +Whatever is grounded in the nature of our powers will be found to be +in harmony with the final purpose and proper employment of these +powers, when once we have discovered their true direction and aim. +We are entitled to suppose, therefore, that there exists a mode of +employing transcendental ideas which is proper and immanent; although, +when we mistake their meaning, and regard them as conceptions of +actual things, their mode of application is transcendent and delusive. +For it is not the idea itself, but only the employment of the idea +in relation to possible experience, that is transcendent or +immanent. An idea is employed transcendently, when it is applied to +an object falsely believed to be adequate with and to correspond to +it; imminently, when it is applied solely to the employment of the +understanding in the sphere of experience. Thus all errors of +subreptio--of misapplication, are to be ascribed to defects of +judgement, and not to understanding or reason. + +Reason never has an immediate relation to an object; it relates +immediately to the understanding alone. It is only through the +understanding that it can be employed in the field of experience. It +does not form conceptions of objects, it merely arranges them and +gives to them that unity which they are capable of possessing when +the sphere of their application has been extended as widely as possible. +Reason avails itself of the conception of the understanding for the +sole purpose of producing totality in the different series. This +totality the understanding does not concern itself with; its only +occupation is the connection of experiences, by which series of +conditions in accordance with conceptions are established. The +object of reason is, therefore, the understanding and its proper +destination. As the latter brings unity into the diversity of +objects by means of its conceptions, so the former brings unity into +the diversity of conceptions by means of ideas; as it sets the final +aim of a collective unity to the operations of the understanding, +which without this occupies itself with a distributive unity alone. + +I accordingly maintain that transcendental ideas can never be +employed as constitutive ideas, that they cannot be conceptions of +objects, and that, when thus considered, they assume a fallacious +and dialectical character. But, on the other hand, they are capable +of an admirable and indispensably necessary application to objects--as +regulative ideas, directing the understanding to a certain aim, the +guiding lines towards which all its laws follow, and in which they +all meet in one point. This point--though a mere idea (focus imaginarius), +that is, not a point from which the conceptions of the understanding +do really proceed, for it lies beyond the sphere of possible +experience--serves, notwithstanding, to give to these conceptions +the greatest possible unity combined with the greatest possible +extension. Hence arises the natural illusion which induces us to +believe that these lines proceed from an object which lies out of +the sphere of empirical cognition, just as objects reflected in a +mirror appear to be behind it. But this illusion--which we may +hinder from imposing upon us--is necessary and unavoidable, if we +desire to see, not only those objects which lie before us, but those +which are at a great distance behind us; that is to say, when, in +the present case, we direct the aims of the understanding, beyond +every given experience, towards an extension as great as can +possibly be attained. + +If we review our cognitions in their entire extent, we shall find +that the peculiar business of reason is to arrange them into a system, +that is to say, to give them connection according to a principle. This +unity presupposes an idea--the idea of the form of a whole (of +cognition), preceding the determinate cognition of the parts, and +containing the conditions which determine a priori to every part its +place and relation to the other parts of the whole system. This +idea, accordingly, demands complete unity in the cognition of the +understanding--not the unity of a contingent aggregate, but that of +a system connected according to necessary laws. It cannot be +affirmed with propriety that this idea is a conception of an object; +it is merely a conception of the complete unity of the conceptions +of objects, in so far as this unity is available to the +understanding as a rule. Such conceptions of reason are not derived +from nature; on the contrary, we employ them for the interrogation +and investigation of nature, and regard our cognition as defective +so long as it is not adequate to them. We admit that such a thing as +pure earth, pure water, or pure air, is not to be discovered. And yet +we require these conceptions (which have their origin in the reason, +so far as regards their absolute purity and completeness) for the purpose +of determining the share which each of these natural causes has in +every phenomenon. Thus the different kinds of matter are all referred +to earths, as mere weight; to salts and inflammable bodies, as pure +force; and finally, to water and air, as the vehicula of the former, +or the machines employed by them in their operations--for the +purpose of explaining the chemical action and reaction of bodies in +accordance with the idea of a mechanism. For, although not actually +so expressed, the influence of such ideas of reason is very observable +in the procedure of natural philosophers. + +If reason is the faculty of deducing the particular from the +general, and if the general be certain in se and given, it is only +necessary that the judgement should subsume the particular under the +general, the particular being thus necessarily determined. I shall +term this the demonstrative or apodeictic employment of reason. If, +however, the general is admitted as problematical only, and is a +mere idea, the particular case is certain, but the universality of +the rule which applies to this particular case remains a problem. +Several particular cases, the certainty of which is beyond doubt, +are then taken and examined, for the purpose of discovering whether +the rule is applicable to them; and if it appears that all the +particular cases which can be collected follow from the rule, its +universality is inferred, and at the same time, all the causes which +have not, or cannot be presented to our observation, are concluded +to be of the same character with those which we have observed. This +I shall term the hypothetical employment of the reason. + +The hypothetical exercise of reason by the aid of ideas employed +as problematical conceptions is properly not constitutive. That is +to say, if we consider the subject strictly, the truth of the rule, +which has been employed as an hypothesis, does not follow from the +use that is made of it by reason. For how can we know all the possible +cases that may arise? some of which may, however, prove exceptions +to the universality of the rule. This employment of reason is merely +regulative, and its sole aim is the introduction of unity into the +aggregate of our particular cognitions, and thereby the +approximating of the rule to universality. + +The object of the hypothetical employment of reason is therefore the +systematic unity of cognitions; and this unity is the criterion of +the truth of a rule. On the other hand, this systematic unity--as a +mere idea--is in fact merely a unity projected, not to be regarded +as given, but only in the light of a problem--a problem which serves, +however, as a principle for the various and particular exercise of +the understanding in experience, directs it with regard to those cases +which are not presented to our observation, and introduces harmony +and consistency into all its operations. + +All that we can be certain of from the above considerations is +that this systematic unity is a logical principle, whose aim is to +assist the understanding, where it cannot of itself attain to rules, +by means of ideas, to bring all these various rules under one +principle, and thus to ensure the most complete consistency and +connection that can be attained. But the assertion that objects and +the understanding by which they are cognized are so constituted as +to be determined to systematic unity, that this may be postulated a +priori, without any reference to the interest of reason, and that we +are justified in declaring all possible cognitions--empirical and +others--to possess systematic unity, and to be subject to general +principles from which, notwithstanding their various character, they +are all derivable such an assertion can be founded only upon a +transcendental principle of reason, which would render this systematic +unity not subjectively and logically--in its character of a method, +but objectively necessary. + +We shall illustrate this by an example. The conceptions of the +understanding make us acquainted, among many other kinds of unity, +with that of the causality of a substance, which is termed power. +The different phenomenal manifestations of the same substance appear +at first view to be so very dissimilar that we are inclined to +assume the existence of just as many different powers as there are +different effects--as, in the case of the human mind, we have feeling, +consciousness, imagination, memory, wit, analysis, pleasure, desire +and so on. Now we are required by a logical maxim to reduce these +differences to as small a number as possible, by comparing them and +discovering the hidden identity which exists. We must inquire, for +example, whether or not imagination (connected with consciousness), +memory, wit, and analysis are not merely different forms of +understanding and reason. The idea of a fundamental power, the +existence of which no effort of logic can assure us of, is the problem +to be solved, for the systematic representation of the existing +variety of powers. The logical principle of reason requires us to +produce as great a unity as is possible in the system of our +cognitions; and the more the phenomena of this and the other power +are found to be identical, the more probable does it become, that they +are nothing but different manifestations of one and the same power, +which may be called, relatively speaking, a fundamental power. And +so with other cases. + +These relatively fundamental powers must again be compared with each +other, to discover, if possible, the one radical and absolutely +fundamental power of which they are but the manifestations. But this +unity is purely hypothetical. It is not maintained, that this unity +does really exist, but that we must, in the interest of reason, that +is, for the establishment of principles for the various rules +presented by experience, try to discover and introduce it, so far as +is practicable, into the sphere of our cognitions. + +But the transcendental employment of the understanding would lead us +to believe that this idea of a fundamental power is not problematical, +but that it possesses objective reality, and thus the systematic unity +of the various powers or forces in a substance is demanded by the +understanding and erected into an apodeictic or necessary principle. +For, without having attempted to discover the unity of the various +powers existing in nature, nay, even after all our attempts have +failed, we notwithstanding presuppose that it does exist, and may +be, sooner or later, discovered. And this reason does, not only, as +in the case above adduced, with regard to the unity of substance, but +where many substances, although all to a certain extent homogeneous, +are discoverable, as in the case of matter in general. Here also +does reason presuppose the existence of the systematic unity of +various powers--inasmuch as particular laws of nature are +subordinate to general laws; and parsimony in principles is not merely +an economical principle of reason, but an essential law of nature. + +We cannot understand, in fact, how a logical principle of unity +can of right exist, unless we presuppose a transcendental principle, +by which such a systematic unit--as a property of objects +themselves--is regarded as necessary a priori. For with what right +can reason, in its logical exercise, require us to regard the variety +of forces which nature displays, as in effect a disguised unity, and +to deduce them from one fundamental force or power, when she is free +to admit that it is just as possible that all forces should be +different in kind, and that a systematic unity is not conformable to +the design of nature? In this view of the case, reason would be +proceeding in direct opposition to her own destination, by setting +as an aim an idea which entirely conflicts with the procedure and +arrangement of nature. Neither can we assert that reason has +previously inferred this unity from the contingent nature of +phenomena. For the law of reason which requires us to seek for this +unity is a necessary law, inasmuch as without it we should not possess +a faculty of reason, nor without reason a consistent and +self-accordant mode of employing the understanding, nor, in the +absence of this, any proper and sufficient criterion of empirical +truth. In relation to this criterion, therefore, we must suppose the +idea of the systematic unity of nature to possess objective validity +and necessity. + +We find this transcendental presupposition lurking in different +forms in the principles of philosophers, although they have neither +recognized it nor confessed to themselves its presence. That the +diversities of individual things do not exclude identity of species, +that the various species must be considered as merely different +determinations of a few genera, and these again as divisions of +still higher races, and so on--that, accordingly, a certain systematic +unity of all possible empirical conceptions, in so far as they can +be deduced from higher and more general conceptions, must be sought +for, is a scholastic maxim or logical principle, without which +reason could not be employed by us. For we can infer the particular +from the general, only in so far as general properties of things +constitute the foundation upon which the particular rest. + +That the same unity exists in nature is presupposed by +philosophers in the well-known scholastic maxim, which forbids us +unnecessarily to augment the number of entities or principles (entia +praeter necessitatem non esse multiplicanda). This maxim asserts +that nature herself assists in the establishment of this unity of +reason, and that the seemingly infinite diversity of phenomena +should not deter us from the expectation of discovering beneath this +diversity a unity of fundamental properties, of which the aforesaid +variety is but a more or less determined form. This unity, although +a mere idea, thinkers have found it necessary rather to moderate the +desire than to encourage it. It was considered a great step when +chemists were able to reduce all salts to two main genera--acids and +alkalis; and they regard this difference as itself a mere variety, +or different manifestation of one and the same fundamental material. +The different kinds of earths (stones and even metals) chemists have +endeavoured to reduce to three, and afterwards to two; but still, +not content with this advance, they cannot but think that behind these +diversities there lurks but one genus--nay, that even salts and earths +have a common principle. It might be conjectured that this is merely +an economical plan of reason, for the purpose of sparing itself +trouble, and an attempt of a purely hypothetical character, which, +when successful, gives an appearance of probability to the principle +of explanation employed by the reason. But a selfish purpose of this +kind is easily to be distinguished from the idea, according to which +every one presupposes that this unity is in accordance with the laws +of nature, and that reason does not in this case request, but +requires, although we are quite unable to determine the proper +limits of this unity. + +If the diversity existing in phenomena--a diversity not of form (for +in this they may be similar) but of content--were so great that the +subtlest human reason could never by comparison discover in them the +least similarity (which is not impossible), in this case the logical +law of genera would be without foundation, the conception of a +genus, nay, all general conceptions would be impossible, and the +faculty of the understanding, the exercise of which is restricted to +the world of conceptions, could not exist. The logical principle of +genera, accordingly, if it is to be applied to nature (by which I mean +objects presented to our senses), presupposes a transcendental +principle. In accordance with this principle, homogeneity is +necessarily presupposed in the variety of phenomena (although we are +unable to determine a priori the degree of this homogeneity), +because without it no empirical conceptions, and consequently no +experience, would be possible. + +The logical principle of genera, which demands identity in +phenomena, is balanced by another principle--that of species, which +requires variety and diversity in things, notwithstanding their +accordance in the same genus, and directs the understanding to +attend to the one no less than to the other. This principle (of the +faculty of distinction) acts as a check upon the reason and reason +exhibits in this respect a double and conflicting interest--on the +one hand, the interest in the extent (the interest of generality) in +relation to genera; on the other, that of the content (the interest +of individuality) in relation to the variety of species. In the former +case, the understanding cogitates more under its conceptions, in the +latter it cogitates more in them. This distinction manifests itself +likewise in the habits of thought peculiar to natural philosophers, +some of whom--the remarkably speculative heads--may be said to be +hostile to heterogeneity in phenomena, and have their eyes always +fixed on the unity of genera, while others--with a strong empirical +tendency--aim unceasingly at the analysis of phenomena, and almost +destroy in us the hope of ever being able to estimate the character +of these according to general principles. + +The latter mode of thought is evidently based upon a logical +principle, the aim of which is the systematic completeness of all +cognitions. This principle authorizes me, beginning at the genus, to +descend to the various and diverse contained under it; and in this +way extension, as in the former case unity, is assured to the system. +For if we merely examine the sphere of the conception which +indicates a genus, we cannot discover how far it is possible to +proceed in the division of that sphere; just as it is impossible, from +the consideration of the space occupied by matter, to determine how +far we can proceed in the division of it. Hence every genus must +contain different species, and these again different subspecies; and +as each of the latter must itself contain a sphere (must be of a +certain extent, as a conceptus communis), reason demands that no +species or sub-species is to be considered as the lowest possible. +For a species or sub-species, being always a conception, which contains +only what is common to a number of different things, does not +completely determine any individual thing, or relate immediately to +it, and must consequently contain other conceptions, that is, other +sub-species under it. This law of specification may be thus expressed: +entium varietates non temere sunt minuendae. + +But it is easy to see that this logical law would likewise be +without sense or application, were it not based upon a +transcendental law of specification, which certainly does not +require that the differences existing phenomena should be infinite +in number, for the logical principle, which merely maintains the +indeterminateness of the logical sphere of a conception, in relation +to its possible division, does not authorize this statement; while +it does impose upon the understanding the duty of searching for +subspecies to every species, and minor differences in every +difference. For, were there no lower conceptions, neither could +there be any higher. Now the understanding cognizes only by means of +conceptions; consequently, how far soever it may proceed in +division, never by mere intuition, but always by lower and lower +conceptions. The cognition of phenomena in their complete +determination (which is possible only by means of the understanding) +requires an unceasingly continued specification of conceptions, and +a progression to ever smaller differences, of which abstraction bad +been made in the conception of the species, and still more in that +of the genus. + +This law of specification cannot be deduced from experience; it +can never present us with a principle of so universal an +application. Empirical specification very soon stops in its +distinction of diversities, and requires the guidance of the +transcendental law, as a principle of the reason--a law which +imposes on us the necessity of never ceasing in our search for +differences, even although these may not present themselves to the +senses. That absorbent earths are of different kinds could only be +discovered by obeying the anticipatory law of reason, which imposes +upon the understanding the task of discovering the differences +existing between these earths, and supposes that nature is richer in +substances than our senses would indicate. The faculty of the +understanding belongs to us just as much under the presupposition of +differences in the objects of nature, as under the condition that +these objects are homogeneous, because we could not possess +conceptions, nor make any use of our understanding, were not the +phenomena included under these conceptions in some respects +dissimilar, as well as similar, in their character. + +Reason thus prepares the sphere of the understanding for the +operations of this faculty: 1. By the principle of the homogeneity +of the diverse in higher genera; 2. By the principle of the variety +of the homogeneous in lower species; and, to complete the systematic +unity, it adds, 3. A law of the affinity of all conceptions which +prescribes a continuous transition from one species to every other +by the gradual increase of diversity. We may term these the principles +of the homogeneity, the specification, and the continuity of forms. +The latter results from the union of the two former, inasmuch as we +regard the systematic connection as complete in thought, in the ascent +to higher genera, as well as in the descent to lower species. For +all diversities must be related to each other, as they all spring from +one highest genus, descending through the different gradations of a +more and more extended determination. + +We may illustrate the systematic unity produced by the three logical +principles in the following manner. Every conception may be regarded +as a point, which, as the standpoint of a spectator, has a certain +horizon, which may be said to enclose a number of things that may be +viewed, so to speak, from that centre. Within this horizon there +must be an infinite number of other points, each of which has its +own horizon, smaller and more circumscribed; in other words, every +species contains sub-species, according to the principle of +specification, and the logical horizon consists of smaller horizons +(subspecies), but not of points (individuals), which possess no +extent. But different horizons or genera, which include under them +so many conceptions, may have one common horizon, from which, as +from a mid-point, they may be surveyed; and we may proceed thus, +till we arrive at the highest genus, or universal and true horizon, +which is determined by the highest conception, and which contains +under itself all differences and varieties, as genera, species, and +subspecies. + +To this highest standpoint I am conducted by the law of homogeneity, +as to all lower and more variously-determined conceptions by the law +of specification. Now as in this way there exists no void in the whole +extent of all possible conceptions, and as out of the sphere of +these the mind can discover nothing, there arises from the +presupposition of the universal horizon above mentioned, and its +complete division, the principle: Non datur vacuum formarum. This +principle asserts that there are not different primitive and highest +genera, which stand isolated, so to speak, from each other, but all +the various genera are mere divisions and limitations of one highest +and universal genus; and hence follows immediately the principle: +Datur continuum formarum. This principle indicates that all +differences of species limit each other, and do not admit of +transition from one to another by a saltus, but only through smaller +degrees of the difference between the one species and the other. In +one word, there are no species or sub-species which (in the view of +reason) are the nearest possible to each other; intermediate species +or sub-species being always possible, the difference of which from +each of the former is always smaller than the difference existing +between these. + +The first law, therefore, directs us to avoid the notion that +there exist different primal genera, and enounces the fact of +perfect homogeneity; the second imposes a check upon this tendency +to unity and prescribes the distinction of sub-species, before +proceeding to apply our general conceptions to individuals. The +third unites both the former, by enouncing the fact of homogeneity +as existing even in the most various diversity, by means of the +gradual transition from one species to another. Thus it indicates a +relationship between the different branches or species, in so far as +they all spring from the same stem. + +But this logical law of the continuum specierum (formarum logicarum) +presupposes a transcendental principle (lex continui in natura), +without which the understanding might be led into error, by +following the guidance of the former, and thus perhaps pursuing a path +contrary to that prescribed by nature. This law must, consequently, +be based upon pure transcendental, and not upon empirical, +considerations. For, in the latter case, it would come later than +the system; whereas it is really itself the parent of all that is +systematic in our cognition of nature. These principles are not mere +hypotheses employed for the purpose of experimenting upon nature; +although when any such connection is discovered, it forms a solid +ground for regarding the hypothetical unity as valid in the sphere +of nature--and thus they are in this respect not without their use. +But we go farther, and maintain that it is manifest that these +principles of parsimony in fundamental causes, variety in effects, +and affinity in phenomena, are in accordance both with reason and +nature, and that they are not mere methods or plans devised for the +purpose of assisting us in our observation of the external world. + +But it is plain that this continuity of forms is a mere idea, to +which no adequate object can be discovered in experience. And this +for two reasons. First, because the species in nature are really +divided, and hence form quanta discreta; and, if the gradual +progression through their affinity were continuous, the intermediate +members lying between two given species must be infinite in number, +which is impossible. Secondly, because we cannot make any +determinate empirical use of this law, inasmuch as it does not present +us with any criterion of affinity which could aid us in determining +how far we ought to pursue the graduation of differences: it merely +contains a general indication that it is our duty to seek for and, +if possible, to discover them. + +When we arrange these principles of systematic unity in the order +conformable to their employment in experience, they will stand thus: +Variety, Affinity, Unity, each of them, as ideas, being taken in the +highest degree of their completeness. Reason presupposes the existence +of cognitions of the understanding, which have a direct relation to +experience, and aims at the ideal unity of these cognitions--a unity +which far transcends all experience or empirical notions. The affinity +of the diverse, notwithstanding the differences existing between its +parts, has a relation to things, but a still closer one to the mere +properties and powers of things. For example, imperfect experience +may represent the orbits of the planets as circular. But we discover +variations from this course, and we proceed to suppose that the +planets revolve in a path which, if not a circle, is of a character +very similar to it. That is to say, the movements of those planets +which do not form a circle will approximate more or less to the +properties of a circle, and probably form an ellipse. The paths of +comets exhibit still greater variations, for, so far as our +observation extends, they do not return upon their own course in a +circle or ellipse. But we proceed to the conjecture that comets +describe a parabola, a figure which is closely allied to the +ellipse. In fact, a parabola is merely an ellipse, with its longer +axis produced to an indefinite extent. Thus these principles conduct +us to a unity in the genera of the forms of these orbits, and, +proceeding farther, to a unity as regards the cause of the motions +of the heavenly bodies--that is, gravitation. But we go on extending +our conquests over nature, and endeavour to explain all seeming +deviations from these rules, and even make additions to our system +which no experience can ever substantiate--for example, the theory, +in affinity with that of ellipses, of hyperbolic paths of comets, +pursuing which, these bodies leave our solar system and, passing +from sun to sun, unite the most distant parts of the infinite +universe, which is held together by the same moving power. + +The most remarkable circumstance connected with these principles +is that they seem to be transcendental, and, although only +containing ideas for the guidance of the empirical exercise of reason, +and although this empirical employment stands to these ideas in an +asymptotic relation alone (to use a mathematical term), that is, +continually approximate, without ever being able to attain to them, +they possess, notwithstanding, as a priori synthetical propositions, +objective though undetermined validity, and are available as rules +for possible experience. In the elaboration of our experience, they +may also be employed with great advantage, as heuristic [Footnote: +From the Greek, eurhioko.] principles. A transcendental deduction of +them cannot be made; such a deduction being always impossible in the +case of ideas, as has been already shown. + +We distinguished, in the Transcendental Analytic, the dynamical +principles of the understanding, which are regulative principles of +intuition, from the mathematical, which are constitutive principles +of intuition. These dynamical laws are, however, constitutive in relation +to experience, inasmuch as they render the conceptions without which +experience could not exist possible a priori. But the principles of +pure reason cannot be constitutive even in regard to empirical +conceptions, because no sensuous schema corresponding to them can be +discovered, and they cannot therefore have an object in concreto. Now, +if I grant that they cannot be employed in the sphere of experience, +as constitutive principles, how shall I secure for them employment +and objective validity as regulative principles, and in what way can +they be so employed? + +The understanding is the object of reason, as sensibility is the +object of the understanding. The production of systematic unity in +all the empirical operations of the understanding is the proper occupation +of reason; just as it is the business of the understanding to +connect the various content of phenomena by means of conceptions, +and subject them to empirical laws. But the operations of the +understanding are, without the schemata of sensibility, +undetermined; and, in the same manner, the unity of reason is +perfectly undetermined as regards the conditions under which, and +the extent to which, the understanding ought to carry the systematic +connection of its conceptions. But, although it is impossible to +discover in intuition a schema for the complete systematic unity of +all the conceptions of the understanding, there must be some +analogon of this schema. This analogon is the idea of the maximum of +the division and the connection of our cognition in one principle. +For we may have a determinate notion of a maximum and an absolutely +perfect, all the restrictive conditions which are connected with an +indeterminate and various content having been abstracted. Thus the +idea of reason is analogous with a sensuous schema, with this +difference, that the application of the categories to the schema of +reason does not present a cognition of any object (as is the case with +the application of the categories to sensuous schemata), but merely +provides us with a rule or principle for the systematic unity of the +exercise of the understanding. Now, as every principle which imposes +upon the exercise of the understanding a priori compliance with the +rule of systematic unity also relates, although only in an indirect +manner, to an object of experience, the principles of pure reason will +also possess objective reality and validity in relation to experience. +But they will not aim at determining our knowledge in regard to any +empirical object; they will merely indicate the procedure, following +which the empirical and determinate exercise of the understanding +may be in complete harmony and connection with itself--a result +which is produced by its being brought into harmony with the principle +of systematic unity, so far as that is possible, and deduced from it. + +I term all subjective principles, which are not derived from +observation of the constitution of an object, but from the interest +which Reason has in producing a certain completeness in her +cognition of that object, maxims of reason. Thus there are maxims of +speculative reason, which are based solely upon its speculative +interest, although they appear to be objective principles. + +When principles which are really regulative are regarded as +constitutive, and employed as objective principles, contradictions +must arise; but if they are considered as mere maxims, there is no +room for contradictions of any kind, as they then merely indicate +the different interests of reason, which occasion differences in the +mode of thought. In effect, Reason has only one single interest, and +the seeming contradiction existing between her maxims merely indicates +a difference in, and a reciprocal limitation of, the methods by +which this interest is satisfied. + +This reasoner has at heart the interest of diversity--in +accordance with the principle of specification; another, the +interest of unity--in accordance with the principle of aggregation. +Each believes that his judgement rests upon a thorough insight into +the subject he is examining, and yet it has been influenced solely +by a greater or less degree of adherence to some one of the two +principles, neither of which are objective, but originate solely +from the interest of reason, and on this account to be termed maxims +rather than principles. When I observe intelligent men disputing about +the distinctive characteristics of men, animals, or plants, and even +of minerals, those on the one side assuming the existence of certain +national characteristics, certain well-defined and hereditary +distinctions of family, race, and so on, while the other side maintain +that nature has endowed all races of men with the same faculties and +dispositions, and that all differences are but the result of +external and accidental circumstances--I have only to consider for +a moment the real nature of the subject of discussion, to arrive at +the conclusion that it is a subject far too deep for us to judge of, +and that there is little probability of either party being able to +speak from a perfect insight into and understanding of the nature of +the subject itself. Both have, in reality, been struggling for the +twofold interest of reason; the one maintaining the one interest, +the other the other. But this difference between the maxims of +diversity and unity may easily be reconciled and adjusted; although, +so long as they are regarded as objective principles, they must +occasion not only contradictions and polemic, but place hinderances +in the way of the advancement of truth, until some means is discovered +of reconciling these conflicting interests, and bringing reason into +union and harmony with itself. + +The same is the case with the so-called law discovered by Leibnitz, and +supported with remarkable ability by Bonnet--the law of the continuous +gradation of created beings, which is nothing more than an inference +from the principle of affinity; for observation and study of the order +of nature could never present it to the mind as an objective truth. The +steps of this ladder, as they appear in experience, are too far apart +from each other, and the so-called petty differences between different +kinds of animals are in nature commonly so wide separations that no +confidence can be placed in such views (particularly when we reflect on +the great variety of things, and the ease with which we can discover +resemblances), and no faith in the laws which are said to express the +aims and purposes of nature. On the other hand, the method of +investigating the order of nature in the light of this principle, and +the maxim which requires us to regard this order--it being still +undetermined how far it extends--as really existing in nature, is +beyond doubt a legitimate and excellent principle of reason--a +principle which extends farther than any experience or observation of +ours and which, without giving us any positive knowledge of anything in +the region of experience, guides us to the goal of systematic unity. + + + +Of the Ultimate End of the Natural Dialectic of Human Reason. + +The ideas of pure reason cannot be, of themselves and in their own +nature, dialectical; it is from their misemployment alone that +fallacies and illusions arise. For they originate in the nature of +reason itself, and it is impossible that this supreme tribunal for +all the rights and claims of speculation should be itself undeserving +of confidence and promotive of error. It is to be expected, therefore, +that these ideas have a genuine and legitimate aim. It is true, the +mob of sophists raise against reason the cry of inconsistency and +contradiction, and affect to despise the government of that faculty, +because they cannot understand its constitution, while it is to its +beneficial influences alone that they owe the position and the +intelligence which enable them to criticize and to blame its +procedure. + +We cannot employ an a priori conception with certainty, until we +have made a transcendental deduction therefore. The ideas of pure +reason do not admit of the same kind of deduction as the categories. +But if they are to possess the least objective validity, and to +represent anything but mere creations of thought (entia rationis +ratiocinantis), a deduction of them must be possible. This deduction +will complete the critical task imposed upon pure reason; and it is +to this part Of our labours that we now proceed. + +There is a great difference between a thing's being presented to the +mind as an object in an absolute sense, or merely as an ideal +object. In the former case I employ my conceptions to determine the +object; in the latter case nothing is present to the mind but a mere +schema, which does not relate directly to an object, not even in a +hypothetical sense, but which is useful only for the purpose of +representing other objects to the mind, in a mediate and indirect +manner, by means of their relation to the idea in the intellect. +Thus I say the conception of a supreme intelligence is a mere idea; +that is to say, its objective reality does not consist in the fact +that it has an immediate relation to an object (for in this sense we +have no means of establishing its objective validity), it is merely +a schema constructed according to the necessary conditions of the +unity of reason--the schema of a thing in general, which is useful +towards the production of the highest degree of systematic unity in +the empirical exercise of reason, in which we deduce this or that +object of experience from the imaginary object of this idea, as the +ground or cause of the said object of experience. In this way, the +idea is properly a heuristic, and not an ostensive, conception; it +does not give us any information respecting the constitution of an +object, it merely indicates how, under the guidance of the idea, we +ought to investigate the constitution and the relations of objects +in the world of experience. Now, if it can be shown that the three +kinds of transcendental ideas (psychological, cosmological, and +theological), although not relating directly to any object nor +determining it, do nevertheless, on the supposition of the existence +of an ideal object, produce systematic unity in the laws of the +empirical employment of the reason, and extend our empirical +cognition, without ever being inconsistent or in opposition with it- +it must be a necessary maxim of reason to regulate its procedure +according to these ideas. And this forms the transcendental +deduction of all speculative ideas, not as constitutive principles +of the extension of our cognition beyond the limits of our experience, +but as regulative principles of the systematic unity of empirical +cognition, which is by the aid of these ideas arranged and emended +within its own proper limits, to an extent unattainable by the +operation of the principles of the understanding alone. + +I shall make this plainer. Guided by the principles involved in +these ideas, we must, in the first place, so connect all the +phenomena, actions, and feelings of the mind, as if it were a simple +substance, which, endowed with personal identity, possesses a +permanent existence (in this life at least), while its states, among +which those of the body are to be included as external conditions, +are in continual change. Secondly, in cosmology, we must investigate +the conditions of all natural phenomena, internal as well as external, +as if they belonged to a chain infinite and without any prime or +supreme member, while we do not, on this account, deny the existence +of intelligible grounds of these phenomena, although we never employ +them to explain phenomena, for the simple reason that they are not +objects of our cognition. Thirdly, in the sphere of theology, we +must regard the whole system of possible experience as forming an +absolute, but dependent and sensuously-conditioned unity, and at the +same time as based upon a sole, supreme, and all-sufficient ground +existing apart from the world itself--a ground which is a +self-subsistent, primeval and creative reason, in relation to which +we so employ our reason in the field of experience, as if all objects +drew their origin from that archetype of all reason. In other words, +we ought not to deduce the internal phenomena of the mind from a +simple thinking substance, but deduce them from each other under the +guidance of the regulative idea of a simple being; we ought not to +deduce the phenomena, order, and unity of the universe from a +supreme intelligence, but merely draw from this idea of a supremely +wise cause the rules which must guide reason in its connection of +causes and effects. + +Now there is nothing to hinder us from admitting these ideas to +possess an objective and hyperbolic existence, except the cosmological +ideas, which lead reason into an antinomy: the psychological and +theological ideas are not antinomial. They contain no contradiction; +and how, then, can any one dispute their objective reality, since he +who denies it knows as little about their possibility as we who +affirm? And yet, when we wish to admit the existence of a thing, it +is not sufficient to convince ourselves that there is no positive +obstacle in the way; for it cannot be allowable to regard mere +creations of thought, which transcend, though they do not +contradict, all our conceptions, as real and determinate objects, +solely upon the authority of a speculative reason striving to +compass its own aims. They cannot, therefore, be admitted to be real +in themselves; they can only possess a comparative reality--that of +a schema of the regulative principle of the systematic unity of all +cognition. They are to be regarded not as actual things, but as in +some measure analogous to them. We abstract from the object of the +idea all the conditions which limit the exercise of our understanding, +but which, on the other hand, are the sole conditions of our +possessing a determinate conception of any given thing. And thus we +cogitate a something, of the real nature of which we have not the +least conception, but which we represent to ourselves as standing in +a relation to the whole system of phenomena, analogous to that in +which phenomena stand to each other. + +By admitting these ideal beings, we do not really extend our +cognitions beyond the objects of possible experience; we extend merely +the empirical unity of our experience, by the aid of systematic unity, +the schema of which is furnished by the idea, which is therefore +valid--not as a constitutive, but as a regulative principle. For +although we posit a thing corresponding to the idea--a something, an +actual existence--we do not on that account aim at the extension of +our cognition by means of transcendent conceptions. This existence +is purely ideal, and not objective; it is the mere expression of the +systematic unity which is to be the guide of reason in the field of +experience. There are no attempts made at deciding what the ground +of this unity may be, or what the real nature of this imaginary being. + +Thus the transcendental and only determinate conception of God, +which is presented to us by speculative reason, is in the strictest +sense deistic. In other words, reason does not assure us of the +objective validity of the conception; it merely gives us the idea of +something, on which the supreme and necessary unity of all +experience is based. This something we cannot, following the analogy +of a real substance, cogitate otherwise than as the cause of all +things operating in accordance with rational laws, if we regard it +as an individual object; although we should rest contented with the +idea alone as a regulative principle of reason, and make no attempt +at completing the sum of the conditions imposed by thought. This +attempt is, indeed, inconsistent with the grand aim of complete +systematic unity in the sphere of cognition--a unity to which no +bounds are set by reason. + +Hence it happens that, admitting a divine being, I can have no +conception of the internal possibility of its perfection, or of the +necessity of its existence. The only advantage of this admission is +that it enables me to answer all other questions relating to the +contingent, and to give reason the most complete satisfaction as +regards the unity which it aims at attaining in the world of +experience. But I cannot satisfy reason with regard to this hypothesis +itself; and this proves that it is not its intelligence and insight +into the subject, but its speculative interest alone which induces +it to proceed from a point lying far beyond the sphere of our +cognition, for the purpose of being able to consider all objects as +parts of a systematic whole. + +Here a distinction presents itself, in regard to the way in which we +may cogitate a presupposition--a distinction which is somewhat subtle, +but of great importance in transcendental philosophy. I may have +sufficient grounds to admit something, or the existence of +something, in a relative point of view (suppositio relativa), +without being justified in admitting it in an absolute sense +(suppositio absoluta). This distinction is undoubtedly requisite, in +the case of a regulative principle, the necessity of which we +recognize, though we are ignorant of the source and cause of that +necessity, and which we assume to be based upon some ultimate +ground, for the purpose of being able to cogitate the universality +of the principle in a more determinate way. For example, I cogitate +the existence of a being corresponding to a pure transcendental +idea. But I cannot admit that this being exists absolutely and in +itself, because all of the conceptions by which I can cogitate an +object in a determinate manner fall short of assuring me of its +existence; nay, the conditions of the objective validity of my +conceptions are excluded by the idea--by the very fact of its being +an idea. The conceptions of reality, substance, causality, nay, even +that of necessity in existence, have no significance out of the sphere +of empirical cognition, and cannot, beyond that sphere, determine any +object. They may, accordingly, be employed to explain the +possibility of things in the world of sense, but they are utterly +inadequate to explain the possibility of the universe itself +considered as a whole; because in this case the ground of +explanation must lie out of and beyond the world, and cannot, +therefore, be an object of possible experience. Now, I may admit the +existence of an incomprehensible being of this nature--the object of +a mere idea, relatively to the world of sense; although I have no ground +to admit its existence absolutely and in itself. For if an idea +(that of a systematic and complete unity, of which I shall presently +speak more particularly) lies at the foundation of the most extended +empirical employment of reason, and if this idea cannot be +adequately represented in concreto, although it is indispensably +necessary for the approximation of empirical unity to the highest +possible degree--I am not only authorized, but compelled, to realize +this idea, that is, to posit a real object corresponding thereto. +But I cannot profess to know this object; it is to me merely a +something, to which, as the ground of systematic unity in cognition, +I attribute such properties as are analogous to the conceptions employed +by the understanding in the sphere of experience. Following the +analogy of the notions of reality, substance, causality, and +necessity, I cogitate a being, which possesses all these attributes +in the highest degree; and, as this idea is the offspring of my reason +alone, I cogitate this being as self-subsistent reason, and as the +cause of the universe operating by means of ideas of the greatest +possible harmony and unity. Thus I abstract all conditions that +would limit my idea, solely for the purpose of rendering systematic +unity possible in the world of empirical diversity, and thus +securing the widest possible extension for the exercise of reason in +that sphere. This I am enabled to do, by regarding all connections +and relations in the world of sense, as if they were the dispositions +of a supreme reason, of which our reason is but a faint image. I then +proceed to cogitate this Supreme Being by conceptions which have, +properly, no meaning or application, except in the world of sense. +But as I am authorized to employ the transcendental hypothesis of such +a being in a relative respect alone, that is, as the substratum of +the greatest possible unity in experience--I may attribute to a being +which I regard as distinct from the world, such properties as belong +solely to the sphere of sense and experience. For I do not desire, +and am not justified in desiring, to cognize this object of my idea, +as it exists in itself; for I possess no conceptions sufficient for +or task, those of reality, substance, causality, nay, even that of +necessity in existence, losing all significance, and becoming merely +the signs of conceptions, without content and without applicability, +when I attempt to carry them beyond the limits of the world of sense. +I cogitate merely the relation of a perfectly unknown being to the +greatest possible systematic unity of experience, solely for the purpose +of employing it as the schema of the regulative principle which directs +reason in its empirical exercise. + +It is evident, at the first view, that we cannot presuppose the +reality of this transcendental object, by means of the conceptions +of reality, substance, causality, and so on, because these conceptions +cannot be applied to anything that is distinct from the world of +sense. Thus the supposition of a Supreme Being or cause is purely +relative; it is cogitated only in behalf of the systematic unity of +experience; such a being is but a something, of whose existence in +itself we have not the least conception. Thus, too, it becomes +sufficiently manifest why we required the idea of a necessary being +in relation to objects given by sense, although we can never have the +least conception of this being, or of its absolute necessity. + +And now we can clearly perceive the result of our transcendental +dialectic, and the proper aim of the ideas of pure reason--which +become dialectical solely from misunderstanding and inconsiderateness. +Pure reason is, in fact, occupied with itself, and not with any +object. Objects are not presented to it to be embraced in the unity +of an empirical conception; it is only the cognitions of the +understanding that are presented to it, for the purpose of receiving +the unity of a rational conception, that is, of being connected +according to a principle. The unity of reason is the unity of +system; and this systematic unity is not an objective principle, +extending its dominion over objects, but a subjective maxim, extending +its authority over the empirical cognition of objects. The +systematic connection which reason gives to the empirical employment +of the understanding not only advances the extension of that +employment, but ensures its correctness, and thus the principle of +a systematic unity of this nature is also objective, although only +in an indefinite respect (principium vagum). It is not, however, a +constitutive principle, determining an object to which it directly +relates; it is merely a regulative principle or maxim, advancing and +strengthening the empirical exercise of reason, by the opening up of +new paths of which the understanding is ignorant, while it never +conflicts with the laws of its exercise in the sphere of experience. + +But reason cannot cogitate this systematic unity, without at the +same time cogitating an object of the idea--an object that cannot be +presented in any experience, which contains no concrete example of +a complete systematic unity. This being (ens rationis ratiocinatae) +is therefore a mere idea and is not assumed to be a thing which is +real absolutely and in itself. On the contrary, it forms merely the +problematical foundation of the connection which the mind introduces +among the phenomena of the sensuous world. We look upon this +connection, in the light of the above-mentioned idea, as if it drew +its origin from the supposed being which corresponds to the idea. +And yet all we aim at is the possession of this idea as a secure +foundation for the systematic unity of experience--a unity +indispensable to reason, advantageous to the understanding, and +promotive of the interests of empirical cognition. + +We mistake the true meaning of this idea when we regard it as an +enouncement, or even as a hypothetical declaration of the existence +of a real thing, which we are to regard as the origin or ground of +a systematic constitution of the universe. On the contrary, it is left +completely undetermined what the nature or properties of this +so-called ground may be. The idea is merely to be adopted as a point +of view, from which this unity, so essential to reason and so +beneficial to the understanding, may be regarded as radiating. In +one word, this transcendental thing is merely the schema of a +regulative principle, by means of which Reason, so far as in her lies, +extends the dominion of systematic unity over the whole sphere of +experience. + +The first object of an idea of this kind is the ego, considered +merely as a thinking nature or soul. If I wish to investigate the +properties of a thinking being, I must interrogate experience. But +I find that I can apply none of the categories to this object, the +schema of these categories, which is the condition of their +application, being given only in sensuous intuition. But I cannot thus +attain to the cognition of a systematic unity of all the phenomena +of the internal sense. Instead, therefore, of an empirical +conception of what the soul really is, reason takes the conception +of the empirical unity of all thought, and, by cogitating this unity +as unconditioned and primitive, constructs the rational conception +or idea of a simple substance which is in itself unchangeable, +possessing personal identity, and in connection with other real things +external to it; in one word, it constructs the idea of a simple +self-subsistent intelligence. But the real aim of reason in this +procedure is the attainment of principles of systematic unity for +the explanation of the phenomena of the soul. That is, reason +desires to be able to represent all the determinations of the internal +sense as existing in one subject, all powers as deduced from one +fundamental power, all changes as mere varieties in the condition of +a being which is permanent and always the same, and all phenomena in +space as entirely different in their nature from the procedure of +thought. Essential simplicity (with the other attributes predicated +of the ego) is regarded as the mere schema of this regulative +principle; it is not assumed that it is the actual ground of the +properties of the soul. For these properties may rest upon quite +different grounds, of which we are completely ignorant; just as the +above predicates could not give us any knowledge of the soul as it +is in itself, even if we regarded them as valid in respect of it, +inasmuch as they constitute a mere idea, which cannot be represented +in concreto. Nothing but good can result from a psychological idea +of this kind, if we only take proper care not to consider it as more +than an idea; that is, if we regard it as valid merely in relation +to the employment of reason, in the sphere of the phenomena of the +soul. Under the guidance of this idea, or principle, no empirical laws +of corporeal phenomena are called in to explain that which is a +phenomenon of the internal sense alone; no windy hypotheses of the +generation, annihilation, and palingenesis of souls are admitted. Thus +the consideration of this object of the internal sense is kept pure, +and unmixed with heterogeneous elements; while the investigation of +reason aims at reducing all the grounds of explanation employed in +this sphere of knowledge to a single principle. All this is best +effected, nay, cannot be effected otherwise than by means of such a +schema, which requires us to regard this ideal thing as an actual +existence. The psychological idea is, therefore, meaningless and +inapplicable, except as the schema of a regulative conception. For, +if I ask whether the soul is not really of a spiritual nature--it is +a question which has no meaning. From such a conception has been +abstracted, not merely all corporeal nature, but all nature, that +is, all the predicates of a possible experience; and consequently, +all the conditions which enable us to cogitate an object to this +conception have disappeared. But, if these conditions are absent, it +is evident that the conception is meaningless. + +The second regulative idea of speculative reason is the conception +of the universe. For nature is properly the only object presented to +us, in regard to which reason requires regulative principles. Nature +is twofold--thinking and corporeal nature. To cogitate the latter in +regard to its internal possibility, that is, to determine the +application of the categories to it, no idea is required--no +representation which transcends experience. In this sphere, therefore, +an idea is impossible, sensuous intuition being our only guide; while, +in the sphere of psychology, we require the fundamental idea (I), +which contains a priori a certain form of thought namely, the unity +of the ego. Pure reason has, therefore, nothing left but nature in +general, and the completeness of conditions in nature in accordance +with some principle. The absolute totality of the series of these +conditions is an idea, which can never be fully realized in the +empirical exercise of reason, while it is serviceable as a rule for +the procedure of reason in relation to that totality. It requires +us, in the explanation of given phenomena (in the regress or ascent +in the series), to proceed as if the series were infinite in itself, +that is, were prolonged in indefinitum,; while on the other hand, where +reason is regarded as itself the determining cause (in the region of +freedom), we are required to proceed as if we had not before us an +object of sense, but of the pure understanding. In this latter case, +the conditions do not exist in the series of phenomena, but may be +placed quite out of and beyond it, and the series of conditions may +be regarded as if it had an absolute beginning from an intelligible +cause. All this proves that the cosmological ideas are nothing but +regulative principles, and not constitutive; and that their aim is +not to realize an actual totality in such series. The full discussion +of this subject will be found in its proper place in the chapter on +the antinomy of pure reason. + +The third idea of pure reason, containing the hypothesis of a +being which is valid merely as a relative hypothesis, is that of the +one and all-sufficient cause of all cosmological series, in other +words, the idea of God. We have not the slightest ground absolutely +to admit the existence of an object corresponding to this idea; for +what can empower or authorize us to affirm the existence of a being +of the highest perfection--a being whose existence is absolutely +necessary--merely because we possess the conception of such a being? +The answer is: It is the existence of the world which renders this +hypothesis necessary. But this answer makes it perfectly evident +that the idea of this being, like all other speculative ideas, is +essentially nothing more than a demand upon reason that it shall +regulate the connection which it and its subordinate faculties +introduce into the phenomena of the world by principles of +systematic unity and, consequently, that it shall regard all phenomena +as originating from one all-embracing being, as the supreme and +all-sufficient cause. From this it is plain that the only aim of +reason in this procedure is the establishment of its own formal rule +for the extension of its dominion in the world of experience; that +it does not aim at an extension of its cognition beyond the limits +of experience; and that, consequently, this idea does not contain +any constitutive principle. + +The highest formal unity, which is based upon ideas alone, is the +unity of all things--a unity in accordance with an aim or purpose; +and the speculative interest of reason renders it necessary to regard +all order in the world as if it originated from the intention and +design of a supreme reason. This principle unfolds to the view of +reason in the sphere of experience new and enlarged prospects, and +invites it to connect the phenomena of the world according to +teleological laws, and in this way to attain to the highest possible +degree of systematic unity. The hypothesis of a supreme +intelligence, as the sole cause of the universe--an intelligence which +has for us no more than an ideal existence--is accordingly always of +the greatest service to reason. Thus, if we presuppose, in relation +to the figure of the earth (which is round, but somewhat flattened +at the poles),* or that of mountains or seas, wise designs on the part +of an author of the universe, we cannot fail to make, by the light +of this supposition, a great number of interesting discoveries. If +we keep to this hypothesis, as a principle which is purely regulative, +even error cannot be very detrimental. For, in this case, error can +have no more serious consequences than that, where we expected to +discover a teleological connection (nexus finalis), only a +mechanical or physical connection appears. In such a case, we merely +fail to find the additional form of unity we expected, but we do not +lose the rational unity which the mind requires in its procedure in +experience. But even a miscarriage of this sort cannot affect the +law in its general and teleological relations. For although we may +convict an anatomist of an error, when he connects the limb of some +animal with a certain purpose, it is quite impossible to prove in a +single case that any arrangement of nature, be it what it may, is +entirely without aim or design. And thus medical physiology, by the +aid of a principle presented to it by pure reason, extends its very +limited empirical knowledge of the purposes of the different parts +of an organized body so far that it may be asserted with the utmost +confidence, and with the approbation of all reflecting men, that every +organ or bodily part of an animal has its use and answers a certain +design. Now, this is a supposition which, if regarded as of a +constitutive character, goes much farther than any experience or +observation of ours can justify. Hence it is evident that it is +nothing more than a regulative principle of reason, which aims at +the highest degree of systematic unity, by the aid of the idea of a +causality according to design in a supreme cause--a cause which it +regards as the highest intelligence. + +[*Footnote: The advantages which a circular form, in the case of the +earth, has over every other, are well known. But few are aware that +the slight flattening at the poles, which gives it the figure of a +spheroid, is the only cause which prevents the elevations of continents +or even of mountains, perhaps thrown up by some internal convulsion, +from continually altering the position of the axis of the earth--and +that to some considerable degree in a short time. The great protuberance +of the earth under the Equator serves to overbalance the impetus of +all other masses of earth, and thus to preserve the axis of the earth, +so far as we can observe, in its present position. And yet this wise +arrangement has been unthinkingly explained from the equilibrium of +the formerly fluid mass.] + +If, however, we neglect this restriction of the idea to a purely +regulative influence, reason is betrayed into numerous errors. For +it has then left the ground of experience, in which alone are to be +found the criteria of truth, and has ventured into the region of the +incomprehensible and unsearchable, on the heights of which it loses +its power and collectedness, because it has completely severed its +connection with experience. + +The first error which arises from our employing the idea of a +Supreme Being as a constitutive (in repugnance to the very nature of +an idea), and not as a regulative principle, is the error of +inactive reason (ignava ratio).* We may so term every principle +which requires us to regard our investigations of nature as absolutely +complete, and allows reason to cease its inquiries, as if it had fully +executed its task. Thus the psychological idea of the ego, when +employed as a constitutive principle for the explanation of the +phenomena of the soul, and for the extension of our knowledge +regarding this subject beyond the limits of experience--even to the +condition of the soul after death--is convenient enough for the +purposes of pure reason, but detrimental and even ruinous to its +interests in the sphere of nature and experience. The dogmatizing +spiritualist explains the unchanging unity of our personality +through all changes of condition from the unity of a thinking +substance, the interest which we take in things and events that can +happen only after our death, from a consciousness of the immaterial +nature of our thinking subject, and so on. Thus he dispenses with +all empirical investigations into the cause of these internal +phenomena, and with all possible explanations of them upon purely +natural grounds; while, at the dictation of a transcendent reason, +he passes by the immanent sources of cognition in experience, +greatly to his own ease and convenience, but to the sacrifice of +all, genuine insight and intelligence. These prejudicial +consequences become still more evident, in the case of the +dogmatical treatment of our idea of a Supreme Intelligence, and the +theological system of nature (physico-theology) which is falsely based +upon it. For, in this case, the aims which we observe in nature, and +often those which we merely fancy to exist, make the investigation +of causes a very easy task, by directing us to refer such and such +phenomena immediately to the unsearchable will and counsel of the +Supreme Wisdom, while we ought to investigate their causes in the +general laws of the mechanism of matter. We are thus recommended to +consider the labour of reason as ended, when we have merely +dispensed with its employment, which is guided surely and safely +only by the order of nature and the series of changes in the world- +which are arranged according to immanent and general laws. This +error may be avoided, if we do not merely consider from the view-point +of final aims certain parts of nature, such as the division and +structure of a continent, the constitution and direction of certain +mountain-chains, or even the organization existing in the vegetable +and animal kingdoms, but look upon this systematic unity of nature +in a perfectly general way, in relation to the idea of a Supreme +Intelligence. If we pursue this advice, we lay as a foundation for +all investigation the conformity to aims of all phenomena of nature +in accordance with universal laws, for which no particular arrangement +of nature is exempt, but only cognized by us with more or less +difficulty; and we possess a regulative principle of the systematic +unity of a teleological connection, which we do not attempt to +anticipate or predetermine. All that we do, and ought to do, is to +follow out the physico-mechanical connection in nature according to +general laws, with the hope of discovering, sooner or later, the +teleological connection also. Thus, and thus only, can the principle +of final unity aid in the extension of the employment of reason in +the sphere of experience, without being in any case detrimental to +its interests. + +[*Footnote: This was the term applied by the old dialecticians to a +sophistical argument, which ran thus: If it is your fate to die of +this disease, you will die, whether you employ a physician or not. +Cicero says that this mode of reasoning has received this appellation, +because, if followed, it puts an end to the employment of reason in +the affairs of life. For a similar reason, I have applied this designation +to the sophistical argument of pure reason.] + +The second error which arises from the misconception of the +principle of systematic unity is that of perverted reason (perversa +ratio, usteron roteron rationis). The idea of systematic unity is +available as a regulative principle in the connection of phenomena +according to general natural laws; and, how far soever we have to +travel upon the path of experience to discover some fact or event, +this idea requires us to believe that we have approached all the +more nearly to the completion of its use in the sphere of nature, +although that completion can never be attained. But this error +reverses the procedure of reason. We begin by hypostatizing the +principle of systematic unity, and by giving an anthropomorphic +determination to the conception of a Supreme Intelligence, and then +proceed forcibly to impose aims upon nature. Thus not only does +teleology, which ought to aid in the completion of unity in accordance +with general laws, operate to the destruction of its influence, but +it hinders reason from attaining its proper aim, that is, the proof, +upon natural grounds, of the existence of a supreme intelligent cause. +For, if we cannot presuppose supreme finality in nature a priori, that +is, as essentially belonging to nature, how can we be directed to +endeavour to discover this unity and, rising gradually through its +different degrees, to approach the supreme perfection of an author +of all--a perfection which is absolutely necessary, and therefore +cognizable a priori? The regulative principle directs us to presuppose +systematic unity absolutely and, consequently, as following from the +essential nature of things--but only as a unity of nature, not +merely cognized empirically, but presupposed a priori, although only +in an indeterminate manner. But if I insist on basing nature upon +the foundation of a supreme ordaining Being, the unity of nature is +in effect lost. For, in this case, it is quite foreign and unessential +to the nature of things, and cannot be cognized from the general laws +of nature. And thus arises a vicious circular argument, what ought +to have been proved having been presupposed. + +To take the regulative principle of systematic unity in nature for +a constitutive principle, and to hypostatize and make a cause out of +that which is properly the ideal ground of the consistent and +harmonious exercise of reason, involves reason in inextricable +embarrassments. The investigation of nature pursues its own path under +the guidance of the chain of natural causes, in accordance with the +general laws of nature, and ever follows the light of the idea of an +author of the universe--not for the purpose of deducing the +finality, which it constantly pursues, from this Supreme Being, but +to attain to the cognition of his existence from the finality which +it seeks in the existence of the phenomena of nature, and, if possible, +in that of all things to cognize this being, consequently, as +absolutely necessary. Whether this latter purpose succeed or not, +the idea is and must always be a true one, and its employment, when +merely regulative, must always be accompanied by truthful and +beneficial results. + +Complete unity, in conformity with aims, constitutes absolute +perfection. But if we do not find this unity in the nature of the +things which go to constitute the world of experience, that is, of +objective cognition, consequently in the universal and necessary +laws of nature, how can we infer from this unity the idea of the +supreme and absolutely necessary perfection of a primal being, which +is the origin of all causality? The greatest systematic unity, and +consequently teleological unity, constitutes the very foundation of +the possibility of the most extended employment of human reason. The +idea of unity is therefore essentially and indissolubly connected with +the nature of our reason. This idea is a legislative one; and hence +it is very natural that we should assume the existence of a legislative +reason corresponding to it, from which the systematic unity of nature- +the object of the operations of reason--must be derived. + +In the course of our discussion of the antinomies, we stated that it +is always possible to answer all the questions which pure reason may +raise; and that the plea of the limited nature of our cognition, which +is unavoidable and proper in many questions regarding natural +phenomena, cannot in this case be admitted, because the questions +raised do not relate to the nature of things, but are necessarily +originated by the nature of reason itself, and relate to its own +internal constitution. We can now establish this assertion, which at +first sight appeared so rash, in relation to the two questions in +which reason takes the greatest interest, and thus complete our +discussion of the dialectic of pure reason. + +If, then, the question is asked, in relation to transcendental +theology,* first, whether there is anything distinct from the world, +which contains the ground of cosmical order and connection according +to general laws? The answer is: Certainly. For the world is a sum of +phenomena; there must, therefore, be some transcendental basis of +these phenomena, that is, a basis cogitable by the pure +understanding alone. If, secondly, the question is asked whether +this being is substance, whether it is of the greatest reality, +whether it is necessary, and so forth? I answer that this question +is utterly without meaning. For all the categories which aid me in +forming a conception of an object cannot be employed except in the +world of sense, and are without meaning when not applied to objects +of actual or possible experience. Out of this sphere, they are not +properly conceptions, but the mere marks or indices of conceptions, +which we may admit, although they cannot, without the help of +experience, help us to understand any subject or thing. If, thirdly, +the question is whether we may not cogitate this being, which is +distinct from the world, in analogy with the objects of experience? +The answer is: Undoubtedly, but only as an ideal, and not as a real +object. That is, we must cogitate it only as an unknown substratum +of the systematic unity, order, and finality of the world--a unity +which reason must employ as the regulative principle of its +investigation of nature. Nay, more, we may admit into the idea certain +anthropomorphic elements, which are promotive of the interests of this +regulative principle. For it is no more than an idea, which does not +relate directly to a being distinct from the world, but to the +regulative principle of the systematic unity of the world, by means, +however, of a schema of this unity--the schema of a Supreme +Intelligence, who is the wisely-designing author of the universe. What +this basis of cosmical unity may be in itself, we know not--we +cannot discover from the idea; we merely know how we ought to employ +the idea of this unity, in relation to the systematic operation of +reason in the sphere of experience. + +[*Footnote: After what has been said of the psychological idea of the +ego and its proper employment as a regulative principle of the operations +of reason, I need not enter into details regarding the transcendental +illusion by which the systematic unity of all the various phenomena +of the internal sense is hypostatized. The procedure is in this case +very similar to that which has been discussed in our remarks on the +theological ideal.] + +But, it will be asked again, can we on these grounds, admit the +existence of a wise and omnipotent author of the world? Without doubt; +and not only so, but we must assume the existence of such a being. +But do we thus extend the limits of our knowledge beyond the field +of possible experience? By no means. For we have merely presupposed +a something, of which we have no conception, which we do not know as +it is in itself; but, in relation to the systematic disposition of +the universe, which we must presuppose in all our observation of nature, +we have cogitated this unknown being in analogy with an intelligent +existence (an empirical conception), that is to say, we have endowed +it with those attributes, which, judging from the nature of our own +reason, may contain the ground of such a systematic unity. This idea +is therefore valid only relatively to the employment in experience +of our reason. But if we attribute to it absolute and objective +validity, we overlook the fact that it is merely an ideal being that +we cogitate; and, by setting out from a basis which is not +determinable by considerations drawn from experience, we place +ourselves in a position which incapacitates us from applying this +principle to the empirical employment of reason. + +But, it will be asked further, can I make any use of this conception +and hypothesis in my investigations into the world and nature? Yes, +for this very purpose was the idea established by reason as a +fundamental basis. But may I regard certain arrangements, which seemed +to have been made in conformity with some fixed aim, as the +arrangements of design, and look upon them as proceeding from the +divine will, with the intervention, however, of certain other +particular arrangements disposed to that end? Yes, you may do so; +but at the same time you must regard it as indifferent, whether it +is asserted that divine wisdom has disposed all things in conformity +with his highest aims, or that the idea of supreme wisdom is a +regulative principle in the investigation of nature, and at the same +time a principle of the systematic unity of nature according to +general laws, even in those cases where we are unable to discover that +unity. In other words, it must be perfectly indifferent to you whether +you say, when you have discovered this unity: God has wisely willed +it so; or: Nature has wisely arranged this. For it was nothing but +the systematic unity, which reason requires as a basis for the +investigation of nature, that justified you in accepting the idea of +a supreme intelligence as a schema for a regulative principle; and, +the farther you advance in the discovery of design and finality, the +more certain the validity of your idea. But, as the whole aim of +this regulative principle was the discovery of a necessary and +systematic unity in nature, we have, in so far as we attain this, to +attribute our success to the idea of a Supreme Being; while, at the +same time, we cannot, without involving ourselves in contradictions, +overlook the general laws of nature, as it was in reference to them +alone that this idea was employed. We cannot, I say, overlook the +general laws of nature, and regard this conformity to aims +observable in nature as contingent or hyperphysical in its origin; +inasmuch as there is no ground which can justify us in the admission +of a being with such properties distinct from and above nature. All +that we are authorized to assert is that this idea may be employed +as a principle, and that the properties of the being which is +assumed to correspond to it may be regarded as systematically +connected in analogy with the causal determination of phenomena. + +For the same reasons we are justified in introducing into the idea +of the supreme cause other anthropomorphic elements (for without these +we could not predicate anything of it); we may regard it as +allowable to cogitate this cause as a being with understanding, the +feelings of pleasure and displeasure, and faculties of desire and will +corresponding to these. At the same time, we may attribute to this +being infinite perfection--a perfection which necessarily transcends +that which our knowledge of the order and design in the world +authorize us to predicate of it. For the regulative law of +systematic unity requires us to study nature on the supposition that +systematic and final unity in infinitum is everywhere discoverable, +even in the highest diversity. For, although we may discover little +of this cosmical perfection, it belongs to the legislative prerogative +of reason to require us always to seek for and to expect it; while +it must always be beneficial to institute all inquiries into nature +in accordance with this principle. But it is evident that, by this +idea of a supreme author of all, which I place as the foundation of +all inquiries into nature, I do not mean to assert the existence of +such a being, or that I have any knowledge of its existence; and, +consequently, I do not really deduce anything from the existence of +this being, but merely from its idea, that is to say, from the +nature of things in this world, in accordance with this idea. A +certain dim consciousness of the true use of this idea seems to have +dictated to the philosophers of all times the moderate language used +by them regarding the cause of the world. We find them employing the +expressions wisdom and care of nature, and divine wisdom, as +synonymous--nay, in purely speculative discussions, preferring the +former, because it does not carry the appearance of greater +pretensions than such as we are entitled to make, and at the same time +directs reason to its proper field of action--nature and her +phenomena. + +Thus, pure reason, which at first seemed to promise us nothing +less than the extension of our cognition beyond the limits of +experience, is found, when thoroughly examined, to contain nothing +but regulative principles, the virtue and function of which is to +introduce into our cognition a higher degree of unity than the +understanding could of itself. These principles, by placing the goal +of all our struggles at so great a distance, realize for us the most +thorough connection between the different parts of our cognition, +and the highest degree of systematic unity. But, on the other hand, +if misunderstood and employed as constitutive principles of +transcendent cognition, they become the parents of illusions and +contradictions, while pretending to introduce us to new regions of +knowledge. + +Thus all human cognition begins with intuitions, proceeds from +thence to conceptions, and ends with ideas. Although it possesses, +in relation to all three elements, a priori sources of cognition, +which seemed to transcend the limits of all experience, a +thoroughgoing criticism demonstrates that speculative reason can +never, by the aid of these elements, pass the bounds of possible +experience, and that the proper destination of this highest faculty +of cognition is to employ all methods, and all the principles of these +methods, for the purpose of penetrating into the innermost secrets +of nature, by the aid of the principles of unity (among all kinds of +which teleological unity is the highest), while it ought not to +attempt to soar above the sphere of experience, beyond which there +lies nought for us but the void inane. The critical examination, in +our Transcendental Analytic, of all the propositions which professed +to extend cognition beyond the sphere of experience, completely +demonstrated that they can only conduct us to a possible experience. +If we were not distrustful even of the clearest abstract theorems, +if we were not allured by specious and inviting prospects to escape +from the constraining power of their evidence, we might spare +ourselves the laborious examination of all the dialectical arguments +which a transcendent reason adduces in support of its pretensions; +for we should know with the most complete certainty that, however honest +such professions might be, they are null and valueless, because they +relate to a kind of knowledge to which no man can by any possibility +attain. But, as there is no end to discussion, if we cannot discover +the true cause of the illusions by which even the wisest are deceived, +and as the analysis of all our transcendent cognition into its +elements is of itself of no slight value as a psychological study, +while it is a duty incumbent on every philosopher--it was found +necessary to investigate the dialectical procedure of reason in its +primary sources. And as the inferences of which this dialectic is +the parent are not only deceitful, but naturally possess a profound +interest for humanity, it was advisable at the same time, to give a +full account of the momenta of this dialectical procedure, and to +deposit it in the archives of human reason, as a warning to all future +metaphysicians to avoid these causes of speculative error. + + + +II. + +TRANSCENDENTAL DOCTRINE OF METHOD. + +If we regard the sum of the cognition of pure speculative reason +as an edifice, the idea of which, at least, exists in the human +mind, it may be said that we have in the Transcendental Doctrine of +Elements examined the materials and determined to what edifice these +belong, and what its height and stability. We have found, indeed, +that, although we had purposed to build for ourselves a tower which +should reach to Heaven, the supply of materials sufficed merely for +a habitation, which was spacious enough for all terrestrial +purposes, and high enough to enable us to survey the level plain of +experience, but that the bold undertaking designed necessarily +failed for want of materials--not to mention the confusion of tongues, +which gave rise to endless disputes among the labourers on the plan +of the edifice, and at last scattered them over all the world, each +to erect a separate building for himself, according to his own plans +and his own inclinations. Our present task relates not to the +materials, but to the plan of an edifice; and, as we have had +sufficient warning not to venture blindly upon a design which may be +found to transcend our natural powers, while, at the same time, we +cannot give up the intention of erecting a secure abode for the +mind, we must proportion our design to the material which is presented +to us, and which is, at the same time, sufficient for all our wants. + +I understand, then, by the transcendental doctrine of method, the +determination of the formal conditions of a complete system of pure +reason. We shall accordingly have to treat of the discipline, the +canon, the architectonic, and, finally, the history of pure reason. +This part of our Critique will accomplish, from the transcendental +point of view, what has been usually attempted, but miserably +executed, under the name of practical logic. It has been badly +executed, I say, because general logic, not being limited to any +particular kind of cognition (not even to the pure cognition of the +understanding) nor to any particular objects, it cannot, without +borrowing from other sciences, do more than present merely the +titles or signs of possible methods and the technical expressions, +which are employed in the systematic parts of all sciences; and thus +the pupil is made acquainted with names, the meaning and application +of which he is to learn only at some future time. + + + +CHAPTER I. The Discipline of Pure Reason. + +Negative judgements--those which are so not merely as regards +their logical form, but in respect of their content--are not +commonly held in especial respect. They are, on the contrary, regarded +as jealous enemies of our insatiable desire for knowledge; and it +almost requires an apology to induce us to tolerate, much less to +prize and to respect them. + +All propositions, indeed, may be logically expressed in a negative +form; but, in relation to the content of our cognition, the peculiar +province of negative judgements is solely to prevent error. For this +reason, too, negative propositions, which are framed for the purpose +of correcting false cognitions where error is absolutely impossible, +are undoubtedly true, but inane and senseless; that is, they are in +reality purposeless and, for this reason, often very ridiculous. +Such is the proposition of the schoolman that Alexander could not have +subdued any countries without an army. + +But where the limits of our possible cognition are very much +contracted, the attraction to new fields of knowledge great, the +illusions to which the mind is subject of the most deceptive +character, and the evil consequences of error of no inconsiderable +magnitude--the negative element in knowledge, which is useful only +to guard us against error, is of far more importance than much of that +positive instruction which makes additions to the sum of our +knowledge. The restraint which is employed to repress, and finally +to extirpate the constant inclination to depart from certain rules, +is termed discipline. It is distinguished from culture, which aims +at the formation of a certain degree of skill, without attempting to +repress or to destroy any other mental power, already existing. In +the cultivation of a talent, which has given evidence of an impulse +towards self-development, discipline takes a negative,* culture and +doctrine a positive, part. + + +[*Footnote: I am well aware that, in the language of the schools, the +term discipline is usually employed as synonymous with instruction. +But there are so many cases in which it is necessary to distinguish +the notion of the former, as a course of corrective training, from +that of the latter, as the communication of knowledge, and the nature +of things itself demands the appropriation of the most suitable +expressions for this distinction, that it is my desire that the former +terms should never be employed in any other than a negative +signification.] + + +That natural dispositions and talents (such as imagination and wit), +which ask a free and unlimited development, require in many respects +the corrective influence of discipline, every one will readily +grant. But it may well appear strange that reason, whose proper duty +it is to prescribe rules of discipline to all the other powers of +the mind, should itself require this corrective. It has, in fact, +hitherto escaped this humiliation, only because, in presence of its +magnificent pretensions and high position, no one could readily +suspect it to be capable of substituting fancies for conceptions, +and words for things. + +Reason, when employed in the field of experience, does not stand +in need of criticism, because its principles are subjected to the +continual test of empirical observations. Nor is criticism requisite +in the sphere of mathematics, where the conceptions of reason must +always be presented in concreto in pure intuition, and baseless or +arbitrary assertions are discovered without difficulty. But where +reason is not held in a plain track by the influence of empirical or +of pure intuition, that is, when it is employed in the +transcendental sphere of pure conceptions, it stands in great need +of discipline, to restrain its propensity to overstep the limits of +possible experience and to keep it from wandering into error. In fact, +the utility of the philosophy of pure reason is entirely of this +negative character. Particular errors may be corrected by particular +animadversions, and the causes of these errors may be eradicated by +criticism. But where we find, as in the case of pure reason, a +complete system of illusions and fallacies, closely connected with +each other and depending upon grand general principles, there seems +to be required a peculiar and negative code of mental legislation, +which, under the denomination of a discipline, and founded upon the +nature of reason and the objects of its exercise, shall constitute +a system of thorough examination and testing, which no fallacy will +be able to withstand or escape from, under whatever disguise or +concealment it may lurk. + +But the reader must remark that, in this the second division of +our transcendental Critique the discipline of pure reason is not +directed to the content, but to the method of the cognition of pure +reason. The former task has been completed in the doctrine of +elements. But there is so much similarity in the mode of employing +the faculty of reason, whatever be the object to which it is applied, +while, at the same time, its employment in the transcendental sphere +is so essentially different in kind from every other, that, without +the warning negative influence of a discipline specially directed to +that end, the errors are unavoidable which spring from the +unskillful employment of the methods which are originated by reason +but which are out of place in this sphere. + + + +SECTION I. The Discipline of Pure Reason in the Sphere of Dogmatism. + +The science of mathematics presents the most brilliant example of +the extension of the sphere of pure reason without the aid of +experience. Examples are always contagious; and they exert an especial +influence on the same faculty, which naturally flatters itself that +it will have the same good fortune in other case as fell to its lot +in one fortunate instance. Hence pure reason hopes to be able to extend +its empire in the transcendental sphere with equal success and +security, especially when it applies the same method which was +attended with such brilliant results in the science of mathematics. +It is, therefore, of the highest importance for us to know whether +the method of arriving at demonstrative certainty, which is termed +mathematical, be identical with that by which we endeavour to attain +the same degree of certainty in philosophy, and which is termed in +that science dogmatical. + +Philosophical cognition is the cognition of reason by means of +conceptions; mathematical cognition is cognition by means of the +construction of conceptions. The construction of a conception is the +presentation a priori of the intuition which corresponds to the +conception. For this purpose a non-empirical intuition is requisite, +which, as an intuition, is an individual object; while, as the +construction of a conception (a general representation), it must be +seen to be universally valid for all the possible intuitions which +rank under that conception. Thus I construct a triangle, by the +presentation of the object which corresponds to this conception, +either by mere imagination, in pure intuition, or upon paper, in +empirical intuition, in both cases completely a priori, without +borrowing the type of that figure from any experience. The +individual figure drawn upon paper is empirical; but it serves, +notwithstanding, to indicate the conception, even in its universality, +because in this empirical intuition we keep our eye merely on the +act of the construction of the conception, and pay no attention to +the various modes of determining it, for example, its size, the length +of its sides, the size of its angles, these not in the least affecting +the essential character of the conception. + +Philosophical cognition, accordingly, regards the particular only in +the general; mathematical the general in the particular, nay, in the +individual. This is done, however, entirely a priori and by means of +pure reason, so that, as this individual figure is determined under +certain universal conditions of construction, the object of the +conception, to which this individual figure corresponds as its schema, +must be cogitated as universally determined. + +The essential difference of these two modes of cognition consists, +therefore, in this formal quality; it does not regard the difference +of the matter or objects of both. Those thinkers who aim at +distinguishing philosophy from mathematics by asserting that the +former has to do with quality merely, and the latter with quantity, +have mistaken the effect for the cause. The reason why mathematical +cognition can relate only to quantity is to be found in its form +alone. For it is the conception of quantities only that is capable +of being constructed, that is, presented a priori in intuition; +while qualities cannot be given in any other than an empirical +intuition. Hence the cognition of qualities by reason is possible only +through conceptions. No one can find an intuition which shall +correspond to the conception of reality, except in experience; it +cannot be presented to the mind a priori and antecedently to the +empirical consciousness of a reality. We can form an intuition, by +means of the mere conception of it, of a cone, without the aid of +experience; but the colour of the cone we cannot know except from +experience. I cannot present an intuition of a cause, except in an +example which experience offers to me. Besides, philosophy, as well +as mathematics, treats of quantities; as, for example, of totality, +infinity, and so on. Mathematics, too, treats of the difference of +lines and surfaces--as spaces of different quality, of the +continuity of extension--as a quality thereof. But, although in such +cases they have a common object, the mode in which reason considers +that object is very different in philosophy from what it is in +mathematics. The former confines itself to the general conceptions; +the latter can do nothing with a mere conception, it hastens to +intuition. In this intuition it regards the conception in concreto, +not empirically, but in an a priori intuition, which it has +constructed; and in which, all the results which follow from the +general conditions of the construction of the conception are in all +cases valid for the object of the constructed conception. + +Suppose that the conception of a triangle is given to a +philosopher and that he is required to discover, by the +philosophical method, what relation the sum of its angles bears to +a right angle. He has nothing before him but the conception of a +figure enclosed within three right lines, and, consequently, with +the same number of angles. He may analyse the conception of a right +line, of an angle, or of the number three as long as he pleases, but +he will not discover any properties not contained in these +conceptions. But, if this question is proposed to a geometrician, he +at once begins by constructing a triangle. He knows that two right +angles are equal to the sum of all the contiguous angles which proceed +from one point in a straight line; and he goes on to produce one +side of his triangle, thus forming two adjacent angles which are +together equal to two right angles. He then divides the exterior of +these angles, by drawing a line parallel with the opposite side of +the triangle, and immediately perceives that he has thus got an exterior +adjacent angle which is equal to the interior. Proceeding in this way, +through a chain of inferences, and always on the ground of +intuition, he arrives at a clear and universally valid solution of +the question. + +But mathematics does not confine itself to the construction of +quantities (quanta), as in the case of geometry; it occupies itself +with pure quantity also (quantitas), as in the case of algebra, +where complete abstraction is made of the properties of the object +indicated by the conception of quantity. In algebra, a certain +method of notation by signs is adopted, and these indicate the +different possible constructions of quantities, the extraction of +roots, and so on. After having thus denoted the general conception +of quantities, according to their different relations, the different +operations by which quantity or number is increased or diminished +are presented in intuition in accordance with general rules. Thus, +when one quantity is to be divided by another, the signs which +denote both are placed in the form peculiar to the operation of +division; and thus algebra, by means of a symbolical construction of +quantity, just as geometry, with its ostensive or geometrical +construction (a construction of the objects themselves), arrives at +results which discursive cognition cannot hope to reach by the aid +of mere conceptions. + +Now, what is the cause of this difference in the fortune of the +philosopher and the mathematician, the former of whom follows the path +of conceptions, while the latter pursues that of intuitions, which +he represents, a priori, in correspondence with his conceptions? The +cause is evident from what has been already demonstrated in the +introduction to this Critique. We do not, in the present case, want +to discover analytical propositions, which may be produced merely by +analysing our conceptions--for in this the philosopher would have +the advantage over his rival; we aim at the discovery of synthetical +propositions--such synthetical propositions, moreover, as can be +cognized a priori. I must not confine myself to that which I +actually cogitate in my conception of a triangle, for this is +nothing more than the mere definition; I must try to go beyond that, +and to arrive at properties which are not contained in, although +they belong to, the conception. Now, this is impossible, unless I +determine the object present to my mind according to the conditions, +either of empirical, or of pure, intuition. In the former case, I +should have an empirical proposition (arrived at by actual measurement +of the angles of the triangle), which would possess neither +universality nor necessity; but that would be of no value. In the +latter, I proceed by geometrical construction, by means of which I +collect, in a pure intuition, just as I would in an empirical +intuition, all the various properties which belong to the schema of +a triangle in general, and consequently to its conception, and thus +construct synthetical propositions which possess the attribute of +universality. + +It would be vain to philosophize upon the triangle, that is, to +reflect on it discursively; I should get no further than the +definition with which I had been obliged to set out. There are +certainly transcendental synthetical propositions which are framed +by means of pure conceptions, and which form the peculiar +distinction of philosophy; but these do not relate to any particular +thing, but to a thing in general, and enounce the conditions under +which the perception of it may become a part of possible experience. +But the science of mathematics has nothing to do with such +questions, nor with the question of existence in any fashion; it is +concerned merely with the properties of objects in themselves, only +in so far as these are connected with the conception of the objects. + +In the above example, we merely attempted to show the great +difference which exists between the discursive employment of reason +in the sphere of conceptions, and its intuitive exercise by means of +the construction of conceptions. The question naturally arises: What +is the cause which necessitates this twofold exercise of reason, and +how are we to discover whether it is the philosophical or the +mathematical method which reason is pursuing in an argument? + +All our knowledge relates, finally, to possible intuitions, for it +is these alone that present objects to the mind. An a priori or +non-empirical conception contains either a pure intuition--and in this +case it can be constructed; or it contains nothing but the synthesis +of possible intuitions, which are not given a priori. In this latter +case, it may help us to form synthetical a priori judgements, but only +in the discursive method, by conceptions, not in the intuitive, by +means of the construction of conceptions. + +The only a priori intuition is that of the pure form of phenomena- +space and time. A conception of space and time as quanta may be +presented a priori in intuition, that is, constructed, either alone +with their quality (figure), or as pure quantity (the mere synthesis +of the homogeneous), by means of number. But the matter of +phenomena, by which things are given in space and time, can be +presented only in perception, a posteriori. The only conception +which represents a priori this empirical content of phenomena is the +conception of a thing in general; and the a priori synthetical +cognition of this conception can give us nothing more than the rule +for the synthesis of that which may be contained in the +corresponding a posteriori perception; it is utterly inadequate to +present an a priori intuition of the real object, which must +necessarily be empirical. + +Synthetical propositions, which relate to things in general, an a +priori intuition of which is impossible, are transcendental. For +this reason transcendental propositions cannot be framed by means of +the construction of conceptions; they are a priori, and based entirely +on conceptions themselves. They contain merely the rule, by which we +are to seek in the world of perception or experience the synthetical +unity of that which cannot be intuited a priori. But they are +incompetent to present any of the conceptions which appear in them +in an a priori intuition; these can be given only a posteriori, in +experience, which, however, is itself possible only through these +synthetical principles. + +If we are to form a synthetical judgement regarding a conception, we +must go beyond it, to the intuition in which it is given. If we keep +to what is contained in the conception, the judgement is merely +analytical--it is merely an explanation of what we have cogitated in +the conception. But I can pass from the conception to the pure or +empirical intuition which corresponds to it. I can proceed to +examine my conception in concreto, and to cognize, either a priori +or a posterio, what I find in the object of the conception. The +former--a priori cognition--is rational-mathematical cognition by +means of the construction of the conception; the latter--a +posteriori cognition--is purely empirical cognition, which does not +possess the attributes of necessity and universality. Thus I may +analyse the conception I have of gold; but I gain no new information +from this analysis, I merely enumerate the different properties +which I had connected with the notion indicated by the word. My +knowledge has gained in logical clearness and arrangement, but no +addition has been made to it. But if I take the matter which is +indicated by this name, and submit it to the examination of my senses, +I am enabled to form several synthetical--although still empirical- +propositions. The mathematical conception of a triangle I should +construct, that is, present a priori in intuition, and in this way +attain to rational-synthetical cognition. But when the +transcendental conception of reality, or substance, or power is +presented to my mind, I find that it does not relate to or indicate +either an empirical or pure intuition, but that it indicates merely +the synthesis of empirical intuitions, which cannot of course be given +a priori. The synthesis in such a conception cannot proceed a +priori--without the aid of experience--to the intuition which +corresponds to the conception; and, for this reason, none of these +conceptions can produce a determinative synthetical proposition, +they can never present more than a principle of the synthesis* of +possible empirical intuitions. A transcendental proposition is, +therefore, a synthetical cognition of reason by means of pure +conceptions and the discursive method, and it renders possible all +synthetical unity in empirical cognition, though it cannot present +us with any intuition a priori. + + +[*Footnote: In the case of the conception of cause, I do really go +beyond the empirical conception of an event--but not to the intuition +which presents this conception in concreto, but only to the +time-conditions, which may be found in experience to correspond to +the conception. My procedure is, therefore, strictly according to +conceptions; I cannot in a case of this kind employ the construction +of conceptions, because the conception is merely a rule for the synthesis +of perceptions, which are not pure intuitions, and which, therefore, +cannot be given a priori.] + + +There is thus a twofold exercise of reason. Both modes have the +properties of universality and an a priori origin in common, but +are, in their procedure, of widely different character. The reason +of this is that in the world of phenomena, in which alone objects +are presented to our minds, there are two main elements--the form of +intuition (space and time), which can be cognized and determined +completely a priori, and the matter or content--that which is +presented in space and time, and which, consequently, contains a +something--an existence corresponding to our powers of sensation. As +regards the latter, which can never be given in a determinate mode +except by experience, there are no a priori notions which relate to +it, except the undetermined conceptions of the synthesis of possible +sensations, in so far as these belong (in a possible experience) to +the unity of consciousness. As regards the former, we can determine +our conceptions a priori in intuition, inasmuch as we are ourselves +the creators of the objects of the conceptions in space and time- +these objects being regarded simply as quanta. In the one case, reason +proceeds according to conceptions and can do nothing more than subject +phenomena to these--which can only be determined empirically, that +is, a posteriori--in conformity, however, with those conceptions as +the rules of all empirical synthesis. In the other case, reason proceeds +by the construction of conceptions; and, as these conceptions relate +to an a priori intuition, they may be given and determined in pure +intuition a priori, and without the aid of empirical data. The +examination and consideration of everything that exists in space or +time--whether it is a quantum or not, in how far the particular +something (which fills space or time) is a primary substratum, or a +mere determination of some other existence, whether it relates to +anything else--either as cause or effect, whether its existence is +isolated or in reciprocal connection with and dependence upon +others, the possibility of this existence, its reality and necessity +or opposites--all these form part of the cognition of reason on the +ground of conceptions, and this cognition is termed philosophical. +But to determine a priori an intuition in space (its figure), to divide +time into periods, or merely to cognize the quantity of an intuition +in space and time, and to determine it by number--all this is an +operation of reason by means of the construction of conceptions, and +is called mathematical. + +The success which attends the efforts of reason in the sphere of +mathematics naturally fosters the expectation that the same good +fortune will be its lot, if it applies the mathematical method in +other regions of mental endeavour besides that of quantities. Its +success is thus great, because it can support all its conceptions by +a priori intuitions and, in this way, make itself a master, as it +were, over nature; while pure philosophy, with its a priori discursive +conceptions, bungles about in the world of nature, and cannot accredit +or show any a priori evidence of the reality of these conceptions. +Masters in the science of mathematics are confident of the success +of this method; indeed, it is a common persuasion that it is capable +of being applied to any subject of human thought. They have hardly +ever reflected or philosophized on their favourite science--a task +of great difficulty; and the specific difference between the two modes +of employing the faculty of reason has never entered their thoughts. +Rules current in the field of common experience, and which common +sense stamps everywhere with its approval, are regarded by them as +axiomatic. From what source the conceptions of space and time, with +which (as the only primitive quanta) they have to deal, enter their +minds, is a question which they do not trouble themselves to answer; +and they think it just as unnecessary to examine into the origin of +the pure conceptions of the understanding and the extent of their +validity. All they have to do with them is to employ them. In all this +they are perfectly right, if they do not overstep the limits of the +sphere of nature. But they pass, unconsciously, from the world of +sense to the insecure ground of pure transcendental conceptions +(instabilis tellus, innabilis unda), where they can neither stand +nor swim, and where the tracks of their footsteps are obliterated by +time; while the march of mathematics is pursued on a broad and +magnificent highway, which the latest posterity shall frequent without +fear of danger or impediment. + +As we have taken upon us the task of determining, clearly and +certainly, the limits of pure reason in the sphere of +transcendentalism, and as the efforts of reason in this direction +are persisted in, even after the plainest and most expressive +warnings, hope still beckoning us past the limits of experience into +the splendours of the intellectual world--it becomes necessary to +cut away the last anchor of this fallacious and fantastic hope. We +shall, accordingly, show that the mathematical method is unattended +in the sphere of philosophy by the least advantage--except, perhaps, +that it more plainly exhibits its own inadequacy--that geometry and +philosophy are two quite different things, although they go band in +hand in hand in the field of natural science, and, consequently, +that the procedure of the one can never be imitated by the other. + +The evidence of mathematics rests upon definitions, axioms, and +demonstrations. I shall be satisfied with showing that none of these +forms can be employed or imitated in philosophy in the sense in +which they are understood by mathematicians; and that the +geometrician, if he employs his method in philosophy, will succeed +only in building card-castles, while the employment of the +philosophical method in mathematics can result in nothing but mere +verbiage. The essential business of philosophy, indeed, is to mark +out the limits of the science; and even the mathematician, unless his +talent is naturally circumscribed and limited to this particular +department of knowledge, cannot turn a deaf ear to the warnings of +philosophy, or set himself above its direction. + +I. Of Definitions. A definition is, as the term itself indicates, +the representation, upon primary grounds, of the complete conception +of a thing within its own limits.* Accordingly, an empirical +conception cannot be defined, it can only be explained. For, as +there are in such a conception only a certain number of marks or +signs, which denote a certain class of sensuous objects, we can +never be sure that we do not cogitate under the word which indicates +the same object, at one time a greater, at another a smaller number +of signs. Thus, one person may cogitate in his conception of gold, +in addition to its properties of weight, colour, malleability, that +of resisting rust, while another person may be ignorant of this +quality. We employ certain signs only so long as we require them for +the sake of distinction; new observations abstract some and add new +ones, so that an empirical conception never remains within permanent +limits. It is, in fact, useless to define a conception of this kind. +If, for example, we are speaking of water and its properties, we do +not stop at what we actually think by the word water, but proceed to +observation and experiment; and the word, with the few signs +attached to it, is more properly a designation than a conception of +the thing. A definition in this case would evidently be nothing more +than a determination of the word. In the second place, no a priori +conception, such as those of substance, cause, right, fitness, and +so on, can be defined. For I can never be sure, that the clear +representation of a given conception (which is given in a confused +state) has been fully developed, until I know that the +representation is adequate with its object. But, inasmuch as the +conception, as it is presented to the mind, may contain a number of +obscure representations, which we do not observe in our analysis, +although we employ them in our application of the conception, I can +never be sure that my analysis is complete, while examples may make +this probable, although they can never demonstrate the fact. Instead +of the word definition, I should rather employ the term exposition-- +a more modest expression, which the critic may accept without +surrendering his doubts as to the completeness of the analysis of +any such conception. As, therefore, neither empirical nor a priori +conceptions are capable of definition, we have to see whether the only +other kind of conceptions--arbitrary conceptions--can be subjected +to this mental operation. Such a conception can always be defined; +for I must know thoroughly what I wished to cogitate in it, as it was +I who created it, and it was not given to my mind either by the nature +of my understanding or by experience. At the same time, I cannot say +that, by such a definition, I have defined a real object. If the +conception is based upon empirical conditions, if, for example, I have +a conception of a clock for a ship, this arbitrary conception does +not assure me of the existence or even of the possibility of the object. +My definition of such a conception would with more propriety be termed +a declaration of a project than a definition of an object. There +are no other conceptions which can bear definition, except those which +contain an arbitrary synthesis, which can be constructed a priori. +Consequently, the science of mathematics alone possesses +definitions. For the object here thought is presented a priori in +intuition; and thus it can never contain more or less than the +conception, because the conception of the object has been given by +the definition--and primarily, that is, without deriving the definition +from any other source. Philosophical definitions are, therefore, +merely expositions of given conceptions, while mathematical +definitions are constructions of conceptions originally formed by +the mind itself; the former are produced by analysis, the completeness +of which is never demonstratively certain, the latter by a +synthesis. In a mathematical definition the conception is formed, in +a philosophical definition it is only explained. From this it follows: + +[*Footnote: The definition must describe the conception completely +that is, omit none of the marks or signs of which it composed; within +its own limits, that is, it must be precise, and enumerate no more +signs than belong to the conception; and on primary grounds, that is +to say, the limitations of the bounds of the conception must not be +deduced from other conceptions, as in this case a proof would be necessary, +and the so-called definition would be incapable of taking its place +at the bead of all the judgements we have to form regarding an object.] + +(a) That we must not imitate, in philosophy, the mathematical +usage of commencing with definitions--except by way of hypothesis or +experiment. For, as all so-called philosophical definitions are merely +analyses of given conceptions, these conceptions, although only in +a confused form, must precede the analysis; and the incomplete +exposition must precede the complete, so that we may be able to draw +certain inferences from the characteristics which an incomplete +analysis has enabled us to discover, before we attain to the +complete exposition or definition of the conception. In one word, a +full and clear definition ought, in philosophy, rather to form the +conclusion than the commencement of our labours.* In mathematics, on +the contrary, we cannot have a conception prior to the definition; +it is the definition which gives us the conception, and it must for +this reason form the commencement of every chain of mathematical +reasoning. + +[*Footnote: Philosophy abounds in faulty definitions, especially such +as contain some of the elements requisite to form a complete +definition. If a conception could not be employed in reasoning +before it had been defined, it would fare ill with all philosophical +thought. But, as incompletely defined conceptions may always be +employed without detriment to truth, so far as our analysis of the +elements contained in them proceeds, imperfect definitions, that is, +propositions which are properly not definitions, but merely +approximations thereto, may be used with great advantage. In +mathematics, definition belongs ad esse, in philosophy ad melius esse. +It is a difficult task to construct a proper definition. Jurists are +still without a complete definition of the idea of right.] + +(b) Mathematical definitions cannot be erroneous. For the conception +is given only in and through the definition, and thus it contains only +what has been cogitated in the definition. But although a definition +cannot be incorrect, as regards its content, an error may sometimes, +although seldom, creep into the form. This error consists in a want +of precision. Thus the common definition of a circle--that it is a +curved line, every point in which is equally distant from another point +called the centre--is faulty, from the fact that the determination +indicated by the word curved is superfluous. For there ought to be +a particular theorem, which may be easily proved from the definition, +to the effect that every line, which has all its points at equal +distances from another point, must be a curved line--that is, that +not even the smallest part of it can be straight. Analytical +definitions, on the other hand, may be erroneous in many respects, +either by the introduction of signs which do not actually exist in +the conception, or by wanting in that completeness which forms the +essential of a definition. In the latter case, the definition is +necessarily defective, because we can never be fully certain of the +completeness of our analysis. For these reasons, the method of +definition employed in mathematics cannot be imitated in philosophy. + +2. Of Axioms. These, in so far as they are immediately certain, +are a priori synthetical principles. Now, one conception cannot be +connected synthetically and yet immediately with another; because, +if we wish to proceed out of and beyond a conception, a third +mediating cognition is necessary. And, as philosophy is a cognition +of reason by the aid of conceptions alone, there is to be found in +it no principle which deserves to be called an axiom. Mathematics, +on the other hand, may possess axioms, because it can always connect +the predicates of an object a priori, and without any mediating term, +by means of the construction of conceptions in intuition. Such is the +case with the proposition: Three points can always lie in a plane. +On the other hand, no synthetical principle which is based upon +conceptions, can ever be immediately certain (for example, the +proposition: Everything that happens has a cause), because I require +a mediating term to connect the two conceptions of event and cause- +namely, the condition of time-determination in an experience, and I +cannot cognize any such principle immediately and from conceptions +alone. Discursive principles are, accordingly, very different from +intuitive principles or axioms. The former always require deduction, +which in the case of the latter may be altogether dispensed with. +Axioms are, for this reason, always self-evident, while +philosophical principles, whatever may be the degree of certainty they +possess, cannot lay any claim to such a distinction. No synthetical +proposition of pure transcendental reason can be so evident, as is +often rashly enough declared, as the statement, twice two are four. +It is true that in the Analytic I introduced into the list of +principles of the pure understanding, certain axioms of intuition; +but the principle there discussed was not itself an axiom, but served +merely to present the principle of the possibility of axioms in +general, while it was really nothing more than a principle based +upon conceptions. For it is one part of the duty of transcendental +philosophy to establish the possibility of mathematics itself. +Philosophy possesses, then, no axioms, and has no right to impose +its a priori principles upon thought, until it has established their +authority and validity by a thoroughgoing deduction. + +3. Of Demonstrations. Only an apodeictic proof, based upon +intuition, can be termed a demonstration. Experience teaches us what +is, but it cannot convince us that it might not have been otherwise. +Hence a proof upon empirical grounds cannot be apodeictic. A priori +conceptions, in discursive cognition, can never produce intuitive +certainty or evidence, however certain the judgement they present +may be. Mathematics alone, therefore, contains demonstrations, because +it does not deduce its cognition from conceptions, but from the +construction of conceptions, that is, from intuition, which can be +given a priori in accordance with conceptions. The method of +algebra, in equations, from which the correct answer is deduced by +reduction, is a kind of construction--not geometrical, but by symbols- +in which all conceptions, especially those of the relations of +quantities, are represented in intuition by signs; and thus the +conclusions in that science are secured from errors by the fact that +every proof is submitted to ocular evidence. Philosophical cognition +does not possess this advantage, it being required to consider the +general always in abstracto (by means of conceptions), while +mathematics can always consider it in concreto (in an individual +intuition), and at the same time by means of a priori +representation, whereby all errors are rendered manifest to the +senses. The former--discursive proofs--ought to be termed acroamatic +proofs, rather than demonstrations, as only words are employed in +them, while demonstrations proper, as the term itself indicates, +always require a reference to the intuition of the object. + +It follows from all these considerations that it is not consonant +with the nature of philosophy, especially in the sphere of pure +reason, to employ the dogmatical method, and to adorn itself with +the titles and insignia of mathematical science. It does not belong +to that order, and can only hope for a fraternal union with that science. +Its attempts at mathematical evidence are vain pretensions, which +can only keep it back from its true aim, which is to detect the +illusory procedure of reason when transgressing its proper limits, +and by fully explaining and analysing our conceptions, to conduct us +from the dim regions of speculation to the clear region of modest +self-knowledge. Reason must not, therefore, in its transcendental +endeavours, look forward with such confidence, as if the path it is +pursuing led straight to its aim, nor reckon with such security upon +its premisses, as to consider it unnecessary to take a step back, or +to keep a strict watch for errors, which, overlooked in the +principles, may be detected in the arguments themselves--in which case +it may be requisite either to determine these principles with +greater strictness, or to change them entirely. + +I divide all apodeictic propositions, whether demonstrable or +immediately certain, into dogmata and mathemata. A direct +synthetical proposition, based on conceptions, is a dogma; a +proposition of the same kind, based on the construction of +conceptions, is a mathema. Analytical judgements do not teach us any +more about an object than what was contained in the conception we +had of it; because they do not extend our cognition beyond our +conception of an object, they merely elucidate the conception. They +cannot therefore be with propriety termed dogmas. Of the two kinds +of a priori synthetical propositions above mentioned, only those which +are employed in philosophy can, according to the general mode of +speech, bear this name; those of arithmetic or geometry would not be +rightly so denominated. Thus the customary mode of speaking confirms +the explanation given above, and the conclusion arrived at, that +only those judgements which are based upon conceptions, not on the +construction of conceptions, can be termed dogmatical. + +Thus, pure reason, in the sphere of speculation, does not contain +a single direct synthetical judgement based upon conceptions. By means +of ideas, it is, as we have shown, incapable of producing +synthetical judgements, which are objectively valid; by means of the +conceptions of the understanding, it establishes certain indubitable +principles, not, however, directly on the basis of conceptions, but +only indirectly by means of the relation of these conceptions to +something of a purely contingent nature, namely, possible +experience. When experience is presupposed, these principles are +apodeictically certain, but in themselves, and directly, they cannot +even be cognized a priori. Thus the given conceptions of cause and +event will not be sufficient for the demonstration of the proposition: +Every event has a cause. For this reason, it is not a dogma; +although from another point of view, that of experience, it is capable +of being proved to demonstration. The proper term for such a +proposition is principle, and not theorem (although it does require +to be proved), because it possesses the remarkable peculiarity of being +the condition of the possibility of its own ground of proof, that +is, experience, and of forming a necessary presupposition in all +empirical observation. + +If then, in the speculative sphere of pure reason, no dogmata are to +be found; all dogmatical methods, whether borrowed from mathematics, +or invented by philosophical thinkers, are alike inappropriate and +inefficient. They only serve to conceal errors and fallacies, and to +deceive philosophy, whose duty it is to see that reason pursues a safe +and straight path. A philosophical method may, however, be +systematical. For our reason is, subjectively considered, itself a +system, and, in the sphere of mere conceptions, a system of +investigation according to principles of unity, the material being +supplied by experience alone. But this is not the proper place for +discussing the peculiar method of transcendental philosophy, as our +present task is simply to examine whether our faculties are capable +of erecting an edifice on the basis of pure reason, and how far they +may proceed with the materials at their command. + + + +SECTION II. The Discipline of Pure Reason in Polemics. + +Reason must be subject, in all its operations, to criticism, which +must always be permitted to exercise its functions without +restraint; otherwise its interests are imperilled and its influence +obnoxious to suspicion. There is nothing, however useful, however +sacred it may be, that can claim exemption from the searching +examination of this supreme tribunal, which has no respect of persons. +The very existence of reason depends upon this freedom; for the +voice of reason is not that of a dictatorial and despotic power, it +is rather like the vote of the citizens of a free state, every member +of which must have the privilege of giving free expression to his +doubts, and possess even the right of veto. + +But while reason can never decline to submit itself to the +tribunal of criticism, it has not always cause to dread the +judgement of this court. Pure reason, however, when engaged in the +sphere of dogmatism, is not so thoroughly conscious of a strict +observance of its highest laws, as to appear before a higher +judicial reason with perfect confidence. On the contrary, it must +renounce its magnificent dogmatical pretensions in philosophy. + +Very different is the case when it has to defend itself, not +before a judge, but against an equal. If dogmatical assertions are +advanced on the negative side, in opposition to those made by reason +on the positive side, its justification kat authrhopon is complete, +although the proof of its propositions is kat aletheian +unsatisfactory. + +By the polemic of pure reason I mean the defence of its propositions +made by reason, in opposition to the dogmatical counter-propositions +advanced by other parties. The question here is not whether its own +statements may not also be false; it merely regards the fact that +reason proves that the opposite cannot be established with +demonstrative certainty, nor even asserted with a higher degree of +probability. Reason does not hold her possessions upon sufferance; +for, although she cannot show a perfectly satisfactory title to +them, no one can prove that she is not the rightful possessor. + +It is a melancholy reflection that reason, in its highest +exercise, falls into an antithetic; and that the supreme tribunal +for the settlement of differences should not be at union with +itself. It is true that we had to discuss the question of an +apparent antithetic, but we found that it was based upon a +misconception. In conformity with the common prejudice, phenomena were +regarded as things in themselves, and thus an absolute completeness +in their synthesis was required in the one mode or in the other (it +was shown to be impossible in both); a demand entirely out of place +in regard to phenomena. There was, then, no real self-contradiction +of reason in the propositions: The series of phenomena given in +themselves has an absolutely first beginning; and: This series is +absolutely and in itself without beginning. The two propositions are +perfectly consistent with each other, because phenomena as phenomena +are in themselves nothing, and consequently the hypothesis that they +are things in themselves must lead to self-contradictory inferences. + +But there are cases in which a similar misunderstanding cannot be +provided against, and the dispute must remain unsettled. Take, for +example, the theistic proposition: There is a Supreme Being; and on +the other hand, the atheistic counter-statement: There exists no +Supreme Being; or, in psychology: Everything that thinks possesses +the attribute of absolute and permanent unity, which is utterly +different from the transitory unity of material phenomena; and the +counter-proposition: The soul is not an immaterial unity, and its +nature is transitory, like that of phenomena. The objects of these +questions contain no heterogeneous or contradictory elements, for they +relate to things in themselves, and not to phenomena. There would +arise, indeed, a real contradiction, if reason came forward with a +statement on the negative side of these questions alone. As regards +the criticism to which the grounds of proof on the affirmative side +must be subjected, it may be freely admitted, without necessitating +the surrender of the affirmative propositions, which have, at least, +the interest of reason in their favour--an advantage which the +opposite party cannot lay claim to. + +I cannot agree with the opinion of several admirable thinkers--Sulzer +among the rest--that, in spite of the weakness of the arguments +hitherto in use, we may hope, one day, to see sufficient demonstrations +of the two cardinal propositions of pure reason--the existence of a +Supreme Being, and the immortality of the soul. I am certain, on the +contrary, that this will never be the case. For on what ground can +reason base such synthetical propositions, which do not relate to the +objects of experience and their internal possibility? But it is also +demonstratively certain that no one will ever be able to maintain the +contrary with the least show of probability. For, as he can attempt +such a proof solely upon the basis of pure reason, he is bound to prove +that a Supreme Being, and a thinking subject in the character of a pure +intelligence, are impossible. But where will he find the knowledge +which can enable him to enounce synthetical judgements in regard to +things which transcend the region of experience? We may, therefore, +rest assured that the opposite never will be demonstrated. We need not, +then, have recourse to scholastic arguments; we may always admit the +truth of those propositions which are consistent with the speculative +interests of reason in the sphere of experience, and form, moreover, +the only means of uniting the speculative with the practical interest. +Our opponent, who must not be considered here as a critic solely, we +can be ready to meet with a non liquet which cannot fail to disconcert +him; while we cannot deny his right to a similar retort, as we have on +our side the advantage of the support of the subjective maxim of +reason, and can therefore look upon all his sophistical arguments with +calm indifference. + +From this point of view, there is properly no antithetic of pure +reason. For the only arena for such a struggle would be upon the field +of pure theology and psychology; but on this ground there can appear +no combatant whom we need to fear. Ridicule and boasting can be his +only weapons; and these may be laughed at, as mere child's play. +This consideration restores to Reason her courage; for what source +of confidence could be found, if she, whose vocation it is to +destroy error, were at variance with herself and without any +reasonable hope of ever reaching a state of permanent repose? + +Everything in nature is good for some purpose. Even poisons are +serviceable; they destroy the evil effects of other poisons generated +in our system, and must always find a place in every complete +pharmacopoeia. The objections raised against the fallacies and +sophistries of speculative reason, are objections given by the nature +of this reason itself, and must therefore have a destination and +purpose which can only be for the good of humanity. For what purpose +has Providence raised many objects, in which we have the deepest +interest, so far above us, that we vainly try to cognize them with +certainty, and our powers of mental vision are rather excited than +satisfied by the glimpses we may chance to seize? It is very doubtful +whether it is for our benefit to advance bold affirmations regarding +subjects involved in such obscurity; perhaps it would even be +detrimental to our best interests. But it is undoubtedly always +beneficial to leave the investigating, as well as the critical reason, +in perfect freedom, and permit it to take charge of its own interests, +which are advanced as much by its limitation, as by its extension of +its views, and which always suffer by the interference of foreign +powers forcing it, against its natural tendencies, to bend to certain +preconceived designs. + +Allow your opponent to say what he thinks reasonable, and combat him +only with the weapons of reason. Have no anxiety for the practical +interests of humanity--these are never imperilled in a purely +speculative dispute. Such a dispute serves merely to disclose the +antinomy of reason, which, as it has its source in the nature of +reason, ought to be thoroughly investigated. Reason is benefited by +the examination of a subject on both sides, and its judgements are +corrected by being limited. It is not the matter that may give +occasion to dispute, but the manner. For it is perfectly permissible +to employ, in the presence of reason, the language of a firmly +rooted faith, even after we have been obliged to renounce all +pretensions to knowledge. + +If we were to ask the dispassionate David Hume--a philosopher +endowed, in a degree that few are, with a well-balanced judgement: +What motive induced you to spend so much labour and thought in +undermining the consoling and beneficial persuasion that reason is +capable of assuring us of the existence, and presenting us with a +determinate conception of a Supreme Being?--his answer would be: +Nothing but the desire of teaching reason to know its own powers +better, and, at the same time, a dislike of the procedure by which +that faculty was compelled to support foregone conclusions, and +prevented from confessing the internal weaknesses which it cannot +but feel when it enters upon a rigid self-examination. If, on the +other hand, we were to ask Priestley--a philosopher who had no taste +for transcendental speculation, but was entirely devoted to the +principles of empiricism--what his motives were for overturning +those two main pillars of religion--the doctrines of the freedom of +the will and the immortality of the soul (in his view the hope of a +future life is but the expectation of the miracle of resurrection)- +this philosopher, himself a zealous and pious teacher of religion, +could give no other answer than this: I acted in the interest of +reason, which always suffers, when certain objects are explained and +judged by a reference to other supposed laws than those of material +nature--the only laws which we know in a determinate manner. It +would be unfair to decry the latter philosopher, who endeavoured to +harmonize his paradoxical opinions with the interests of religion, +and to undervalue an honest and reflecting man, because he finds himself +at a loss the moment he has left the field of natural science. The +same grace must be accorded to Hume, a man not less well-disposed, +and quite as blameless in his moral character, and who pushed his abstract +speculations to an extreme length, because, as he rightly believed, +the object of them lies entirely beyond the bounds of natural science, +and within the sphere of pure ideas. + +What is to be done to provide against the danger which seems in +the present case to menace the best interests of humanity? The +course to be pursued in reference to this subject is a perfectly plain +and natural one. Let each thinker pursue his own path; if he shows +talent, if he gives evidence of profound thought, in one word, if he +shows that he possesses the power of reasoning--reason is always the +gainer. If you have recourse to other means, if you attempt to +coerce reason, if you raise the cry of treason to humanity, if you +excite the feelings of the crowd, which can neither understand nor +sympathize with such subtle speculations--you will only make +yourselves ridiculous. For the question does not concern the advantage +or disadvantage which we are expected to reap from such inquiries; +the question is merely how far reason can advance in the field of +speculation, apart from all kinds of interest, and whether we may +depend upon the exertions of speculative reason, or must renounce +all reliance on it. Instead of joining the combatants, it is your part +to be a tranquil spectator of the struggle--a laborious struggle for +the parties engaged, but attended, in its progress as well as in its +result, with the most advantageous consequences for the interests of +thought and knowledge. It is absurd to expect to be enlightened by +Reason, and at the same time to prescribe to her what side of the +question she must adopt. Moreover, reason is sufficiently held in +check by its own power, the limits imposed on it by its own nature +are sufficient; it is unnecessary for you to place over it additional +guards, as if its power were dangerous to the constitution of the +intellectual state. In the dialectic of reason there is no victory +gained which need in the least disturb your tranquility. + +The strife of dialectic is a necessity of reason, and we cannot +but wish that it had been conducted long ere this with that perfect +freedom which ought to be its essential condition. In this case, we +should have had at an earlier period a matured and profound criticism, +which must have put an end to all dialectical disputes, by exposing +the illusions and prejudices in which they originated. + +There is in human nature an unworthy propensity--a propensity which, +like everything that springs from nature, must in its final purpose +be conducive to the good of humanity--to conceal our real sentiments, +and to give expression only to certain received opinions, which are +regarded as at once safe and promotive of the common good. It is true, +this tendency, not only to conceal our real sentiments, but to profess +those which may gain us favour in the eyes of society, has not only +civilized, but, in a certain measure, moralized us; as no one can +break through the outward covering of respectability, honour, and +morality, and thus the seemingly-good examples which we which we see +around us form an excellent school for moral improvement, so long as +our belief in their genuineness remains unshaken. But this disposition +to represent ourselves as better than we are, and to utter opinions +which are not our own, can be nothing more than a kind of provisionary +arrangement of nature to lead us from the rudeness of an uncivilized +state, and to teach us how to assume at least the appearance and +manner of the good we see. But when true principles have been +developed, and have obtained a sure foundation in our habit of +thought, this conventionalism must be attacked with earnest vigour, +otherwise it corrupts the heart, and checks the growth of good +dispositions with the mischievous weed of air appearances. + +I am sorry to remark the same tendency to misrepresentation and +hypocrisy in the sphere of speculative discussion, where there is less +temptation to restrain the free expression of thought. For what can +be more prejudicial to the interests of intelligence than to falsify +our real sentiments, to conceal the doubts which we feel in regard +to our statements, or to maintain the validity of grounds of proof +which we well know to be insufficient? So long as mere personal vanity +is the source of these unworthy artifices--and this is generally the +case in speculative discussions, which are mostly destitute of +practical interest, and are incapable of complete demonstration--the +vanity of the opposite party exaggerates as much on the other side; +and thus the result is the same, although it is not brought about so +soon as if the dispute had been conducted in a sincere and upright +spirit. But where the mass entertains the notion that the aim of +certain subtle speculators is nothing less than to shake the very +foundations of public welfare and morality--it seems not only prudent, +but even praise worthy, to maintain the good cause by illusory +arguments, rather than to give to our supposed opponents the advantage +of lowering our declarations to the moderate tone of a merely +practical conviction, and of compelling us to confess our inability +to attain to apodeictic certainty in speculative subjects. But we ought +to reflect that there is nothing, in the world more fatal to the +maintenance of a good cause than deceit, misrepresentation, and +falsehood. That the strictest laws of honesty should be observed in +the discussion of a purely speculative subject is the least +requirement that can be made. If we could reckon with security even +upon so little, the conflict of speculative reason regarding the +important questions of God, immortality, and freedom, would have +been either decided long ago, or would very soon be brought to a +conclusion. But, in general, the uprightness of the defence stands +in an inverse ratio to the goodness of the cause; and perhaps more +honesty and fairness are shown by those who deny than by those who +uphold these doctrines. + +I shall persuade myself, then, that I have readers who do not wish +to see a righteous cause defended by unfair arguments. Such will now +recognize the fact that, according to the principles of this Critique, +if we consider not what is, but what ought to be the case, there can +be really no polemic of pure reason. For how can two persons dispute +about a thing, the reality of which neither can present in actual or +even in possible experience? Each adopts the plan of meditating on +his idea for the purpose of drawing from the idea, if he can, what +is more than the idea, that is, the reality of the object which it +indicates. How shall they settle the dispute, since neither is able +to make his assertions directly comprehensible and certain, but must +restrict himself to attacking and confuting those of his opponent? +All statements enounced by pure reason transcend the conditions of +possible experience, beyond the sphere of which we can discover no +criterion of truth, while they are at the same time framed in +accordance with the laws of the understanding, which are applicable +only to experience; and thus it is the fate of all such speculative +discussions that while the one party attacks the weaker side of his +opponent, he infallibly lays open his own weaknesses. + +The critique of pure reason may be regarded as the highest +tribunal for all speculative disputes; for it is not involved in these +disputes, which have an immediate relation to certain objects and +not to the laws of the mind, but is instituted for the purpose of +determining the rights and limits of reason. + +Without the control of criticism, reason is, as it were, in a +state of nature, and can only establish its claims and assertions by +war. Criticism, on the contrary, deciding all questions according to +the fundamental laws of its own institution, secures to us the peace +of law and order, and enables us to discuss all differences in the +more tranquil manner of a legal process. In the former case, +disputes are ended by victory, which both sides may claim and which +is followed by a hollow armistice; in the latter, by a sentence, which, +as it strikes at the root of all speculative differences, ensures to +all concerned a lasting peace. The endless disputes of a dogmatizing +reason compel us to look for some mode of arriving at a settled +decision by a critical investigation of reason itself; just as +Hobbes maintains that the state of nature is a state of injustice +and violence, and that we must leave it and submit ourselves to the +constraint of law, which indeed limits individual freedom, but only +that it may consist with the freedom of others and with the common +good of all. + +This freedom will, among other things, permit of our openly +stating the difficulties and doubts which we are ourselves unable to +solve, without being decried on that account as turbulent and +dangerous citizens. This privilege forms part of the native rights +of human reason, which recognizes no other judge than the universal +reason of humanity; and as this reason is the source of all progress +and improvement, such a privilege is to be held sacred and inviolable. +It is unwise, moreover, to denounce as dangerous any bold assertions +against, or rash attacks upon, an opinion which is held by the largest +and most moral class of the community; for that would be giving them +an importance which they do not deserve. When I hear that the +freedom of the will, the hope of a future life, and the existence of +God have been overthrown by the arguments of some able writer, I +feel a strong desire to read his book; for I expect that he will add +to my knowledge and impart greater clearness and distinctness to my +views by the argumentative power shown in his writings. But I am +perfectly certain, even before I have opened the book, that he has +not succeeded in a single point, not because I believe I am in +possession of irrefutable demonstrations of these important +propositions, but because this transcendental critique, which has +disclosed to me the power and the limits of pure reason, has fully +convinced me that, as it is insufficient to establish the affirmative, +it is as powerless, and even more so, to assure us of the truth of +the negative answer to these questions. From what source does this +free-thinker derive his knowledge that there is, for example, no +Supreme Being? This proposition lies out of the field of possible +experience, and, therefore, beyond the limits of human cognition. +But I would not read at, all the answer which the dogmatical +maintainer of the good cause makes to his opponent, because I know +well beforehand, that he will merely attack the fallacious grounds +of his adversary, without being able to establish his own +assertions. Besides, a new illusory argument, in the construction of +which talent and acuteness are shown, is suggestive of new ideas and +new trains of reasoning, and in this respect the old and everyday +sophistries are quite useless. Again, the dogmatical opponent of +religion gives employment to criticism, and enables us to test and +correct its principles, while there is no occasion for anxiety in +regard to the influence and results of his reasoning. + +But, it will be said, must we not warn the youth entrusted to +academical care against such writings, must we not preserve them +from the knowledge of these dangerous assertions, until their +judgement is ripened, or rather until the doctrines which we wish to +inculcate are so firmly rooted in their minds as to withstand all +attempts at instilling the contrary dogmas, from whatever quarter they +may come? + +If we are to confine ourselves to the dogmatical procedure in the +sphere of pure reason, and find ourselves unable to settle such +disputes otherwise than by becoming a party in them, and setting +counter-assertions against the statements advanced by our opponents, +there is certainly no plan more advisable for the moment, but, at +the same time, none more absurd and inefficient for the future, than +this retaining of the youthful mind under guardianship for a time, +and thus preserving it--for so long at least--from seduction into error. +But when, at a later period, either curiosity, or the prevalent +fashion of thought places such writings in their hands, will the +so-called convictions of their youth stand firm? The young thinker, +who has in his armoury none but dogmatical weapons with which to +resist the attacks of his opponent, and who cannot detect the latent +dialectic which lies in his own opinions as well as in those of the +opposite party, sees the advance of illusory arguments and grounds +of proof which have the advantage of novelty, against as illusory +grounds of proof destitute of this advantage, and which, perhaps, +excite the suspicion that the natural credulity of his youth has +been abused by his instructors. He thinks he can find no better +means of showing that he has out grown the discipline of his +minority than by despising those well-meant warnings, and, knowing +no system of thought but that of dogmatism, he drinks deep draughts +of the poison that is to sap the principles in which his early years +were trained. + +Exactly the opposite of the system here recommended ought to be +pursued in academical instruction. This can only be effected, however, +by a thorough training in the critical investigation of pure reason. +For, in order to bring the principles of this critique into exercise +as soon as possible, and to demonstrate their perfect even in the +presence of the highest degree of dialectical illusion, the student +ought to examine the assertions made on both sides of speculative +questions step by step, and to test them by these principles. It +cannot be a difficult task for him to show the fallacies inherent in +these propositions, and thus he begins early to feel his own power +of securing himself against the influence of such sophistical +arguments, which must finally lose, for him, all their illusory power. +And, although the same blows which overturn the edifice of his +opponent are as fatal to his own speculative structures, if such he +has wished to rear; he need not feel any sorrow in regard to this +seeming misfortune, as he has now before him a fair prospect into +the practical region in which he may reasonably hope to find a more +secure foundation for a rational system. + +There is, accordingly, no proper polemic in the sphere of pure +reason. Both parties beat the air and fight with their own shadows, +as they pass beyond the limits of nature, and can find no tangible +point of attack--no firm footing for their dogmatical conflict. +Fight as vigorously as they may, the shadows which they hew down, +immediately start up again, like the heroes in Walhalla, and renew +the bloodless and unceasing contest. + +But neither can we admit that there is any proper sceptical +employment of pure reason, such as might be based upon the principle +of neutrality in all speculative disputes. To excite reason against +itself, to place weapons in the hands of the party on the one side +as well as in those of the other, and to remain an undisturbed and +sarcastic spectator of the fierce struggle that ensues, seems, from +the dogmatical point of view, to be a part fitting only a malevolent +disposition. But, when the sophist evidences an invincible obstinacy +and blindness, and a pride which no criticism can moderate, there is +no other practicable course than to oppose to this pride and obstinacy +similar feelings and pretensions on the other side, equally well or +ill founded, so that reason, staggered by the reflections thus +forced upon it, finds it necessary to moderate its confidence in +such pretensions and to listen to the advice of criticism. But we +cannot stop at these doubts, much less regard the conviction of our +ignorance, not only as a cure for the conceit natural to dogmatism, +but as the settlement of the disputes in which reason is involved with +itself. On the contrary, scepticism is merely a means of awakening +reason from its dogmatic dreams and exciting it to a more careful +investigation into its own powers and pretensions. But, as +scepticism appears to be the shortest road to a permanent peace in +the domain of philosophy, and as it is the track pursued by the many +who aim at giving a philosophical colouring to their contemptuous +dislike of all inquiries of this kind, I think it necessary to present +to my readers this mode of thought in its true light. + + + +Scepticism not a Permanent State for Human Reason. + +The consciousness of ignorance--unless this ignorance is +recognized to be absolutely necessary ought, instead of forming the +conclusion of my inquiries, to be the strongest motive to the +pursuit of them. All ignorance is either ignorance of things or of +the limits of knowledge. If my ignorance is accidental and not +necessary, it must incite me, in the first case, to a dogmatical +inquiry regarding the objects of which I am ignorant; in the second, +to a critical investigation into the bounds of all possible knowledge. +But that my ignorance is absolutely necessary and unavoidable, and +that it consequently absolves from the duty of all further +investigation, is a fact which cannot be made out upon empirical +grounds--from observation--but upon critical grounds alone, that is, +by a thoroughgoing investigation into the primary sources of +cognition. It follows that the determination of the bounds of reason +can be made only on a priori grounds; while the empirical limitation +of reason, which is merely an indeterminate cognition of an +ignorance that can never be completely removed, can take place only +a posteriori. In other words, our empirical knowledge is limited by +that which yet remains for us to know. The former cognition of our +ignorance, which is possible only on a rational basis, is a science; +the latter is merely a perception, and we cannot say how far the +inferences drawn from it may extend. If I regard the earth, as it +really appears to my senses, as a flat surface, I am ignorant how +far this surface extends. But experience teaches me that, how far +soever I go, I always see before me a space in which I can proceed +farther; and thus I know the limits--merely visual--of my actual +knowledge of the earth, although I am ignorant of the limits of the +earth itself. But if I have got so far as to know that the earth is +a sphere, and that its surface is spherical, I can cognize a priori +and determine upon principles, from my knowledge of a small part of +this surface--say to the extent of a degree--the diameter and +circumference of the earth; and although I am ignorant of the +objects which this surface contains, I have a perfect knowledge of +its limits and extent. + +The sum of all the possible objects of our cognition seems to us +to be a level surface, with an apparent horizon--that which forms +the limit of its extent, and which has been termed by us the idea of +unconditioned totality. To reach this limit by empirical means is +impossible, and all attempts to determine it a priori according to +a principle, are alike in vain. But all the questions raised by pure +reason relate to that which lies beyond this horizon, or, at least, +in its boundary line. + +The celebrated David Hume was one of those geographers of human +reason who believe that they have given a sufficient answer to all +such questions by declaring them to lie beyond the horizon of our +knowledge--a horizon which, however, Hume was unable to determine. +His attention especially was directed to the principle of causality; +and he remarked with perfect justice that the truth of this principle, +and even the objective validity of the conception of a cause, was not +commonly based upon clear insight, that is, upon a priori cognition. +Hence he concluded that this law does not derive its authority from +its universality and necessity, but merely from its general +applicability in the course of experience, and a kind of subjective +necessity thence arising, which he termed habit. From the inability +of reason to establish this principle as a necessary law for the +acquisition of all experience, he inferred the nullity of all the +attempts of reason to pass the region of the empirical. + +This procedure of subjecting the facta of reason to examination, +and, if necessary, to disapproval, may be termed the censura of +reason. This censura must inevitably lead us to doubts regarding all +transcendent employment of principles. But this is only the second +step in our inquiry. The first step in regard to the subjects of +pure reason, and which marks the infancy of that faculty, is that of +dogmatism. The second, which we have just mentioned, is that of +scepticism, and it gives evidence that our judgement has been improved +by experience. But a third step is necessary--indicative of the +maturity and manhood of the judgement, which now lays a firm +foundation upon universal and necessary principles. This is the period +of criticism, in which we do not examine the facta of reason, but +reason itself, in the whole extent of its powers, and in regard to +its capability of a priori cognition; and thus we determine not merely +the empirical and ever-shifting bounds of our knowledge, but its necessary +and eternal limits. We demonstrate from indubitable principles, not +merely our ignorance in respect to this or that subject, but in regard +to all possible questions of a certain class. Thus scepticism is a +resting place for reason, in which it may reflect on its dogmatical +wanderings and gain some knowledge of the region in which it happens +to be, that it may pursue its way with greater certainty; but it +cannot be its permanent dwelling-place. It must take up its abode only +in the region of complete certitude, whether this relates to the +cognition of objects themselves, or to the limits which bound all +our cognition. + +Reason is not to be considered as an indefinitely extended plane, of +the bounds of which we have only a general knowledge; it ought +rather to be compared to a sphere, the radius of which may be found +from the curvature of its surface--that is, the nature of a priori +synthetical propositions--and, consequently, its circumference and +extent. Beyond the sphere of experience there are no objects which +it can cognize; nay, even questions regarding such supposititious +objects relate only to the subjective principles of a complete +determination of the relations which exist between the +understanding-conceptions which lie within this sphere. + +We are actually in possession of a priori synthetical cognitions, as +is proved by the existence of the principles of the understanding, +which anticipate experience. If any one cannot comprehend the +possibility of these principles, he may have some reason to doubt +whether they are really a priori; but he cannot on this account +declare them to be impossible, and affirm the nullity of the steps +which reason may have taken under their guidance. He can only say: +If we perceived their origin and their authenticity, we should be able +to determine the extent and limits of reason; but, till we can do +this, all propositions regarding the latter are mere random +assertions. In this view, the doubt respecting all dogmatical +philosophy, which proceeds without the guidance of criticism, is +well grounded; but we cannot therefore deny to reason the ability to +construct a sound philosophy, when the way has been prepared by a +thorough critical investigation. All the conceptions produced, and +all the questions raised, by pure reason, do not lie in the sphere +of experience, but in that of reason itself, and hence they must be +solved, and shown to be either valid or inadmissible, by that faculty. +We have no right to decline the solution of such problems, on the +ground that the solution can be discovered only from the nature of +things, and under pretence of the limitation of human faculties, for +reason is the sole creator of all these ideas, and is therefore +bound either to establish their validity or to expose their illusory +nature. + +The polemic of scepticism is properly directed against the +dogmatist, who erects a system of philosophy without having examined +the fundamental objective principles on which it is based, for the +purpose of evidencing the futility of his designs, and thus bringing +him to a knowledge of his own powers. But, in itself, scepticism +does not give us any certain information in regard to the bounds of +our knowledge. All unsuccessful dogmatical attempts of reason are +facia, which it is always useful to submit to the censure of the +sceptic. But this cannot help us to any decision regarding the +expectations which reason cherishes of better success in future +endeavours; the investigations of scepticism cannot, therefore, settle +the dispute regarding the rights and powers of human reason. + +Hume is perhaps the ablest and most ingenious of all sceptical +philosophers, and his writings have, undoubtedly, exerted the most +powerful influence in awakening reason to a thorough investigation +into its own powers. It will, therefore, well repay our labours to +consider for a little the course of reasoning which he followed and +the errors into which he strayed, although setting out on the path +of truth and certitude. + +Hume was probably aware, although he never clearly developed the +notion, that we proceed in judgements of a certain class beyond our +conception if the object. I have termed this kind of judgement +synthetical. As regard the manner in which I pass beyond my conception +by the aid of experience, no doubts can be entertained. Experience +is itself a synthesis of perceptions; and it employs perceptions to +increment the conception, which I obtain by means of another +perception. But we feel persuaded that we are able to proceed beyond +a conception, and to extend our cognition a priori. We attempt this +in two ways--either, through the pure understanding, in relation to +that which may become an object of experience, or, through pure +reason, in relation to such properties of things, or of the +existence of things, as can never be presented in any experience. This +sceptical philosopher did not distinguish these two kinds of +judgements, as he ought to have done, but regarded this augmentation +of conceptions, and, if we may so express ourselves, the spontaneous +generation of understanding and reason, independently of the +impregnation of experience, as altogether impossible. The so-called +a priori principles of these faculties he consequently held to be +invalid and imaginary, and regarded them as nothing but subjective +habits of thought originating in experience, and therefore purely +empirical and contingent rules, to which we attribute a spurious +necessity and universality. In support of this strange assertion, he +referred us to the generally acknowledged principle of the relation +between cause and effect. No faculty of the mind can conduct us from +the conception of a thing to the existence of something else; and +hence he believed he could infer that, without experience, we +possess no source from which we can augment a conception, and no +ground sufficient to justify us in framing a judgement that is to +extend our cognition a priori. That the light of the sun, which shines +upon a piece of wax, at the same time melts it, while it hardens clay, +no power of the understanding could infer from the conceptions which +we previously possessed of these substances; much less is there any +a priori law that could conduct us to such a conclusion, which +experience alone can certify. On the other hand, we have seen in our +discussion of transcendental logic, that, although we can never +proceed immediately beyond the content of the conception which is +given us, we can always cognize completely a priori--in relation, +however, to a third term, namely, possible experience--the law of +its connection with other things. For example, if I observe that a +piece of wax melts, I can cognize a priori that there must have been +something (the sun's heat) preceding, which this law; although, +without the aid of experience, I could not cognize a priori and in +a determinate manner either the cause from the effect, or the effect +from the cause. Hume was, therefore, wrong in inferring, from the +contingency of the determination according to law, the contingency +of the law itself; and the passing beyond the conception of a thing +to possible experience (which is an a priori proceeding, constituting +the objective reality of the conception), he confounded with our synthesis +of objects in actual experience, which is always, of course, +empirical. Thus, too, he regarded the principle of affinity, which +has its seat in the understanding and indicates a necessary connection, +as a mere rule of association, lying in the imitative faculty of +imagination, which can present only contingent, and not objective +connections. + +The sceptical errors of this remarkably acute thinker arose +principally from a defect, which was common to him with the +dogmatists, namely, that he had never made a systematic review of +all the different kinds of a priori synthesis performed by the +understanding. Had he done so, he would have found, to take one +example among many, that the principle of permanence was of this +character, and that it, as well as the principle of causality, +anticipates experience. In this way he might have been able to +describe the determinate limits of the a priori operations of +understanding and reason. But he merely declared the understanding +to be limited, instead of showing what its limits were; he created +a general mistrust in the power of our faculties, without giving us +any determinate knowledge of the bounds of our necessary and +unavoidable ignorance; he examined and condemned some of the +principles of the understanding, without investigating all its +powers with the completeness necessary to criticism. He denies, with +truth, certain powers to the understanding, but he goes further, and +declares it to be utterly inadequate to the a priori extension of +knowledge, although he has not fully examined all the powers which +reside in the faculty; and thus the fate which always overtakes +scepticism meets him too. That is to say, his own declarations are +doubted, for his objections were based upon facta, which are +contingent, and not upon principles, which can alone demonstrate the +necessary invalidity of all dogmatical assertions. + +As Hume makes no distinction between the well-grounded claims of the +understanding and the dialectical pretensions of reason, against +which, however, his attacks are mainly directed, reason does not +feel itself shut out from all attempts at the extension of a priori +cognition, and hence it refuses, in spite of a few checks in this or +that quarter, to relinquish such efforts. For one naturally arms +oneself to resist an attack, and becomes more obstinate in the resolve +to establish the claims he has advanced. But a complete review of +the powers of reason, and the conviction thence arising that we are +in possession of a limited field of action, while we must admit the +vanity of higher claims, puts an end to all doubt and dispute, and +induces reason to rest satisfied with the undisturbed possession of +its limited domain. + +To the uncritical dogmatist, who has not surveyed the sphere of +his understanding, nor determined, in accordance with principles, +the limits of possible cognition, who, consequently, is ignorant of +his own powers, and believes he will discover them by the attempts +he makes in the field of cognition, these attacks of scepticism are +not only dangerous, but destructive. For if there is one proposition +in his chain of reasoning which be he cannot prove, or the fallacy +in which he cannot evolve in accordance with a principle, suspicion +falls on all his statements, however plausible they may appear. + +And thus scepticism, the bane of dogmatical philosophy, conducts +us to a sound investigation into the understanding and the reason. +When we are thus far advanced, we need fear no further +attacks; for the limits of our domain are clearly marked out, and we +can make no claims nor become involved in any disputes regarding the +region that lies beyond these limits. Thus the sceptical procedure +in philosophy does not present any solution of the problems of reason, +but it forms an excellent exercise for its powers, awakening its +circumspection, and indicating the means whereby it may most fully +establish its claims to its legitimate possessions. + + + +SECTION III. The Discipline of Pure Reason in Hypothesis. + +This critique of reason has now taught us that all its efforts to +extend the bounds of knowledge, by means of pure speculation, are +utterly fruitless. So much the wider field, it may appear, lies open +to hypothesis; as, where we cannot know with certainty, we are at +liberty to make guesses and to form suppositions. + +Imagination may be allowed, under the strict surveillance of reason, +to invent suppositions; but, these must be based on something that +is perfectly certain--and that is the possibility of the object. If +we are well assured upon this point, it is allowable to have recourse +to supposition in regard to the reality of the object; but this +supposition must, unless it is utterly groundless, be connected, as +its ground of explanation, with that which is really given and +absolutely certain. Such a supposition is termed a hypothesis. + +It is beyond our power to form the least conception a priori of +the possibility of dynamical connection in phenomena; and the category +of the pure understanding will not enable us to excogitate any +such connection, but merely helps us to understand it, when we meet +with it in experience. For this reason we cannot, in accordance with +the categories, imagine or invent any object or any property of an +object not given, or that may not be given in experience, and employ +it in a hypothesis; otherwise, we should be basing our chain of +reasoning upon mere chimerical fancies, and not upon conceptions of +things. Thus, we have no right to assume the existence of new +powers, not existing in nature--for example, an understanding with +a non-sensuous intuition, a force of attraction without contact, or +some new kind of substances occupying space, and yet without the property +of impenetrability--and, consequently, we cannot assume that there +is any other kind of community among substances than that observable +in experience, any kind of presence than that in space, or any kind +of duration than that in time. In one word, the conditions of possible +experience are for reason the only conditions of the possibility of +things; reason cannot venture to form, independently of these +conditions, any conceptions of things, because such conceptions, +although not self-contradictory, are without object and without +application. + +The conceptions of reason are, as we have already shown, mere ideas, +and do not relate to any object in any kind of experience. At the same +time, they do not indicate imaginary or possible objects. They are +purely problematical in their nature and, as aids to the heuristic +exercise of the faculties, form the basis of the regulative principles +for the systematic employment of the understanding in the field of +experience. If we leave this ground of experience, they become mere +fictions of thought, the possibility of which is quite indemonstrable; +and they cannot, consequently, be employed as hypotheses in the +explanation of real phenomena. It is quite admissible to cogitate +the soul as simple, for the purpose of enabling ourselves to employ +the idea of a perfect and necessary unity of all the faculties of +the mind as the principle of all our inquiries into its internal +phenomena, although we cannot cognize this unity in concreto. But to +assume that the soul is a simple substance (a transcendental +conception) would be enouncing a proposition which is not only +indemonstrable--as many physical hypotheses are--but a proposition +which is purely arbitrary, and in the highest degree rash. The +simple is never presented in experience; and, if by substance is +here meant the permanent object of sensuous intuition, the possibility +of a simple phenomenon is perfectly inconceivable. Reason affords no +good grounds for admitting the existence of intelligible beings, or +of intelligible properties of sensuous things, although--as we have +no conception either of their possibility or of their impossibility--it +will always be out of our power to affirm dogmatically that they do +not exist. In the explanation of given phenomena, no other things +and no other grounds of explanation can be employed than those which +stand in connection with the given phenomena according to the known +laws of experience. A transcendental hypothesis, in which a mere +idea of reason is employed to explain the phenomena of nature, would +not give us any better insight into a phenomenon, as we should be +trying to explain what we do not sufficiently understand from known +empirical principles, by what we do not understand at all. The +principles of such a hypothesis might conduce to the satisfaction of +reason, but it would not assist the understanding in its application +to objects. Order and conformity to aims in the sphere of nature +must be themselves explained upon natural grounds and according to +natural laws; and the wildest hypotheses, if they are only physical, +are here more admissible than a hyperphysical hypothesis, such as that +of a divine author. For such a hypothesis would introduce the +principle of ignava ratio, which requires us to give up the search +for causes that might be discovered in the course of experience and +to rest satisfied with a mere idea. As regards the absolute totality +of the grounds of explanation in the series of these causes, this can +be no hindrance to the understanding in the case of phenomena; +because, as they are to us nothing more than phenomena, we have no +right to look for anything like completeness in the synthesis of the +series of their conditions. + +Transcendental hypotheses are therefore inadmissible; and we +cannot use the liberty of employing, in the absence of physical, +hyperphysical grounds of explanation. And this for two reasons; first, +because such hypothesis do not advance reason, but rather stop it in +its progress; secondly, because this licence would render fruitless +all its exertions in its own proper sphere, which is that of +experience. For, when the explanation of natural phenomena happens +to be difficult, we have constantly at hand a transcendental ground +of explanation, which lifts us above the necessity of investigating +nature; and our inquiries are brought to a close, not because we +have obtained all the requisite knowledge, but because we abut upon +a principle which is incomprehensible and which, indeed, is so far +back in the track of thought as to contain the conception of the +absolutely primal being. + +The next requisite for the admissibility of a hypothesis is its +sufficiency. That is, it must determine a priori the consequences +which are given in experience and which are supposed to follow from +the hypothesis itself. If we require to employ auxiliary hypotheses, +the suspicion naturally arises that they are mere fictions; because +the necessity for each of them requires the same justification as in +the case of the original hypothesis, and thus their testimony is +invalid. If we suppose the existence of an infinitely perfect cause, +we possess sufficient grounds for the explanation of the conformity +to aims, the order and the greatness which we observe in the universe; +but we find ourselves obliged, when we observe the evil in the world +and the exceptions to these laws, to employ new hypothesis in +support of the original one. We employ the idea of the simple nature +of the human soul as the foundation of all the theories we may form +of its phenomena; but when we meet with difficulties in our way, when +we observe in the soul phenomena similar to the changes which take +place in matter, we require to call in new auxiliary hypotheses. These +may, indeed, not be false, but we do not know them to be true, because +the only witness to their certitude is the hypothesis which they +themselves have been called in to explain. + +We are not discussing the above-mentioned assertions regarding the +immaterial unity of the soul and the existence of a Supreme Being as +dogmata, which certain philosophers profess to demonstrate a priori, +but purely as hypotheses. In the former case, the dogmatist must +take care that his arguments possess the apodeictic certainty of a +demonstration. For the assertion that the reality of such ideas is +probable is as absurd as a proof of the probability of a proposition +in geometry. Pure abstract reason, apart from all experience, can +either cognize nothing at all; and hence the judgements it enounces +are never mere opinions, they are either apodeictic certainties, or +declarations that nothing can be known on the subject. Opinions and +probable judgements on the nature of things can only be employed to +explain given phenomena, or they may relate to the effect, in +accordance with empirical laws, of an actually existing cause. In +other words, we must restrict the sphere of opinion to the world of +experience and nature. Beyond this region opinion is mere invention; +unless we are groping about for the truth on a path not yet fully +known, and have some hopes of stumbling upon it by chance. + +But, although hypotheses are inadmissible in answers to the +questions of pure speculative reason, they may be employed in the +defence of these answers. That is to say, hypotheses are admissible +in polemic, but not in the sphere of dogmatism. By the defence of +statements of this character, I do not mean an attempt at +discovering new grounds for their support, but merely the refutation +of the arguments of opponents. All a priori synthetical propositions +possess the peculiarity that, although the philosopher who maintains +the reality of the ideas contained in the proposition is not in +possession of sufficient knowledge to establish the certainty of his +statements, his opponent is as little able to prove the truth of the +opposite. This equality of fortune does not allow the one party to +be superior to the other in the sphere of speculative cognition; and +it is this sphere, accordingly, that is the proper arena of these +endless speculative conflicts. But we shall afterwards show that, in +relation to its practical exercise, Reason has the right of +admitting what, in the field of pure speculation, she would not be +justified in supposing, except upon perfectly sufficient grounds; +because all such suppositions destroy the necessary completeness of +speculation--a condition which the practical reason, however, does +not consider to be requisite. In this sphere, therefore, Reason is +mistress of a possession, her title to which she does not require to +prove--which, in fact, she could not do. The burden of proof +accordingly rests upon the opponent. But as he has just as little +knowledge regarding the subject discussed, and is as little able to +prove the non-existence of the object of an idea, as the philosopher +on the other side is to demonstrate its reality, it is evident that +there is an advantage on the side of the philosopher who maintains +his proposition as a practically necessary supposition (melior est +conditio possidentis). For he is at liberty to employ, in +self-defence, the same weapons as his opponent makes use of in +attacking him; that is, he has a right to use hypotheses not for the +purpose of supporting the arguments in favour of his own propositions, +but to show that his opponent knows no more than himself regarding +the subject under 'discussion and cannot boast of any speculative +advantage. + +Hypotheses are, therefore, admissible in the sphere of pure reason +only as weapons for self-defence, and not as supports to dogmatical +assertions. But the opposing party we must always seek for in +ourselves. For speculative reason is, in the sphere of +transcendentalism, dialectical in its own nature. The difficulties +and objections we have to fear lie in ourselves. They are like old +but never superannuated claims; and we must seek them out, and settle +them once and for ever, if we are to expect a permanent peace. External +tranquility is hollow and unreal. The root of these contradictions, +which lies in the nature of human reason, must be destroyed; and +this can only be done by giving it, in the first instance, freedom +to grow, nay, by nourishing it, that it may send out shoots, and +thus betray its own existence. It is our duty, therefore, to try to +discover new objections, to put weapons in the bands of our +opponent, and to grant him the most favourable position in the arena +that he can wish. We have nothing to fear from these concessions; on +the contrary, we may rather hope that we shall thus make ourselves +master of a possession which no one will ever venture to dispute. + +The thinker requires, to be fully equipped, the hypotheses of pure +reason, which, although but leaden weapons (for they have not been +steeled in the armoury of experience), are as useful as any that can +be employed by his opponents. If, accordingly, we have assumed, from +a non-speculative point of view, the immaterial nature of the soul, +and are met by the objection that experience seems to prove that the +growth and decay of our mental faculties are mere modifications of +the sensuous organism--we can weaken the force of this objection by +the assumption that the body is nothing but the fundamental phenomenon, +to which, as a necessary condition, all sensibility, and consequently +all thought, relates in the present state of our existence; and that +the separation of soul and body forms the conclusion of the sensuous +exercise of our power of cognition and the beginning of the +intellectual. The body would, in this view of the question, be +regarded, not as the cause of thought, but merely as its restrictive +condition, as promotive of the sensuous and animal, but as a hindrance +to the pure and spiritual life; and the dependence of the animal +life on the constitution of the body, would not prove that the whole +life of man was also dependent on the state of the organism. We +might go still farther, and discover new objections, or carry out to +their extreme consequences those which have already been adduced. + +Generation, in the human race as well as among the irrational +animals, depends on so many accidents--of occasion, of proper +sustenance, of the laws enacted by the government of a country of vice +even, that it is difficult to believe in the eternal existence of a +being whose life has begun under circumstances so mean and trivial, +and so entirely dependent upon our own control. As regards the +continuance of the existence of the whole race, we need have no +difficulties, for accident in single cases is subject to general laws; +but, in the case of each individual, it would seem as if we could +hardly expect so wonderful an effect from causes so insignificant. +But, in answer to these objections, we may adduce the transcendental +hypothesis that all life is properly intelligible, and not subject +to changes of time, and that it neither began in birth, nor will end +in death. We may assume that this life is nothing more than a sensuous +representation of pure spiritual life; that the whole world of sense +is but an image, hovering before the faculty of cognition which we +exercise in this sphere, and with no more objective reality than a +dream; and that if we could intuite ourselves and other things as they +really are, we should see ourselves in a world of spiritual natures, +our connection with which did not begin at our birth and will not +cease with the destruction of the body. And so on. + +We cannot be said to know what has been above asserted, nor do we +seriously maintain the truth of these assertions; and the notions +therein indicated are not even ideas of reason, they are purely +fictitious conceptions. But this hypothetical procedure is in +perfect conformity with the laws of reason. Our opponent mistakes +the absence of empirical conditions for a proof of the complete +impossibility of all that we have asserted; and we have to show him +that he has not exhausted the whole sphere of possibility and that +he can as little compass that sphere by the laws of experience and +nature, as we can lay a secure foundation for the operations of reason +beyond the region of experience. Such hypothetical defences against +the pretensions of an opponent must not be regarded as declarations +of opinion. The philosopher abandons them, so soon as the opposite +party renounces its dogmatical conceit. To maintain a simply +negative position in relation to propositions which rest on an +insecure foundation, well befits the moderation of a true philosopher; +but to uphold the objections urged against an opponent as proofs of +the opposite statement is a proceeding just as unwarrantable and +arrogant as it is to attack the position of a philosopher who advances +affirmative propositions regarding such a subject. + +It is evident, therefore, that hypotheses, in the speculative +sphere, are valid, not as independent propositions, but only +relatively to opposite transcendent assumptions. For, to make the +principles of possible experience conditions of the possibility of +things in general is just as transcendent a procedure as to maintain +the objective reality of ideas which can be applied to no objects +except such as lie without the limits of possible experience. The +judgements enounced by pure reason must be necessary, or they must +not be enounced at all. Reason cannot trouble herself with opinions. +But the hypotheses we have been discussing are merely problematical +judgements, which can neither be confuted nor proved; while, +therefore, they are not personal opinions, they are indispensable as +answers to objections which are liable to be raised. But we must +take care to confine them to this function, and guard against any +assumption on their part of absolute validity, a proceeding which +would involve reason in inextricable difficulties and contradictions. + + + +SECTION IV. The Discipline of Pure Reason in Relation to Proofs. + +It is a peculiarity, which distinguishes the proofs of transcendental +synthetical propositions from those of all other a priori synthetical +cognitions, that reason, in the case of the former, does not apply its +conceptions directly to an object, but is first obliged to prove, a +priori, the objective validity of these conceptions and the possibility +of their syntheses. This is not merely a prudential rule, it is +essential to the very possibility of the proof of a transcendental +proposition. If I am required to pass, a priori, beyond the conception +of an object, I find that it is utterly impossible without the guidance +of something which is not contained in the conception. In mathematics, +it is a priori intuition that guides my synthesis; and, in this case, +all our conclusions may be drawn immediately from pure intuition. In +transcendental cognition, so long as we are dealing only with +conceptions of the understanding, we are guided by possible experience. +That is to say, a proof in the sphere of transcendental cognition does +not show that the given conception (that of an event, for example) +leads directly to another conception (that of a cause)--for this would +be a saltus which nothing can justify; but it shows that experience +itself, and consequently the object of experience, is impossible +without the connection indicated by these conceptions. It follows that +such a proof must demonstrate the possibility of arriving, +synthetically and a priori, at a certain knowledge of things, which was +not contained in our conceptions of these things. Unless we pay +particular attention to this requirement, our proofs, instead of +pursuing the straight path indicated by reason, follow the tortuous +road of mere subjective association. The illusory conviction, which +rests upon subjective causes of association, and which is considered as +resulting from the perception of a real and objective natural affinity, +is always open to doubt and suspicion. For this reason, all the +attempts which have been made to prove the principle of sufficient +reason, have, according to the universal admission of philosophers, +been quite unsuccessful; and, before the appearance of transcendental +criticism, it was considered better, as this principle could not be +abandoned, to appeal boldly to the common sense of mankind (a +proceeding which always proves that the problem, which reason ought to +solve, is one in which philosophers find great difficulties), rather +than attempt to discover new dogmatical proofs. + +But, if the proposition to be proved is a proposition of pure +reason, and if I aim at passing beyond my empirical conceptions by +the aid of mere ideas, it is necessary that the proof should first +show that such a step in synthesis is possible (which it is not), before +it proceeds to prove the truth of the proposition itself. The so-called +proof of the simple nature of the soul from the unity of apperception, +is a very plausible one. But it contains no answer to the objection, +that, as the notion of absolute simplicity is not a conception which +is directly applicable to a perception, but is an idea which must be +inferred--if at all--from observation, it is by no means evident how +the mere fact of consciousness, which is contained in all thought, +although in so far a simple representation, can conduct me to the +consciousness and cognition of a thing which is purely a thinking +substance. When I represent to my mind the power of my body as in +motion, my body in this thought is so far absolute unity, and my +representation of it is a simple one; and hence I can indicate this +representation by the motion of a point, because I have made +abstraction of the size or volume of the body. But I cannot hence +infer that, given merely the moving power of a body, the body may be +cogitated as simple substance, merely because the representation in +my mind takes no account of its content in space, and is consequently +simple. The simple, in abstraction, is very different from the +objectively simple; and hence the Ego, which is simple in the first +sense, may, in the second sense, as indicating the soul itself, be +a very complex conception, with a very various content. Thus it is +evident that in all such arguments there lurks a paralogism. We +guess (for without some such surmise our suspicion would not be +excited in reference to a proof of this character) at the presence +of the paralogism, by keeping ever before us a criterion of the +possibility of those synthetical propositions which aim at proving +more than experience can teach us. This criterion is obtained from +the observation that such proofs do not lead us directly from the +subject of the proposition to be proved to the required predicate, +but find it necessary to presuppose the possibility of extending our +cognition a priori by means of ideas. We must, accordingly, always +use the greatest caution; we require, before attempting any proof, +to consider how it is possible to extend the sphere of cognition by +the operations of pure reason, and from what source we are to derive +knowledge, which is not obtained from the analysis of conceptions, +nor relates, by anticipation, to possible experience. We shall thus +spare ourselves much severe and fruitless labour, by not expecting +from reason what is beyond its power, or rather by subjecting it to +discipline, and teaching it to moderate its vehement desires for the +extension of the sphere of cognition. + +The first rule for our guidance is, therefore, not to attempt a +transcendental proof, before we have considered from what source we +are to derive the principles upon which the proof is to be based, +and what right we have to expect that our conclusions from these +principles will be veracious. If they are principles of the +understanding, it is vain to expect that we should attain by their +means to ideas of pure reason; for these principles are valid only +in regard to objects of possible experience. If they are principles +of pure reason, our labour is alike in vain. For the principles of +reason, if employed as objective, are without exception dialectical +and possess no validity or truth, except as regulative principles of +the systematic employment of reason in experience. But when such +delusive proof are presented to us, it is our duty to meet them with +the non liquet of a matured judgement; and, although we are unable +to expose the particular sophism upon which the proof is based, we +have a right to demand a deduction of the principles employed in it; +and, if these principles have their origin in pure reason alone, +such a deduction is absolutely impossible. And thus it is +unnecessary that we should trouble ourselves with the exposure and +confutation of every sophistical illusion; we may, at once, bring +all dialectic, which is inexhaustible in the production of +fallacies, before the bar of critical reason, which tests the +principles upon which all dialectical procedure is based. The second +peculiarity of transcendental proof is that a transcendental +proposition cannot rest upon more than a single proof. If I am drawing +conclusions, not from conceptions, but from intuition corresponding +to a conception, be it pure intuition, as in mathematics, or empirical, +as in natural science, the intuition which forms the basis of my +inferences presents me with materials for many synthetical +propositions, which I can connect in various modes, while, as it is +allowable to proceed from different points in the intention, I can +arrive by different paths at the same proposition. + +But every transcendental proposition sets out from a conception, and +posits the synthetical condition of the possibility of an object +according to this conception. There must, therefore, be but one ground +of proof, because it is the conception alone which determines the +object; and thus the proof cannot contain anything more than the +determination of the object according to the conception. In our +Transcendental Analytic, for example, we inferred the principle: Every +event has a cause, from the only condition of the objective +possibility of our conception of an event. This is that an event +cannot be determined in time, and consequently cannot form a part of +experience, unless it stands under this dynamical law. This is the +only possible ground of proof; for our conception of an event +possesses objective validity, that is, is a true conception, only +because the law of causality determines an object to which it can +refer. Other arguments in support of this principle have been +attempted--such as that from the contingent nature of a phenomenon; +but when this argument is considered, we can discover no criterion +of contingency, except the fact of an event--of something happening, +that is to say, the existence which is preceded by the non-existence +of an object, and thus we fall back on the very thing to be proved. +If the proposition: "Every thinking being is simple," is to be proved, +we keep to the conception of the ego, which is simple, and to which +all thought has a relation. The same is the case with the transcendental +proof of the existence of a Deity, which is based solely upon the +harmony and reciprocal fitness of the conceptions of an ens +realissimum and a necessary being, and cannot be attempted in any +other manner. + +This caution serves to simplify very much the criticism of all +propositions of reason. When reason employs conceptions alone, only +one proof of its thesis is possible, if any. When, therefore, the +dogmatist advances with ten arguments in favour of a proposition, we +may be sure that not one of them is conclusive. For if he possessed +one which proved the proposition he brings forward to demonstration- +as must always be the case with the propositions of pure reason- +what need is there for any more? His intention can only be similar +to that of the advocate who had different arguments for different +judges; this availing himself of the weakness of those who examine +his arguments, who, without going into any profound investigation, +adopt the view of the case which seems most probable at first sight +and decide according to it. + +The third rule for the guidance of pure reason in the conduct of a +proof is that all transcendental proofs must never be apagogic or +indirect, but always ostensive or direct. The direct or ostensive +proof not only establishes the truth of the proposition to be +proved, but exposes the grounds of its truth; the apagogic, on the +other hand, may assure us of the truth of the proposition, but it +cannot enable us to comprehend the grounds of its possibility. The +latter is, accordingly, rather an auxiliary to an argument, than a +strictly philosophical and rational mode of procedure. In one respect, +however, they have an advantage over direct proofs, from the fact that +the mode of arguing by contradiction, which they employ, renders our +understanding of the question more clear, and approximates the proof +to the certainty of an intuitional demonstration. + +The true reason why indirect proofs are employed in different +sciences is this. When the grounds upon which we seek to base a +cognition are too various or too profound, we try whether or not we +may not discover the truth of our cognition from its consequences. +The modus ponens of reasoning from the truth of its inferences to the +truth of a proposition would be admissible if all the inferences +that can be drawn from it are known to be true; for in this case there +can be only one possible ground for these inferences, and that is +the true one. But this is a quite impracticable procedure, as it +surpasses all our powers to discover all the possible inferences +that can be drawn from a proposition. But this mode of reasoning is +employed, under favour, when we wish to prove the truth of an +hypothesis; in which case we admit the truth of the conclusion- +which is supported by analogy--that, if all the inferences we have +drawn and examined agree with the proposition assumed, all other +possible inferences will also agree with it. But, in this way, an +hypothesis can never be established as a demonstrated truth. The modus +tollens of reasoning from known inferences to the unknown proposition, +is not only a rigorous, but a very easy mode of proof. For, if it +can be shown that but one inference from a proposition is false, +then the proposition must itself be false. Instead, then, of +examining, in an ostensive argument, the whole series of the grounds +on which the truth of a proposition rests, we need only take the +opposite of this proposition, and if one inference from it be false, +then must the opposite be itself false; and, consequently, the +proposition which we wished to prove must be true. + +The apagogic method of proof is admissible only in those sciences +where it is impossible to mistake a subjective representation for an +objective cognition. Where this is possible, it is plain that the +opposite of a given proposition may contradict merely the subjective +conditions of thought, and not the objective cognition; or it may +happen that both propositions contradict each other only under a +subjective condition, which is incorrectly considered to be objective, +and, as the condition is itself false, both propositions may be false, +and it will, consequently, be impossible to conclude the truth of +the one from the falseness of the other. + +In mathematics such subreptions are impossible; and it is in this +science, accordingly, that the indirect mode of proof has its true +place. In the science of nature, where all assertion is based upon +empirical intuition, such subreptions may be guarded against by the +repeated comparison of observations; but this mode of proof is of +little value in this sphere of knowledge. But the transcendental +efforts of pure reason are all made in the sphere of the subjective, +which is the real medium of all dialectical illusion; and thus +reason endeavours, in its premisses, to impose upon us subjective +representations for objective cognitions. In the transcendental sphere +of pure reason, then, and in the case of synthetical propositions, +it is inadmissible to support a statement by disproving the +counter-statement. For only two cases are possible; either, the +counter-statement is nothing but the enouncement of the +inconsistency of the opposite opinion with the subjective conditions +of reason, which does not affect the real case (for example, we cannot +comprehend the unconditioned necessity of the existence of a being, +and hence every speculative proof of the existence of such a being +must be opposed on subjective grounds, while the possibility of this +being in itself cannot with justice be denied); or, both propositions, +being dialectical in their nature, are based upon an impossible +conception. In this latter case the rule applies: non entis nulla sunt +predicata; that is to say, what we affirm and what we deny, respecting +such an object, are equally untrue, and the apagogic mode of +arriving at the truth is in this case impossible. If, for example, +we presuppose that the world of sense is given in itself in its +totality, it is false, either that it is infinite, or that it is +finite and limited in space. Both are false, because the hypothesis +is false. For the notion of phenomena (as mere representations) which +are given in themselves (as objects) is self-contradictory; and the +infinitude of this imaginary whole would, indeed, be unconditioned, +but would be inconsistent (as everything in the phenomenal world is +conditioned) with the unconditioned determination and finitude of +quantities which is presupposed in our conception. + +The apagogic mode of proof is the true source of those illusions +which have always had so strong an attraction for the admirers of +dogmatical philosophy. It may be compared to a champion who +maintains the honour and claims of the party he has adopted by +offering battle to all who doubt the validity of these claims and +the purity of that honour; while nothing can be proved in this way, +except the respective strength of the combatants, and the advantage, +in this respect, is always on the side of the attacking party. +Spectators, observing that each party is alternately conqueror and +conquered, are led to regard the subject of dispute as beyond the +power of man to decide upon. But such an opinion cannot be +justified; and it is sufficient to apply to these reasoners the +remark: + + Non defensoribus istis + Tempus eget. + +Each must try to establish his assertions by a transcendental +deduction of the grounds of proof employed in his argument, and thus +enable us to see in what way the claims of reason may be supported. +If an opponent bases his assertions upon subjective grounds, he may +be refuted with ease; not, however to the advantage of the dogmatist, +who likewise depends upon subjective sources of cognition and is in +like manner driven into a corner by his opponent. But, if parties employ +the direct method of procedure, they will soon discover the +difficulty, nay, the impossibility of proving their assertions, and +will be forced to appeal to prescription and precedence; or they will, +by the help of criticism, discover with ease the dogmatical +illusions by which they had been mocked, and compel reason to renounce +its exaggerated pretensions to speculative insight and to confine +itself within the limits of its proper sphere--that of practical +principles. + + + +CHAPTER II. The Canon of Pure Reason. + +It is a humiliating consideration for human reason that it is +incompetent to discover truth by means of pure speculation, but, on +the contrary, stands in need of discipline to check its deviations +from the straight path and to expose the illusions which it +originates. But, on the other hand, this consideration ought to +elevate and to give it confidence, for this discipline is exercised +by itself alone, and it is subject to the censure of no other power. +The bounds, moreover, which it is forced to set to its speculative +exercise, form likewise a check upon the fallacious pretensions of +opponents; and thus what remains of its possessions, after these +exaggerated claims have been disallowed, is secure from attack or +usurpation. The greatest, and perhaps the only, use of all +philosophy of pure reason is, accordingly, of a purely negative +character. It is not an organon for the extension, but a discipline +for the determination, of the limits of its exercise; and without +laying claim to the discovery of new truth, it has the modest merit +of guarding against error. + +At the same time, there must be some source of positive cognitions +which belong to the domain of pure reason and which become the +causes of error only from our mistaking their true character, while +they form the goal towards which reason continually strives. How +else can we account for the inextinguishable desire in the human +mind to find a firm footing in some region beyond the limits of the +world of experience? It hopes to attain to the possession of a +knowledge in which it has the deepest interest. It enters upon the +path of pure speculation; but in vain. We have some reason, however, +to expect that, in the only other way that lies open to it--the path +of practical reason--it may meet with better success. + +I understand by a canon a list of the a priori principles of the +proper employment of certain faculties of cognition. Thus general +logic, in its analytical department, is a formal canon for the +faculties of understanding and reason. In the same way, Transcendental +Analytic was seen to be a canon of the pure understanding; for it +alone is competent to enounce true a priori synthetical cognitions. +But, when no proper employment of a faculty of cognition is +possible, no canon can exist. But the synthetical cognition of pure +speculative reason is, as has been shown, completely impossible. There +cannot, therefore, exist any canon for the speculative exercise of +this faculty--for its speculative exercise is entirely dialectical; +and, consequently, transcendental logic, in this respect, is merely +a discipline, and not a canon. If, then, there is any proper mode of +employing the faculty of pure reason--in which case there must be a +canon for this faculty--this canon will relate, not to the +speculative, but to the practical use of reason. This canon we now +proceed to investigate. + + + +SECTION I. Of the Ultimate End of the Pure Use of Reason. + +There exists in the faculty of reason a natural desire to venture +beyond the field of experience, to attempt to reach the utmost +bounds of all cognition by the help of ideas alone, and not to rest +satisfied until it has fulfilled its course and raised the sum of +its cognitions into a self-subsistent systematic whole. Is the +motive for this endeavour to be found in its speculative, or in its +practical interests alone? + +Setting aside, at present, the results of the labours of pure reason +in its speculative exercise, I shall merely inquire regarding the +problems the solution of which forms its ultimate aim, whether reached +or not, and in relation to which all other aims are but partial and +intermediate. These highest aims must, from the nature of reason, +possess complete unity; otherwise the highest interest of humanity +could not be successfully promoted. + +The transcendental speculation of reason relates to three things: +the freedom of the will, the immortality of the soul, and the +existence of God. The speculative interest which reason has in those +questions is very small; and, for its sake alone, we should not +undertake the labour of transcendental investigation--a labour full +of toil and ceaseless struggle. We should be loth to undertake this +labour, because the discoveries we might make would not be of the +smallest use in the sphere of concrete or physical investigation. We +may find out that the will is free, but this knowledge only relates +to the intelligible cause of our volition. As regards the phenomena +or expressions of this will, that is, our actions, we are bound, in +obedience to an inviolable maxim, without which reason cannot be +employed in the sphere of experience, to explain these in the same +way as we explain all the other phenomena of nature, that is to say, +according to its unchangeable laws. We may have discovered the +spirituality and immortality of the soul, but we cannot employ this +knowledge to explain the phenomena of this life, nor the peculiar +nature of the future, because our conception of an incorporeal +nature is purely negative and does not add anything to our +knowledge, and the only inferences to be drawn from it are purely +fictitious. If, again, we prove the existence of a supreme +intelligence, we should be able from it to make the conformity to aims +existing in the arrangement of the world comprehensible; but we should +not be justified in deducing from it any particular arrangement or +disposition, or inferring any where it is not perceived. For it is +a necessary rule of the speculative use of reason that we must not +overlook natural causes, or refuse to listen to the teaching of +experience, for the sake of deducing what we know and perceive from +something that transcends all our knowledge. In one word, these +three propositions are, for the speculative reason, always +transcendent, and cannot be employed as immanent principles in +relation to the objects of experience; they are, consequently, of no +use to us in this sphere, being but the valueless results of the +severe but unprofitable efforts of reason. + +If, then, the actual cognition of these three cardinal propositions is +perfectly useless, while Reason uses her utmost endeavours to induce us +to admit them, it is plain that their real value and importance relate +to our practical, and not to our speculative interest. + +I term all that is possible through free will, practical. But if the +conditions of the exercise of free volition are empirical, reason +can have only a regulative, and not a constitutive, influence upon +it, and is serviceable merely for the introduction of unity into its +empirical laws. In the moral philosophy of prudence, for example, +the sole business of reason is to bring about a union of all the ends, +which are aimed at by our inclinations, into one ultimate end--that +of happiness--and to show the agreement which should exist among the +means of attaining that end. In this sphere, accordingly, reason +cannot present to us any other than pragmatical laws of free action, +for our guidance towards the aims set up by the senses, and is +incompetent to give us laws which are pure and determined completely +a priori. On the other hand, pure practical laws, the ends of which +have been given by reason entirely a priori, and which are not +empirically conditioned, but are, on the contrary, absolutely +imperative in their nature, would be products of pure reason. Such +are the moral laws; and these alone belong to the sphere of the +practical exercise of reason, and admit of a canon. + +All the powers of reason, in the sphere of what may be termed pure +philosophy, are, in fact, directed to the three above-mentioned +problems alone. These again have a still higher end--the answer to +the question, what we ought to do, if the will is free, if there is +a God and a future world. Now, as this problem relates to our in +reference to the highest aim of humanity, it is evident that the +ultimate intention of nature, in the constitution of our reason, has +been directed to the moral alone. + +We must take care, however, in turning our attention to an object +which is foreign* to the sphere of transcendental philosophy, not to +injure the unity of our system by digressions, nor, on the other hand, +to fail in clearness, by saying too little on the new subject of +discussion. I hope to avoid both extremes, by keeping as close as +possible to the transcendental, and excluding all psychological, +that is, empirical, elements. + +[*Footnote: All practical conceptions relate to objects of pleasure +and pain, and consequently--in an indirect manner, at least--to objects +of feeling. But as feeling is not a faculty of representation, but +lies out of the sphere of our powers of cognition, the elements of +our judgements, in so far as they relate to pleasure or pain, that +is, the elements of our practical judgements, do not belong to +transcendental philosophy, which has to do with pure a priori +cognitions alone.] + +I have to remark, in the first place, that at present I treat of the +conception of freedom in the practical sense only, and set aside the +corresponding transcendental conception, which cannot be employed as +a ground of explanation in the phenomenal world, but is itself a problem +for pure reason. A will is purely animal (arbitrium brutum) when it +is determined by sensuous impulses or instincts only, that is, when +it is determined in a pathological manner. A will, which can be determined +independently of sensuous impulses, consequently by motives +presented by reason alone, is called a free will (arbitrium +liberum); and everything which is connected with this free will, +either as principle or consequence, is termed practical. The existence +of practical freedom can be proved from experience alone. For the +human will is not determined by that alone which immediately affects +the senses; on the contrary, we have the power, by calling up the +notion of what is useful or hurtful in a more distant relation, of +overcoming the immediate impressions on our sensuous faculty of +desire. But these considerations of what is desirable in relation to +our whole state, that is, is in the end good and useful, are based +entirely upon reason. This faculty, accordingly, enounces laws, +which are imperative or objective laws of freedom and which tell us +what ought to take place, thus distinguishing themselves from the laws +of nature, which relate to that which does take place. The laws of +freedom or of free will are hence termed practical laws. + +Whether reason is not itself, in the actual delivery of these +laws, determined in its turn by other influences, and whether the +action which, in relation to sensuous impulses, we call free, may not, +in relation to higher and more remote operative causes, really form +a part of nature--these are questions which do not here concern us. +They are purely speculative questions; and all we have to do, in the +practical sphere, is to inquire into the rule of conduct which +reason has to present. Experience demonstrates to us the existence +of practical freedom as one of the causes which exist in nature, +that is, it shows the causal power of reason in the determination of +the will. The idea of transcendental freedom, on the contrary, +requires that reason--in relation to its causal power of commencing +a series of phenomena--should be independent of all sensuous +determining causes; and thus it seems to be in opposition to the law +of nature and to all possible experience. It therefore remains a +problem for the human mind. But this problem does not concern reason +in its practical use; and we have, therefore, in a canon of pure +reason, to do with only two questions, which relate to the practical +interest of pure reason: Is there a God? and, Is there a future +life? The question of transcendental freedom is purely speculative, +and we may therefore set it entirely aside when we come to treat of +practical reason. Besides, we have already discussed this subject in +the antinomy of pure reason. + + + +SECTION II. Of the Ideal of the Summum Bonum as a Determining + Ground of the Ultimate End of Pure Reason. + +Reason conducted us, in its speculative use, through the field of +experience and, as it can never find complete satisfaction in that +sphere, from thence to speculative ideas--which, however, in the end +brought us back again to experience, and thus fulfilled the purpose +of reason, in a manner which, though useful, was not at all in accordance +with our expectations. It now remains for us to consider whether +pure reason can be employed in a practical sphere, and whether it will +here conduct us to those ideas which attain the highest ends of pure +reason, as we have just stated them. We shall thus ascertain +whether, from the point of view of its practical interest, reason +may not be able to supply us with that which, on the speculative side, +it wholly denies us. + +The whole interest of reason, speculative as well as practical, is +centred in the three following questions: + + 1. WHAT CAN I KNOW? + 2. WHAT OUGHT I TO DO? + 3. WHAT MAY I HOPE? + +The first question is purely speculative. We have, as I flatter +myself, exhausted all the replies of which it is susceptible, and have +at last found the reply with which reason must content itself, and +with which it ought to be content, so long as it pays no regard to +the practical. But from the two great ends to the attainment of which +all these efforts of pure reason were in fact directed, we remain just +as far removed as if we had consulted our ease and declined the task +at the outset. So far, then, as knowledge is concerned, thus much, +at least, is established, that, in regard to those two problems, it +lies beyond our reach. + +The second question is purely practical. As such it may indeed +fall within the province of pure reason, but still it is not +transcendental, but moral, and consequently cannot in itself form +the subject of our criticism. + +The third question: If I act as I ought to do, what may I then +hope?--is at once practical and theoretical. The practical forms a +clue to the answer of the theoretical, and--in its highest form- +speculative question. For all hoping has happiness for its object +and stands in precisely the same relation to the practical and the +law of morality as knowing to the theoretical cognition of things and +the law of nature. The former arrives finally at the conclusion that +something is (which determines the ultimate end), because something +ought to take place; the latter, that something is (which operates +as the highest cause), because something does take place. + +Happiness is the satisfaction of all our desires; extensive, in +regard to their multiplicity; intensive, in regard to their degree; +and protensive, in regard to their duration. The practical law based +on the motive of happiness I term a pragmatical law (or prudential +rule); but that law, assuming such to exist, which has no other motive +than the worthiness of being happy, I term a moral or ethical law. +The first tells us what we have to do, if we wish to become possessed +of happiness; the second dictates how we ought to act, in order to +deserve happiness. The first is based upon empirical principles; for +it is only by experience that I can learn either what inclinations +exist which desire satisfaction, or what are the natural means of +satisfying them. The second takes no account of our desires or the +means of satisfying them, and regards only the freedom of a rational +being, and the necessary conditions under which alone this freedom +can harmonize with the distribution of happiness according to +principles. This second law may therefore rest upon mere ideas of pure +reason, and may be cognized a priori. + +I assume that there are pure moral laws which determine, entirely +a priori (without regard to empirical motives, that is, to happiness), +the conduct of a rational being, or in other words, to use which it +makes of its freedom, and that these laws are absolutely imperative +(not merely hypothetically, on the supposition of other empirical +ends), and therefore in all respects necessary. I am warranted in +assuming this, not only by the arguments of the most enlightened +moralists, but by the moral judgement of every man who will make the +attempt to form a distinct conception of such a law. + +Pure reason, then, contains, not indeed in its speculative, but in +its practical, or, more strictly, its moral use, principles of the +possibility of experience, of such actions, namely, as, in +accordance with ethical precepts, might be met with in the history +of man. For since reason commands that such actions should take place, +it must be possible for them to take place; and hence a particular +kind of systematic unity--the moral--must be possible. We have +found, it is true, that the systematic unity of nature could not be +established according to speculative principles of reason, because, +while reason possesses a causal power in relation to freedom, it has +none in relation to the whole sphere of nature; and, while moral +principles of reason can produce free actions, they cannot produce +natural laws. It is, then, in its practical, but especially in its +moral use, that the principles of pure reason possess objective +reality. + +I call the world a moral world, in so far as it may be in accordance +with all the ethical laws--which, by virtue of the freedom of +reasonable beings, it can be, and according to the necessary laws of +morality it ought to be. But this world must be conceived only as an +intelligible world, inasmuch as abstraction is therein made of all +conditions (ends), and even of all impediments to morality (the +weakness or pravity of human nature). So far, then, it is a mere idea- +though still a practical idea--which may have, and ought to have, an +influence on the world of sense, so as to bring it as far as +possible into conformity with itself. The idea of a moral world has, +therefore, objective reality, not as referring to an object of +intelligible intuition--for of such an object we can form no +conception whatever--but to the world of sense--conceived, however, +as an object of pure reason in its practical use--and to a corpus +mysticum of rational beings in it, in so far as the liberum +arbitrium of the individual is placed, under and by virtue of moral +laws, in complete systematic unity both with itself and with the +freedom of all others. + +That is the answer to the first of the two questions of pure +reason which relate to its practical interest: Do that which will +render thee worthy of happiness. The second question is this: If I +conduct myself so as not to be unworthy of happiness, may I hope +thereby to obtain happiness? In order to arrive at the solution of +this question, we must inquire whether the principles of pure +reason, which prescribe a priori the law, necessarily also connect +this hope with it. + +I say, then, that just as the moral principles are necessary +according to reason in its practical use, so it is equally necessary +according to reason in its theoretical use to assume that every one +has ground to hope for happiness in the measure in which he has made +himself worthy of it in his conduct, and that therefore the system +of morality is inseparably (though only in the idea of pure reason) +connected with that of happiness. + +Now in an intelligible, that is, in the moral world, in the +conception of which we make abstraction of all the impediments to +morality (sensuous desires), such a system of happiness, connected +with and proportioned to morality, may be conceived as necessary, +because freedom of volition--partly incited, and partly restrained +by moral laws--would be itself the cause of general happiness; and +thus rational beings, under the guidance of such principles, would +be themselves the authors both of their own enduring welfare and +that of others. But such a system of self-rewarding morality is only +an idea, the carrying out of which depends upon the condition that +every one acts as he ought; in other words, that all actions of +reasonable beings be such as they would be if they sprung from a +Supreme Will, comprehending in, or under, itself all particular wills. +But since the moral law is binding on each individual in the use of +his freedom of volition, even if others should not act in conformity +with this law, neither the nature of things, nor the causality of +actions and their relation to morality, determine how the consequences +of these actions will be related to happiness; and the necessary +connection of the hope of happiness with the unceasing endeavour to +become worthy of happiness, cannot be cognized by reason, if we take +nature alone for our guide. This connection can be hoped for only on +the assumption that the cause of nature is a supreme reason, which +governs according to moral laws. + +I term the idea of an intelligence in which the morally most perfect +will, united with supreme blessedness, is the cause of all happiness +in the world, so far as happiness stands in strict relation to +morality (as the worthiness of being happy), the ideal of the supreme +Good. It is only, then, in the ideal of the supreme original good, +that pure reason can find the ground of the practically necessary +connection of both elements of the highest derivative good, and +accordingly of an intelligible, that is, moral world. Now since we are +necessitated by reason to conceive ourselves as belonging to such a +world, while the senses present to us nothing but a world of +phenomena, we must assume the former as a consequence of our conduct +in the world of sense (since the world of sense gives us no hint of +it), and therefore as future in relation to us. Thus God and a future +life are two hypotheses which, according to the principles of pure +reason, are inseparable from the obligation which this reason imposes +upon us. + +Morality per se constitutes a system. But we can form no system of +happiness, except in so far as it is dispensed in strict proportion +to morality. But this is only possible in the intelligible world, under +a wise author and ruler. Such a ruler, together with life in such a +world, which we must look upon as future, reason finds itself +compelled to assume; or it must regard the moral laws as idle +dreams, since the necessary consequence which this same reason +connects with them must, without this hypothesis, fall to the +ground. Hence also the moral laws are universally regarded as +commands, which they could not be did they not connect a priori +adequate consequences with their dictates, and thus carry with them +promises and threats. But this, again, they could not do, did they +not reside in a necessary being, as the Supreme Good, which alone can +render such a teleological unity possible. + +Leibnitz termed the world, when viewed in relation to the rational +beings which it contains, and the moral relations in which they +stand to each other, under the government of the Supreme Good, the +kingdom of Grace, and distinguished it from the kingdom of Nature, +in which these rational beings live, under moral laws, indeed, but +expect no other consequences from their actions than such as follow +according to the course of nature in the world of sense. To view +ourselves, therefore, as in the kingdom of grace, in which all +happiness awaits us, except in so far as we ourselves limit our +participation in it by actions which render us unworthy of +happiness, is a practically necessary idea of reason. + +Practical laws, in so far as they are subjective grounds of actions, +that is, subjective principles, are termed maxims. The judgements of +moral according to in its purity and ultimate results are framed +according ideas; the observance of its laws, according to according +to maxims. + +The whole course of our life must be subject to moral maxims; but +this is impossible, unless with the moral law, which is a mere idea, +reason connects an efficient cause which ordains to all conduct +which is in conformity with the moral law an issue either in this or +in another life, which is in exact conformity with our highest aims. +Thus, without a God and without a world, invisible to us now, but +hoped for, the glorious ideas of morality are, indeed, objects of +approbation and of admiration, but cannot be the springs of purpose +and action. For they do not satisfy all the aims which are natural +to every rational being, and which are determined a priori by pure +reason itself, and necessary. + +Happiness alone is, in the view of reason, far from being the +complete good. Reason does not approve of it (however much inclination +may desire it), except as united with desert. On the other hand, +morality alone, and with it, mere desert, is likewise far from being +the complete good. To make it complete, he who conducts himself in +a manner not unworthy of happiness, must be able to hope for the +possession of happiness. Even reason, unbiased by private ends, or +interested considerations, cannot judge otherwise, if it puts itself +in the place of a being whose business it is to dispense all happiness +to others. For in the practical idea both points are essentially +combined, though in such a way that participation in happiness is +rendered possible by the moral disposition, as its condition, and +not conversely, the moral disposition by the prospect of happiness. +For a disposition which should require the prospect of happiness as +its necessary condition would not be moral, and hence also would not +be worthy of complete happiness--a happiness which, in the view of +reason, recognizes no limitation but such as arises from our own +immoral conduct. + +Happiness, therefore, in exact proportion with the morality of +rational beings (whereby they are made worthy of happiness), +constitutes alone the supreme good of a world into which we absolutely +must transport ourselves according to the commands of pure but +practical reason. This world is, it is true, only an intelligible +world; for of such a systematic unity of ends as it requires, the +world of sense gives us no hint. Its reality can be based on nothing +else but the hypothesis of a supreme original good. In it +independent reason, equipped with all the sufficiency of a supreme +cause, founds, maintains, and fulfils the universal order of things, +with the most perfect teleological harmony, however much this order +may be hidden from us in the world of sense. + +This moral theology has the peculiar advantage, in contrast with +speculative theology, of leading inevitably to the conception of a +sole, perfect, and rational First Cause, whereof speculative +theology does not give us any indication on objective grounds, far +less any convincing evidence. For we find neither in transcendental +nor in natural theology, however far reason may lead us in these, +any ground to warrant us in assuming the existence of one only +Being, which stands at the head of all natural causes, and on which +these are entirely dependent. On the other band, if we take our +stand on moral unity as a necessary law of the universe, and from this +point of view consider what is necessary to give this law adequate +efficiency and, for us, obligatory force, we must come to the +conclusion that there is one only supreme will, which comprehends +all these laws in itself. For how, under different wills, should we +find complete unity of ends? This will must be omnipotent, that all +nature and its relation to morality in the world may be subject to +it; omniscient, that it may have knowledge of the most secret feelings +and their moral worth; omnipresent, that it may be at hand to supply +every necessity to which the highest weal of the world may give rise; +eternal, that this harmony of nature and liberty may never fail; and +so on. + +But this systematic unity of ends in this world of intelligences- +which, as mere nature, is only a world of sense, but, as a system of +freedom of volition, may be termed an intelligible, that is, moral +world (regnum gratiae)--leads inevitably also to the teleological +unity of all things which constitute this great whole, according to +universal natural laws--just as the unity of the former is according +to universal and necessary moral laws--and unites the practical with +the speculative reason. The world must be represented as having +originated from an idea, if it is to harmonize with that use of reason +without which we cannot even consider ourselves as worthy of reason- +namely, the moral use, which rests entirely on the idea of the supreme +good. Hence the investigation of nature receives a teleological +direction, and becomes, in its widest extension, physico-theology. +But this, taking its rise in moral order as a unity founded on the +essence of freedom, and not accidentally instituted by external commands, +establishes the teleological view of nature on grounds which must be +inseparably connected with the internal possibility of things. This +gives rise to a transcendental theology, which takes the ideal of +the highest ontological perfection as a principle of systematic unity; +and this principle connects all things according to universal and +necessary natural laws, because all things have their origin in the +absolute necessity of the one only Primal Being. + +What use can we make of our understanding, even in respect of +experience, if we do not propose ends to ourselves? But the highest +ends are those of morality, and it is only pure reason that can give +us the knowledge of these. Though supplied with these, and putting +ourselves under their guidance, we can make no teleological use of +the knowledge of nature, as regards cognition, unless nature itself +has established teleological unity. For without this unity we should +not even possess reason, because we should have no school for reason, +and no cultivation through objects which afford the materials for +its conceptions. But teleological unity is a necessary unity, and +founded on the essence of the individual will itself. Hence this will, +which is the condition of the application of this unity in concreto, +must be so likewise. In this way the transcendental enlargement of +our rational cognition would be, not the cause, but merely the effect +of the practical teleology which pure reason imposes upon us. + +Hence, also, we find in the history of human reason that, before the +moral conceptions were sufficiently purified and determined, and +before men had attained to a perception of the systematic unity of +ends according to these conceptions and from necessary principles, +the knowledge of nature, and even a considerable amount of intellectual +culture in many other sciences, could produce only rude and vague +conceptions of the Deity, sometimes even admitting of an astonishing +indifference with regard to this question altogether. But the more +enlarged treatment of moral ideas, which was rendered necessary by +the extreme pure moral law of our religion, awakened the interest, +and thereby quickened the perceptions of reason in relation to this +object. In this way, and without the help either of an extended +acquaintance with nature, or of a reliable transcendental insight (for +these have been wanting in all ages), a conception of the Divine Being +was arrived at, which we now bold to be the correct one, not because +speculative reason convinces us of its correctness, but because it +accords with the moral principles of reason. Thus it is to pure +reason, but only in its practical use, that we must ascribe the +merit of having connected with our highest interest a cognition, of +which mere speculation was able only to form a conjecture, but the +validity of which it was unable to establish--and of having thereby +rendered it, not indeed a demonstrated dogma, but a hypothesis +absolutely necessary to the essential ends of reason. + +But if practical reason has reached this elevation, and has attained +to the conception of a sole Primal Being as the supreme good, it +must not, therefore, imagine that it has transcended the empirical +conditions of its application, and risen to the immediate cognition +of new objects; it must not presume to start from the conception which +it has gained, and to deduce from it the moral laws themselves. For +it was these very laws, the internal practical necessity of which led +us to the hypothesis of an independent cause, or of a wise ruler of +the universe, who should give them effect. Hence we are not entitled +to regard them as accidental and derived from the mere will of the +ruler, especially as we have no conception of such a will, except as +formed in accordance with these laws. So far, then, as practical +reason has the right to conduct us, we shall not look upon actions +as binding on us, because they are the commands of God, but we shall +regard them as divine commands, because we are internally bound by +them. We shall study freedom under the teleological unity which +accords with principles of reason; we shall look upon ourselves as +acting in conformity with the divine will only in so far as we hold +sacred the moral law which reason teaches us from the nature of +actions themselves, and we shall believe that we can obey that will +only by promoting the weal of the universe in ourselves and in others. +Moral theology is, therefore, only of immanent use. It teaches us to +fulfil our destiny here in the world, by placing ourselves in +harmony with the general system of ends, and warns us against the +fanaticism, nay, the crime of depriving reason of its legislative +authority in the moral conduct of life, for the purpose of directly +connecting this authority with the idea of the Supreme Being. For this +would be, not an immanent, but a transcendent use of moral theology, +and, like the transcendent use of mere speculation, would inevitably +pervert and frustrate the ultimate ends of reason. + + + +SECTION III. Of Opinion, Knowledge, and Belief. + +The holding of a thing to be true is a phenomenon in our +understanding which may rest on objective grounds, but requires, also, +subjective causes in the mind of the person judging. If a judgement +is valid for every rational being, then its ground is objectively +sufficient, and it is termed a conviction. If, on the other hand, it +has its ground in the particular character of the subject, it is +termed a persuasion. + +Persuasion is a mere illusion, the ground of the judgement, which +lies solely in the subject, being regarded as objective. Hence a +judgement of this kind has only private validity--is only valid for +the individual who judges, and the holding of a thing to be true in +this way cannot be communicated. But truth depends upon agreement with +the object, and consequently the judgements of all understandings, +if true, must be in agreement with each other (consentientia uni +tertio consentiunt inter se). Conviction may, therefore, be +distinguished, from an external point of view, from persuasion, by +the possibility of communicating it and by showing its validity for +the reason of every man; for in this case the presumption, at least, +arises that the agreement of all judgements with each other, in +spite of the different characters of individuals, rests upon the +common ground of the agreement of each with the object, and thus the +correctness of the judgement is established. + +Persuasion, accordingly, cannot be subjectively distinguished from +conviction, that is, so long as the subject views its judgement simply +as a phenomenon of its own mind. But if we inquire whether the grounds +of our judgement, which are valid for us, produce the same effect on +the reason of others as on our own, we have then the means, though +only subjective means, not, indeed, of producing conviction, but of +detecting the merely private validity of the judgement; in other +words, of discovering that there is in it the element of mere +persuasion. + +If we can, in addition to this, develop the subjective causes of the +judgement, which we have taken for its objective grounds, and thus +explain the deceptive judgement as a phenomenon in our mind, apart +altogether from the objective character of the object, we can then +expose the illusion and need be no longer deceived by it, although, +if its subjective cause lies in our nature, we cannot hope altogether +to escape its influence. + +I can only maintain, that is, affirm as necessarily valid for +every one, that which produces conviction. Persuasion I may keep for +myself, if it is agreeable to me; but I cannot, and ought not, to +attempt to impose it as binding upon others. + +Holding for true, or the subjective validity of a judgement in +relation to conviction (which is, at the same time, objectively +valid), has the three following degrees: opinion, belief, and +knowledge. Opinion is a consciously insufficient judgement, +subjectively as well as objectively. Belief is subjectively +sufficient, but is recognized as being objectively insufficient. +Knowledge is both subjectively and objectively sufficient. +Subjective sufficiency is termed conviction (for myself); objective +sufficiency is termed certainty (for all). I need not dwell longer +on the explanation of such simple conceptions. + +I must never venture to be of opinion, without knowing something, at +least, by which my judgement, in itself merely problematical, is +brought into connection with the truth--which connection, although +not perfect, is still something more than an arbitrary fiction. +Moreover, the law of such a connection must be certain. For if, in +relation to this law, I have nothing more than opinion, my judgement +is but a play of the imagination, without the least relation to truth. +In the judgements of pure reason, opinion has no place. For, as they +do not rest on empirical grounds and as the sphere of pure reason is +that of necessary truth and a priori cognition, the principle of +connection in it requires universality and necessity, and consequently +perfect certainty--otherwise we should have no guide to the truth at +all. Hence it is absurd to have an opinion in pure mathematics; we +must know, or abstain from forming a judgement altogether. The case +is the same with the maxims of morality. For we must not hazard an +action on the mere opinion that it is allowed, but we must know it +to be so. In the transcendental sphere of reason, on the other hand, +the term opinion is too weak, while the word knowledge is too strong. +From the merely speculative point of view, therefore, we cannot form +a judgement at all. For the subjective grounds of a judgement, such +as produce belief, cannot be admitted in speculative inquiries, +inasmuch as they cannot stand without empirical support and are +incapable of being communicated to others in equal measure. + +But it is only from the practical point of view that a theoretically +insufficient judgement can be termed belief. Now the practical +reference is either to skill or to morality; to the former, when the +end proposed is arbitrary and accidental, to the latter, when it is +absolutely necessary. + +If we propose to ourselves any end whatever, the conditions of its +attainment are hypothetically necessary. The necessity is +subjectively, but still only comparatively, sufficient, if I am +acquainted with no other conditions under which the end can be +attained. On the other hand, it is sufficient, absolutely and for +every one, if I know for certain that no one can be acquainted with +any other conditions under which the attainment of the proposed end +would be possible. In the former case my supposition--my judgement +with regard to certain conditions--is a merely accidental belief; in +the latter it is a necessary belief. The physician must pursue some +course in the case of a patient who is in danger, but is ignorant of +the nature of the disease. He observes the symptoms, and concludes, +according to the best of his judgement, that it is a case of phthisis. +His belief is, even in his own judgement, only contingent: another +man might, perhaps come nearer the truth. Such a belief, contingent +indeed, but still forming the ground of the actual use of means for +the attainment of certain ends, I term Pragmatical belief. + +The usual test, whether that which any one maintains is merely his +persuasion, or his subjective conviction at least, that is, his firm +belief, is a bet. It frequently happens that a man delivers his +opinions with so much boldness and assurance, that he appears to be +under no apprehension as to the possibility of his being in error. +The offer of a bet startles him, and makes him pause. Sometimes it +turns out that his persuasion may be valued at a ducat, but not at +ten. For he does not hesitate, perhaps, to venture a ducat, but if +it is proposed to stake ten, he immediately becomes aware of the +possibility of his being mistaken--a possibility which has hitherto +escaped his observation. If we imagine to ourselves that we have to +stake the happiness of our whole life on the truth of any proposition, +our judgement drops its air of triumph, we take the alarm, and discover +the actual strength of our belief. Thus pragmatical belief has +degrees, varying in proportion to the interests at stake. + +Now, in cases where we cannot enter upon any course of action in +reference to some object, and where, accordingly, our judgement is +purely theoretical, we can still represent to ourselves, in thought, +the possibility of a course of action, for which we suppose that we +have sufficient grounds, if any means existed of ascertaining the +truth of the matter. Thus we find in purely theoretical judgements +an analogon of practical judgements, to which the word belief may +properly be applied, and which we may term doctrinal belief. I +should not hesitate to stake my all on the truth of the proposition- +if there were any possibility of bringing it to the test of +experience--that, at least, some one of the planets, which we see, +is inhabited. Hence I say that I have not merely the opinion, but +the strong belief, on the correctness of which I would stake even many +of the advantages of life, that there are inhabitants in other worlds. + +Now we must admit that the doctrine of the existence of God +belongs to doctrinal belief. For, although in respect to the +theoretical cognition of the universe I do not require to form any +theory which necessarily involves this idea, as the condition of my +explanation of the phenomena which the universe presents, but, on +the contrary, am rather bound so to use my reason as if everything +were mere nature, still teleological unity is so important a condition +of the application of my reason to nature, that it is impossible for +me to ignore it--especially since, in addition to these +considerations, abundant examples of it are supplied by experience. +But the sole condition, so far as my knowledge extends, under which +this unity can be my guide in the investigation of nature, is the +assumption that a supreme intelligence has ordered all things +according to the wisest ends. Consequently, the hypothesis of a wise +author of the universe is necessary for my guidance in the +investigation of nature--is the condition under which alone I can +fulfil an end which is contingent indeed, but by no means unimportant. +Moreover, since the result of my attempts so frequently confirms the +utility of this assumption, and since nothing decisive can be +adduced against it, it follows that it would be saying far too +little to term my judgement, in this case, a mere opinion, and that, +even in this theoretical connection, I may assert that I firmly +believe in God. Still, if we use words strictly, this must not be +called a practical, but a doctrinal belief, which the theology of +nature (physico-theology) must also produce in my mind. In the +wisdom of a Supreme Being, and in the shortness of life, so inadequate +to the development of the glorious powers of human nature, we may find +equally sufficient grounds for a doctrinal belief in the future life +of the human soul. + +The expression of belief is, in such cases, an expression of modesty +from the objective point of view, but, at the same time, of firm +confidence, from the subjective. If I should venture to term this +merely theoretical judgement even so much as a hypothesis which I am +entitled to assume; a more complete conception, with regard to another +world and to the cause of the world, might then be justly required +of me than I am, in reality, able to give. For, if I assume +anything, even as a mere hypothesis, I must, at least, know so much +of the properties of such a being as will enable me, not to form the +conception, but to imagine the existence of it. But the word belief +refers only to the guidance which an idea gives me, and to its +subjective influence on the conduct of my reason, which forces me to +hold it fast, though I may not be in a position to give a +speculative account of it. + +But mere doctrinal belief is, to some extent, wanting in +stability. We often quit our hold of it, in consequence of the +difficulties which occur in speculation, though in the end we +inevitably return to it again. + +It is quite otherwise with moral belief. For in this sphere action +is absolutely necessary, that is, I must act in obedience to the moral +law in all points. The end is here incontrovertibly established, and +there is only one condition possible, according to the best of my +perception, under which this end can harmonize with all other ends, +and so have practical validity--namely, the existence of a God and +of a future world. I know also, to a certainty, that no one can be +acquainted with any other conditions which conduct to the same unity +of ends under the moral law. But since the moral precept is, at the +same time, my maxim (as reason requires that it should be), I am +irresistibly constrained to believe in the existence of God and in +a future life; and I am sure that nothing can make me waver in this +belief, since I should thereby overthrow my moral maxims, the +renunciation of which would render me hateful in my own eyes. + +Thus, while all the ambitious attempts of reason to penetrate beyond +the limits of experience end in disappointment, there is still +enough left to satisfy us in a practical point of view. No one, it +is true, will be able to boast that he knows that there is a God and +a future life; for, if he knows this, he is just the man whom I have +long wished to find. All knowledge, regarding an object of mere +reason, can be communicated; and I should thus be enabled to hope that +my own knowledge would receive this wonderful extension, through the +instrumentality of his instruction. No, my conviction is not +logical, but moral certainty; and since it rests on subjective grounds +(of the moral sentiment), I must not even say: It is morally certain +that there is a God, etc., but: I am morally certain, that is, my +belief in God and in another world is so interwoven with my moral +nature that I am under as little apprehension of having the former +torn from me as of losing the latter. + +The only point in this argument that may appear open to suspicion is +that this rational belief presupposes the existence of moral +sentiments. If we give up this assumption, and take a man who is +entirely indifferent with regard to moral laws, the question which +reason proposes, becomes then merely a problem for speculation and +may, indeed, be supported by strong grounds from analogy, but not by +such as will compel the most obstinate scepticism to give way.* But +in these questions no man is free from all interest. For though the +want of good sentiments may place him beyond the influence of moral +interests, still even in this case enough may be left to make him fear +the existence of God and a future life. For he cannot pretend to any +certainty of the non-existence of God and of a future life, unless- +since it could only be proved by mere reason, and therefore +apodeictically--he is prepared to establish the impossibility of both, +which certainly no reasonable man would undertake to do. This would +be a negative belief, which could not, indeed, produce morality and +good sentiments, but still could produce an analogon of these, by +operating as a powerful restraint on the outbreak of evil +dispositions. + +[*Footnote: The human mind (as, I believe, every rational being must +of necessity do) takes a natural interest in morality, although this +interest is not undivided, and may not be practically in +preponderance. If you strengthen and increase it, you will find the +reason become docile, more enlightened, and more capable of uniting +the speculative interest with the practical. But if you do not take +care at the outset, or at least midway, to make men good, you will +never force them into an honest belief.] + +But, it will be said, is this all that pure reason can effect, in +opening up prospects beyond the limits of experience? Nothing more +than two articles of belief? Common sense could have done as much as +this, without taking the philosophers to counsel in the matter! + +I shall not here eulogize philosophy for the benefits which the +laborious efforts of its criticism have conferred on human reason- +even granting that its merit should turn out in the end to be only +negative--for on this point something more will be said in the next +section. But, I ask, do you require that that knowledge which concerns +all men, should transcend the common understanding, and should only +be revealed to you by philosophers? The very circumstance which has +called forth your censure, is the best confirmation of the correctness +of our previous assertions, since it discloses, what could not have +been foreseen, that Nature is not chargeable with any partial +distribution of her gifts in those matters which concern all men +without distinction and that, in respect to the essential ends of +human nature, we cannot advance further with the help of the highest +philosophy, than under the guidance which nature has vouchsafed to +the meanest understanding. + + + +CHAPTER III. The Architectonic of Pure Reason. + +By the term architectonic I mean the art of constructing a system. +Without systematic unity, our knowledge cannot become science; it will +be an aggregate, and not a system. Thus architectonic is the +doctrine of the scientific in cognition, and therefore necessarily +forms part of our methodology. + +Reason cannot permit our knowledge to remain in an unconnected and +rhapsodistic state, but requires that the sum of our cognitions should +constitute a system. It is thus alone that they can advance the ends +of reason. By a system I mean the unity of various cognitions under +one idea. This idea is the conception--given by reason--of the form +of a whole, in so far as the conception determines a priori not only +the limits of its content, but the place which each of its parts is +to occupy. The scientific idea contains, therefore, the end and the +form of the whole which is in accordance with that end. The unity of +the end, to which all the parts of the system relate, and through +which all have a relation to each other, communicates unity to the +whole system, so that the absence of any part can be immediately +detected from our knowledge of the rest; and it determines a priori +the limits of the system, thus excluding all contingent or arbitrary +additions. The whole is thus an organism (articulatio), and not an +aggregate (coacervatio); it may grow from within (per +intussusceptionem), but it cannot increase by external additions +(per appositionem). It is, thus, like an animal body, the growth of +which does not add any limb, but, without changing their +proportions, makes each in its sphere stronger and more active. + +We require, for the execution of the idea of a system, a schema, +that is, a content and an arrangement of parts determined a priori +by the principle which the aim of the system prescribes. A schema +which is not projected in accordance with an idea, that is, from the +standpoint of the highest aim of reason, but merely empirically, in +accordance with accidental aims and purposes (the number of which +cannot be predetermined), can give us nothing more than technical +unity. But the schema which is originated from an idea (in which +case reason presents us with aims a priori, and does not look for them +to experience), forms the basis of architectonical unity. A science, +in the proper acceptation of that term, cannot be formed +technically, that is, from observation of the similarity existing +between different objects, and the purely contingent use we make of +our knowledge in concreto with reference to all kinds of arbitrary +external aims; its constitution must be framed on architectonical +principles, that is, its parts must be shown to possess an essential +affinity, and be capable of being deduced from one supreme and +internal aim or end, which forms the condition of the possibility of +the scientific whole. The schema of a science must give a priori the +plan of it (monogramma), and the division of the whole into parts, +in conformity with the idea of the science; and it must also +distinguish this whole from all others, according to certain +understood principles. + +No one will attempt to construct a science, unless he have some idea +to rest on as a proper basis. But, in the elaboration of the +science, he finds that the schema, nay, even the definition which he +at first gave of the science, rarely corresponds with his idea; for +this idea lies, like a germ, in our reason, its parts undeveloped +and hid even from microscopical observation. For this reason, we ought +to explain and define sciences, not according to the description which +the originator gives of them, but according to the idea which we +find based in reason itself, and which is suggested by the natural +unity of the parts of the science already accumulated. For it will +of ten be found that the originator of a science and even his latest +successors remain attached to an erroneous idea, which they cannot +render clear to themselves, and that they thus fail in determining +the true content, the articulation or systematic unity, and the limits +of their science. + +It is unfortunate that, only after having occupied ourselves for a +long time in the collection of materials, under the guidance of an +idea which lies undeveloped in the mind, but not according to any +definite plan of arrangement--nay, only after we have spent much +time and labour in the technical disposition of our materials, does +it become possible to view the idea of a science in a clear light, +and to project, according to architectonical principles, a plan of +the whole, in accordance with the aims of reason. Systems seem, like +certain worms, to be formed by a kind of generatio aequivoca--by the +mere confluence of conceptions, and to gain completeness only with +the progress of time. But the schema or germ of all lies in reason; +and thus is not only every system organized according to its own idea, +but all are united into one grand system of human knowledge, of which +they form members. For this reason, it is possible to frame an +architectonic of all human cognition, the formation of which, at the +present time, considering the immense materials collected or to be +found in the ruins of old systems, would not indeed be very difficult. +Our purpose at present is merely to sketch the plan of the +architectonic of all cognition given by pure reason; and we begin from +the point where the main root of human knowledge divides into two, +one of which is reason. By reason I understand here the whole higher +faculty of cognition, the rational being placed in contradistinction +to the empirical. + +If I make complete abstraction of the content of cognition, +objectively considered, all cognition is, from a subjective point of +view, either historical or rational. Historical cognition is +cognitio ex datis, rational, cognitio ex principiis. Whatever may be +the original source of a cognition, it is, in relation to the person +who possesses it, merely historical, if he knows only what has been +given him from another quarter, whether that knowledge was +communicated by direct experience or by instruction. Thus the Person +who has learned a system of philosophy--say the Wolfian--although he +has a perfect knowledge of all the principles, definitions, and +arguments in that philosophy, as well as of the divisions that have +been made of the system, possesses really no more than an historical +knowledge of the Wolfian system; he knows only what has been told him, +his judgements are only those which he has received from his teachers. +Dispute the validity of a definition, and he is completely at a loss +to find another. He has formed his mind on another's; but the +imitative faculty is not the productive. His knowledge has not been +drawn from reason; and although, objectively considered, it is +rational knowledge, subjectively, it is merely historical. He has +learned this or that philosophy and is merely a plaster cast of a +living man. Rational cognitions which are objective, that is, which +have their source in reason, can be so termed from a subjective +point of view, only when they have been drawn by the individual +himself from the sources of reason, that is, from principles; and it +is in this way alone that criticism, or even the rejection of what +has been already learned, can spring up in the mind. + +All rational cognition is, again, based either on conceptions, or on +the construction of conceptions. The former is termed philosophical, +the latter mathematical. I have already shown the essential difference +of these two methods of cognition in the first chapter. A cognition +may be objectively philosophical and subjectively historical--as is +the case with the majority of scholars and those who cannot look +beyond the limits of their system, and who remain in a state of +pupilage all their lives. But it is remarkable that mathematical +knowledge, when committed to memory, is valid, from the subjective +point of view, as rational knowledge also, and that the same +distinction cannot be drawn here as in the case of philosophical +cognition. The reason is that the only way of arriving at this +knowledge is through the essential principles of reason, and thus it +is always certain and indisputable; because reason is employed in +concreto--but at the same time a priori--that is, in pure and, +therefore, infallible intuition; and thus all causes of illusion and +error are excluded. Of all the a priori sciences of reason, therefore, +mathematics alone can be learned. Philosophy--unless it be in an +historical manner--cannot be learned; we can at most learn to +philosophize. + +Philosophy is the system of all philosophical cognition. We must use +this term in an objective sense, if we understand by it the archetype +of all attempts at philosophizing, and the standard by which all +subjective philosophies are to be judged. In this sense, philosophy is +merely the idea of a possible science, which does not exist in +concreto, but to which we endeavour in various ways to approximate, +until we have discovered the right path to pursue--a path overgrown by +the errors and illusions of sense--and the image we have hitherto tried +in vain to shape has become a perfect copy of the great prototype. +Until that time, we cannot learn philosophy--it does not exist; if it +does, where is it, who possesses it, and how shall we know it? We can +only learn to philosophize; in other words, we can only exercise our +powers of reasoning in accordance with general principles, retaining at +the same time, the right of investigating the sources of these +principles, of testing, and even of rejecting them. + +Until then, our conception of philosophy is only a scholastic +conception--a conception, that is, of a system of cognition which we +are trying to elaborate into a science; all that we at present know +being the systematic unity of this cognition, and consequently the +logical completeness of the cognition for the desired end. But there +is also a cosmical conception (conceptus cosmicus) of philosophy, +which has always formed the true basis of this term, especially when +philosophy was personified and presented to us in the ideal of a +philosopher. In this view philosophy is the science of the relation +of all cognition to the ultimate and essential aims of human reason +(teleologia rationis humanae), and the philosopher is not merely an +artist--who occupies himself with conceptions--but a lawgiver, +legislating for human reason. In this sense of the word, it would be +in the highest degree arrogant to assume the title of philosopher, +and to pretend that we had reached the perfection of the prototype +which lies in the idea alone. + +The mathematician, the natural philosopher, and the logician--how +far soever the first may have advanced in rational, and the two latter +in philosophical knowledge--are merely artists, engaged in the +arrangement and formation of conceptions; they cannot be termed +philosophers. Above them all, there is the ideal teacher, who +employs them as instruments for the advancement of the essential +aims of human reason. Him alone can we call philosopher; but he +nowhere exists. But the idea of his legislative power resides in the +mind of every man, and it alone teaches us what kind of systematic +unity philosophy demands in view of the ultimate aims of reason. +This idea is, therefore, a cosmical conception.* + +[*Footnote: By a cosmical conception, I mean one in which all men +necessarily take an interest; the aim of a science must accordingly +be determined according to scholastic conceptions, if it is regarded +merely as a means to certain arbitrarily proposed ends.] + +In view of the complete systematic unity of reason, there can only +be one ultimate end of all the operations of the mind. To this all +other aims are subordinate, and nothing more than means for its +attainment. This ultimate end is the destination of man, and the +philosophy which relates to it is termed moral philosophy. The +superior position occupied by moral philosophy, above all other +spheres for the operations of reason, sufficiently indicates the +reason why the ancients always included the idea--and in an especial +manner--of moralist in that of philosopher. Even at the present day, +we call a man who appears to have the power of self-government, even +although his knowledge may be very limited, by the name of +philosopher. + +The legislation of human reason, or philosophy, has two objects- +nature and freedom--and thus contains not only the laws of nature, +but also those of ethics, at first in two separate systems, which, +finally, merge into one grand philosophical system of cognition. The +philosophy of nature relates to that which is, that of ethics to +that which ought to be. + +But all philosophy is either cognition on the basis of pure +reason, or the cognition of reason on the basis of empirical +principles. The former is termed pure, the latter empirical +philosophy. + +The philosophy of pure reason is either propaedeutic, that is, an +inquiry into the powers of reason in regard to pure a priori +cognition, and is termed critical philosophy; or it is, secondly, +the system of pure reason--a science containing the systematic +presentation of the whole body of philosophical knowledge, true as +well as illusory, given by pure reason--and is called metaphysic. This +name may, however, be also given to the whole system of pure +philosophy, critical philosophy included, and may designate the +investigation into the sources or possibility of a priori cognition, +as well as the presentation of the a priori cognitions which form a +system of pure philosophy--excluding, at the same time, all +empirical and mathematical elements. + +Metaphysic is divided into that of the speculative and that of the +practical use of pure reason, and is, accordingly, either the +metaphysic of nature, or the metaphysic of ethics. The former contains +all the pure rational principles--based upon conceptions alone (and +thus excluding mathematics)--of all theoretical cognition; the latter, +the principles which determine and necessitate a priori all action. +Now moral philosophy alone contains a code of laws--for the regulation +of our actions--which are deduced from principles entirely a priori. +Hence the metaphysic of ethics is the only pure moral philosophy, as +it is not based upon anthropological or other empirical +considerations. The metaphysic of speculative reason is what is +commonly called metaphysic in the more limited sense. But as pure +moral philosophy properly forms a part of this system of cognition, +we must allow it to retain the name of metaphysic, although it is not +requisite that we should insist on so terming it in our present +discussion. + +It is of the highest importance to separate those cognitions which +differ from others both in kind and in origin, and to take great +care that they are not confounded with those with which they are +generally found connected. What the chemist does in the analysis of +substances, what the mathematician in pure mathematics, is, in a still +higher degree, the duty of the philosopher, that the value of each +different kind of cognition, and the part it takes in the operations +of the mind, may be clearly defined. Human reason has never wanted +a metaphysic of some kind, since it attained the power of thought, +or rather of reflection; but it has never been able to keep this sphere +of thought and cognition pure from all admixture of foreign +elements. The idea of a science of this kind is as old as +speculation itself; and what mind does not speculate--either in the +scholastic or in the popular fashion? At the same time, it must be +admitted that even thinkers by profession have been unable clearly +to explain the distinction between the two elements of our +cognition--the one completely a priori, the other a posteriori; and +hence the proper definition of a peculiar kind of cognition, and +with it the just idea of a science which has so long and so deeply +engaged the attention of the human mind, has never been established. +When it was said: "Metaphysic is the science of the first principles +of human cognition," this definition did not signalize a peculiarity +in kind, but only a difference in degree; these first principles +were thus declared to be more general than others, but no criterion +of distinction from empirical principles was given. Of these some are +more general, and therefore higher, than others; and--as we cannot +distinguish what is completely a priori from that which is known to +be a posteriori--where shall we draw the line which is to separate +the higher and so-called first principles, from the lower and +subordinate principles of cognition? What would be said if we were +asked to be satisfied with a division of the epochs of the world +into the earlier centuries and those following them? "Does the +fifth, or the tenth century belong to the earlier centuries?" it would +be asked. In the same way I ask: Does the conception of extension +belong to metaphysics? You answer, "Yes." Well, that of body too? +"Yes." And that of a fluid body? You stop, you are unprepared to admit +this; for if you do, everything will belong to metaphysics. From +this it is evident that the mere degree of subordination--of the +particular to the general--cannot determine the limits of a science; +and that, in the present case, we must expect to find a difference +in the conceptions of metaphysics both in kind and in origin. The +fundamental idea of metaphysics was obscured on another side by the +fact that this kind of a priori cognition showed a certain +similarity in character with the science of mathematics. Both have +the property in common of possessing an a priori origin; but, in the +one, our knowledge is based upon conceptions, in the other, on the +construction of conceptions. Thus a decided dissimilarity between +philosophical and mathematical cognition comes out--a dissimilarity +which was always felt, but which could not be made distinct for want +of an insight into the criteria of the difference. And thus it +happened that, as philosophers themselves failed in the proper +development of the idea of their science, the elaboration of the +science could not proceed with a definite aim, or under trustworthy +guidance. Thus, too, philosophers, ignorant of the path they ought +to pursue and always disputing with each other regarding the +discoveries which each asserted he had made, brought their science +into disrepute with the rest of the world, and finally, even among +themselves. + +All pure a priori cognition forms, therefore, in view of the +peculiar faculty which originates it, a peculiar and distinct unity; +and metaphysic is the term applied to the philosophy which attempts +to represent that cognition in this systematic unity. The speculative +part of metaphysic, which has especially appropriated this +appellation--that which we have called the metaphysic of nature--and +which considers everything, as it is (not as it ought to be), by means +of a priori conceptions, is divided in the following manner. + +Metaphysic, in the more limited acceptation of the term, consists of +two parts--transcendental philosophy and the physiology of pure +reason. The former presents the system of all the conceptions and +principles belonging to the understanding and the reason, and which +relate to objects in general, but not to any particular given +objects (Ontologia); the latter has nature for its subject-matter, +that is, the sum of given objects--whether given to the senses, or, +if we will, to some other kind of intuition--and is accordingly +physiology, although only rationalis. But the use of the faculty of +reason in this rational mode of regarding nature is either physical +or hyperphysical, or, more properly speaking, immanent or transcendent. +The former relates to nature, in so far as our knowledge regarding +it may be applied in experience (in concreto); the latter to that +connection of the objects of experience, which transcends all +experience. Transcendent physiology has, again, an internal and an +external connection with its object, both, however, transcending +possible experience; the former is the physiology of nature as a +whole, or transcendental cognition of the world, the latter of the +connection of the whole of nature with a being above nature, or +transcendental cognition of God. + +Immanent physiology, on the contrary, considers nature as the sum of +all sensuous objects, consequently, as it is presented to us--but +still according to a priori conditions, for it is under these alone +that nature can be presented to our minds at all. The objects of +immanent physiology are of two kinds: 1. Those of the external senses, +or corporeal nature; 2. The object of the internal sense, the soul, +or, in accordance with our fundamental conceptions of it, thinking +nature. The metaphysics of corporeal nature is called physics; but, +as it must contain only the principles of an a priori cognition of +nature, we must term it rational physics. The metaphysics of +thinking nature is called psychology, and for the same reason is to +be regarded as merely the rational cognition of the soul. + +Thus the whole system of metaphysics consists of four principal +parts: 1. Ontology; 2. Rational Physiology; 3. Rational cosmology; +and 4. Rational theology. The second part--that of the rational doctrine +of nature--may be subdivided into two, physica rationalis* and +psychologia rationalis. + +[*Footnote: It must not be supposed that I mean by this appellation +what is generally called physica general is, and which is rather +mathematics than a philosophy of nature. For the metaphysic of nature +is completely different from mathematics, nor is it so rich in results, +although it is of great importance as a critical test of the +application of pure understanding-cognition to nature. For want of +its guidance, even mathematicians, adopting certain common notions- +which are, in fact, metaphysical--have unconsciously crowded their +theories of nature with hypotheses, the fallacy of which becomes +evident upon the application of the principles of this metaphysic, +without detriment, however, to the employment of mathematics in this +sphere of cognition.] + +The fundamental idea of a philosophy of pure reason of necessity +dictates this division; it is, therefore, architectonical--in +accordance with the highest aims of reason, and not merely +technical, or according to certain accidentally-observed +similarities existing between the different parts of the whole +science. For this reason, also, is the division immutable and of +legislative authority. But the reader may observe in it a few points +to which he ought to demur, and which may weaken his conviction of +its truth and legitimacy. + +In the first place, how can I desire an a priori cognition or +metaphysic of objects, in so far as they are given a posteriori? and +how is it possible to cognize the nature of things according to a +priori principles, and to attain to a rational physiology? The +answer is this. We take from experience nothing more than is requisite +to present us with an object (in general) of the external or of the +internal sense; in the former case, by the mere conception of matter +(impenetrable and inanimate extension), in the latter, by the +conception of a thinking being--given in the internal empirical +representation, I think. As to the rest, we must not employ in our +metaphysic of these objects any empirical principles (which add to +the content of our conceptions by means of experience), for the purpose +of forming by their help any judgements respecting these objects. + +Secondly, what place shall we assign to empirical psychology, +which has always been considered a part of metaphysics, and from which +in our time such important philosophical results have been expected, +after the hope of constructing an a priori system of knowledge had +been abandoned? I answer: It must be placed by the side of empirical +physics or physics proper; that is, must be regarded as forming a part +of applied philosophy, the a priori principles of which are +contained in pure philosophy, which is therefore connected, although +it must not be confounded, with psychology. Empirical psychology +must therefore be banished from the sphere of metaphysics, and is +indeed excluded by the very idea of that science. In conformity, +however, with scholastic usage, we must permit it to occupy a place +in metaphysics--but only as an appendix to it. We adopt this course +from motives of economy; as psychology is not as yet full enough to +occupy our attention as an independent study, while it is, at the same +time, of too great importance to be entirely excluded or placed +where it has still less affinity than it has with the subject of +metaphysics. It is a stranger who has been long a guest; and we make +it welcome to stay, until it can take up a more suitable abode in a +complete system of anthropology--the pendant to empirical physics. + +The above is the general idea of metaphysics, which, as more was +expected from it than could be looked for with justice, and as these +pleasant expectations were unfortunately never realized, fell into +general disrepute. Our Critique must have fully convinced the reader +that, although metaphysics cannot form the foundation of religion, +it must always be one of its most important bulwarks, and that human +reason, which naturally pursues a dialectical course, cannot do +without this science, which checks its tendencies towards dialectic +and, by elevating reason to a scientific and clear self-knowledge, +prevents the ravages which a lawless speculative reason would +infallibly commit in the sphere of morals as well as in that of +religion. We may be sure, therefore, whatever contempt may be thrown +upon metaphysics by those who judge a science not by its own nature, +but according to the accidental effects it may have produced, that +it can never be completely abandoned, that we must always return to +it as to a beloved one who has been for a time estranged, because the +questions with which it is engaged relate to the highest aims of +humanity, and reason must always labour either to attain to settled +views in regard to these, or to destroy those which others have +already established. + +Metaphysic, therefore--that of nature, as well as that of ethics, +but in an especial manner the criticism which forms the propaedeutic +to all the operations of reason--forms properly that department of +knowledge which may be termed, in the truest sense of the word, +philosophy. The path which it pursues is that of science, which, +when it has once been discovered, is never lost, and never misleads. +Mathematics, natural science, the common experience of men, have a +high value as means, for the most part, to accidental ends--but at +last also, to those which are necessary and essential to the existence +of humanity. But to guide them to this high goal, they require the +aid of rational cognition on the basis of pure conceptions, which, +be it termed as it may, is properly nothing but metaphysics. + +For the same reason, metaphysics forms likewise the completion of +the culture of human reason. In this respect, it is indispensable, +setting aside altogether the influence which it exerts as a science. +For its subject-matter is the elements and highest maxims of reason, +which form the basis of the possibility of some sciences and of the +use of all. That, as a purely speculative science, it is more useful +in preventing error than in the extension of knowledge, does not +detract from its value; on the contrary, the supreme office of +censor which it occupies assures to it the highest authority and +importance. This office it administers for the purpose of securing +order, harmony, and well-being to science, and of directing its +noble and fruitful labours to the highest possible aim--the +happiness of all mankind. + + + +CHAPTER IV. The History of Pure Reason. + +This title is placed here merely for the purpose of designating a +division of the system of pure reason of which I do not intend to +treat at present. I shall content myself with casting a cursory +glance, from a purely transcendental point of view--that of the nature +of pure reason--on the labours of philosophers up to the present time. +They have aimed at erecting an edifice of philosophy; but to my eye +this edifice appears to be in a very ruinous condition. + +It is very remarkable, although naturally it could not have been +otherwise, that, in the infancy of philosophy, the study of the nature +of God and the constitution of a future world formed the commencement, +rather than the conclusion, as we should have it, of the speculative +efforts of the human mind. However rude the religious conceptions +generated by the remains of the old manners and customs of a less +cultivated time, the intelligent classes were not thereby prevented +from devoting themselves to free inquiry into the existence and nature +of God; and they easily saw that there could be no surer way of +pleasing the invisible ruler of the world, and of attaining to +happiness in another world at least, than a good and honest course +of life in this. Thus theology and morals formed the two chief +motives, or rather the points of attraction in all abstract inquiries. +But it was the former that especially occupied the attention of +speculative reason, and which afterwards became so celebrated under +the name of metaphysics. + +I shall not at present indicate the periods of time at which the +greatest changes in metaphysics took place, but shall merely give a +hasty sketch of the different ideas which occasioned the most +important revolutions in this sphere of thought. There are three +different ends in relation to which these revolutions have taken +place. + +1. In relation to the object of the cognition of reason, +philosophers may be divided into sensualists and intellectualists. +Epicurus may be regarded as the head of the former, Plato of the +latter. The distinction here signalized, subtle as it is, dates from +the earliest times, and was long maintained. The former asserted +that reality resides in sensuous objects alone, and that everything +else is merely imaginary; the latter, that the senses are the +parents of illusion and that truth is to be found in the understanding +alone. The former did not deny to the conceptions of the understanding +a certain kind of reality; but with them it was merely logical, with +the others it was mystical. The former admitted intellectual +conceptions, but declared that sensuous objects alone possessed real +existence. The latter maintained that all real objects were +intelligible, and believed that the pure understanding possessed a +faculty of intuition apart from sense, which, in their opinion, served +only to confuse the ideas of the understanding. + +2. In relation to the origin of the pure cognitions of reason, we +find one school maintaining that they are derived entirely from +experience, and another that they have their origin in reason alone. +Aristotle may be regarded as the bead of the empiricists, and Plato +of the noologists. Locke, the follower of Aristotle in modern times, +and Leibnitz of Plato (although he cannot be said to have imitated +him in his mysticism), have not been able to bring this question to +a settled conclusion. The procedure of Epicurus in his sensual system, +in which he always restricted his conclusions to the sphere of +experience, was much more consequent than that of Aristotle and Locke. +The latter especially, after having derived all the conceptions and +principles of the mind from experience, goes so far, in the employment +of these conceptions and principles, as to maintain that we can +prove the existence of God and the existence of God and the +immortality of them objects lying beyond the soul--both of them of +possible experience--with the same force of demonstration as any +mathematical proposition. + +3. In relation to method. Method is procedure according to +principles. We may divide the methods at present employed in the field +of inquiry into the naturalistic and the scientific. The naturalist +of pure reason lays it down as his principle that common reason, +without the aid of science--which he calls sound reason, or common +sense--can give a more satisfactory answer to the most important +questions of metaphysics than speculation is able to do. He must +maintain, therefore, that we can determine the content and +circumference of the moon more certainly by the naked eye, than by +the aid of mathematical reasoning. But this system is mere misology +reduced to principles; and, what is the most absurd thing in this +doctrine, the neglect of all scientific means is paraded as a peculiar +method of extending our cognition. As regards those who are +naturalists because they know no better, they are certainly not to +be blamed. They follow common sense, without parading their +ignorance as a method which is to teach us the wonderful secret, how +we are to find the truth which lies at the bottom of the well of +Democritus. + + Quod sapio satis est mihi, non ego curo Esse quod + Arcesilas aerumnosique Solones. PERSIUS + -- Satirae, iii. 78-79. + +is their motto, under which they may lead a pleasant and praiseworthy +life, without troubling themselves with science or troubling science +with them. + +As regards those who wish to pursue a scientific method, they have +now the choice of following either the dogmatical or the sceptical, +while they are bound never to desert the systematic mode of procedure. +When I mention, in relation to the former, the celebrated Wolf, and +as regards the latter, David Hume, I may leave, in accordance with +my present intention, all others unnamed. The critical path alone is +still open. If my reader has been kind and patient enough to accompany +me on this hitherto untravelled route, he can now judge whether, if +he and others will contribute their exertions towards making this +narrow footpath a high road of thought, that which many centuries have +failed to accomplish may not be executed before the close of the +present--namely, to bring Reason to perfect contentment in regard to +that which has always, but without permanent results, occupied her +powers and engaged her ardent desire for knowledge. diff --git a/tests/org.simantics.db.tests/data/graph.txt b/tests/org.simantics.db.tests/data/graph.txt new file mode 100644 index 000000000..81d787b1f --- /dev/null +++ b/tests/org.simantics.db.tests/data/graph.txt @@ -0,0 +1,6003 @@ +b http:/ 0 0 +b http://www.simantics.org/Layer0-1.0/InstanceOf 2 1 +b http://www.simantics.org/Layer0-1.0/SubrelationOf 3 1 +b http://www.simantics.org/Layer0-1.0/InverseOf 4 1 +b http://www.simantics.org/Layer0-1.0/Inherits 5 1 +b http://www.simantics.org/Configuration/PublishedProjectFeatures 582 1 +b http://www.simantics.org/Layer0-1.0/HasName 6 1 +b http://www.simantics.org/Layer0-1.0/PartOf 7 1 +b http://www.simantics.org/Project-1.0/Project2 584 1 +b http://www.simantics.org/Layer0-1.0/ConsistsOf 9 1 +b http://www.simantics.org/Layer0-1.0/FunctionalRelation 42 1 +b http://www.simantics.org/Layer0-1.0/Library 45 1 +b http://www.simantics.org/Users 46 1 +b http://www.simantics.org/Projects 47 1 +b http://www.simantics.org/Configuration 48 1 +b http://www.simantics.org/Configuration#AgentServers 49 1 +b http://www.simantics.org/Users/DefaultUser 50 1 +b http://www.simantics.org/Layer0-1.0/SuperrelationOf 51 1 +b http://www.simantics.org/Layer0-1.0/HasPasswordHash 52 1 +b http://www.simantics.org/Layer0-1.0/Ontology 53 1 +b http://www.simantics.org/Layer0-1.0/Asserts 54 1 +b http://www.simantics.org/Layer0-1.0/HasPredicate 55 1 +b http://www.simantics.org/Layer0-1.0/HasObject 56 1 +r 0 0 9 1 57 1 +r 0 0 9 1 49 1 +r 0 0 9 1 48 1 +r 0 0 9 1 47 1 +r 0 0 9 1 46 1 +r 0 0 2 1 45 1 +r 0 0 6 1 915 1 +r 1 1 1112 1 666 1 +r 1 1 1112 1 476 1 +r 1 1 1112 1 423 1 +r 1 1 1112 1 208 1 +r 1 1 1112 1 38 1 +r 1 1 1112 1 4 1 +r 1 1 1112 1 3 1 +r 1 1 1113 1 481 1 +r 1 1 1113 1 4 1 +r 1 1 1113 1 3 1 +r 1 1 171 1 8 1 +r 1 1 172 1 447 1 +r 1 1 172 1 427 1 +r 1 1 172 1 351 1 +r 1 1 172 1 90 1 +r 1 1 172 1 42 1 +r 1 1 100 1 207 1 +r 1 1 100 1 206 1 +r 1 1 100 1 205 1 +r 1 1 100 1 204 1 +r 1 1 69 1 203 1 +r 1 1 5 1 202 1 +r 1 1 6 1 937 1 +r 1 1 1111 1 182 1 +r 1 1 7 1 44 1 +r 2 1 89 1 2 1 +r 2 1 3 1 77 1 +r 2 1 1116 1 210 1 +r 2 1 4 1 171 1 +r 2 1 28 1 87 1 +r 2 1 6 1 922 1 +r 2 1 7 1 44 1 +r 3 1 89 1 3 1 +r 3 1 3 1 80 1 +r 3 1 1116 1 205 1 +r 3 1 4 1 51 1 +r 3 1 28 1 1 1 +r 3 1 29 1 1 1 +r 3 1 6 1 945 1 +r 3 1 7 1 44 1 +r 4 1 89 1 4 1 +r 4 1 2 1 42 1 +r 4 1 3 1 82 1 +r 4 1 3 1 80 1 +r 4 1 1116 1 206 1 +r 4 1 4 1 4 1 +r 4 1 28 1 1 1 +r 4 1 29 1 1 1 +r 4 1 69 1 88 1 +r 4 1 6 1 921 1 +r 4 1 7 1 44 1 +r 5 1 89 1 5 1 +r 5 1 3 1 80 1 +r 5 1 1116 1 198 1 +r 5 1 4 1 172 1 +r 5 1 28 1 87 1 +r 5 1 29 1 87 1 +r 5 1 6 1 960 1 +r 5 1 7 1 44 1 +r 6 1 113 1 114 1 +r 6 1 2 1 42 1 +r 6 1 3 1 74 1 +r 6 1 1116 1 219 1 +r 6 1 1116 1 215 1 +r 6 1 1116 1 176 1 +r 6 1 1116 1 162 1 +r 6 1 4 1 115 1 +r 6 1 28 1 10 1 +r 6 1 6 1 874 1 +r 6 1 7 1 44 1 +r 7 1 3 1 85 1 +r 7 1 1116 1 402 1 +r 7 1 4 1 9 1 +r 7 1 6 1 853 1 +r 7 1 7 1 44 1 +r 8 1 2 1 1 1 +r 8 1 51 1 1195 1 +r 8 1 51 1 1158 1 +r 8 1 51 1 560 1 +r 8 1 51 1 468 1 +r 8 1 51 1 444 1 +r 8 1 51 1 306 1 +r 8 1 51 1 233 1 +r 8 1 51 1 232 1 +r 8 1 51 1 231 1 +r 8 1 51 1 230 1 +r 8 1 51 1 79 1 +r 8 1 51 1 77 1 +r 8 1 4 1 8 1 +r 8 1 69 1 76 1 +r 8 1 6 1 1007 1 +r 8 1 7 1 44 1 +r 9 1 3 1 83 1 +r 9 1 1116 1 713 1 +r 9 1 1116 1 710 1 +r 9 1 1116 1 585 1 +r 9 1 1116 1 521 1 +r 9 1 1116 1 419 1 +r 9 1 1116 1 383 1 +r 9 1 1116 1 376 1 +r 9 1 1116 1 372 1 +r 9 1 1116 1 191 1 +r 9 1 1116 1 187 1 +r 9 1 1116 1 184 1 +r 9 1 1116 1 181 1 +r 9 1 1116 1 178 1 +r 9 1 4 1 7 1 +r 9 1 6 1 908 1 +r 9 1 7 1 44 1 +r 10 1 1112 1 692 1 +r 10 1 1112 1 657 1 +r 10 1 1112 1 642 1 +r 10 1 1112 1 627 1 +r 10 1 1112 1 588 1 +r 10 1 1112 1 564 1 +r 10 1 1112 1 241 1 +r 10 1 1112 1 238 1 +r 10 1 1112 1 223 1 +r 10 1 1112 1 214 1 +r 10 1 1112 1 127 1 +r 10 1 1112 1 126 1 +r 10 1 1112 1 119 1 +r 10 1 1112 1 116 1 +r 10 1 1112 1 113 1 +r 10 1 1112 1 71 1 +r 10 1 1112 1 69 1 +r 10 1 1112 1 65 1 +r 10 1 1112 1 63 1 +r 10 1 1112 1 52 1 +r 10 1 1112 1 6 1 +r 10 1 171 1 1110 1 +r 10 1 171 1 1109 1 +r 10 1 171 1 1108 1 +r 10 1 171 1 1107 1 +r 10 1 171 1 1106 1 +r 10 1 171 1 1105 1 +r 10 1 171 1 1104 1 +r 10 1 171 1 1103 1 +r 10 1 171 1 1102 1 +r 10 1 171 1 1101 1 +r 10 1 171 1 1100 1 +r 10 1 171 1 1099 1 +r 10 1 171 1 1098 1 +r 10 1 171 1 1097 1 +r 10 1 171 1 1096 1 +r 10 1 171 1 1095 1 +r 10 1 171 1 1094 1 +r 10 1 171 1 1093 1 +r 10 1 171 1 1092 1 +r 10 1 171 1 1091 1 +r 10 1 171 1 1090 1 +r 10 1 171 1 1089 1 +r 10 1 171 1 1088 1 +r 10 1 171 1 1087 1 +r 10 1 171 1 1086 1 +r 10 1 171 1 1085 1 +r 10 1 171 1 1084 1 +r 10 1 171 1 1083 1 +r 10 1 171 1 1082 1 +r 10 1 171 1 1081 1 +r 10 1 171 1 1080 1 +r 10 1 171 1 1079 1 +r 10 1 171 1 1078 1 +r 10 1 171 1 1077 1 +r 10 1 171 1 1076 1 +r 10 1 171 1 1075 1 +r 10 1 171 1 1074 1 +r 10 1 171 1 1073 1 +r 10 1 171 1 1072 1 +r 10 1 171 1 1071 1 +r 10 1 171 1 1070 1 +r 10 1 171 1 1069 1 +r 10 1 171 1 1068 1 +r 10 1 171 1 1067 1 +r 10 1 171 1 1066 1 +r 10 1 171 1 1065 1 +r 10 1 171 1 1064 1 +r 10 1 171 1 1063 1 +r 10 1 171 1 1062 1 +r 10 1 171 1 1061 1 +r 10 1 171 1 1060 1 +r 10 1 171 1 1059 1 +r 10 1 171 1 1058 1 +r 10 1 171 1 1057 1 +r 10 1 171 1 1056 1 +r 10 1 171 1 1055 1 +r 10 1 171 1 1054 1 +r 10 1 171 1 1053 1 +r 10 1 171 1 1052 1 +r 10 1 171 1 1051 1 +r 10 1 171 1 1050 1 +r 10 1 171 1 1049 1 +r 10 1 171 1 1048 1 +r 10 1 171 1 1047 1 +r 10 1 171 1 1046 1 +r 10 1 171 1 1045 1 +r 10 1 171 1 1044 1 +r 10 1 171 1 1043 1 +r 10 1 171 1 1042 1 +r 10 1 171 1 1041 1 +r 10 1 171 1 1040 1 +r 10 1 171 1 1039 1 +r 10 1 171 1 1038 1 +r 10 1 171 1 1037 1 +r 10 1 171 1 1036 1 +r 10 1 171 1 1035 1 +r 10 1 171 1 1034 1 +r 10 1 171 1 1033 1 +r 10 1 171 1 1032 1 +r 10 1 171 1 1031 1 +r 10 1 171 1 1030 1 +r 10 1 171 1 1029 1 +r 10 1 171 1 1028 1 +r 10 1 171 1 1027 1 +r 10 1 171 1 1026 1 +r 10 1 171 1 1025 1 +r 10 1 171 1 1024 1 +r 10 1 171 1 1023 1 +r 10 1 171 1 1022 1 +r 10 1 171 1 1021 1 +r 10 1 171 1 1020 1 +r 10 1 171 1 1019 1 +r 10 1 171 1 1018 1 +r 10 1 171 1 1017 1 +r 10 1 171 1 1016 1 +r 10 1 171 1 1015 1 +r 10 1 171 1 1014 1 +r 10 1 171 1 1013 1 +r 10 1 171 1 1012 1 +r 10 1 171 1 1011 1 +r 10 1 171 1 1010 1 +r 10 1 171 1 1009 1 +r 10 1 171 1 1008 1 +r 10 1 171 1 1007 1 +r 10 1 171 1 1006 1 +r 10 1 171 1 1005 1 +r 10 1 171 1 1004 1 +r 10 1 171 1 1003 1 +r 10 1 171 1 1002 1 +r 10 1 171 1 1001 1 +r 10 1 171 1 1000 1 +r 10 1 171 1 999 1 +r 10 1 171 1 998 1 +r 10 1 171 1 997 1 +r 10 1 171 1 996 1 +r 10 1 171 1 995 1 +r 10 1 171 1 994 1 +r 10 1 171 1 993 1 +r 10 1 171 1 992 1 +r 10 1 171 1 991 1 +r 10 1 171 1 990 1 +r 10 1 171 1 989 1 +r 10 1 171 1 988 1 +r 10 1 171 1 987 1 +r 10 1 171 1 986 1 +r 10 1 171 1 985 1 +r 10 1 171 1 984 1 +r 10 1 171 1 983 1 +r 10 1 171 1 982 1 +r 10 1 171 1 981 1 +r 10 1 171 1 980 1 +r 10 1 171 1 979 1 +r 10 1 171 1 978 1 +r 10 1 171 1 977 1 +r 10 1 171 1 976 1 +r 10 1 171 1 975 1 +r 10 1 171 1 974 1 +r 10 1 171 1 973 1 +r 10 1 171 1 972 1 +r 10 1 171 1 971 1 +r 10 1 171 1 970 1 +r 10 1 171 1 969 1 +r 10 1 171 1 968 1 +r 10 1 171 1 967 1 +r 10 1 171 1 966 1 +r 10 1 171 1 965 1 +r 10 1 171 1 964 1 +r 10 1 171 1 963 1 +r 10 1 171 1 962 1 +r 10 1 171 1 961 1 +r 10 1 171 1 960 1 +r 10 1 171 1 959 1 +r 10 1 171 1 958 1 +r 10 1 171 1 957 1 +r 10 1 171 1 956 1 +r 10 1 171 1 955 1 +r 10 1 171 1 954 1 +r 10 1 171 1 953 1 +r 10 1 171 1 952 1 +r 10 1 171 1 951 1 +r 10 1 171 1 950 1 +r 10 1 171 1 949 1 +r 10 1 171 1 948 1 +r 10 1 171 1 947 1 +r 10 1 171 1 946 1 +r 10 1 171 1 945 1 +r 10 1 171 1 944 1 +r 10 1 171 1 943 1 +r 10 1 171 1 942 1 +r 10 1 171 1 941 1 +r 10 1 171 1 940 1 +r 10 1 171 1 939 1 +r 10 1 171 1 938 1 +r 10 1 171 1 937 1 +r 10 1 171 1 936 1 +r 10 1 171 1 935 1 +r 10 1 171 1 934 1 +r 10 1 171 1 933 1 +r 10 1 171 1 932 1 +r 10 1 171 1 931 1 +r 10 1 171 1 930 1 +r 10 1 171 1 929 1 +r 10 1 171 1 928 1 +r 10 1 171 1 927 1 +r 10 1 171 1 926 1 +r 10 1 171 1 925 1 +r 10 1 171 1 924 1 +r 10 1 171 1 923 1 +r 10 1 171 1 922 1 +r 10 1 171 1 921 1 +r 10 1 171 1 920 1 +r 10 1 171 1 919 1 +r 10 1 171 1 918 1 +r 10 1 171 1 917 1 +r 10 1 171 1 916 1 +r 10 1 171 1 915 1 +r 10 1 171 1 914 1 +r 10 1 171 1 913 1 +r 10 1 171 1 912 1 +r 10 1 171 1 911 1 +r 10 1 171 1 910 1 +r 10 1 171 1 909 1 +r 10 1 171 1 908 1 +r 10 1 171 1 907 1 +r 10 1 171 1 906 1 +r 10 1 171 1 905 1 +r 10 1 171 1 904 1 +r 10 1 171 1 903 1 +r 10 1 171 1 902 1 +r 10 1 171 1 901 1 +r 10 1 171 1 900 1 +r 10 1 171 1 899 1 +r 10 1 171 1 898 1 +r 10 1 171 1 897 1 +r 10 1 171 1 896 1 +r 10 1 171 1 895 1 +r 10 1 171 1 894 1 +r 10 1 171 1 893 1 +r 10 1 171 1 892 1 +r 10 1 171 1 891 1 +r 10 1 171 1 890 1 +r 10 1 171 1 889 1 +r 10 1 171 1 888 1 +r 10 1 171 1 887 1 +r 10 1 171 1 886 1 +r 10 1 171 1 885 1 +r 10 1 171 1 884 1 +r 10 1 171 1 883 1 +r 10 1 171 1 882 1 +r 10 1 171 1 881 1 +r 10 1 171 1 880 1 +r 10 1 171 1 879 1 +r 10 1 171 1 878 1 +r 10 1 171 1 877 1 +r 10 1 171 1 876 1 +r 10 1 171 1 875 1 +r 10 1 171 1 874 1 +r 10 1 171 1 873 1 +r 10 1 171 1 872 1 +r 10 1 171 1 871 1 +r 10 1 171 1 870 1 +r 10 1 171 1 869 1 +r 10 1 171 1 868 1 +r 10 1 171 1 867 1 +r 10 1 171 1 866 1 +r 10 1 171 1 865 1 +r 10 1 171 1 864 1 +r 10 1 171 1 863 1 +r 10 1 171 1 862 1 +r 10 1 171 1 861 1 +r 10 1 171 1 860 1 +r 10 1 171 1 859 1 +r 10 1 171 1 858 1 +r 10 1 171 1 857 1 +r 10 1 171 1 856 1 +r 10 1 171 1 855 1 +r 10 1 171 1 854 1 +r 10 1 171 1 853 1 +r 10 1 171 1 852 1 +r 10 1 171 1 851 1 +r 10 1 171 1 850 1 +r 10 1 171 1 849 1 +r 10 1 171 1 848 1 +r 10 1 171 1 847 1 +r 10 1 171 1 846 1 +r 10 1 171 1 845 1 +r 10 1 171 1 844 1 +r 10 1 171 1 843 1 +r 10 1 171 1 842 1 +r 10 1 171 1 841 1 +r 10 1 171 1 840 1 +r 10 1 171 1 839 1 +r 10 1 171 1 838 1 +r 10 1 171 1 837 1 +r 10 1 171 1 836 1 +r 10 1 171 1 835 1 +r 10 1 171 1 834 1 +r 10 1 171 1 833 1 +r 10 1 171 1 832 1 +r 10 1 171 1 831 1 +r 10 1 171 1 830 1 +r 10 1 171 1 829 1 +r 10 1 171 1 828 1 +r 10 1 171 1 827 1 +r 10 1 171 1 826 1 +r 10 1 171 1 825 1 +r 10 1 171 1 824 1 +r 10 1 171 1 823 1 +r 10 1 171 1 822 1 +r 10 1 171 1 821 1 +r 10 1 171 1 820 1 +r 10 1 171 1 819 1 +r 10 1 171 1 818 1 +r 10 1 171 1 817 1 +r 10 1 171 1 816 1 +r 10 1 171 1 815 1 +r 10 1 171 1 814 1 +r 10 1 171 1 813 1 +r 10 1 171 1 812 1 +r 10 1 171 1 811 1 +r 10 1 171 1 810 1 +r 10 1 171 1 809 1 +r 10 1 171 1 808 1 +r 10 1 171 1 807 1 +r 10 1 171 1 806 1 +r 10 1 171 1 805 1 +r 10 1 171 1 804 1 +r 10 1 171 1 803 1 +r 10 1 171 1 802 1 +r 10 1 171 1 801 1 +r 10 1 171 1 800 1 +r 10 1 171 1 799 1 +r 10 1 171 1 798 1 +r 10 1 171 1 797 1 +r 10 1 171 1 796 1 +r 10 1 171 1 795 1 +r 10 1 171 1 794 1 +r 10 1 171 1 793 1 +r 10 1 171 1 792 1 +r 10 1 171 1 791 1 +r 10 1 171 1 790 1 +r 10 1 171 1 789 1 +r 10 1 171 1 788 1 +r 10 1 171 1 787 1 +r 10 1 171 1 786 1 +r 10 1 171 1 785 1 +r 10 1 171 1 784 1 +r 10 1 171 1 783 1 +r 10 1 171 1 782 1 +r 10 1 171 1 781 1 +r 10 1 171 1 780 1 +r 10 1 171 1 779 1 +r 10 1 171 1 778 1 +r 10 1 171 1 777 1 +r 10 1 171 1 776 1 +r 10 1 171 1 775 1 +r 10 1 171 1 774 1 +r 10 1 171 1 773 1 +r 10 1 171 1 772 1 +r 10 1 171 1 771 1 +r 10 1 171 1 770 1 +r 10 1 171 1 769 1 +r 10 1 171 1 768 1 +r 10 1 171 1 767 1 +r 10 1 171 1 766 1 +r 10 1 171 1 765 1 +r 10 1 171 1 764 1 +r 10 1 171 1 763 1 +r 10 1 171 1 762 1 +r 10 1 171 1 761 1 +r 10 1 171 1 760 1 +r 10 1 171 1 759 1 +r 10 1 171 1 758 1 +r 10 1 171 1 757 1 +r 10 1 171 1 756 1 +r 10 1 171 1 755 1 +r 10 1 171 1 754 1 +r 10 1 171 1 753 1 +r 10 1 171 1 752 1 +r 10 1 171 1 751 1 +r 10 1 171 1 750 1 +r 10 1 171 1 749 1 +r 10 1 171 1 748 1 +r 10 1 171 1 747 1 +r 10 1 171 1 746 1 +r 10 1 171 1 745 1 +r 10 1 171 1 744 1 +r 10 1 171 1 743 1 +r 10 1 171 1 742 1 +r 10 1 171 1 741 1 +r 10 1 171 1 740 1 +r 10 1 171 1 739 1 +r 10 1 171 1 738 1 +r 10 1 171 1 737 1 +r 10 1 171 1 736 1 +r 10 1 171 1 735 1 +r 10 1 171 1 734 1 +r 10 1 171 1 733 1 +r 10 1 171 1 732 1 +r 10 1 171 1 731 1 +r 10 1 171 1 730 1 +r 10 1 171 1 729 1 +r 10 1 171 1 728 1 +r 10 1 171 1 727 1 +r 10 1 171 1 726 1 +r 10 1 171 1 725 1 +r 10 1 171 1 724 1 +r 10 1 171 1 723 1 +r 10 1 171 1 722 1 +r 10 1 171 1 721 1 +r 10 1 171 1 719 1 +r 10 1 171 1 717 1 +r 10 1 171 1 703 1 +r 10 1 171 1 695 1 +r 10 1 171 1 693 1 +r 10 1 171 1 683 1 +r 10 1 171 1 674 1 +r 10 1 171 1 672 1 +r 10 1 171 1 671 1 +r 10 1 171 1 668 1 +r 10 1 171 1 628 1 +r 10 1 171 1 626 1 +r 10 1 171 1 625 1 +r 10 1 171 1 621 1 +r 10 1 171 1 620 1 +r 10 1 171 1 618 1 +r 10 1 171 1 614 1 +r 10 1 171 1 613 1 +r 10 1 171 1 611 1 +r 10 1 171 1 610 1 +r 10 1 171 1 606 1 +r 10 1 171 1 601 1 +r 10 1 171 1 599 1 +r 10 1 171 1 593 1 +r 10 1 171 1 590 1 +r 10 1 171 1 581 1 +r 10 1 171 1 579 1 +r 10 1 171 1 553 1 +r 10 1 171 1 527 1 +r 10 1 171 1 509 1 +r 10 1 171 1 507 1 +r 10 1 171 1 503 1 +r 10 1 171 1 498 1 +r 10 1 171 1 496 1 +r 10 1 171 1 495 1 +r 10 1 171 1 492 1 +r 10 1 171 1 485 1 +r 10 1 171 1 477 1 +r 10 1 171 1 471 1 +r 10 1 171 1 439 1 +r 10 1 171 1 436 1 +r 10 1 171 1 435 1 +r 10 1 171 1 420 1 +r 10 1 171 1 416 1 +r 10 1 171 1 413 1 +r 10 1 171 1 408 1 +r 10 1 171 1 397 1 +r 10 1 171 1 396 1 +r 10 1 171 1 394 1 +r 10 1 171 1 392 1 +r 10 1 171 1 370 1 +r 10 1 171 1 369 1 +r 10 1 171 1 367 1 +r 10 1 171 1 366 1 +r 10 1 171 1 363 1 +r 10 1 171 1 354 1 +r 10 1 171 1 352 1 +r 10 1 171 1 350 1 +r 10 1 171 1 340 1 +r 10 1 171 1 339 1 +r 10 1 171 1 338 1 +r 10 1 171 1 337 1 +r 10 1 171 1 333 1 +r 10 1 171 1 330 1 +r 10 1 171 1 327 1 +r 10 1 171 1 323 1 +r 10 1 171 1 321 1 +r 10 1 171 1 305 1 +r 10 1 171 1 303 1 +r 10 1 171 1 302 1 +r 10 1 171 1 301 1 +r 10 1 171 1 299 1 +r 10 1 171 1 281 1 +r 10 1 171 1 243 1 +r 10 1 171 1 242 1 +r 10 1 171 1 209 1 +r 10 1 171 1 203 1 +r 10 1 171 1 201 1 +r 10 1 171 1 196 1 +r 10 1 171 1 175 1 +r 10 1 171 1 125 1 +r 10 1 171 1 123 1 +r 10 1 171 1 118 1 +r 10 1 171 1 117 1 +r 10 1 171 1 114 1 +r 10 1 171 1 99 1 +r 10 1 171 1 96 1 +r 10 1 171 1 95 1 +r 10 1 171 1 94 1 +r 10 1 171 1 93 1 +r 10 1 171 1 91 1 +r 10 1 171 1 88 1 +r 10 1 171 1 86 1 +r 10 1 171 1 84 1 +r 10 1 171 1 81 1 +r 10 1 171 1 78 1 +r 10 1 171 1 76 1 +r 10 1 171 1 75 1 +r 10 1 171 1 72 1 +r 10 1 171 1 70 1 +r 10 1 171 1 68 1 +r 10 1 171 1 66 1 +r 10 1 171 1 64 1 +r 10 1 171 1 59 1 +r 10 1 171 1 58 1 +r 10 1 172 1 555 1 +r 10 1 172 1 122 1 +r 10 1 172 1 121 1 +r 10 1 172 1 62 1 +r 10 1 5 1 111 1 +r 10 1 6 1 843 1 +r 10 1 7 1 44 1 +r 11 1 1112 1 702 1 +r 11 1 1112 1 701 1 +r 11 1 1112 1 678 1 +r 11 1 1112 1 677 1 +r 11 1 1112 1 656 1 +r 11 1 1112 1 655 1 +r 11 1 1112 1 638 1 +r 11 1 1112 1 633 1 +r 11 1 1112 1 318 1 +r 11 1 1112 1 316 1 +r 11 1 171 1 334 1 +r 11 1 171 1 331 1 +r 11 1 171 1 329 1 +r 11 1 171 1 328 1 +r 11 1 171 1 325 1 +r 11 1 171 1 324 1 +r 11 1 171 1 322 1 +r 11 1 5 1 112 1 +r 11 1 6 1 977 1 +r 11 1 7 1 44 1 +r 12 1 1112 1 680 1 +r 12 1 1112 1 679 1 +r 12 1 1112 1 661 1 +r 12 1 1112 1 660 1 +r 12 1 1112 1 652 1 +r 12 1 1112 1 649 1 +r 12 1 1112 1 533 1 +r 12 1 1112 1 531 1 +r 12 1 1112 1 529 1 +r 12 1 1112 1 513 1 +r 12 1 1112 1 159 1 +r 12 1 5 1 112 1 +r 12 1 6 1 899 1 +r 12 1 7 1 44 1 +r 13 1 5 1 112 1 +r 13 1 6 1 844 1 +r 13 1 7 1 44 1 +r 14 1 171 1 300 1 +r 14 1 171 1 298 1 +r 14 1 5 1 111 1 +r 14 1 6 1 1004 1 +r 14 1 7 1 44 1 +r 15 1 1112 1 563 1 +r 15 1 5 1 112 1 +r 15 1 6 1 1037 1 +r 15 1 7 1 44 1 +r 16 1 1112 1 240 1 +r 16 1 5 1 112 1 +r 16 1 6 1 887 1 +r 16 1 7 1 44 1 +r 17 1 5 1 111 1 +r 17 1 6 1 975 1 +r 17 1 7 1 44 1 +r 18 1 5 1 111 1 +r 18 1 6 1 928 1 +r 18 1 7 1 44 1 +r 19 1 5 1 111 1 +r 19 1 6 1 830 1 +r 19 1 7 1 44 1 +r 20 1 5 1 111 1 +r 20 1 6 1 1013 1 +r 20 1 7 1 44 1 +r 21 1 5 1 111 1 +r 21 1 6 1 938 1 +r 21 1 7 1 44 1 +r 22 1 1112 1 681 1 +r 22 1 5 1 111 1 +r 22 1 6 1 933 1 +r 22 1 7 1 44 1 +r 23 1 5 1 111 1 +r 23 1 6 1 1001 1 +r 23 1 7 1 44 1 +r 24 1 1112 1 525 1 +r 24 1 1112 1 74 1 +r 24 1 2 1 106 1 +r 24 1 172 1 193 1 +r 24 1 92 1 24 1 +r 24 1 5 1 25 1 +r 24 1 6 1 912 1 +r 24 1 1111 1 519 1 +r 24 1 1111 1 518 1 +r 24 1 7 1 44 1 +r 25 1 2 1 87 1 +r 25 1 171 1 582 1 +r 25 1 100 1 211 1 +r 25 1 100 1 210 1 +r 25 1 172 1 675 1 +r 25 1 172 1 663 1 +r 25 1 172 1 650 1 +r 25 1 172 1 647 1 +r 25 1 172 1 646 1 +r 25 1 172 1 630 1 +r 25 1 172 1 592 1 +r 25 1 172 1 589 1 +r 25 1 172 1 583 1 +r 25 1 172 1 565 1 +r 25 1 172 1 561 1 +r 25 1 172 1 558 1 +r 25 1 172 1 534 1 +r 25 1 172 1 522 1 +r 25 1 172 1 520 1 +r 25 1 172 1 499 1 +r 25 1 172 1 487 1 +r 25 1 172 1 486 1 +r 25 1 172 1 482 1 +r 25 1 172 1 470 1 +r 25 1 172 1 466 1 +r 25 1 172 1 457 1 +r 25 1 172 1 455 1 +r 25 1 172 1 451 1 +r 25 1 172 1 440 1 +r 25 1 172 1 433 1 +r 25 1 172 1 415 1 +r 25 1 172 1 398 1 +r 25 1 172 1 388 1 +r 25 1 172 1 384 1 +r 25 1 172 1 378 1 +r 25 1 172 1 374 1 +r 25 1 172 1 361 1 +r 25 1 172 1 360 1 +r 25 1 172 1 359 1 +r 25 1 172 1 358 1 +r 25 1 172 1 357 1 +r 25 1 172 1 356 1 +r 25 1 172 1 355 1 +r 25 1 172 1 347 1 +r 25 1 172 1 346 1 +r 25 1 172 1 343 1 +r 25 1 172 1 315 1 +r 25 1 172 1 312 1 +r 25 1 172 1 304 1 +r 25 1 172 1 287 1 +r 25 1 172 1 286 1 +r 25 1 172 1 278 1 +r 25 1 172 1 276 1 +r 25 1 172 1 272 1 +r 25 1 172 1 269 1 +r 25 1 172 1 237 1 +r 25 1 172 1 228 1 +r 25 1 172 1 227 1 +r 25 1 172 1 217 1 +r 25 1 172 1 212 1 +r 25 1 172 1 202 1 +r 25 1 172 1 195 1 +r 25 1 172 1 189 1 +r 25 1 172 1 144 1 +r 25 1 172 1 134 1 +r 25 1 172 1 132 1 +r 25 1 172 1 129 1 +r 25 1 172 1 102 1 +r 25 1 172 1 97 1 +r 25 1 172 1 67 1 +r 25 1 172 1 45 1 +r 25 1 172 1 24 1 +r 25 1 69 1 209 1 +r 25 1 6 1 847 1 +r 25 1 7 1 44 1 +r 26 1 2 1 90 1 +r 26 1 3 1 79 1 +r 26 1 3 1 77 1 +r 26 1 4 1 26 1 +r 26 1 29 1 87 1 +r 26 1 69 1 94 1 +r 26 1 6 1 932 1 +r 26 1 7 1 44 1 +r 27 1 3 1 80 1 +r 27 1 1116 1 199 1 +r 27 1 1116 1 148 1 +r 27 1 1116 1 147 1 +r 27 1 1116 1 146 1 +r 27 1 4 1 1111 1 +r 27 1 28 1 144 1 +r 27 1 6 1 920 1 +r 27 1 7 1 44 1 +r 28 1 3 1 80 1 +r 28 1 4 1 1112 1 +r 28 1 28 1 144 1 +r 28 1 6 1 849 1 +r 28 1 7 1 44 1 +r 29 1 3 1 80 1 +r 29 1 4 1 1113 1 +r 29 1 28 1 144 1 +r 29 1 6 1 1005 1 +r 29 1 7 1 44 1 +r 30 1 3 1 80 1 +r 30 1 1116 1 156 1 +r 30 1 1116 1 150 1 +r 30 1 4 1 1114 1 +r 30 1 28 1 87 1 +r 30 1 69 1 86 1 +r 30 1 6 1 827 1 +r 30 1 7 1 44 1 +r 31 1 3 1 77 1 +r 31 1 1116 1 149 1 +r 31 1 4 1 1115 1 +r 31 1 6 1 949 1 +r 31 1 7 1 44 1 +r 32 1 100 1 147 1 +r 32 1 5 1 144 1 +r 32 1 6 1 1016 1 +r 32 1 7 1 44 1 +r 33 1 171 1 714 1 +r 33 1 171 1 711 1 +r 33 1 171 1 595 1 +r 33 1 171 1 519 1 +r 33 1 171 1 518 1 +r 33 1 171 1 517 1 +r 33 1 171 1 430 1 +r 33 1 171 1 377 1 +r 33 1 171 1 373 1 +r 33 1 171 1 192 1 +r 33 1 171 1 188 1 +r 33 1 171 1 185 1 +r 33 1 171 1 182 1 +r 33 1 171 1 179 1 +r 33 1 100 1 146 1 +r 33 1 5 1 144 1 +r 33 1 6 1 833 1 +r 33 1 7 1 44 1 +r 34 1 100 1 148 1 +r 34 1 5 1 144 1 +r 34 1 6 1 983 1 +r 34 1 7 1 44 1 +r 35 1 171 1 434 1 +r 35 1 171 1 432 1 +r 35 1 171 1 431 1 +r 35 1 100 1 150 1 +r 35 1 5 1 144 1 +r 35 1 6 1 981 1 +r 35 1 7 1 44 1 +r 36 1 100 1 149 1 +r 36 1 5 1 144 1 +r 36 1 6 1 897 1 +r 36 1 7 1 44 1 +r 37 1 1112 1 199 1 +r 37 1 171 1 713 1 +r 37 1 171 1 710 1 +r 37 1 171 1 376 1 +r 37 1 171 1 372 1 +r 37 1 171 1 251 1 +r 37 1 171 1 250 1 +r 37 1 171 1 191 1 +r 37 1 171 1 187 1 +r 37 1 171 1 184 1 +r 37 1 171 1 181 1 +r 37 1 171 1 178 1 +r 37 1 100 1 154 1 +r 37 1 100 1 153 1 +r 37 1 100 1 152 1 +r 37 1 100 1 151 1 +r 37 1 5 1 144 1 +r 37 1 6 1 919 1 +r 37 1 7 1 44 1 +r 38 1 3 1 77 1 +r 38 1 1116 1 307 1 +r 38 1 1116 1 151 1 +r 38 1 4 1 1116 1 +r 38 1 28 1 1 1 +r 38 1 6 1 956 1 +r 38 1 7 1 44 1 +r 39 1 2 1 42 1 +r 39 1 3 1 74 1 +r 39 1 1116 1 308 1 +r 39 1 1116 1 152 1 +r 39 1 4 1 1117 1 +r 39 1 28 1 121 1 +r 39 1 6 1 829 1 +r 39 1 7 1 44 1 +r 40 1 3 1 80 1 +r 40 1 1116 1 153 1 +r 40 1 4 1 1118 1 +r 40 1 28 1 144 1 +r 40 1 6 1 967 1 +r 40 1 7 1 44 1 +r 41 1 3 1 80 1 +r 41 1 1116 1 154 1 +r 41 1 4 1 1119 1 +r 41 1 28 1 144 1 +r 41 1 6 1 856 1 +r 41 1 7 1 44 1 +r 42 1 171 1 472 1 +r 42 1 171 1 452 1 +r 42 1 171 1 412 1 +r 42 1 171 1 138 1 +r 42 1 171 1 116 1 +r 42 1 171 1 113 1 +r 42 1 171 1 69 1 +r 42 1 171 1 60 1 +r 42 1 171 1 56 1 +r 42 1 171 1 55 1 +r 42 1 171 1 39 1 +r 42 1 171 1 6 1 +r 42 1 171 1 4 1 +r 42 1 172 1 437 1 +r 42 1 172 1 140 1 +r 42 1 69 1 95 1 +r 42 1 5 1 1 1 +r 42 1 6 1 998 1 +r 42 1 7 1 44 1 +r 43 1 3 1 77 1 +r 43 1 1116 1 145 1 +r 43 1 4 1 1120 1 +r 43 1 28 1 90 1 +r 43 1 6 1 900 1 +r 43 1 7 1 44 1 +r 44 1 9 1 653 1 +r 44 1 9 1 629 1 +r 44 1 9 1 361 1 +r 44 1 9 1 360 1 +r 44 1 9 1 359 1 +r 44 1 9 1 358 1 +r 44 1 9 1 357 1 +r 44 1 9 1 356 1 +r 44 1 9 1 355 1 +r 44 1 9 1 353 1 +r 44 1 9 1 351 1 +r 44 1 9 1 349 1 +r 44 1 9 1 348 1 +r 44 1 9 1 347 1 +r 44 1 9 1 346 1 +r 44 1 9 1 345 1 +r 44 1 9 1 344 1 +r 44 1 9 1 343 1 +r 44 1 9 1 342 1 +r 44 1 9 1 335 1 +r 44 1 9 1 332 1 +r 44 1 9 1 326 1 +r 44 1 9 1 320 1 +r 44 1 9 1 319 1 +r 44 1 9 1 317 1 +r 44 1 9 1 315 1 +r 44 1 9 1 314 1 +r 44 1 9 1 313 1 +r 44 1 9 1 312 1 +r 44 1 9 1 311 1 +r 44 1 9 1 310 1 +r 44 1 9 1 306 1 +r 44 1 9 1 304 1 +r 44 1 9 1 302 1 +r 44 1 9 1 300 1 +r 44 1 9 1 298 1 +r 44 1 9 1 297 1 +r 44 1 9 1 295 1 +r 44 1 9 1 293 1 +r 44 1 9 1 291 1 +r 44 1 9 1 289 1 +r 44 1 9 1 288 1 +r 44 1 9 1 287 1 +r 44 1 9 1 286 1 +r 44 1 9 1 284 1 +r 44 1 9 1 283 1 +r 44 1 9 1 282 1 +r 44 1 9 1 280 1 +r 44 1 9 1 279 1 +r 44 1 9 1 278 1 +r 44 1 9 1 277 1 +r 44 1 9 1 276 1 +r 44 1 9 1 275 1 +r 44 1 9 1 274 1 +r 44 1 9 1 272 1 +r 44 1 9 1 269 1 +r 44 1 9 1 253 1 +r 44 1 9 1 244 1 +r 44 1 9 1 241 1 +r 44 1 9 1 240 1 +r 44 1 9 1 239 1 +r 44 1 9 1 238 1 +r 44 1 9 1 237 1 +r 44 1 9 1 236 1 +r 44 1 9 1 235 1 +r 44 1 9 1 234 1 +r 44 1 9 1 233 1 +r 44 1 9 1 232 1 +r 44 1 9 1 231 1 +r 44 1 9 1 230 1 +r 44 1 9 1 229 1 +r 44 1 9 1 228 1 +r 44 1 9 1 227 1 +r 44 1 9 1 226 1 +r 44 1 9 1 225 1 +r 44 1 9 1 223 1 +r 44 1 9 1 221 1 +r 44 1 9 1 220 1 +r 44 1 9 1 217 1 +r 44 1 9 1 216 1 +r 44 1 9 1 214 1 +r 44 1 9 1 212 1 +r 44 1 9 1 208 1 +r 44 1 9 1 202 1 +r 44 1 9 1 195 1 +r 44 1 9 1 193 1 +r 44 1 9 1 190 1 +r 44 1 9 1 189 1 +r 44 1 9 1 186 1 +r 44 1 9 1 183 1 +r 44 1 9 1 180 1 +r 44 1 9 1 177 1 +r 44 1 9 1 172 1 +r 44 1 9 1 171 1 +r 44 1 9 1 170 1 +r 44 1 9 1 169 1 +r 44 1 9 1 168 1 +r 44 1 9 1 167 1 +r 44 1 9 1 166 1 +r 44 1 9 1 161 1 +r 44 1 9 1 160 1 +r 44 1 9 1 159 1 +r 44 1 9 1 155 1 +r 44 1 9 1 144 1 +r 44 1 9 1 143 1 +r 44 1 9 1 140 1 +r 44 1 9 1 139 1 +r 44 1 9 1 138 1 +r 44 1 9 1 136 1 +r 44 1 9 1 134 1 +r 44 1 9 1 132 1 +r 44 1 9 1 131 1 +r 44 1 9 1 129 1 +r 44 1 9 1 128 1 +r 44 1 9 1 127 1 +r 44 1 9 1 126 1 +r 44 1 9 1 124 1 +r 44 1 9 1 122 1 +r 44 1 9 1 121 1 +r 44 1 9 1 120 1 +r 44 1 9 1 119 1 +r 44 1 9 1 116 1 +r 44 1 9 1 115 1 +r 44 1 9 1 113 1 +r 44 1 9 1 112 1 +r 44 1 9 1 111 1 +r 44 1 9 1 110 1 +r 44 1 9 1 108 1 +r 44 1 9 1 107 1 +r 44 1 9 1 106 1 +r 44 1 9 1 103 1 +r 44 1 9 1 102 1 +r 44 1 9 1 100 1 +r 44 1 9 1 98 1 +r 44 1 9 1 97 1 +r 44 1 9 1 92 1 +r 44 1 9 1 90 1 +r 44 1 9 1 89 1 +r 44 1 9 1 87 1 +r 44 1 9 1 85 1 +r 44 1 9 1 83 1 +r 44 1 9 1 82 1 +r 44 1 9 1 80 1 +r 44 1 9 1 79 1 +r 44 1 9 1 77 1 +r 44 1 9 1 74 1 +r 44 1 9 1 73 1 +r 44 1 9 1 71 1 +r 44 1 9 1 69 1 +r 44 1 9 1 67 1 +r 44 1 9 1 65 1 +r 44 1 9 1 63 1 +r 44 1 9 1 62 1 +r 44 1 9 1 60 1 +r 44 1 9 1 56 1 +r 44 1 9 1 55 1 +r 44 1 9 1 54 1 +r 44 1 9 1 53 1 +r 44 1 9 1 52 1 +r 44 1 9 1 51 1 +r 44 1 9 1 45 1 +r 44 1 9 1 43 1 +r 44 1 9 1 42 1 +r 44 1 9 1 41 1 +r 44 1 9 1 40 1 +r 44 1 9 1 39 1 +r 44 1 9 1 38 1 +r 44 1 9 1 37 1 +r 44 1 9 1 36 1 +r 44 1 9 1 35 1 +r 44 1 9 1 34 1 +r 44 1 9 1 33 1 +r 44 1 9 1 32 1 +r 44 1 9 1 31 1 +r 44 1 9 1 30 1 +r 44 1 9 1 29 1 +r 44 1 9 1 28 1 +r 44 1 9 1 27 1 +r 44 1 9 1 26 1 +r 44 1 9 1 25 1 +r 44 1 9 1 24 1 +r 44 1 9 1 23 1 +r 44 1 9 1 22 1 +r 44 1 9 1 21 1 +r 44 1 9 1 20 1 +r 44 1 9 1 19 1 +r 44 1 9 1 18 1 +r 44 1 9 1 17 1 +r 44 1 9 1 16 1 +r 44 1 9 1 15 1 +r 44 1 9 1 14 1 +r 44 1 9 1 13 1 +r 44 1 9 1 12 1 +r 44 1 9 1 11 1 +r 44 1 9 1 10 1 +r 44 1 9 1 9 1 +r 44 1 9 1 8 1 +r 44 1 9 1 7 1 +r 44 1 9 1 6 1 +r 44 1 9 1 5 1 +r 44 1 9 1 4 1 +r 44 1 9 1 3 1 +r 44 1 9 1 2 1 +r 44 1 9 1 1 1 +r 44 1 65 1 66 1 +r 44 1 2 1 53 1 +r 44 1 60 1 61 1 +r 44 1 6 1 59 1 +r 44 1 7 1 57 1 +r 44 1 63 1 64 1 +r 45 1 1112 1 585 1 +r 45 1 171 1 653 1 +r 45 1 171 1 629 1 +r 45 1 171 1 623 1 +r 45 1 171 1 608 1 +r 45 1 171 1 335 1 +r 45 1 171 1 253 1 +r 45 1 171 1 244 1 +r 45 1 171 1 57 1 +r 45 1 171 1 49 1 +r 45 1 171 1 48 1 +r 45 1 171 1 47 1 +r 45 1 171 1 46 1 +r 45 1 171 1 0 0 +r 45 1 100 1 176 1 +r 45 1 172 1 712 1 +r 45 1 172 1 709 1 +r 45 1 172 1 584 1 +r 45 1 172 1 375 1 +r 45 1 172 1 371 1 +r 45 1 172 1 190 1 +r 45 1 172 1 186 1 +r 45 1 172 1 183 1 +r 45 1 172 1 180 1 +r 45 1 172 1 177 1 +r 45 1 172 1 53 1 +r 45 1 5 1 25 1 +r 45 1 6 1 931 1 +r 45 1 7 1 44 1 +r 46 1 9 1 50 1 +r 46 1 2 1 45 1 +r 46 1 6 1 997 1 +r 46 1 7 1 0 0 +r 47 1 2 1 45 1 +r 47 1 6 1 944 1 +r 47 1 7 1 0 0 +r 48 1 9 1 582 1 +r 48 1 2 1 45 1 +r 48 1 6 1 865 1 +r 48 1 7 1 0 0 +r 49 1 2 1 45 1 +r 49 1 6 1 1036 1 +r 49 1 7 1 0 0 +r 50 1 73 1 50 1 +r 50 1 2 1 67 1 +r 50 1 69 1 70 1 +r 50 1 6 1 68 1 +r 50 1 7 1 46 1 +r 50 1 71 1 72 1 +r 51 1 3 1 82 1 +r 51 1 1116 1 207 1 +r 51 1 4 1 3 1 +r 51 1 6 1 836 1 +r 51 1 7 1 44 1 +r 52 1 3 1 74 1 +r 52 1 1116 1 164 1 +r 52 1 4 1 1121 1 +r 52 1 28 1 10 1 +r 52 1 6 1 995 1 +r 52 1 7 1 44 1 +r 53 1 1113 1 63 1 +r 53 1 171 1 716 1 +r 53 1 171 1 669 1 +r 53 1 171 1 617 1 +r 53 1 171 1 578 1 +r 53 1 171 1 552 1 +r 53 1 171 1 493 1 +r 53 1 171 1 393 1 +r 53 1 171 1 364 1 +r 53 1 171 1 44 1 +r 53 1 100 1 174 1 +r 53 1 100 1 173 1 +r 53 1 5 1 45 1 +r 53 1 6 1 927 1 +r 53 1 7 1 44 1 +r 53 1 119 1 175 1 +r 54 1 3 1 77 1 +r 54 1 1116 1 197 1 +r 54 1 4 1 98 1 +r 54 1 28 1 97 1 +r 54 1 29 1 87 1 +r 54 1 69 1 96 1 +r 54 1 6 1 1033 1 +r 54 1 7 1 44 1 +r 55 1 2 1 42 1 +r 55 1 3 1 77 1 +r 55 1 1116 1 250 1 +r 55 1 1116 1 248 1 +r 55 1 1116 1 246 1 +r 55 1 1116 1 101 1 +r 55 1 4 1 1122 1 +r 55 1 29 1 97 1 +r 55 1 6 1 891 1 +r 55 1 7 1 44 1 +r 56 1 2 1 42 1 +r 56 1 3 1 77 1 +r 56 1 1116 1 104 1 +r 56 1 4 1 1123 1 +r 56 1 29 1 97 1 +r 56 1 6 1 877 1 +r 56 1 7 1 44 1 +r 57 1 9 1 716 1 +r 57 1 9 1 669 1 +r 57 1 9 1 617 1 +r 57 1 9 1 578 1 +r 57 1 9 1 552 1 +r 57 1 9 1 493 1 +r 57 1 9 1 393 1 +r 57 1 9 1 364 1 +r 57 1 9 1 44 1 +r 57 1 2 1 45 1 +r 57 1 6 1 58 1 +r 57 1 7 1 0 0 +r 58 1 2 1 10 1 s www.simantics.org +r 58 1 115 1 57 1 +r 59 1 2 1 10 1 s Layer0-1.0 +r 59 1 115 1 44 1 +r 60 1 2 1 42 1 +r 60 1 3 1 74 1 +r 60 1 1116 1 568 1 +r 60 1 1116 1 173 1 +r 60 1 4 1 1124 1 +r 60 1 28 1 62 1 +r 60 1 6 1 972 1 +r 60 1 7 1 44 1 +r 61 1 2 1 62 1 s 1.0 +r 61 1 1124 1 44 1 +r 62 1 1112 1 60 1 +r 62 1 171 1 718 1 +r 62 1 171 1 673 1 +r 62 1 171 1 619 1 +r 62 1 171 1 580 1 +r 62 1 171 1 554 1 +r 62 1 171 1 497 1 +r 62 1 171 1 395 1 +r 62 1 171 1 368 1 +r 62 1 171 1 61 1 +r 62 1 5 1 10 1 +r 62 1 6 1 905 1 +r 62 1 7 1 44 1 +r 63 1 3 1 74 1 +r 63 1 4 1 1125 1 +r 63 1 28 1 10 1 +r 63 1 29 1 53 1 +r 63 1 69 1 75 1 +r 63 1 6 1 914 1 +r 63 1 7 1 44 1 +r 64 1 2 1 10 1 s org.simantics.db.Builtins +r 64 1 1125 1 44 1 +r 65 1 3 1 74 1 +r 65 1 1116 1 174 1 +r 65 1 4 1 1126 1 +r 65 1 28 1 10 1 +r 65 1 6 1 890 1 +r 65 1 7 1 44 1 +r 66 1 2 1 10 1 s layer0 +r 66 1 1126 1 44 1 +r 67 1 1112 1 166 1 +r 67 1 1113 1 166 1 +r 67 1 171 1 50 1 +r 67 1 100 1 165 1 +r 67 1 100 1 164 1 +r 67 1 100 1 163 1 +r 67 1 100 1 162 1 +r 67 1 5 1 25 1 +r 67 1 6 1 1011 1 +r 67 1 7 1 44 1 +r 68 1 2 1 10 1 s Default User +r 68 1 115 1 50 1 +r 69 1 113 1 118 1 +r 69 1 2 1 42 1 +r 69 1 3 1 74 1 +r 69 1 1116 1 163 1 +r 69 1 4 1 1127 1 +r 69 1 28 1 10 1 +r 69 1 6 1 889 1 +r 69 1 7 1 44 1 +r 70 1 2 1 10 1 s Anonymous account. +r 70 1 1127 1 50 1 +r 71 1 3 1 74 1 +r 71 1 1116 1 165 1 +r 71 1 4 1 1128 1 +r 71 1 28 1 10 1 +r 71 1 6 1 936 1 +r 71 1 7 1 44 1 +r 72 1 1128 1 50 1 +r 72 1 2 1 10 1 s anonymous@simantics.org +r 73 1 3 1 166 1 +r 73 1 4 1 73 1 +r 73 1 6 1 968 1 +r 73 1 7 1 44 1 +r 74 1 51 1 702 1 +r 74 1 51 1 701 1 +r 74 1 51 1 681 1 +r 74 1 51 1 680 1 +r 74 1 51 1 679 1 +r 74 1 51 1 678 1 +r 74 1 51 1 677 1 +r 74 1 51 1 661 1 +r 74 1 51 1 660 1 +r 74 1 51 1 657 1 +r 74 1 51 1 656 1 +r 74 1 51 1 655 1 +r 74 1 51 1 627 1 +r 74 1 51 1 602 1 +r 74 1 51 1 588 1 +r 74 1 51 1 562 1 +r 74 1 51 1 556 1 +r 74 1 51 1 542 1 +r 74 1 51 1 463 1 +r 74 1 51 1 461 1 +r 74 1 51 1 438 1 +r 74 1 51 1 390 1 +r 74 1 51 1 342 1 +r 74 1 51 1 241 1 +r 74 1 51 1 238 1 +r 74 1 51 1 223 1 +r 74 1 51 1 214 1 +r 74 1 51 1 160 1 +r 74 1 51 1 159 1 +r 74 1 51 1 119 1 +r 74 1 51 1 116 1 +r 74 1 51 1 113 1 +r 74 1 51 1 110 1 +r 74 1 51 1 71 1 +r 74 1 51 1 69 1 +r 74 1 51 1 65 1 +r 74 1 51 1 63 1 +r 74 1 51 1 60 1 +r 74 1 51 1 52 1 +r 74 1 51 1 39 1 +r 74 1 51 1 6 1 +r 74 1 3 1 83 1 +r 74 1 1116 1 211 1 +r 74 1 28 1 24 1 +r 74 1 4 1 107 1 +r 74 1 6 1 971 1 +r 74 1 7 1 44 1 +r 75 1 2 1 10 1 s A Java classname for a file containing selected resources from ontology. +r 75 1 1127 1 63 1 +r 76 1 2 1 10 1 s A basis for all relations. Makes as weak as possible connection between its subject and object. +r 76 1 1127 1 8 1 +r 77 1 51 1 692 1 +r 77 1 51 1 666 1 +r 77 1 51 1 662 1 +r 77 1 51 1 659 1 +r 77 1 51 1 658 1 +r 77 1 51 1 652 1 +r 77 1 51 1 649 1 +r 77 1 51 1 644 1 +r 77 1 51 1 642 1 +r 77 1 51 1 638 1 +r 77 1 51 1 635 1 +r 77 1 51 1 633 1 +r 77 1 51 1 600 1 +r 77 1 51 1 598 1 +r 77 1 51 1 591 1 +r 77 1 51 1 514 1 +r 77 1 51 1 489 1 +r 77 1 51 1 483 1 +r 77 1 51 1 481 1 +r 77 1 51 1 476 1 +r 77 1 51 1 472 1 +r 77 1 51 1 469 1 +r 77 1 51 1 465 1 +r 77 1 51 1 456 1 +r 77 1 51 1 454 1 +r 77 1 51 1 452 1 +r 77 1 51 1 450 1 +r 77 1 51 1 444 1 +r 77 1 51 1 423 1 +r 77 1 51 1 410 1 +r 77 1 51 1 407 1 +r 77 1 51 1 405 1 +r 77 1 51 1 391 1 +r 77 1 51 1 389 1 +r 77 1 51 1 344 1 +r 77 1 51 1 319 1 +r 77 1 51 1 317 1 +r 77 1 51 1 314 1 +r 77 1 51 1 313 1 +r 77 1 51 1 310 1 +r 77 1 51 1 297 1 +r 77 1 51 1 295 1 +r 77 1 51 1 293 1 +r 77 1 51 1 283 1 +r 77 1 51 1 282 1 +r 77 1 51 1 279 1 +r 77 1 51 1 277 1 +r 77 1 51 1 275 1 +r 77 1 51 1 262 1 +r 77 1 51 1 259 1 +r 77 1 51 1 257 1 +r 77 1 51 1 240 1 +r 77 1 51 1 235 1 +r 77 1 51 1 234 1 +r 77 1 51 1 233 1 +r 77 1 51 1 231 1 +r 77 1 51 1 229 1 +r 77 1 51 1 225 1 +r 77 1 51 1 220 1 +r 77 1 51 1 216 1 +r 77 1 51 1 166 1 +r 77 1 51 1 100 1 +r 77 1 51 1 92 1 +r 77 1 51 1 89 1 +r 77 1 51 1 80 1 +r 77 1 51 1 56 1 +r 77 1 51 1 55 1 +r 77 1 51 1 54 1 +r 77 1 51 1 43 1 +r 77 1 51 1 38 1 +r 77 1 51 1 31 1 +r 77 1 51 1 26 1 +r 77 1 51 1 2 1 +r 77 1 3 1 8 1 +r 77 1 4 1 79 1 +r 77 1 69 1 78 1 +r 77 1 6 1 1028 1 +r 77 1 7 1 44 1 +r 78 1 2 1 10 1 s A typical relation, does not imply dependency. +r 78 1 1127 1 77 1 +r 79 1 3 1 8 1 +r 79 1 51 1 1227 1 +r 79 1 51 1 1218 1 +r 79 1 51 1 1217 1 +r 79 1 51 1 1214 1 +r 79 1 51 1 1213 1 +r 79 1 51 1 1209 1 +r 79 1 51 1 1208 1 +r 79 1 51 1 1207 1 +r 79 1 51 1 1206 1 +r 79 1 51 1 1205 1 +r 79 1 51 1 1204 1 +r 79 1 51 1 1203 1 +r 79 1 51 1 1188 1 +r 79 1 51 1 1187 1 +r 79 1 51 1 1186 1 +r 79 1 51 1 1185 1 +r 79 1 51 1 1184 1 +r 79 1 51 1 1183 1 +r 79 1 51 1 1182 1 +r 79 1 51 1 1181 1 +r 79 1 51 1 1178 1 +r 79 1 51 1 1177 1 +r 79 1 51 1 1176 1 +r 79 1 51 1 1175 1 +r 79 1 51 1 1172 1 +r 79 1 51 1 1171 1 +r 79 1 51 1 1170 1 +r 79 1 51 1 1165 1 +r 79 1 51 1 1162 1 +r 79 1 51 1 1161 1 +r 79 1 51 1 1160 1 +r 79 1 51 1 1159 1 +r 79 1 51 1 1157 1 +r 79 1 51 1 1156 1 +r 79 1 51 1 1155 1 +r 79 1 51 1 1154 1 +r 79 1 51 1 1153 1 +r 79 1 51 1 1152 1 +r 79 1 51 1 1151 1 +r 79 1 51 1 1150 1 +r 79 1 51 1 1148 1 +r 79 1 51 1 1147 1 +r 79 1 51 1 1146 1 +r 79 1 51 1 1145 1 +r 79 1 51 1 1144 1 +r 79 1 51 1 1142 1 +r 79 1 51 1 1123 1 +r 79 1 51 1 1122 1 +r 79 1 51 1 1120 1 +r 79 1 51 1 1116 1 +r 79 1 51 1 1115 1 +r 79 1 51 1 600 1 +r 79 1 51 1 598 1 +r 79 1 51 1 591 1 +r 79 1 51 1 468 1 +r 79 1 51 1 424 1 +r 79 1 51 1 417 1 +r 79 1 51 1 389 1 +r 79 1 51 1 310 1 +r 79 1 51 1 283 1 +r 79 1 51 1 282 1 +r 79 1 51 1 274 1 +r 79 1 51 1 232 1 +r 79 1 51 1 230 1 +r 79 1 51 1 220 1 +r 79 1 51 1 171 1 +r 79 1 51 1 166 1 +r 79 1 51 1 100 1 +r 79 1 51 1 98 1 +r 79 1 51 1 92 1 +r 79 1 51 1 89 1 +r 79 1 51 1 82 1 +r 79 1 51 1 26 1 +r 79 1 4 1 77 1 +r 79 1 6 1 876 1 +r 79 1 7 1 44 1 +r 80 1 51 1 715 1 +r 80 1 51 1 676 1 +r 80 1 51 1 596 1 +r 80 1 51 1 587 1 +r 80 1 51 1 564 1 +r 80 1 51 1 563 1 +r 80 1 51 1 557 1 +r 80 1 51 1 525 1 +r 80 1 51 1 505 1 +r 80 1 51 1 428 1 +r 80 1 51 1 401 1 +r 80 1 51 1 386 1 +r 80 1 51 1 382 1 +r 80 1 51 1 380 1 +r 80 1 51 1 353 1 +r 80 1 51 1 208 1 +r 80 1 51 1 161 1 +r 80 1 51 1 138 1 +r 80 1 51 1 136 1 +r 80 1 51 1 131 1 +r 80 1 51 1 128 1 +r 80 1 51 1 127 1 +r 80 1 51 1 126 1 +r 80 1 51 1 83 1 +r 80 1 51 1 41 1 +r 80 1 51 1 40 1 +r 80 1 51 1 30 1 +r 80 1 51 1 29 1 +r 80 1 51 1 28 1 +r 80 1 51 1 27 1 +r 80 1 51 1 5 1 +r 80 1 51 1 4 1 +r 80 1 51 1 3 1 +r 80 1 3 1 77 1 +r 80 1 4 1 82 1 +r 80 1 69 1 81 1 +r 80 1 6 1 1027 1 +r 80 1 7 1 44 1 +r 81 1 2 1 10 1 s States that subject depends on the object. +r 81 1 1127 1 80 1 +r 82 1 3 1 79 1 +r 82 1 51 1 1230 1 +r 82 1 51 1 1219 1 +r 82 1 51 1 1199 1 +r 82 1 51 1 1198 1 +r 82 1 51 1 1197 1 +r 82 1 51 1 1189 1 +r 82 1 51 1 1168 1 +r 82 1 51 1 1167 1 +r 82 1 51 1 1166 1 +r 82 1 51 1 1140 1 +r 82 1 51 1 1139 1 +r 82 1 51 1 1136 1 +r 82 1 51 1 1135 1 +r 82 1 51 1 1134 1 +r 82 1 51 1 1133 1 +r 82 1 51 1 1132 1 +r 82 1 51 1 1119 1 +r 82 1 51 1 1118 1 +r 82 1 51 1 1114 1 +r 82 1 51 1 1113 1 +r 82 1 51 1 1112 1 +r 82 1 51 1 1111 1 +r 82 1 51 1 597 1 +r 82 1 51 1 559 1 +r 82 1 51 1 501 1 +r 82 1 51 1 442 1 +r 82 1 51 1 429 1 +r 82 1 51 1 385 1 +r 82 1 51 1 172 1 +r 82 1 51 1 143 1 +r 82 1 51 1 85 1 +r 82 1 51 1 51 1 +r 82 1 51 1 4 1 +r 82 1 4 1 80 1 +r 82 1 6 1 1012 1 +r 82 1 7 1 44 1 +r 83 1 51 1 412 1 +r 83 1 51 1 74 1 +r 83 1 51 1 9 1 +r 83 1 3 1 80 1 +r 83 1 4 1 85 1 +r 83 1 69 1 84 1 +r 83 1 6 1 851 1 +r 83 1 7 1 44 1 +r 84 1 2 1 10 1 s States that subject owns the object. +r 84 1 1127 1 83 1 +r 85 1 3 1 82 1 +r 85 1 51 1 414 1 +r 85 1 51 1 107 1 +r 85 1 51 1 7 1 +r 85 1 4 1 83 1 +r 85 1 6 1 1009 1 +r 85 1 7 1 44 1 +r 86 1 2 1 10 1 s A reference to a type. +r 86 1 1127 1 30 1 +r 87 1 1112 1 30 1 +r 87 1 1112 1 5 1 +r 87 1 1112 1 2 1 +r 87 1 1113 1 216 1 +r 87 1 1113 1 92 1 +r 87 1 1113 1 54 1 +r 87 1 1113 1 26 1 +r 87 1 1113 1 5 1 +r 87 1 171 1 25 1 +r 87 1 172 1 654 1 +r 87 1 172 1 399 1 +r 87 1 172 1 349 1 +r 87 1 172 1 311 1 +r 87 1 172 1 284 1 +r 87 1 172 1 108 1 +r 87 1 172 1 106 1 +r 87 1 100 1 200 1 +r 87 1 100 1 199 1 +r 87 1 100 1 198 1 +r 87 1 100 1 197 1 +r 87 1 69 1 196 1 +r 87 1 5 1 195 1 +r 87 1 6 1 924 1 +r 87 1 1111 1 179 1 +r 87 1 7 1 44 1 +r 87 1 119 1 201 1 +r 88 1 2 1 10 1 s States that subject and object (relations) are inverses. +r 88 1 1127 1 4 1 +r 89 1 2 1 90 1 +r 89 1 3 1 79 1 +r 89 1 3 1 77 1 +r 89 1 4 1 89 1 +r 89 1 6 1 970 1 +r 89 1 7 1 44 1 +r 90 1 1112 1 43 1 +r 90 1 171 1 591 1 +r 90 1 171 1 389 1 +r 90 1 171 1 220 1 +r 90 1 171 1 166 1 +r 90 1 171 1 92 1 +r 90 1 171 1 89 1 +r 90 1 171 1 26 1 +r 90 1 69 1 91 1 +r 90 1 5 1 1 1 +r 90 1 6 1 935 1 +r 90 1 7 1 44 1 +r 90 1 1111 1 192 1 +r 91 1 2 1 10 1 s A relation for which subject = object, used to model simple boolean statements. +r 91 1 1127 1 90 1 +r 92 1 2 1 90 1 +r 92 1 3 1 79 1 +r 92 1 3 1 77 1 +r 92 1 4 1 92 1 +r 92 1 29 1 87 1 +r 92 1 69 1 93 1 +r 92 1 6 1 886 1 +r 92 1 7 1 44 1 +r 93 1 2 1 10 1 s Instances of a type tagged as Abstract cannot be directly instantiated. +r 93 1 1127 1 92 1 +r 94 1 2 1 10 1 s Instances of a type tagged Enumeration cannot be instantiated outside of the ontology that defines it. +r 94 1 1127 1 26 1 +r 95 1 2 1 10 1 s The cardinality of this relation for any subject is at most one. +r 95 1 1127 1 42 1 +r 96 1 2 1 10 1 s The statement modelled by an assertion is implied for all instances of the asserting type. +r 96 1 1127 1 54 1 +r 97 1 1112 1 54 1 +r 97 1 1113 1 56 1 +r 97 1 1113 1 55 1 +r 97 1 100 1 105 1 +r 97 1 100 1 104 1 +r 97 1 100 1 101 1 +r 97 1 69 1 99 1 +r 97 1 5 1 25 1 +r 97 1 6 1 878 1 +r 97 1 7 1 44 1 +r 98 1 3 1 79 1 +r 98 1 1116 1 105 1 +r 98 1 4 1 54 1 +r 98 1 6 1 909 1 +r 98 1 7 1 44 1 +r 99 1 2 1 10 1 s The statement modelled by an assertion is implied for all instances of the asserting type. +r 99 1 1127 1 97 1 +r 100 1 3 1 79 1 +r 100 1 3 1 77 1 +r 100 1 1116 1 200 1 +r 100 1 4 1 310 1 +r 100 1 6 1 1023 1 +r 100 1 7 1 44 1 +r 101 1 2 1 102 1 +r 101 1 310 1 97 1 +r 101 1 38 1 55 1 +r 101 1 39 1 103 1 +r 102 1 1112 1 200 1 +r 102 1 171 1 708 1 +r 102 1 171 1 707 1 +r 102 1 171 1 706 1 +r 102 1 171 1 705 1 +r 102 1 171 1 700 1 +r 102 1 171 1 699 1 +r 102 1 171 1 698 1 +r 102 1 171 1 697 1 +r 102 1 171 1 696 1 +r 102 1 171 1 691 1 +r 102 1 171 1 690 1 +r 102 1 171 1 689 1 +r 102 1 171 1 688 1 +r 102 1 171 1 687 1 +r 102 1 171 1 686 1 +r 102 1 171 1 665 1 +r 102 1 171 1 664 1 +r 102 1 171 1 651 1 +r 102 1 171 1 648 1 +r 102 1 171 1 643 1 +r 102 1 171 1 641 1 +r 102 1 171 1 639 1 +r 102 1 171 1 637 1 +r 102 1 171 1 634 1 +r 102 1 171 1 632 1 +r 102 1 171 1 616 1 +r 102 1 171 1 607 1 +r 102 1 171 1 594 1 +r 102 1 171 1 586 1 +r 102 1 171 1 585 1 +r 102 1 171 1 577 1 +r 102 1 171 1 575 1 +r 102 1 171 1 573 1 +r 102 1 171 1 572 1 +r 102 1 171 1 571 1 +r 102 1 171 1 568 1 +r 102 1 171 1 567 1 +r 102 1 171 1 566 1 +r 102 1 171 1 548 1 +r 102 1 171 1 547 1 +r 102 1 171 1 545 1 +r 102 1 171 1 544 1 +r 102 1 171 1 537 1 +r 102 1 171 1 532 1 +r 102 1 171 1 530 1 +r 102 1 171 1 528 1 +r 102 1 171 1 524 1 +r 102 1 171 1 523 1 +r 102 1 171 1 521 1 +r 102 1 171 1 516 1 +r 102 1 171 1 515 1 +r 102 1 171 1 513 1 +r 102 1 171 1 511 1 +r 102 1 171 1 504 1 +r 102 1 171 1 500 1 +r 102 1 171 1 490 1 +r 102 1 171 1 488 1 +r 102 1 171 1 475 1 +r 102 1 171 1 474 1 +r 102 1 171 1 467 1 +r 102 1 171 1 464 1 +r 102 1 171 1 462 1 +r 102 1 171 1 460 1 +r 102 1 171 1 453 1 +r 102 1 171 1 446 1 +r 102 1 171 1 443 1 +r 102 1 171 1 441 1 +r 102 1 171 1 426 1 +r 102 1 171 1 422 1 +r 102 1 171 1 419 1 +r 102 1 171 1 411 1 +r 102 1 171 1 409 1 +r 102 1 171 1 406 1 +r 102 1 171 1 404 1 +r 102 1 171 1 403 1 +r 102 1 171 1 402 1 +r 102 1 171 1 400 1 +r 102 1 171 1 387 1 +r 102 1 171 1 383 1 +r 102 1 171 1 381 1 +r 102 1 171 1 379 1 +r 102 1 171 1 341 1 +r 102 1 171 1 318 1 +r 102 1 171 1 316 1 +r 102 1 171 1 309 1 +r 102 1 171 1 308 1 +r 102 1 171 1 307 1 +r 102 1 171 1 296 1 +r 102 1 171 1 294 1 +r 102 1 171 1 292 1 +r 102 1 171 1 290 1 +r 102 1 171 1 285 1 +r 102 1 171 1 273 1 +r 102 1 171 1 271 1 +r 102 1 171 1 270 1 +r 102 1 171 1 268 1 +r 102 1 171 1 266 1 +r 102 1 171 1 264 1 +r 102 1 171 1 261 1 +r 102 1 171 1 258 1 +r 102 1 171 1 256 1 +r 102 1 171 1 248 1 +r 102 1 171 1 246 1 +r 102 1 171 1 224 1 +r 102 1 171 1 222 1 +r 102 1 171 1 219 1 +r 102 1 171 1 218 1 +r 102 1 171 1 215 1 +r 102 1 171 1 213 1 +r 102 1 171 1 211 1 +r 102 1 171 1 210 1 +r 102 1 171 1 207 1 +r 102 1 171 1 206 1 +r 102 1 171 1 205 1 +r 102 1 171 1 204 1 +r 102 1 171 1 200 1 +r 102 1 171 1 199 1 +r 102 1 171 1 198 1 +r 102 1 171 1 197 1 +r 102 1 171 1 194 1 +r 102 1 171 1 176 1 +r 102 1 171 1 174 1 +r 102 1 171 1 173 1 +r 102 1 171 1 165 1 +r 102 1 171 1 164 1 +r 102 1 171 1 163 1 +r 102 1 171 1 162 1 +r 102 1 171 1 158 1 +r 102 1 171 1 157 1 +r 102 1 171 1 156 1 +r 102 1 171 1 154 1 +r 102 1 171 1 153 1 +r 102 1 171 1 152 1 +r 102 1 171 1 151 1 +r 102 1 171 1 150 1 +r 102 1 171 1 149 1 +r 102 1 171 1 148 1 +r 102 1 171 1 147 1 +r 102 1 171 1 146 1 +r 102 1 171 1 145 1 +r 102 1 171 1 142 1 +r 102 1 171 1 141 1 +r 102 1 171 1 137 1 +r 102 1 171 1 135 1 +r 102 1 171 1 133 1 +r 102 1 171 1 130 1 +r 102 1 171 1 109 1 +r 102 1 171 1 105 1 +r 102 1 171 1 104 1 +r 102 1 171 1 101 1 +r 102 1 100 1 309 1 +r 102 1 100 1 308 1 +r 102 1 100 1 307 1 +r 102 1 5 1 25 1 +r 102 1 6 1 951 1 +r 102 1 7 1 44 1 +r 103 1 2 1 315 1 +r 103 1 1117 1 708 1 +r 103 1 1117 1 707 1 +r 103 1 1117 1 706 1 +r 103 1 1117 1 705 1 +r 103 1 1117 1 696 1 +r 103 1 1117 1 688 1 +r 103 1 1117 1 687 1 +r 103 1 1117 1 686 1 +r 103 1 1117 1 664 1 +r 103 1 1117 1 651 1 +r 103 1 1117 1 648 1 +r 103 1 1117 1 641 1 +r 103 1 1117 1 639 1 +r 103 1 1117 1 637 1 +r 103 1 1117 1 634 1 +r 103 1 1117 1 632 1 +r 103 1 1117 1 594 1 +r 103 1 1117 1 572 1 +r 103 1 1117 1 571 1 +r 103 1 1117 1 568 1 +r 103 1 1117 1 567 1 +r 103 1 1117 1 566 1 +r 103 1 1117 1 548 1 +r 103 1 1117 1 547 1 +r 103 1 1117 1 545 1 +r 103 1 1117 1 544 1 +r 103 1 1117 1 537 1 +r 103 1 1117 1 532 1 +r 103 1 1117 1 530 1 +r 103 1 1117 1 528 1 +r 103 1 1117 1 516 1 +r 103 1 1117 1 515 1 +r 103 1 1117 1 475 1 +r 103 1 1117 1 474 1 +r 103 1 1117 1 422 1 +r 103 1 1117 1 379 1 +r 103 1 1117 1 341 1 +r 103 1 1117 1 294 1 +r 103 1 1117 1 292 1 +r 103 1 1117 1 290 1 +r 103 1 1117 1 285 1 +r 103 1 1117 1 271 1 +r 103 1 1117 1 270 1 +r 103 1 1117 1 264 1 +r 103 1 1117 1 261 1 +r 103 1 1117 1 258 1 +r 103 1 1117 1 256 1 +r 103 1 1117 1 224 1 +r 103 1 1117 1 222 1 +r 103 1 1117 1 219 1 +r 103 1 1117 1 218 1 +r 103 1 1117 1 215 1 +r 103 1 1117 1 213 1 +r 103 1 1117 1 176 1 +r 103 1 1117 1 174 1 +r 103 1 1117 1 173 1 +r 103 1 1117 1 165 1 +r 103 1 1117 1 164 1 +r 103 1 1117 1 163 1 +r 103 1 1117 1 162 1 +r 103 1 1117 1 157 1 +r 103 1 1117 1 156 1 +r 103 1 1117 1 151 1 +r 103 1 1117 1 150 1 +r 103 1 1117 1 149 1 +r 103 1 1117 1 148 1 +r 103 1 1117 1 135 1 +r 103 1 1117 1 133 1 +r 103 1 1117 1 130 1 +r 103 1 1117 1 105 1 +r 103 1 1117 1 104 1 +r 103 1 1117 1 101 1 +r 103 1 317 1 325 1 +r 103 1 6 1 323 1 +r 103 1 7 1 44 1 +r 103 1 319 1 324 1 +r 104 1 2 1 102 1 +r 104 1 310 1 97 1 +r 104 1 38 1 56 1 +r 104 1 39 1 103 1 +r 105 1 2 1 102 1 +r 105 1 310 1 97 1 +r 105 1 38 1 98 1 +r 105 1 39 1 103 1 +r 106 1 171 1 24 1 +r 106 1 5 1 87 1 +r 106 1 6 1 846 1 +r 106 1 1111 1 185 1 +r 106 1 7 1 44 1 +r 107 1 3 1 85 1 +r 107 1 51 1 1229 1 +r 107 1 51 1 1228 1 +r 107 1 51 1 1224 1 +r 107 1 51 1 1223 1 +r 107 1 51 1 1222 1 +r 107 1 51 1 1221 1 +r 107 1 51 1 1220 1 +r 107 1 51 1 1216 1 +r 107 1 51 1 1215 1 +r 107 1 51 1 1212 1 +r 107 1 51 1 1211 1 +r 107 1 51 1 1210 1 +r 107 1 51 1 1202 1 +r 107 1 51 1 1201 1 +r 107 1 51 1 1200 1 +r 107 1 51 1 1196 1 +r 107 1 51 1 1194 1 +r 107 1 51 1 1193 1 +r 107 1 51 1 1180 1 +r 107 1 51 1 1179 1 +r 107 1 51 1 1173 1 +r 107 1 51 1 1169 1 +r 107 1 51 1 1164 1 +r 107 1 51 1 1149 1 +r 107 1 51 1 1143 1 +r 107 1 51 1 1141 1 +r 107 1 51 1 1138 1 +r 107 1 51 1 1137 1 +r 107 1 51 1 1131 1 +r 107 1 51 1 1130 1 +r 107 1 51 1 1129 1 +r 107 1 51 1 1128 1 +r 107 1 51 1 1127 1 +r 107 1 51 1 1126 1 +r 107 1 51 1 1125 1 +r 107 1 51 1 1124 1 +r 107 1 51 1 1121 1 +r 107 1 51 1 1117 1 +r 107 1 51 1 239 1 +r 107 1 51 1 120 1 +r 107 1 51 1 115 1 +r 107 1 1116 1 194 1 +r 107 1 4 1 74 1 +r 107 1 6 1 913 1 +r 107 1 7 1 44 1 +r 108 1 1112 1 156 1 +r 108 1 171 1 111 1 +r 108 1 100 1 109 1 +r 108 1 5 1 87 1 +r 108 1 6 1 989 1 +r 108 1 7 1 44 1 +r 109 1 2 1 102 1 +r 109 1 310 1 108 1 +r 109 1 38 1 110 1 +r 110 1 3 1 74 1 +r 110 1 1116 1 157 1 +r 110 1 1116 1 109 1 +r 110 1 4 1 1129 1 +r 110 1 28 1 121 1 +r 110 1 6 1 939 1 +r 110 1 7 1 44 1 +r 111 1 1114 1 431 1 +r 111 1 2 1 108 1 +r 111 1 172 1 112 1 +r 111 1 172 1 23 1 +r 111 1 172 1 22 1 +r 111 1 172 1 21 1 +r 111 1 172 1 20 1 +r 111 1 172 1 19 1 +r 111 1 172 1 18 1 +r 111 1 172 1 17 1 +r 111 1 172 1 14 1 +r 111 1 172 1 10 1 +r 111 1 92 1 111 1 +r 111 1 100 1 194 1 +r 111 1 5 1 193 1 +r 111 1 6 1 828 1 +r 111 1 7 1 44 1 +r 112 1 172 1 16 1 +r 112 1 172 1 15 1 +r 112 1 172 1 13 1 +r 112 1 172 1 12 1 +r 112 1 172 1 11 1 +r 112 1 5 1 111 1 +r 112 1 6 1 1029 1 +r 112 1 7 1 44 1 +r 113 1 2 1 42 1 +r 113 1 3 1 74 1 +r 113 1 1116 1 204 1 +r 113 1 4 1 1130 1 +r 113 1 28 1 10 1 +r 113 1 6 1 941 1 +r 113 1 7 1 44 1 +r 114 1 1130 1 6 1 +r 114 1 2 1 10 1 s Name +r 115 1 3 1 107 1 +r 115 1 4 1 6 1 +r 115 1 6 1 864 1 +r 115 1 7 1 44 1 +r 116 1 113 1 117 1 +r 116 1 2 1 42 1 +r 116 1 3 1 74 1 +r 116 1 4 1 1131 1 +r 116 1 28 1 10 1 +r 116 1 6 1 871 1 +r 116 1 7 1 44 1 +r 117 1 1130 1 116 1 +r 117 1 2 1 10 1 s Label +r 118 1 1130 1 69 1 +r 118 1 2 1 10 1 s Description +r 119 1 3 1 74 1 +r 119 1 4 1 120 1 +r 119 1 28 1 10 1 +r 119 1 6 1 991 1 +r 119 1 7 1 44 1 +r 120 1 3 1 107 1 +r 120 1 4 1 119 1 +r 120 1 6 1 840 1 +r 120 1 7 1 44 1 +r 121 1 1112 1 110 1 +r 121 1 1112 1 39 1 +r 121 1 171 1 252 1 +r 121 1 5 1 10 1 +r 121 1 6 1 955 1 +r 121 1 7 1 44 1 +r 122 1 1112 1 602 1 +r 122 1 172 1 124 1 +r 122 1 69 1 123 1 +r 122 1 5 1 10 1 +r 122 1 6 1 948 1 +r 122 1 7 1 44 1 +r 123 1 2 1 10 1 s A Uniform Resource Identifier (URI) is just a unique string that uniquely identifies something, commonly a namespace. Sometimes they look like a URL that you could type into the address bar of your web browser, but it doesn't have to point to any physical resource on the web. +r 123 1 1127 1 122 1 +r 124 1 1112 1 556 1 +r 124 1 69 1 125 1 +r 124 1 5 1 122 1 +r 124 1 6 1 950 1 +r 124 1 7 1 44 1 +r 125 1 2 1 10 1 s A Uniform Resource Locator (URL) is an URI which locates a resource on the web. +r 125 1 1127 1 124 1 +r 126 1 3 1 80 1 +r 126 1 4 1 1132 1 +r 126 1 28 1 10 1 +r 126 1 6 1 979 1 +r 126 1 7 1 44 1 +r 127 1 3 1 80 1 +r 127 1 1116 1 133 1 +r 127 1 1116 1 130 1 +r 127 1 4 1 1133 1 +r 127 1 28 1 10 1 +r 127 1 6 1 904 1 +r 127 1 7 1 44 1 +r 128 1 3 1 80 1 +r 128 1 4 1 1134 1 +r 128 1 28 1 129 1 +r 128 1 6 1 1019 1 +r 128 1 7 1 44 1 +r 129 1 1112 1 128 1 +r 129 1 100 1 130 1 +r 129 1 5 1 25 1 +r 129 1 6 1 1008 1 +r 129 1 7 1 44 1 +r 130 1 2 1 102 1 +r 130 1 310 1 129 1 +r 130 1 38 1 127 1 +r 130 1 39 1 103 1 +r 131 1 3 1 80 1 +r 131 1 4 1 1135 1 +r 131 1 28 1 132 1 +r 131 1 6 1 1032 1 +r 131 1 7 1 44 1 +r 132 1 1112 1 131 1 +r 132 1 100 1 133 1 +r 132 1 5 1 25 1 +r 132 1 6 1 996 1 +r 132 1 7 1 44 1 +r 133 1 2 1 102 1 +r 133 1 310 1 132 1 +r 133 1 38 1 127 1 +r 133 1 39 1 103 1 +r 134 1 1112 1 542 1 +r 134 1 100 1 137 1 +r 134 1 100 1 135 1 +r 134 1 5 1 25 1 +r 134 1 6 1 930 1 +r 134 1 7 1 44 1 +r 135 1 2 1 102 1 +r 135 1 310 1 134 1 +r 135 1 38 1 136 1 +r 135 1 39 1 103 1 +r 136 1 2 1 140 1 +r 136 1 51 1 336 1 +r 136 1 3 1 80 1 +r 136 1 1116 1 141 1 +r 136 1 1116 1 135 1 +r 136 1 4 1 143 1 +r 136 1 6 1 1021 1 +r 136 1 7 1 44 1 +r 137 1 2 1 102 1 +r 137 1 310 1 134 1 +r 137 1 38 1 138 1 +r 137 1 39 1 139 1 +r 138 1 2 1 42 1 +r 138 1 3 1 80 1 +r 138 1 1116 1 137 1 +r 138 1 4 1 1136 1 +r 138 1 6 1 1018 1 +r 138 1 7 1 44 1 +r 139 1 2 1 315 1 +r 139 1 1117 1 700 1 +r 139 1 1117 1 699 1 +r 139 1 1117 1 698 1 +r 139 1 1117 1 697 1 +r 139 1 1117 1 691 1 +r 139 1 1117 1 690 1 +r 139 1 1117 1 689 1 +r 139 1 1117 1 665 1 +r 139 1 1117 1 643 1 +r 139 1 1117 1 464 1 +r 139 1 1117 1 462 1 +r 139 1 1117 1 460 1 +r 139 1 1117 1 411 1 +r 139 1 1117 1 387 1 +r 139 1 1117 1 318 1 +r 139 1 1117 1 316 1 +r 139 1 1117 1 296 1 +r 139 1 1117 1 158 1 +r 139 1 1117 1 152 1 +r 139 1 1117 1 137 1 +r 139 1 317 1 331 1 +r 139 1 6 1 330 1 +r 139 1 7 1 44 1 +r 140 1 171 1 136 1 +r 140 1 172 1 645 1 +r 140 1 172 1 421 1 +r 140 1 172 1 288 1 +r 140 1 100 1 142 1 +r 140 1 100 1 141 1 +r 140 1 5 1 42 1 +r 140 1 6 1 884 1 +r 140 1 7 1 44 1 +r 141 1 2 1 102 1 +r 141 1 310 1 140 1 +r 141 1 38 1 136 1 +r 142 1 2 1 102 1 +r 142 1 310 1 140 1 +r 142 1 38 1 143 1 +r 143 1 51 1 1163 1 +r 143 1 3 1 82 1 +r 143 1 1116 1 142 1 +r 143 1 4 1 136 1 +r 143 1 6 1 893 1 +r 143 1 7 1 44 1 +r 144 1 1112 1 41 1 +r 144 1 1112 1 40 1 +r 144 1 1112 1 29 1 +r 144 1 1112 1 28 1 +r 144 1 1112 1 27 1 +r 144 1 172 1 155 1 +r 144 1 172 1 37 1 +r 144 1 172 1 36 1 +r 144 1 172 1 35 1 +r 144 1 172 1 34 1 +r 144 1 172 1 33 1 +r 144 1 172 1 32 1 +r 144 1 92 1 144 1 +r 144 1 100 1 145 1 +r 144 1 5 1 25 1 +r 144 1 6 1 875 1 +r 144 1 7 1 44 1 +r 145 1 2 1 102 1 +r 145 1 310 1 144 1 +r 145 1 38 1 43 1 +r 146 1 2 1 102 1 +r 146 1 310 1 33 1 +r 146 1 38 1 27 1 +r 147 1 2 1 102 1 +r 147 1 310 1 32 1 +r 147 1 38 1 27 1 +r 148 1 2 1 102 1 +r 148 1 310 1 34 1 +r 148 1 38 1 27 1 +r 148 1 39 1 103 1 +r 149 1 2 1 102 1 +r 149 1 310 1 36 1 +r 149 1 38 1 31 1 +r 149 1 39 1 103 1 +r 150 1 2 1 102 1 +r 150 1 310 1 35 1 +r 150 1 38 1 30 1 +r 150 1 39 1 103 1 +r 151 1 2 1 102 1 +r 151 1 310 1 37 1 +r 151 1 38 1 38 1 +r 151 1 39 1 103 1 +r 152 1 2 1 102 1 +r 152 1 310 1 37 1 +r 152 1 38 1 39 1 +r 152 1 39 1 139 1 +r 153 1 2 1 102 1 +r 153 1 310 1 37 1 +r 153 1 38 1 40 1 +r 154 1 2 1 102 1 +r 154 1 310 1 37 1 +r 154 1 38 1 41 1 +r 155 1 1112 1 160 1 +r 155 1 100 1 158 1 +r 155 1 100 1 157 1 +r 155 1 100 1 156 1 +r 155 1 5 1 144 1 +r 155 1 6 1 953 1 +r 155 1 7 1 44 1 +r 156 1 2 1 102 1 +r 156 1 28 1 108 1 +r 156 1 310 1 155 1 +r 156 1 38 1 30 1 +r 156 1 39 1 103 1 +r 157 1 2 1 102 1 +r 157 1 310 1 155 1 +r 157 1 38 1 110 1 +r 157 1 39 1 103 1 +r 158 1 2 1 102 1 +r 158 1 310 1 155 1 +r 158 1 38 1 159 1 +r 158 1 39 1 139 1 +r 159 1 3 1 74 1 +r 159 1 1116 1 158 1 +r 159 1 4 1 1137 1 +r 159 1 28 1 12 1 +r 159 1 6 1 903 1 +r 159 1 7 1 44 1 +r 160 1 3 1 74 1 +r 160 1 4 1 1138 1 +r 160 1 28 1 155 1 +r 160 1 6 1 990 1 +r 160 1 7 1 44 1 +r 161 1 3 1 80 1 +r 161 1 4 1 1139 1 +r 161 1 6 1 879 1 +r 161 1 7 1 44 1 +r 162 1 2 1 102 1 +r 162 1 310 1 67 1 +r 162 1 38 1 6 1 +r 162 1 39 1 103 1 +r 163 1 2 1 102 1 +r 163 1 310 1 67 1 +r 163 1 38 1 69 1 +r 163 1 39 1 103 1 +r 164 1 2 1 102 1 +r 164 1 310 1 67 1 +r 164 1 38 1 52 1 +r 164 1 39 1 103 1 +r 165 1 2 1 102 1 +r 165 1 310 1 67 1 +r 165 1 38 1 71 1 +r 165 1 39 1 103 1 +r 166 1 2 1 90 1 +r 166 1 51 1 170 1 +r 166 1 51 1 169 1 +r 166 1 51 1 168 1 +r 166 1 51 1 167 1 +r 166 1 51 1 73 1 +r 166 1 3 1 79 1 +r 166 1 3 1 77 1 +r 166 1 4 1 166 1 +r 166 1 28 1 67 1 +r 166 1 29 1 67 1 +r 166 1 6 1 926 1 +r 166 1 7 1 44 1 +r 167 1 3 1 166 1 +r 167 1 4 1 167 1 +r 167 1 6 1 962 1 +r 167 1 7 1 44 1 +r 168 1 3 1 166 1 +r 168 1 4 1 168 1 +r 168 1 6 1 993 1 +r 168 1 7 1 44 1 +r 169 1 3 1 166 1 +r 169 1 4 1 169 1 +r 169 1 6 1 911 1 +r 169 1 7 1 44 1 +r 170 1 3 1 166 1 +r 170 1 4 1 170 1 +r 170 1 6 1 895 1 +r 170 1 7 1 44 1 +r 171 1 3 1 79 1 +r 171 1 4 1 2 1 +r 171 1 6 1 850 1 +r 171 1 7 1 44 1 +r 172 1 3 1 82 1 +r 172 1 4 1 5 1 +r 172 1 6 1 1025 1 +r 172 1 7 1 44 1 +r 173 1 2 1 102 1 +r 173 1 310 1 53 1 +r 173 1 38 1 60 1 +r 173 1 39 1 103 1 +r 174 1 2 1 102 1 +r 174 1 310 1 53 1 +r 174 1 38 1 65 1 +r 174 1 39 1 103 1 +r 175 1 120 1 53 1 +r 175 1 2 1 10 1 s Is it reasonable to restrict possible libraries under Ontology? +r 176 1 2 1 102 1 +r 176 1 310 1 45 1 +r 176 1 38 1 6 1 +r 176 1 39 1 103 1 +r 177 1 171 1 667 1 +r 177 1 171 1 491 1 +r 177 1 171 1 362 1 +r 177 1 27 1 178 1 +r 177 1 5 1 45 1 +r 177 1 6 1 883 1 +r 177 1 1111 1 179 1 +r 177 1 7 1 44 1 +r 178 1 40 1 179 1 +r 178 1 2 1 37 1 +r 178 1 38 1 9 1 +r 178 1 1111 1 177 1 +r 179 1 2 1 33 1 +r 179 1 27 1 177 1 +r 179 1 27 1 87 1 +r 179 1 1118 1 178 1 +r 180 1 171 1 670 1 +r 180 1 171 1 494 1 +r 180 1 171 1 365 1 +r 180 1 27 1 181 1 +r 180 1 5 1 45 1 +r 180 1 6 1 1024 1 +r 180 1 1111 1 182 1 +r 180 1 7 1 44 1 +r 181 1 40 1 182 1 +r 181 1 2 1 37 1 +r 181 1 38 1 9 1 +r 181 1 1111 1 180 1 +r 182 1 2 1 33 1 +r 182 1 27 1 180 1 +r 182 1 27 1 1 1 +r 182 1 1118 1 181 1 +r 183 1 27 1 184 1 +r 183 1 5 1 45 1 +r 183 1 6 1 916 1 +r 183 1 1111 1 185 1 +r 183 1 7 1 44 1 +r 184 1 40 1 185 1 +r 184 1 2 1 37 1 +r 184 1 38 1 9 1 +r 184 1 1111 1 183 1 +r 185 1 2 1 33 1 +r 185 1 27 1 183 1 +r 185 1 27 1 106 1 +r 185 1 1118 1 184 1 +r 186 1 27 1 187 1 +r 186 1 5 1 45 1 +r 186 1 6 1 947 1 +r 186 1 1111 1 188 1 +r 186 1 7 1 44 1 +r 187 1 40 1 188 1 +r 187 1 2 1 37 1 +r 187 1 38 1 9 1 +r 187 1 1111 1 186 1 +r 188 1 2 1 33 1 +r 188 1 27 1 189 1 +r 188 1 27 1 186 1 +r 188 1 1118 1 187 1 +r 189 1 5 1 25 1 +r 189 1 6 1 868 1 +r 189 1 1111 1 188 1 +r 189 1 7 1 44 1 +r 190 1 27 1 191 1 +r 190 1 5 1 45 1 +r 190 1 6 1 974 1 +r 190 1 1111 1 192 1 +r 190 1 7 1 44 1 +r 191 1 40 1 192 1 +r 191 1 2 1 37 1 +r 191 1 38 1 9 1 +r 191 1 1111 1 190 1 +r 192 1 2 1 33 1 +r 192 1 27 1 190 1 +r 192 1 27 1 90 1 +r 192 1 1118 1 191 1 +r 193 1 100 1 341 1 +r 193 1 172 1 111 1 +r 193 1 5 1 24 1 +r 193 1 6 1 1014 1 +r 193 1 7 1 44 1 +r 194 1 2 1 102 1 +r 194 1 310 1 111 1 +r 194 1 38 1 107 1 +r 195 1 1112 1 293 1 +r 195 1 1112 1 248 1 +r 195 1 1112 1 246 1 +r 195 1 1116 1 251 1 +r 195 1 172 1 249 1 +r 195 1 172 1 247 1 +r 195 1 172 1 245 1 +r 195 1 172 1 87 1 +r 195 1 5 1 25 1 +r 195 1 6 1 1030 1 +r 195 1 7 1 44 1 +r 196 1 2 1 10 1 s All types are instances of this type. +r 196 1 1127 1 87 1 +r 197 1 2 1 102 1 +r 197 1 310 1 87 1 +r 197 1 38 1 54 1 +r 198 1 2 1 102 1 +r 198 1 310 1 87 1 +r 198 1 38 1 5 1 +r 199 1 2 1 102 1 +r 199 1 28 1 37 1 +r 199 1 310 1 87 1 +r 199 1 38 1 27 1 +r 200 1 2 1 102 1 +r 200 1 28 1 102 1 +r 200 1 310 1 87 1 +r 200 1 38 1 100 1 +r 201 1 120 1 87 1 +r 201 1 2 1 10 1 s We allow currently only Relation Requirements in types. Could this restriction be lifted? +r 202 1 1112 1 262 1 +r 202 1 1112 1 259 1 +r 202 1 1112 1 257 1 +r 202 1 171 1 254 1 +r 202 1 172 1 267 1 +r 202 1 172 1 265 1 +r 202 1 172 1 263 1 +r 202 1 172 1 260 1 +r 202 1 172 1 255 1 +r 202 1 172 1 1 1 +r 202 1 5 1 25 1 +r 202 1 6 1 976 1 +r 202 1 7 1 44 1 +r 203 1 2 1 10 1 s All relations are instances of this type. +r 203 1 1127 1 1 1 +r 204 1 2 1 102 1 +r 204 1 310 1 1 1 +r 204 1 38 1 113 1 +r 205 1 2 1 102 1 +r 205 1 310 1 1 1 +r 205 1 38 1 3 1 +r 206 1 2 1 102 1 +r 206 1 310 1 1 1 +r 206 1 38 1 4 1 +r 207 1 2 1 102 1 +r 207 1 310 1 1 1 +r 207 1 38 1 51 1 +r 208 1 3 1 80 1 +r 208 1 1116 1 290 1 +r 208 1 4 1 1140 1 +r 208 1 28 1 1 1 +r 208 1 6 1 987 1 +r 208 1 7 1 44 1 +r 209 1 2 1 10 1 s All types are inherited from this type. +r 209 1 1127 1 25 1 +r 210 1 2 1 102 1 +r 210 1 310 1 25 1 +r 210 1 38 1 2 1 +r 211 1 2 1 102 1 +r 211 1 310 1 25 1 +r 211 1 38 1 74 1 +r 212 1 1112 1 216 1 +r 212 1 1113 1 220 1 +r 212 1 172 1 221 1 +r 212 1 100 1 215 1 +r 212 1 100 1 213 1 +r 212 1 5 1 25 1 +r 212 1 6 1 959 1 +r 212 1 7 1 44 1 +r 213 1 2 1 102 1 +r 213 1 310 1 212 1 +r 213 1 38 1 214 1 +r 213 1 39 1 103 1 +r 214 1 3 1 74 1 +r 214 1 1116 1 218 1 +r 214 1 1116 1 213 1 +r 214 1 4 1 1141 1 +r 214 1 28 1 10 1 +r 214 1 6 1 831 1 +r 214 1 7 1 44 1 +r 215 1 2 1 102 1 +r 215 1 310 1 212 1 +r 215 1 38 1 6 1 +r 215 1 39 1 103 1 +r 216 1 3 1 77 1 +r 216 1 4 1 1142 1 +r 216 1 28 1 212 1 +r 216 1 29 1 87 1 +r 216 1 6 1 860 1 +r 216 1 7 1 44 1 +r 217 1 1112 1 225 1 +r 217 1 171 1 280 1 +r 217 1 100 1 219 1 +r 217 1 100 1 218 1 +r 217 1 5 1 25 1 +r 217 1 6 1 882 1 +r 217 1 7 1 44 1 +r 218 1 2 1 102 1 +r 218 1 310 1 217 1 +r 218 1 38 1 214 1 +r 218 1 39 1 103 1 +r 219 1 2 1 102 1 +r 219 1 310 1 217 1 +r 219 1 38 1 6 1 +r 219 1 39 1 103 1 +r 220 1 2 1 90 1 +r 220 1 3 1 79 1 +r 220 1 3 1 77 1 +r 220 1 4 1 220 1 +r 220 1 29 1 212 1 +r 220 1 6 1 925 1 +r 220 1 7 1 44 1 +r 221 1 172 1 226 1 +r 221 1 100 1 224 1 +r 221 1 100 1 222 1 +r 221 1 5 1 212 1 +r 221 1 6 1 885 1 +r 221 1 7 1 44 1 +r 222 1 2 1 102 1 +r 222 1 310 1 221 1 +r 222 1 38 1 223 1 +r 222 1 39 1 103 1 +r 223 1 3 1 74 1 +r 223 1 1116 1 270 1 +r 223 1 1116 1 222 1 +r 223 1 4 1 1143 1 +r 223 1 28 1 10 1 +r 223 1 6 1 1017 1 +r 223 1 7 1 44 1 +r 224 1 2 1 102 1 +r 224 1 310 1 221 1 +r 224 1 38 1 225 1 +r 224 1 39 1 103 1 +r 225 1 3 1 77 1 +r 225 1 1116 1 271 1 +r 225 1 1116 1 224 1 +r 225 1 4 1 1144 1 +r 225 1 28 1 217 1 +r 225 1 6 1 1020 1 +r 225 1 7 1 44 1 +r 226 1 5 1 221 1 +r 226 1 6 1 1003 1 +r 226 1 7 1 44 1 +r 227 1 172 1 236 1 +r 227 1 5 1 25 1 +r 227 1 6 1 952 1 +r 227 1 7 1 44 1 +r 228 1 5 1 25 1 +r 228 1 6 1 838 1 +r 228 1 7 1 44 1 +r 229 1 3 1 77 1 +r 229 1 4 1 1145 1 +r 229 1 6 1 881 1 +r 229 1 7 1 44 1 +r 230 1 3 1 79 1 +r 230 1 3 1 8 1 +r 230 1 4 1 231 1 +r 230 1 6 1 957 1 +r 230 1 7 1 44 1 +r 231 1 3 1 77 1 +r 231 1 3 1 8 1 +r 231 1 4 1 230 1 +r 231 1 6 1 1010 1 +r 231 1 7 1 44 1 +r 232 1 3 1 79 1 +r 232 1 3 1 8 1 +r 232 1 4 1 233 1 +r 232 1 6 1 966 1 +r 232 1 7 1 44 1 +r 233 1 3 1 77 1 +r 233 1 3 1 8 1 +r 233 1 4 1 232 1 +r 233 1 6 1 942 1 +r 233 1 7 1 44 1 +r 234 1 3 1 77 1 +r 234 1 4 1 1146 1 +r 234 1 6 1 854 1 +r 234 1 7 1 44 1 +r 235 1 3 1 77 1 +r 235 1 4 1 1147 1 +r 235 1 6 1 855 1 +r 235 1 7 1 44 1 +r 236 1 5 1 227 1 +r 236 1 6 1 892 1 +r 236 1 7 1 44 1 +r 237 1 5 1 25 1 +r 237 1 6 1 898 1 +r 237 1 7 1 44 1 +r 238 1 3 1 74 1 +r 238 1 28 1 10 1 +r 238 1 4 1 239 1 +r 238 1 6 1 985 1 +r 238 1 7 1 44 1 +r 239 1 3 1 107 1 +r 239 1 4 1 238 1 +r 239 1 6 1 999 1 +r 239 1 7 1 44 1 +r 240 1 3 1 77 1 +r 240 1 4 1 1148 1 +r 240 1 28 1 16 1 +r 240 1 6 1 917 1 +r 240 1 7 1 44 1 +r 241 1 3 1 74 1 +r 241 1 4 1 1149 1 +r 241 1 28 1 10 1 +r 241 1 116 1 242 1 +r 241 1 69 1 243 1 +r 241 1 6 1 859 1 +r 241 1 7 1 44 1 +r 242 1 2 1 10 1 s Generated Name Prefix +r 242 1 1131 1 241 1 +r 243 1 2 1 10 1 s Indicates the prefix used to be used for naming instances of the property owner. +r 243 1 1127 1 241 1 +r 244 1 9 1 249 1 +r 244 1 9 1 247 1 +r 244 1 9 1 245 1 +r 244 1 2 1 45 1 +r 244 1 6 1 1034 1 +r 244 1 7 1 44 1 +r 245 1 100 1 246 1 +r 245 1 5 1 195 1 +r 245 1 6 1 910 1 +r 245 1 7 1 244 1 +r 246 1 2 1 102 1 +r 246 1 28 1 195 1 +r 246 1 310 1 245 1 +r 246 1 38 1 55 1 +r 247 1 100 1 248 1 +r 247 1 5 1 195 1 +r 247 1 6 1 946 1 +r 247 1 7 1 244 1 +r 248 1 2 1 102 1 +r 248 1 28 1 195 1 +r 248 1 310 1 247 1 +r 248 1 38 1 55 1 +r 249 1 27 1 250 1 +r 249 1 5 1 195 1 +r 249 1 6 1 980 1 +r 249 1 7 1 244 1 +r 250 1 40 1 251 1 +r 250 1 2 1 37 1 +r 250 1 38 1 55 1 +r 250 1 1111 1 249 1 +r 251 1 2 1 37 1 +r 251 1 1118 1 250 1 +r 251 1 38 1 195 1 +r 251 1 39 1 252 1 +r 252 1 2 1 121 1 s 1 +r 252 1 1117 1 251 1 +r 253 1 9 1 267 1 +r 253 1 9 1 265 1 +r 253 1 9 1 263 1 +r 253 1 9 1 262 1 +r 253 1 9 1 260 1 +r 253 1 9 1 259 1 +r 253 1 9 1 257 1 +r 253 1 9 1 255 1 +r 253 1 9 1 254 1 +r 253 1 2 1 45 1 +r 253 1 6 1 873 1 +r 253 1 7 1 44 1 +r 254 1 2 1 202 1 +r 254 1 6 1 992 1 +r 254 1 7 1 253 1 +r 255 1 100 1 258 1 +r 255 1 100 1 256 1 +r 255 1 5 1 202 1 +r 255 1 6 1 834 1 +r 255 1 7 1 253 1 +r 256 1 2 1 102 1 +r 256 1 310 1 255 1 +r 256 1 38 1 257 1 +r 256 1 39 1 103 1 +r 257 1 3 1 77 1 +r 257 1 1116 1 256 1 +r 257 1 4 1 1150 1 +r 257 1 28 1 202 1 +r 257 1 6 1 961 1 +r 257 1 7 1 253 1 +r 258 1 2 1 102 1 +r 258 1 310 1 255 1 +r 258 1 38 1 259 1 +r 258 1 39 1 103 1 +r 259 1 3 1 77 1 +r 259 1 1116 1 258 1 +r 259 1 4 1 1151 1 +r 259 1 28 1 202 1 +r 259 1 6 1 857 1 +r 259 1 7 1 253 1 +r 260 1 100 1 261 1 +r 260 1 5 1 202 1 +r 260 1 6 1 896 1 +r 260 1 7 1 253 1 +r 261 1 2 1 102 1 +r 261 1 310 1 260 1 +r 261 1 38 1 262 1 +r 261 1 39 1 103 1 +r 262 1 3 1 77 1 +r 262 1 1116 1 268 1 +r 262 1 1116 1 266 1 +r 262 1 1116 1 264 1 +r 262 1 1116 1 261 1 +r 262 1 4 1 1152 1 +r 262 1 28 1 202 1 +r 262 1 6 1 872 1 +r 262 1 7 1 253 1 +r 263 1 100 1 264 1 +r 263 1 5 1 202 1 +r 263 1 6 1 858 1 +r 263 1 7 1 253 1 +r 264 1 2 1 102 1 +r 264 1 310 1 263 1 +r 264 1 38 1 262 1 +r 264 1 39 1 103 1 +r 265 1 100 1 266 1 +r 265 1 5 1 202 1 +r 265 1 6 1 842 1 +r 265 1 7 1 253 1 +r 266 1 2 1 102 1 +r 266 1 310 1 265 1 +r 266 1 38 1 262 1 +r 267 1 100 1 268 1 +r 267 1 5 1 202 1 +r 267 1 6 1 839 1 +r 267 1 7 1 253 1 +r 268 1 2 1 102 1 +r 268 1 310 1 267 1 +r 268 1 38 1 262 1 +r 269 1 100 1 271 1 +r 269 1 100 1 270 1 +r 269 1 5 1 25 1 +r 269 1 6 1 862 1 +r 269 1 7 1 44 1 +r 270 1 2 1 102 1 +r 270 1 310 1 269 1 +r 270 1 38 1 223 1 +r 270 1 39 1 103 1 +r 271 1 2 1 102 1 +r 271 1 310 1 269 1 +r 271 1 38 1 225 1 +r 271 1 39 1 103 1 +r 272 1 1112 1 275 1 +r 272 1 100 1 273 1 +r 272 1 5 1 25 1 +r 272 1 6 1 841 1 +r 272 1 7 1 44 1 +r 273 1 2 1 102 1 +r 273 1 310 1 272 1 +r 273 1 38 1 274 1 +r 274 1 3 1 79 1 +r 274 1 1116 1 273 1 +r 274 1 4 1 275 1 +r 274 1 6 1 954 1 +r 274 1 7 1 44 1 +r 275 1 3 1 77 1 +r 275 1 4 1 274 1 +r 275 1 28 1 272 1 +r 275 1 6 1 894 1 +r 275 1 7 1 44 1 +r 276 1 1112 1 277 1 +r 276 1 5 1 25 1 +r 276 1 6 1 982 1 +r 276 1 7 1 44 1 +r 277 1 3 1 77 1 +r 277 1 4 1 1153 1 +r 277 1 28 1 276 1 +r 277 1 6 1 958 1 +r 277 1 7 1 44 1 +r 278 1 1112 1 279 1 +r 278 1 5 1 25 1 +r 278 1 6 1 934 1 +r 278 1 7 1 44 1 +r 279 1 3 1 77 1 +r 279 1 4 1 1154 1 +r 279 1 28 1 278 1 +r 279 1 6 1 869 1 +r 279 1 7 1 44 1 +r 280 1 2 1 217 1 +r 280 1 69 1 281 1 +r 280 1 6 1 918 1 +r 280 1 7 1 44 1 +r 281 1 2 1 10 1 s A relation used for performing model dependency indexing. +r 281 1 1127 1 280 1 +r 282 1 3 1 79 1 +r 282 1 3 1 77 1 +r 282 1 1116 1 285 1 +r 282 1 4 1 283 1 +r 282 1 6 1 837 1 +r 282 1 7 1 44 1 +r 283 1 3 1 79 1 +r 283 1 3 1 77 1 +r 283 1 4 1 282 1 +r 283 1 6 1 848 1 +r 283 1 7 1 44 1 +r 284 1 100 1 285 1 +r 284 1 5 1 87 1 +r 284 1 6 1 1015 1 +r 284 1 7 1 44 1 +r 285 1 2 1 102 1 +r 285 1 310 1 284 1 +r 285 1 38 1 282 1 +r 285 1 39 1 103 1 +r 286 1 5 1 25 1 +r 286 1 6 1 880 1 +r 286 1 7 1 44 1 +r 287 1 1112 1 297 1 +r 287 1 1112 1 295 1 +r 287 1 172 1 291 1 +r 287 1 172 1 289 1 +r 287 1 172 1 288 1 +r 287 1 5 1 25 1 +r 287 1 6 1 940 1 +r 287 1 7 1 44 1 +r 288 1 5 1 287 1 +r 288 1 5 1 140 1 +r 288 1 6 1 973 1 +r 288 1 7 1 44 1 +r 289 1 100 1 290 1 +r 289 1 5 1 287 1 +r 289 1 6 1 994 1 +r 289 1 7 1 44 1 +r 290 1 2 1 102 1 +r 290 1 310 1 289 1 +r 290 1 38 1 208 1 +r 290 1 39 1 103 1 +r 291 1 100 1 296 1 +r 291 1 100 1 294 1 +r 291 1 100 1 292 1 +r 291 1 5 1 287 1 +r 291 1 6 1 870 1 +r 291 1 7 1 44 1 +r 292 1 2 1 102 1 +r 292 1 310 1 291 1 +r 292 1 38 1 293 1 +r 292 1 39 1 103 1 +r 293 1 3 1 77 1 +r 293 1 1116 1 292 1 +r 293 1 4 1 1155 1 +r 293 1 28 1 195 1 +r 293 1 6 1 845 1 +r 293 1 7 1 44 1 +r 294 1 2 1 102 1 +r 294 1 310 1 291 1 +r 294 1 38 1 295 1 +r 294 1 39 1 103 1 +r 295 1 3 1 77 1 +r 295 1 1116 1 294 1 +r 295 1 4 1 1156 1 +r 295 1 28 1 287 1 +r 295 1 6 1 1031 1 +r 295 1 7 1 44 1 +r 296 1 2 1 102 1 +r 296 1 310 1 291 1 +r 296 1 38 1 297 1 +r 296 1 39 1 139 1 +r 297 1 3 1 77 1 +r 297 1 1116 1 296 1 +r 297 1 4 1 1157 1 +r 297 1 28 1 287 1 +r 297 1 6 1 832 1 +r 297 1 7 1 44 1 +r 298 1 2 1 14 1 b true +r 298 1 6 1 299 1 +r 298 1 7 1 44 1 +r 299 1 2 1 10 1 s True +r 299 1 115 1 298 1 +r 300 1 2 1 14 1 b false +r 300 1 6 1 301 1 +r 300 1 7 1 44 1 +r 301 1 2 1 10 1 s False +r 301 1 115 1 300 1 +r 302 1 2 1 10 1 s +r 302 1 6 1 303 1 +r 302 1 7 1 44 1 +r 303 1 2 1 10 1 s Empty String +r 303 1 115 1 302 1 +r 304 1 1112 1 306 1 +r 304 1 69 1 305 1 +r 304 1 5 1 25 1 +r 304 1 6 1 929 1 +r 304 1 7 1 44 1 +r 305 1 2 1 10 1 s Template defines a subgraph. Instances can be adapted to org.simantics.db.layer0.adapter.Template +r 305 1 1127 1 304 1 +r 306 1 51 1 448 1 +r 306 1 3 1 8 1 +r 306 1 4 1 1158 1 +r 306 1 28 1 304 1 +r 306 1 6 1 984 1 +r 306 1 7 1 44 1 +r 307 1 2 1 102 1 +r 307 1 310 1 102 1 +r 307 1 38 1 38 1 +r 308 1 2 1 102 1 +r 308 1 310 1 102 1 +r 308 1 38 1 39 1 +r 309 1 2 1 102 1 +r 309 1 310 1 102 1 +r 309 1 38 1 310 1 +r 310 1 3 1 79 1 +r 310 1 3 1 77 1 +r 310 1 1116 1 309 1 +r 310 1 4 1 100 1 +r 310 1 6 1 1035 1 +r 310 1 7 1 44 1 +r 311 1 5 1 87 1 +r 311 1 6 1 888 1 +r 311 1 7 1 44 1 +r 312 1 5 1 25 1 +r 312 1 6 1 969 1 +r 312 1 7 1 44 1 +r 313 1 3 1 77 1 +r 313 1 4 1 1159 1 +r 313 1 6 1 923 1 +r 313 1 7 1 44 1 +r 314 1 3 1 77 1 +r 314 1 4 1 1160 1 +r 314 1 6 1 943 1 +r 314 1 7 1 44 1 +r 315 1 171 1 332 1 +r 315 1 171 1 326 1 +r 315 1 171 1 320 1 +r 315 1 171 1 139 1 +r 315 1 171 1 103 1 +r 315 1 100 1 318 1 +r 315 1 100 1 316 1 +r 315 1 5 1 25 1 +r 315 1 6 1 1002 1 +r 315 1 7 1 44 1 +r 316 1 2 1 102 1 +r 316 1 28 1 11 1 +r 316 1 310 1 315 1 +r 316 1 38 1 317 1 +r 316 1 39 1 139 1 +r 317 1 3 1 77 1 +r 317 1 1116 1 316 1 +r 317 1 4 1 1161 1 +r 317 1 6 1 902 1 +r 317 1 7 1 44 1 +r 318 1 2 1 102 1 +r 318 1 28 1 11 1 +r 318 1 310 1 315 1 +r 318 1 38 1 319 1 +r 318 1 39 1 139 1 +r 319 1 3 1 77 1 +r 319 1 1116 1 318 1 +r 319 1 4 1 1162 1 +r 319 1 6 1 1006 1 +r 319 1 7 1 44 1 +r 320 1 2 1 315 1 +r 320 1 317 1 322 1 +r 320 1 6 1 321 1 +r 320 1 7 1 44 1 +r 321 1 2 1 10 1 s Cardinality 0 +r 321 1 115 1 320 1 +r 322 1 1161 1 320 1 +r 322 1 2 1 11 1 i 0 +r 323 1 2 1 10 1 s Cardinality 1 +r 323 1 115 1 103 1 +r 324 1 1162 1 103 1 +r 324 1 2 1 11 1 i 1 +r 325 1 1161 1 103 1 +r 325 1 2 1 11 1 i 1 +r 326 1 2 1 315 1 +r 326 1 1117 1 511 1 +r 326 1 317 1 329 1 +r 326 1 6 1 327 1 +r 326 1 7 1 44 1 +r 326 1 319 1 328 1 +r 327 1 2 1 10 1 s Cardinality 2 +r 327 1 115 1 326 1 +r 328 1 1162 1 326 1 +r 328 1 2 1 11 1 i 2 +r 329 1 1161 1 326 1 +r 329 1 2 1 11 1 i 2 +r 330 1 2 1 10 1 s Cardinality at most 1 +r 330 1 115 1 139 1 +r 331 1 1161 1 139 1 +r 331 1 2 1 11 1 i 1 +r 332 1 2 1 315 1 +r 332 1 6 1 333 1 +r 332 1 7 1 44 1 +r 332 1 319 1 334 1 +r 333 1 2 1 10 1 s Cardinality at least 1 +r 333 1 115 1 332 1 +r 334 1 1162 1 332 1 +r 334 1 2 1 11 1 i 1 +r 335 1 9 1 336 1 +r 335 1 2 1 45 1 +r 335 1 6 1 964 1 +r 335 1 7 1 44 1 +r 336 1 336 1 337 1 +r 336 1 1163 1 340 1 +r 336 1 3 1 136 1 +r 336 1 4 1 1163 1 +r 336 1 7 1 335 1 +r 337 1 336 1 338 1 +r 337 1 2 1 10 1 s First element +r 337 1 1163 1 336 1 +r 338 1 336 1 339 1 +r 338 1 2 1 10 1 s Second element +r 338 1 1163 1 337 1 +r 339 1 336 1 340 1 +r 339 1 2 1 10 1 s Third element +r 339 1 1163 1 338 1 +r 340 1 336 1 336 1 +r 340 1 2 1 10 1 s Fourth element +r 340 1 1163 1 339 1 +r 341 1 2 1 102 1 +r 341 1 310 1 193 1 +r 341 1 38 1 342 1 +r 341 1 39 1 103 1 +r 342 1 3 1 74 1 +r 342 1 1116 1 341 1 +r 342 1 4 1 1164 1 +r 342 1 6 1 1022 1 +r 342 1 7 1 44 1 +r 343 1 1112 1 344 1 +r 343 1 171 1 345 1 +r 343 1 5 1 25 1 +r 343 1 6 1 1026 1 +r 343 1 7 1 44 1 +r 344 1 3 1 77 1 +r 344 1 4 1 1165 1 +r 344 1 28 1 343 1 +r 344 1 6 1 1000 1 +r 344 1 7 1 44 1 +r 345 1 2 1 343 1 +r 345 1 6 1 906 1 +r 345 1 7 1 44 1 +r 346 1 5 1 25 1 +r 346 1 6 1 866 1 +r 346 1 7 1 44 1 +r 347 1 171 1 348 1 +r 347 1 5 1 25 1 +r 347 1 6 1 901 1 +r 347 1 7 1 44 1 +r 348 1 2 1 347 1 +r 348 1 6 1 986 1 +r 348 1 7 1 44 1 +r 349 1 69 1 350 1 +r 349 1 5 1 87 1 +r 349 1 6 1 863 1 +r 349 1 7 1 44 1 +r 350 1 2 1 10 1 s A type whose subtypes are in some sense similar and changeable. +r 350 1 1127 1 349 1 +r 351 1 69 1 352 1 +r 351 1 5 1 1 1 +r 351 1 6 1 988 1 +r 351 1 7 1 44 1 +r 352 1 2 1 10 1 s A relation whose subrelation are in some sense similar and changeable. +r 352 1 1127 1 351 1 +r 353 1 3 1 80 1 +r 353 1 4 1 1166 1 +r 353 1 69 1 354 1 +r 353 1 6 1 835 1 +r 353 1 7 1 44 1 +r 354 1 2 1 10 1 s Refers to an alternative version of the instance with a different type that may substitute the instance, when the type is changed. +r 354 1 1127 1 353 1 +r 355 1 5 1 25 1 +r 355 1 6 1 867 1 +r 355 1 7 1 44 1 +r 356 1 5 1 25 1 +r 356 1 6 1 852 1 +r 356 1 7 1 44 1 +r 357 1 5 1 25 1 +r 357 1 6 1 978 1 +r 357 1 7 1 44 1 +r 358 1 5 1 25 1 +r 358 1 6 1 965 1 +r 358 1 7 1 44 1 +r 359 1 5 1 25 1 +r 359 1 6 1 963 1 +r 359 1 7 1 44 1 +r 360 1 5 1 25 1 +r 360 1 6 1 861 1 +r 360 1 7 1 44 1 +r 361 1 5 1 25 1 +r 361 1 6 1 907 1 +r 361 1 7 1 44 1 +r 362 1 9 1 388 1 +r 362 1 9 1 384 1 +r 362 1 9 1 378 1 +r 362 1 9 1 375 1 +r 362 1 9 1 374 1 +r 362 1 9 1 371 1 +r 362 1 2 1 177 1 +r 362 1 6 1 363 1 +r 362 1 7 1 364 1 +r 363 1 2 1 10 1 s Types +r 363 1 115 1 362 1 +r 364 1 65 1 370 1 +r 364 1 9 1 365 1 +r 364 1 9 1 362 1 +r 364 1 2 1 53 1 +r 364 1 60 1 368 1 +r 364 1 6 1 367 1 +r 364 1 63 1 369 1 +r 364 1 7 1 57 1 +r 365 1 9 1 391 1 +r 365 1 9 1 390 1 +r 365 1 9 1 389 1 +r 365 1 9 1 386 1 +r 365 1 9 1 385 1 +r 365 1 9 1 382 1 +r 365 1 9 1 380 1 +r 365 1 2 1 180 1 +r 365 1 6 1 366 1 +r 365 1 7 1 364 1 +r 366 1 2 1 10 1 s Relations +r 366 1 115 1 365 1 +r 367 1 2 1 10 1 s Simulation-1.0 +r 367 1 115 1 364 1 +r 368 1 2 1 62 1 s 1.0 +r 368 1 1124 1 364 1 +r 369 1 2 1 10 1 s org.simantics.db.Builtins +r 369 1 1125 1 364 1 +r 370 1 2 1 10 1 s simulation +r 370 1 1126 1 364 1 +r 371 1 27 1 372 1 +r 371 1 5 1 45 1 +r 371 1 6 1 1048 1 +r 371 1 7 1 362 1 +r 371 1 1111 1 373 1 +r 372 1 40 1 373 1 +r 372 1 2 1 37 1 +r 372 1 38 1 9 1 +r 372 1 1111 1 371 1 +r 373 1 2 1 33 1 +r 373 1 27 1 374 1 +r 373 1 27 1 371 1 +r 373 1 1118 1 372 1 +r 374 1 100 1 383 1 +r 374 1 100 1 381 1 +r 374 1 100 1 379 1 +r 374 1 5 1 25 1 +r 374 1 6 1 1043 1 +r 374 1 7 1 362 1 +r 374 1 1111 1 373 1 +r 375 1 27 1 376 1 +r 375 1 5 1 45 1 +r 375 1 6 1 1039 1 +r 375 1 7 1 362 1 +r 375 1 1111 1 377 1 +r 376 1 40 1 377 1 +r 376 1 2 1 37 1 +r 376 1 38 1 9 1 +r 376 1 1111 1 375 1 +r 377 1 2 1 33 1 +r 377 1 27 1 378 1 +r 377 1 27 1 375 1 +r 377 1 1118 1 376 1 +r 378 1 100 1 387 1 +r 378 1 5 1 25 1 +r 378 1 6 1 1047 1 +r 378 1 7 1 362 1 +r 378 1 1111 1 377 1 +r 379 1 2 1 102 1 +r 379 1 310 1 374 1 +r 379 1 38 1 380 1 +r 379 1 39 1 103 1 +r 380 1 3 1 80 1 +r 380 1 1116 1 379 1 +r 380 1 4 1 385 1 +r 380 1 6 1 1049 1 +r 380 1 7 1 365 1 +r 381 1 2 1 102 1 +r 381 1 310 1 374 1 +r 381 1 38 1 382 1 +r 382 1 3 1 80 1 +r 382 1 1116 1 381 1 +r 382 1 4 1 1167 1 +r 382 1 28 1 384 1 +r 382 1 6 1 1044 1 +r 382 1 7 1 365 1 +r 383 1 2 1 102 1 +r 383 1 310 1 374 1 +r 383 1 38 1 9 1 +r 384 1 1112 1 382 1 +r 384 1 5 1 25 1 +r 384 1 6 1 1045 1 +r 384 1 7 1 362 1 +r 385 1 3 1 82 1 +r 385 1 1116 1 403 1 +r 385 1 4 1 380 1 +r 385 1 6 1 1050 1 +r 385 1 7 1 365 1 +r 386 1 3 1 80 1 +r 386 1 1116 1 387 1 +r 386 1 4 1 1168 1 +r 386 1 6 1 1046 1 +r 386 1 7 1 365 1 +r 387 1 2 1 102 1 +r 387 1 310 1 378 1 +r 387 1 38 1 386 1 +r 387 1 39 1 139 1 +r 388 1 5 1 25 1 +r 388 1 6 1 1042 1 +r 388 1 7 1 362 1 +r 389 1 2 1 90 1 +r 389 1 3 1 79 1 +r 389 1 3 1 77 1 +r 389 1 4 1 389 1 +r 389 1 6 1 1041 1 +r 389 1 7 1 365 1 +r 390 1 3 1 74 1 +r 390 1 4 1 1169 1 +r 390 1 6 1 1040 1 +r 390 1 7 1 365 1 +r 391 1 3 1 77 1 +r 391 1 4 1 1170 1 +r 391 1 69 1 392 1 +r 391 1 6 1 1038 1 +r 391 1 7 1 365 1 +r 392 1 2 1 10 1 s Adapter relation for configurations. +r 392 1 1127 1 391 1 +r 393 1 9 1 489 1 +r 393 1 9 1 487 1 +r 393 1 9 1 486 1 +r 393 1 9 1 484 1 +r 393 1 9 1 483 1 +r 393 1 9 1 482 1 +r 393 1 9 1 481 1 +r 393 1 9 1 480 1 +r 393 1 9 1 479 1 +r 393 1 9 1 478 1 +r 393 1 9 1 476 1 +r 393 1 9 1 473 1 +r 393 1 9 1 472 1 +r 393 1 9 1 470 1 +r 393 1 9 1 469 1 +r 393 1 9 1 468 1 +r 393 1 9 1 466 1 +r 393 1 9 1 465 1 +r 393 1 9 1 463 1 +r 393 1 9 1 461 1 +r 393 1 9 1 459 1 +r 393 1 9 1 458 1 +r 393 1 9 1 457 1 +r 393 1 9 1 456 1 +r 393 1 9 1 455 1 +r 393 1 9 1 454 1 +r 393 1 9 1 452 1 +r 393 1 9 1 451 1 +r 393 1 9 1 450 1 +r 393 1 9 1 449 1 +r 393 1 9 1 448 1 +r 393 1 9 1 447 1 +r 393 1 9 1 445 1 +r 393 1 9 1 444 1 +r 393 1 9 1 442 1 +r 393 1 9 1 440 1 +r 393 1 9 1 438 1 +r 393 1 9 1 437 1 +r 393 1 9 1 433 1 +r 393 1 9 1 430 1 +r 393 1 9 1 429 1 +r 393 1 9 1 428 1 +r 393 1 9 1 427 1 +r 393 1 9 1 425 1 +r 393 1 9 1 424 1 +r 393 1 9 1 423 1 +r 393 1 9 1 421 1 +r 393 1 9 1 418 1 +r 393 1 9 1 417 1 +r 393 1 9 1 415 1 +r 393 1 9 1 414 1 +r 393 1 9 1 412 1 +r 393 1 9 1 410 1 +r 393 1 9 1 407 1 +r 393 1 9 1 405 1 +r 393 1 9 1 401 1 +r 393 1 9 1 399 1 +r 393 1 9 1 398 1 +r 393 1 65 1 396 1 +r 393 1 2 1 53 1 +r 393 1 60 1 395 1 +r 393 1 6 1 394 1 +r 393 1 63 1 397 1 +r 393 1 7 1 57 1 +r 394 1 2 1 10 1 s Structural-1.0 +r 394 1 115 1 393 1 +r 395 1 2 1 62 1 s 2.0 +r 395 1 1124 1 393 1 +r 396 1 2 1 10 1 s structural +r 396 1 1126 1 393 1 +r 397 1 2 1 10 1 s org.simantics.structural.stubs.StructuralResource2 +r 397 1 1125 1 393 1 +r 398 1 1112 1 419 1 +r 398 1 1112 1 412 1 +r 398 1 2 1 399 1 +r 398 1 172 1 421 1 +r 398 1 172 1 418 1 +r 398 1 100 1 406 1 +r 398 1 100 1 404 1 +r 398 1 100 1 403 1 +r 398 1 100 1 402 1 +r 398 1 100 1 400 1 +r 398 1 92 1 398 1 +r 398 1 69 1 408 1 +r 398 1 5 1 25 1 +r 398 1 6 1 739 1 +r 398 1 7 1 393 1 +r 399 1 1113 1 410 1 +r 399 1 171 1 398 1 +r 399 1 100 1 411 1 +r 399 1 100 1 409 1 +r 399 1 69 1 413 1 +r 399 1 5 1 87 1 +r 399 1 6 1 768 1 +r 399 1 7 1 393 1 +r 400 1 2 1 102 1 +r 400 1 310 1 398 1 +r 400 1 38 1 401 1 +r 401 1 2 1 449 1 +r 401 1 3 1 80 1 +r 401 1 1116 1 400 1 +r 401 1 4 1 442 1 +r 401 1 92 1 401 1 +r 401 1 6 1 763 1 +r 401 1 7 1 393 1 +r 402 1 2 1 102 1 +r 402 1 310 1 398 1 +r 402 1 38 1 7 1 +r 403 1 2 1 102 1 +r 403 1 310 1 398 1 +r 403 1 38 1 385 1 +r 404 1 2 1 102 1 +r 404 1 310 1 398 1 +r 404 1 38 1 405 1 +r 405 1 3 1 77 1 +r 405 1 1116 1 490 1 +r 405 1 1116 1 404 1 +r 405 1 4 1 1171 1 +r 405 1 28 1 486 1 +r 405 1 6 1 740 1 +r 405 1 7 1 393 1 +r 406 1 2 1 102 1 +r 406 1 310 1 398 1 +r 406 1 38 1 407 1 +r 407 1 3 1 77 1 +r 407 1 1116 1 406 1 +r 407 1 4 1 1172 1 +r 407 1 28 1 487 1 +r 407 1 6 1 761 1 +r 407 1 7 1 393 1 +r 408 1 2 1 10 1 s Defines a structure by instantiating some Type. +r 408 1 1127 1 398 1 +r 409 1 2 1 102 1 +r 409 1 310 1 399 1 +r 409 1 38 1 410 1 +r 410 1 3 1 77 1 +r 410 1 1116 1 409 1 +r 410 1 4 1 417 1 +r 410 1 28 1 415 1 +r 410 1 69 1 416 1 +r 410 1 29 1 399 1 +r 410 1 6 1 764 1 +r 410 1 7 1 393 1 +r 411 1 2 1 102 1 +r 411 1 310 1 399 1 +r 411 1 38 1 412 1 +r 411 1 39 1 139 1 +r 412 1 2 1 42 1 +r 412 1 3 1 83 1 +r 412 1 1116 1 411 1 +r 412 1 4 1 414 1 +r 412 1 28 1 398 1 +r 412 1 6 1 734 1 +r 412 1 7 1 393 1 +r 413 1 2 1 10 1 s Parametric structure that can be instantiated. +r 413 1 1127 1 399 1 +r 414 1 3 1 85 1 +r 414 1 4 1 412 1 +r 414 1 6 1 750 1 +r 414 1 7 1 393 1 +r 415 1 1112 1 410 1 +r 415 1 172 1 445 1 +r 415 1 172 1 425 1 +r 415 1 100 1 422 1 +r 415 1 92 1 415 1 +r 415 1 5 1 25 1 +r 415 1 6 1 770 1 +r 415 1 7 1 393 1 +r 416 1 2 1 10 1 s Denotes that the given relation is a parameter to the Type. +r 416 1 1127 1 410 1 +r 417 1 3 1 79 1 +r 417 1 4 1 410 1 +r 417 1 6 1 757 1 +r 417 1 7 1 393 1 +r 418 1 1113 1 472 1 +r 418 1 1113 1 469 1 +r 418 1 100 1 419 1 +r 418 1 69 1 420 1 +r 418 1 5 1 398 1 +r 418 1 6 1 738 1 +r 418 1 7 1 393 1 +r 419 1 2 1 102 1 +r 419 1 28 1 398 1 +r 419 1 310 1 418 1 +r 419 1 38 1 9 1 +r 420 1 2 1 10 1 s A structure defined as a set of other structures. +r 420 1 1127 1 418 1 +r 421 1 5 1 398 1 +r 421 1 5 1 140 1 +r 421 1 6 1 752 1 +r 421 1 7 1 393 1 +r 422 1 2 1 102 1 +r 422 1 310 1 415 1 +r 422 1 38 1 423 1 +r 422 1 39 1 103 1 +r 423 1 3 1 77 1 +r 423 1 1116 1 446 1 +r 423 1 1116 1 426 1 +r 423 1 1116 1 422 1 +r 423 1 4 1 424 1 +r 423 1 28 1 1 1 +r 423 1 6 1 762 1 +r 423 1 7 1 393 1 +r 424 1 3 1 79 1 +r 424 1 4 1 423 1 +r 424 1 6 1 747 1 +r 424 1 7 1 393 1 +r 425 1 1114 1 434 1 +r 425 1 100 1 426 1 +r 425 1 5 1 415 1 +r 425 1 6 1 753 1 +r 425 1 7 1 393 1 +r 426 1 2 1 102 1 +r 426 1 28 1 427 1 +r 426 1 310 1 425 1 +r 426 1 38 1 423 1 +r 427 1 1112 1 426 1 +r 427 1 171 1 428 1 +r 427 1 5 1 1 1 +r 427 1 6 1 741 1 +r 427 1 7 1 393 1 +r 428 1 2 1 427 1 +r 428 1 3 1 80 1 +r 428 1 4 1 429 1 +r 428 1 92 1 428 1 +r 428 1 6 1 783 1 +r 428 1 7 1 393 1 +r 429 1 3 1 82 1 +r 429 1 4 1 428 1 +r 429 1 6 1 746 1 +r 429 1 7 1 393 1 +r 430 1 1112 1 438 1 +r 430 1 2 1 33 1 +r 430 1 27 1 434 1 +r 430 1 27 1 432 1 +r 430 1 27 1 431 1 +r 430 1 69 1 435 1 +r 430 1 6 1 726 1 +r 430 1 7 1 393 1 +r 431 1 2 1 35 1 +r 431 1 30 1 111 1 +r 431 1 1111 1 430 1 +r 432 1 2 1 35 1 +r 432 1 30 1 433 1 +r 432 1 1111 1 430 1 +r 433 1 1114 1 432 1 +r 433 1 92 1 433 1 +r 433 1 69 1 436 1 +r 433 1 5 1 25 1 +r 433 1 6 1 743 1 +r 433 1 7 1 393 1 +r 434 1 2 1 35 1 +r 434 1 30 1 425 1 +r 434 1 1111 1 430 1 +r 435 1 2 1 10 1 s Requirement for all types that can be given as a parameter to Component. +r 435 1 1127 1 430 1 +r 436 1 2 1 10 1 s Supertype of all value types that are not simple constant values or variables. +r 436 1 1127 1 433 1 +r 437 1 171 1 438 1 +r 437 1 5 1 42 1 +r 437 1 6 1 745 1 +r 437 1 7 1 393 1 +r 438 1 2 1 437 1 +r 438 1 3 1 74 1 +r 438 1 4 1 1173 1 +r 438 1 28 1 430 1 +r 438 1 92 1 438 1 +r 438 1 69 1 439 1 +r 438 1 6 1 772 1 +r 438 1 7 1 393 1 +r 439 1 2 1 10 1 s Assigns a value to some parameter. +r 439 1 1127 1 438 1 +r 440 1 1113 1 444 1 +r 440 1 172 1 445 1 +r 440 1 100 1 443 1 +r 440 1 100 1 441 1 +r 440 1 5 1 25 1 +r 440 1 6 1 769 1 +r 440 1 7 1 393 1 +r 441 1 2 1 102 1 +r 441 1 310 1 440 1 +r 441 1 38 1 442 1 +r 442 1 3 1 82 1 +r 442 1 1116 1 441 1 +r 442 1 4 1 401 1 +r 442 1 6 1 771 1 +r 442 1 7 1 393 1 +r 443 1 2 1 102 1 +r 443 1 310 1 440 1 +r 443 1 38 1 444 1 +r 444 1 3 1 77 1 +r 444 1 3 1 8 1 +r 444 1 1116 1 443 1 +r 444 1 4 1 468 1 +r 444 1 28 1 466 1 +r 444 1 29 1 440 1 +r 444 1 6 1 730 1 +r 444 1 7 1 393 1 +r 445 1 100 1 446 1 +r 445 1 5 1 440 1 +r 445 1 5 1 415 1 +r 445 1 6 1 777 1 +r 445 1 7 1 393 1 +r 446 1 2 1 102 1 +r 446 1 28 1 447 1 +r 446 1 310 1 445 1 +r 446 1 38 1 423 1 +r 447 1 1112 1 446 1 +r 447 1 172 1 449 1 +r 447 1 5 1 1 1 +r 447 1 6 1 759 1 +r 447 1 7 1 393 1 +r 448 1 3 1 306 1 +r 448 1 4 1 1174 1 +r 448 1 6 1 731 1 +r 448 1 7 1 393 1 +r 449 1 171 1 401 1 +r 449 1 5 1 447 1 +r 449 1 6 1 775 1 +r 449 1 7 1 393 1 +r 450 1 3 1 77 1 +r 450 1 4 1 1175 1 +r 450 1 28 1 451 1 +r 450 1 6 1 744 1 +r 450 1 7 1 393 1 +r 451 1 1112 1 481 1 +r 451 1 1112 1 452 1 +r 451 1 1112 1 450 1 +r 451 1 1113 1 483 1 +r 451 1 171 1 478 1 +r 451 1 100 1 453 1 +r 451 1 5 1 25 1 +r 451 1 6 1 760 1 +r 451 1 7 1 393 1 +r 452 1 2 1 42 1 +r 452 1 3 1 77 1 +r 452 1 1116 1 474 1 +r 452 1 4 1 1176 1 +r 452 1 28 1 451 1 +r 452 1 6 1 755 1 +r 452 1 7 1 393 1 +r 453 1 2 1 102 1 +r 453 1 28 1 455 1 +r 453 1 310 1 451 1 +r 453 1 38 1 454 1 +r 454 1 3 1 77 1 +r 454 1 1116 1 453 1 +r 454 1 4 1 1177 1 +r 454 1 6 1 733 1 +r 454 1 7 1 393 1 +r 455 1 1112 1 453 1 +r 455 1 100 1 464 1 +r 455 1 100 1 462 1 +r 455 1 100 1 460 1 +r 455 1 5 1 25 1 +r 455 1 6 1 778 1 +r 455 1 7 1 393 1 +r 456 1 3 1 77 1 +r 456 1 4 1 1178 1 +r 456 1 28 1 457 1 +r 456 1 6 1 780 1 +r 456 1 7 1 393 1 +r 457 1 1112 1 456 1 +r 457 1 171 1 459 1 +r 457 1 171 1 458 1 +r 457 1 5 1 25 1 +r 457 1 6 1 742 1 +r 457 1 7 1 393 1 +r 458 1 2 1 457 1 +r 458 1 6 1 782 1 +r 458 1 7 1 393 1 +r 459 1 2 1 457 1 +r 459 1 6 1 751 1 +r 459 1 7 1 393 1 +r 460 1 2 1 102 1 +r 460 1 310 1 455 1 +r 460 1 38 1 461 1 +r 460 1 39 1 139 1 +r 461 1 3 1 74 1 +r 461 1 1116 1 460 1 +r 461 1 4 1 1179 1 +r 461 1 6 1 758 1 +r 461 1 7 1 393 1 +r 462 1 2 1 102 1 +r 462 1 310 1 455 1 +r 462 1 38 1 463 1 +r 462 1 39 1 139 1 +r 463 1 3 1 74 1 +r 463 1 1116 1 462 1 +r 463 1 4 1 1180 1 +r 463 1 6 1 774 1 +r 463 1 7 1 393 1 +r 464 1 2 1 102 1 +r 464 1 310 1 455 1 +r 464 1 38 1 465 1 +r 464 1 39 1 139 1 +r 465 1 3 1 77 1 +r 465 1 1116 1 464 1 +r 465 1 4 1 1181 1 +r 465 1 6 1 776 1 +r 465 1 7 1 393 1 +r 466 1 1112 1 469 1 +r 466 1 1112 1 444 1 +r 466 1 100 1 467 1 +r 466 1 5 1 25 1 +r 466 1 6 1 727 1 +r 466 1 7 1 393 1 +r 467 1 2 1 102 1 +r 467 1 310 1 466 1 +r 467 1 38 1 468 1 +r 468 1 3 1 79 1 +r 468 1 3 1 8 1 +r 468 1 1116 1 467 1 +r 468 1 4 1 444 1 +r 468 1 6 1 749 1 +r 468 1 7 1 393 1 +r 469 1 3 1 77 1 +r 469 1 4 1 1182 1 +r 469 1 28 1 466 1 +r 469 1 29 1 418 1 +r 469 1 6 1 781 1 +r 469 1 7 1 393 1 +r 470 1 1112 1 472 1 +r 470 1 171 1 480 1 +r 470 1 172 1 473 1 +r 470 1 69 1 471 1 +r 470 1 5 1 25 1 +r 470 1 6 1 773 1 +r 470 1 7 1 393 1 +r 471 1 2 1 10 1 s Defines what can be populated to a composite and what can be connected. See . +r 471 1 1127 1 470 1 +r 472 1 2 1 42 1 +r 472 1 3 1 77 1 +r 472 1 4 1 1183 1 +r 472 1 28 1 470 1 +r 472 1 29 1 418 1 +r 472 1 6 1 748 1 +r 472 1 7 1 393 1 +r 473 1 171 1 479 1 +r 473 1 100 1 475 1 +r 473 1 100 1 474 1 +r 473 1 69 1 477 1 +r 473 1 5 1 470 1 +r 473 1 6 1 765 1 +r 473 1 7 1 393 1 +r 474 1 2 1 102 1 +r 474 1 310 1 473 1 +r 474 1 38 1 452 1 +r 474 1 39 1 103 1 +r 475 1 2 1 102 1 +r 475 1 310 1 473 1 +r 475 1 38 1 476 1 +r 475 1 39 1 103 1 +r 476 1 3 1 77 1 +r 476 1 1116 1 475 1 +r 476 1 4 1 1184 1 +r 476 1 28 1 1 1 +r 476 1 6 1 766 1 +r 476 1 7 1 393 1 +r 477 1 2 1 10 1 s Modeling rules that allow all connections. +r 477 1 1127 1 473 1 +r 478 1 1176 1 479 1 +r 478 1 2 1 451 1 +r 478 1 6 1 736 1 +r 478 1 7 1 393 1 +r 479 1 2 1 473 1 +r 479 1 452 1 478 1 +r 479 1 6 1 737 1 +r 479 1 7 1 393 1 +r 480 1 2 1 470 1 +r 480 1 6 1 729 1 +r 480 1 7 1 393 1 +r 481 1 3 1 77 1 +r 481 1 4 1 1185 1 +r 481 1 28 1 451 1 +r 481 1 29 1 1 1 +r 481 1 6 1 779 1 +r 481 1 7 1 393 1 +r 482 1 1112 1 483 1 +r 482 1 171 1 484 1 +r 482 1 5 1 25 1 +r 482 1 6 1 732 1 +r 482 1 7 1 393 1 +r 483 1 3 1 77 1 +r 483 1 4 1 1186 1 +r 483 1 28 1 482 1 +r 483 1 29 1 451 1 +r 483 1 6 1 754 1 +r 483 1 7 1 393 1 +r 484 1 2 1 482 1 +r 484 1 69 1 485 1 +r 484 1 6 1 735 1 +r 484 1 7 1 393 1 +r 485 1 2 1 10 1 s Requires that connection sets uses two different kinds of attachment relations. +r 485 1 1127 1 484 1 +r 486 1 1112 1 489 1 +r 486 1 1112 1 405 1 +r 486 1 5 1 25 1 +r 486 1 6 1 767 1 +r 486 1 7 1 393 1 +r 487 1 1112 1 407 1 +r 487 1 100 1 490 1 +r 487 1 100 1 488 1 +r 487 1 5 1 25 1 +r 487 1 6 1 756 1 +r 487 1 7 1 393 1 +r 488 1 2 1 102 1 +r 488 1 310 1 487 1 +r 488 1 38 1 489 1 +r 489 1 3 1 77 1 +r 489 1 1116 1 488 1 +r 489 1 4 1 1187 1 +r 489 1 28 1 486 1 +r 489 1 6 1 728 1 +r 489 1 7 1 393 1 +r 490 1 2 1 102 1 +r 490 1 310 1 487 1 +r 490 1 38 1 405 1 +r 491 1 9 1 551 1 +r 491 1 9 1 550 1 +r 491 1 9 1 549 1 +r 491 1 9 1 546 1 +r 491 1 9 1 543 1 +r 491 1 9 1 541 1 +r 491 1 9 1 540 1 +r 491 1 9 1 539 1 +r 491 1 9 1 538 1 +r 491 1 9 1 536 1 +r 491 1 9 1 535 1 +r 491 1 9 1 534 1 +r 491 1 9 1 526 1 +r 491 1 9 1 522 1 +r 491 1 9 1 520 1 +r 491 1 9 1 512 1 +r 491 1 9 1 510 1 +r 491 1 9 1 508 1 +r 491 1 9 1 506 1 +r 491 1 9 1 502 1 +r 491 1 9 1 499 1 +r 491 1 2 1 177 1 +r 491 1 6 1 492 1 +r 491 1 7 1 493 1 +r 492 1 2 1 10 1 s Types +r 492 1 115 1 491 1 +r 493 1 9 1 494 1 +r 493 1 9 1 491 1 +r 493 1 2 1 53 1 +r 493 1 60 1 497 1 +r 493 1 6 1 496 1 +r 493 1 63 1 498 1 +r 493 1 7 1 57 1 +r 494 1 9 1 542 1 +r 494 1 9 1 533 1 +r 494 1 9 1 531 1 +r 494 1 9 1 529 1 +r 494 1 9 1 525 1 +r 494 1 9 1 514 1 +r 494 1 9 1 505 1 +r 494 1 9 1 501 1 +r 494 1 2 1 180 1 +r 494 1 6 1 495 1 +r 494 1 7 1 493 1 +r 495 1 2 1 10 1 s Relations +r 495 1 115 1 494 1 +r 496 1 2 1 10 1 s Equation-1.0 +r 496 1 115 1 493 1 +r 497 1 2 1 62 1 s 1.0 +r 497 1 1124 1 493 1 +r 498 1 2 1 10 1 s org.simantics.equation.stubs.EquationResource +r 498 1 1125 1 493 1 +r 499 1 1112 1 523 1 +r 499 1 1112 1 521 1 +r 499 1 172 1 546 1 +r 499 1 172 1 543 1 +r 499 1 172 1 512 1 +r 499 1 172 1 510 1 +r 499 1 172 1 502 1 +r 499 1 100 1 500 1 +r 499 1 92 1 499 1 +r 499 1 5 1 25 1 +r 499 1 6 1 1071 1 +r 499 1 7 1 491 1 +r 499 1 1111 1 519 1 +r 499 1 1111 1 517 1 +r 500 1 2 1 102 1 +r 500 1 310 1 499 1 +r 500 1 38 1 501 1 +r 501 1 3 1 82 1 +r 501 1 1116 1 548 1 +r 501 1 1116 1 545 1 +r 501 1 1116 1 516 1 +r 501 1 1116 1 500 1 +r 501 1 4 1 505 1 +r 501 1 6 1 1080 1 +r 501 1 7 1 494 1 +r 502 1 172 1 508 1 +r 502 1 172 1 506 1 +r 502 1 100 1 504 1 +r 502 1 92 1 502 1 +r 502 1 5 1 499 1 +r 502 1 6 1 503 1 +r 502 1 7 1 491 1 +r 503 1 2 1 10 1 s AggregateExpression +r 503 1 115 1 502 1 +r 504 1 2 1 102 1 +r 504 1 310 1 502 1 +r 504 1 38 1 505 1 +r 505 1 3 1 80 1 +r 505 1 1116 1 547 1 +r 505 1 1116 1 523 1 +r 505 1 1116 1 515 1 +r 505 1 1116 1 511 1 +r 505 1 1116 1 504 1 +r 505 1 28 1 519 1 +r 505 1 4 1 501 1 +r 505 1 29 1 517 1 +r 505 1 6 1 1070 1 +r 505 1 7 1 494 1 +r 506 1 5 1 502 1 +r 506 1 6 1 507 1 +r 506 1 7 1 491 1 +r 507 1 2 1 10 1 s SumExpression +r 507 1 115 1 506 1 +r 508 1 5 1 502 1 +r 508 1 6 1 509 1 +r 508 1 7 1 491 1 +r 509 1 2 1 10 1 s ProductExpression +r 509 1 115 1 508 1 +r 510 1 100 1 511 1 +r 510 1 5 1 499 1 +r 510 1 6 1 1088 1 +r 510 1 7 1 491 1 +r 510 1 1111 1 518 1 +r 511 1 2 1 102 1 +r 511 1 310 1 510 1 +r 511 1 38 1 505 1 +r 511 1 39 1 326 1 +r 512 1 172 1 526 1 +r 512 1 100 1 516 1 +r 512 1 100 1 515 1 +r 512 1 100 1 513 1 +r 512 1 5 1 499 1 +r 512 1 6 1 1084 1 +r 512 1 7 1 491 1 +r 513 1 2 1 102 1 +r 513 1 28 1 12 1 +r 513 1 310 1 512 1 +r 513 1 38 1 514 1 +r 514 1 51 1 533 1 +r 514 1 51 1 531 1 +r 514 1 51 1 529 1 +r 514 1 3 1 77 1 +r 514 1 1116 1 513 1 +r 514 1 4 1 1188 1 +r 514 1 6 1 1066 1 +r 514 1 7 1 494 1 +r 515 1 2 1 102 1 +r 515 1 310 1 512 1 +r 515 1 38 1 505 1 +r 515 1 39 1 103 1 +r 516 1 2 1 102 1 +r 516 1 310 1 512 1 +r 516 1 38 1 501 1 +r 516 1 39 1 103 1 +r 517 1 1113 1 505 1 +r 517 1 2 1 33 1 +r 517 1 27 1 518 1 +r 517 1 27 1 499 1 +r 518 1 2 1 33 1 +r 518 1 27 1 510 1 +r 518 1 27 1 24 1 +r 518 1 1111 1 517 1 +r 519 1 1112 1 505 1 +r 519 1 2 1 33 1 +r 519 1 27 1 499 1 +r 519 1 27 1 24 1 +r 520 1 100 1 521 1 +r 520 1 5 1 25 1 +r 520 1 6 1 1089 1 +r 520 1 7 1 491 1 +r 521 1 2 1 102 1 +r 521 1 28 1 499 1 +r 521 1 310 1 520 1 +r 521 1 38 1 9 1 +r 522 1 100 1 524 1 +r 522 1 100 1 523 1 +r 522 1 5 1 25 1 +r 522 1 6 1 1074 1 +r 522 1 7 1 491 1 +r 523 1 2 1 102 1 +r 523 1 28 1 499 1 +r 523 1 310 1 522 1 +r 523 1 38 1 505 1 +r 524 1 2 1 102 1 +r 524 1 310 1 522 1 +r 524 1 38 1 525 1 +r 525 1 3 1 80 1 +r 525 1 1116 1 537 1 +r 525 1 1116 1 524 1 +r 525 1 4 1 1189 1 +r 525 1 28 1 24 1 +r 525 1 6 1 1091 1 +r 525 1 7 1 494 1 +r 526 1 100 1 532 1 +r 526 1 100 1 530 1 +r 526 1 100 1 528 1 +r 526 1 69 1 527 1 +r 526 1 5 1 512 1 +r 526 1 6 1 1076 1 +r 526 1 7 1 491 1 +r 527 1 2 1 10 1 s Defines a second order equation in form of: ax^2 + bx + c = y , x=[source], y=[target] +r 527 1 1127 1 526 1 +r 528 1 2 1 102 1 +r 528 1 310 1 526 1 +r 528 1 38 1 529 1 +r 528 1 39 1 103 1 +r 529 1 3 1 514 1 +r 529 1 1116 1 528 1 +r 529 1 4 1 1190 1 +r 529 1 28 1 12 1 +r 529 1 6 1 1077 1 +r 529 1 7 1 494 1 +r 530 1 2 1 102 1 +r 530 1 310 1 526 1 +r 530 1 38 1 531 1 +r 530 1 39 1 103 1 +r 531 1 3 1 514 1 +r 531 1 1116 1 530 1 +r 531 1 4 1 1191 1 +r 531 1 28 1 12 1 +r 531 1 6 1 1078 1 +r 531 1 7 1 494 1 +r 532 1 2 1 102 1 +r 532 1 310 1 526 1 +r 532 1 38 1 533 1 +r 532 1 39 1 103 1 +r 533 1 3 1 514 1 +r 533 1 1116 1 532 1 +r 533 1 4 1 1192 1 +r 533 1 28 1 12 1 +r 533 1 6 1 1079 1 +r 533 1 7 1 494 1 +r 534 1 172 1 536 1 +r 534 1 172 1 535 1 +r 534 1 5 1 25 1 +r 534 1 6 1 1075 1 +r 534 1 7 1 491 1 +r 535 1 172 1 541 1 +r 535 1 172 1 540 1 +r 535 1 172 1 539 1 +r 535 1 172 1 538 1 +r 535 1 5 1 534 1 +r 535 1 6 1 1067 1 +r 535 1 7 1 491 1 +r 536 1 100 1 537 1 +r 536 1 5 1 534 1 +r 536 1 6 1 1087 1 +r 536 1 7 1 491 1 +r 537 1 2 1 102 1 +r 537 1 310 1 536 1 +r 537 1 38 1 525 1 +r 537 1 39 1 103 1 +r 538 1 5 1 535 1 +r 538 1 6 1 1072 1 +r 538 1 7 1 491 1 +r 539 1 5 1 535 1 +r 539 1 6 1 1090 1 +r 539 1 7 1 491 1 +r 540 1 5 1 535 1 +r 540 1 6 1 1083 1 +r 540 1 7 1 491 1 +r 541 1 5 1 535 1 +r 541 1 6 1 1086 1 +r 541 1 7 1 491 1 +r 542 1 3 1 74 1 +r 542 1 1116 1 544 1 +r 542 1 4 1 1193 1 +r 542 1 28 1 134 1 +r 542 1 6 1 1073 1 +r 542 1 7 1 494 1 +r 543 1 100 1 545 1 +r 543 1 100 1 544 1 +r 543 1 5 1 499 1 +r 543 1 6 1 1068 1 +r 543 1 7 1 491 1 +r 544 1 2 1 102 1 +r 544 1 310 1 543 1 +r 544 1 38 1 542 1 +r 544 1 39 1 103 1 +r 545 1 2 1 102 1 +r 545 1 310 1 543 1 +r 545 1 38 1 501 1 +r 545 1 39 1 103 1 +r 546 1 172 1 551 1 +r 546 1 172 1 550 1 +r 546 1 172 1 549 1 +r 546 1 100 1 548 1 +r 546 1 100 1 547 1 +r 546 1 5 1 499 1 +r 546 1 6 1 1069 1 +r 546 1 7 1 491 1 +r 547 1 2 1 102 1 +r 547 1 310 1 546 1 +r 547 1 38 1 505 1 +r 547 1 39 1 103 1 +r 548 1 2 1 102 1 +r 548 1 310 1 546 1 +r 548 1 38 1 501 1 +r 548 1 39 1 103 1 +r 549 1 5 1 546 1 +r 549 1 6 1 1085 1 +r 549 1 7 1 491 1 +r 550 1 5 1 546 1 +r 550 1 6 1 1082 1 +r 550 1 7 1 491 1 +r 551 1 5 1 546 1 +r 551 1 6 1 1081 1 +r 551 1 7 1 491 1 +r 552 1 9 1 576 1 +r 552 1 9 1 574 1 +r 552 1 9 1 570 1 +r 552 1 9 1 569 1 +r 552 1 9 1 565 1 +r 552 1 9 1 564 1 +r 552 1 9 1 563 1 +r 552 1 9 1 562 1 +r 552 1 9 1 561 1 +r 552 1 9 1 560 1 +r 552 1 9 1 559 1 +r 552 1 9 1 558 1 +r 552 1 9 1 557 1 +r 552 1 9 1 556 1 +r 552 1 9 1 555 1 +r 552 1 2 1 53 1 +r 552 1 60 1 554 1 +r 552 1 6 1 553 1 +r 552 1 7 1 57 1 +r 553 1 2 1 10 1 s Deployment-1.0 +r 553 1 115 1 552 1 +r 554 1 2 1 62 1 s 1.0 +r 554 1 1124 1 552 1 +r 555 1 1112 1 562 1 +r 555 1 5 1 10 1 +r 555 1 6 1 1061 1 +r 555 1 7 1 552 1 +r 556 1 3 1 74 1 +r 556 1 1116 1 566 1 +r 556 1 4 1 1194 1 +r 556 1 28 1 124 1 +r 556 1 6 1 1058 1 +r 556 1 7 1 552 1 +r 557 1 3 1 80 1 +r 557 1 4 1 559 1 +r 557 1 28 1 558 1 +r 557 1 6 1 1060 1 +r 557 1 7 1 552 1 +r 558 1 1112 1 557 1 +r 558 1 172 1 576 1 +r 558 1 172 1 574 1 +r 558 1 100 1 573 1 +r 558 1 100 1 572 1 +r 558 1 100 1 571 1 +r 558 1 5 1 25 1 +r 558 1 6 1 1064 1 +r 558 1 7 1 552 1 +r 559 1 3 1 82 1 +r 559 1 4 1 557 1 +r 559 1 6 1 1062 1 +r 559 1 7 1 552 1 +r 560 1 3 1 8 1 +r 560 1 1116 1 577 1 +r 560 1 1116 1 575 1 +r 560 1 1116 1 573 1 +r 560 1 4 1 1195 1 +r 560 1 28 1 561 1 +r 560 1 6 1 1055 1 +r 560 1 7 1 552 1 +r 561 1 1112 1 560 1 +r 561 1 172 1 570 1 +r 561 1 172 1 569 1 +r 561 1 100 1 568 1 +r 561 1 100 1 567 1 +r 561 1 5 1 25 1 +r 561 1 6 1 1057 1 +r 561 1 7 1 552 1 +r 562 1 3 1 74 1 +r 562 1 1116 1 572 1 +r 562 1 4 1 1196 1 +r 562 1 28 1 555 1 +r 562 1 6 1 1052 1 +r 562 1 7 1 552 1 +r 563 1 3 1 80 1 +r 563 1 4 1 1197 1 +r 563 1 28 1 15 1 +r 563 1 6 1 1059 1 +r 563 1 7 1 552 1 +r 564 1 3 1 80 1 +r 564 1 1116 1 571 1 +r 564 1 1116 1 567 1 +r 564 1 4 1 1198 1 +r 564 1 28 1 10 1 +r 564 1 6 1 1065 1 +r 564 1 7 1 552 1 +r 565 1 100 1 566 1 +r 565 1 5 1 25 1 +r 565 1 6 1 1053 1 +r 565 1 7 1 552 1 +r 566 1 2 1 102 1 +r 566 1 310 1 565 1 +r 566 1 38 1 556 1 +r 566 1 39 1 103 1 +r 567 1 2 1 102 1 +r 567 1 310 1 561 1 +r 567 1 38 1 564 1 +r 567 1 39 1 103 1 +r 568 1 2 1 102 1 +r 568 1 310 1 561 1 +r 568 1 38 1 60 1 +r 568 1 39 1 103 1 +r 569 1 1112 1 575 1 +r 569 1 5 1 561 1 +r 569 1 6 1 1063 1 +r 569 1 7 1 552 1 +r 570 1 1112 1 577 1 +r 570 1 5 1 561 1 +r 570 1 6 1 1051 1 +r 570 1 7 1 552 1 +r 571 1 2 1 102 1 +r 571 1 310 1 558 1 +r 571 1 38 1 564 1 +r 571 1 39 1 103 1 +r 572 1 2 1 102 1 +r 572 1 310 1 558 1 +r 572 1 38 1 562 1 +r 572 1 39 1 103 1 +r 573 1 2 1 102 1 +r 573 1 310 1 558 1 +r 573 1 38 1 560 1 +r 574 1 100 1 575 1 +r 574 1 5 1 558 1 +r 574 1 6 1 1054 1 +r 574 1 7 1 552 1 +r 575 1 2 1 102 1 +r 575 1 28 1 569 1 +r 575 1 310 1 574 1 +r 575 1 38 1 560 1 +r 576 1 100 1 577 1 +r 576 1 5 1 558 1 +r 576 1 6 1 1056 1 +r 576 1 7 1 552 1 +r 577 1 2 1 102 1 +r 577 1 28 1 570 1 +r 577 1 310 1 576 1 +r 577 1 38 1 560 1 +r 578 1 9 1 615 1 +r 578 1 9 1 608 1 +r 578 1 9 1 605 1 +r 578 1 9 1 604 1 +r 578 1 9 1 603 1 +r 578 1 9 1 602 1 +r 578 1 9 1 600 1 +r 578 1 9 1 598 1 +r 578 1 9 1 597 1 +r 578 1 9 1 596 1 +r 578 1 9 1 592 1 +r 578 1 9 1 591 1 +r 578 1 9 1 589 1 +r 578 1 9 1 588 1 +r 578 1 9 1 587 1 +r 578 1 9 1 584 1 +r 578 1 9 1 583 1 +r 578 1 2 1 53 1 +r 578 1 60 1 580 1 +r 578 1 6 1 579 1 +r 578 1 63 1 581 1 +r 578 1 7 1 57 1 +r 579 1 2 1 10 1 s Project-1.0 +r 579 1 115 1 578 1 +r 580 1 2 1 62 1 s 1.0 +r 580 1 1124 1 578 1 +r 581 1 2 1 10 1 s org.simantics.db.Builtins +r 581 1 1125 1 578 1 +r 582 1 9 1 720 1 +r 582 1 2 1 25 1 +r 582 1 6 1 1099 1 +r 582 1 7 1 48 1 +r 583 1 171 1 584 1 +r 583 1 5 1 25 1 +r 583 1 6 1 1096 1 +r 583 1 7 1 578 1 +r 584 1 2 1 583 1 +r 584 1 100 1 586 1 +r 584 1 100 1 585 1 +r 584 1 5 1 45 1 +r 584 1 6 1 1098 1 +r 584 1 7 1 578 1 +r 585 1 2 1 102 1 +r 585 1 28 1 45 1 +r 585 1 310 1 584 1 +r 585 1 38 1 9 1 +r 586 1 2 1 102 1 +r 586 1 310 1 584 1 +r 586 1 38 1 587 1 +r 587 1 3 1 80 1 +r 587 1 1116 1 586 1 +r 587 1 4 1 1199 1 +r 587 1 28 1 595 1 +r 587 1 6 1 1095 1 +r 587 1 7 1 578 1 +r 588 1 3 1 74 1 +r 588 1 1116 1 594 1 +r 588 1 4 1 1200 1 +r 588 1 28 1 10 1 +r 588 1 6 1 1100 1 +r 588 1 7 1 578 1 +r 589 1 1112 1 600 1 +r 589 1 1112 1 598 1 +r 589 1 1113 1 600 1 +r 589 1 1113 1 598 1 +r 589 1 1113 1 591 1 +r 589 1 171 1 720 1 +r 589 1 172 1 622 1 +r 589 1 172 1 615 1 +r 589 1 172 1 605 1 +r 589 1 172 1 604 1 +r 589 1 172 1 603 1 +r 589 1 69 1 590 1 +r 589 1 5 1 25 1 +r 589 1 6 1 1109 1 +r 589 1 7 1 578 1 +r 589 1 1111 1 595 1 +r 590 1 2 1 10 1 s An entity that is used to attach a feature to a project instance. Features are defined through database resource adaptation. This feature can then configure itself into that project and also deconfigure itself from that project. The configuration happens through the org.simantics.project.features.IProjectFeature interface into which instances of this entity must be adaptable. Project features should also be adaptable to org.simatnics.project.features.IProjectFeatureDescriptor and optionally org.simantics.project.IProjectLifeCycle. +r 590 1 1127 1 589 1 +r 591 1 2 1 90 1 +r 591 1 3 1 79 1 +r 591 1 3 1 77 1 +r 591 1 4 1 591 1 +r 591 1 29 1 589 1 +r 591 1 6 1 1097 1 +r 591 1 7 1 578 1 +r 592 1 100 1 594 1 +r 592 1 69 1 593 1 +r 592 1 5 1 25 1 +r 592 1 6 1 1106 1 +r 592 1 7 1 578 1 +r 592 1 1111 1 595 1 +r 593 1 2 1 10 1 s An entity that is used to attach a feature to a project instance. Extension features are defined through the Eclipse extension framework. This feature can then configure itself into that project and also deconfigure itself from that project. The configuration happens through the org.simantics.project.features.IProjectFeature interface into which instances of this entity must be adaptable. +r 593 1 1127 1 592 1 +r 594 1 2 1 102 1 +r 594 1 310 1 592 1 +r 594 1 38 1 588 1 +r 594 1 39 1 103 1 +r 595 1 1112 1 587 1 +r 595 1 2 1 33 1 +r 595 1 27 1 592 1 +r 595 1 27 1 589 1 +r 596 1 3 1 80 1 +r 596 1 4 1 597 1 +r 596 1 6 1 1105 1 +r 596 1 7 1 578 1 +r 597 1 3 1 82 1 +r 597 1 4 1 596 1 +r 597 1 6 1 1092 1 +r 597 1 7 1 578 1 +r 598 1 3 1 79 1 +r 598 1 3 1 77 1 +r 598 1 4 1 598 1 +r 598 1 28 1 589 1 +r 598 1 29 1 589 1 +r 598 1 69 1 599 1 +r 598 1 6 1 1104 1 +r 598 1 7 1 578 1 +r 599 1 2 1 10 1 s Used to indicate that the referencing feature is guaranteed to be compatible with the referenced feature. +r 599 1 1127 1 598 1 +r 600 1 3 1 79 1 +r 600 1 3 1 77 1 +r 600 1 4 1 600 1 +r 600 1 28 1 589 1 +r 600 1 29 1 589 1 +r 600 1 69 1 601 1 +r 600 1 6 1 1101 1 +r 600 1 7 1 578 1 +r 601 1 2 1 10 1 s Used to indicate that the referencing feature is known to be incompatible with the referenced feature. +r 601 1 1127 1 600 1 +r 602 1 3 1 74 1 +r 602 1 1116 1 616 1 +r 602 1 1116 1 607 1 +r 602 1 4 1 1201 1 +r 602 1 28 1 122 1 +r 602 1 6 1 1103 1 +r 602 1 7 1 578 1 +r 603 1 171 1 609 1 +r 603 1 5 1 589 1 +r 603 1 6 1 1094 1 +r 603 1 7 1 578 1 +r 604 1 171 1 612 1 +r 604 1 5 1 589 1 +r 604 1 6 1 1107 1 +r 604 1 7 1 578 1 +r 605 1 100 1 607 1 +r 605 1 69 1 606 1 +r 605 1 5 1 589 1 +r 605 1 6 1 1108 1 +r 605 1 7 1 578 1 +r 606 1 2 1 10 1 s Features of this type are used for describing ontology requirements. +r 606 1 1127 1 605 1 +r 607 1 2 1 102 1 +r 607 1 310 1 605 1 +r 607 1 38 1 602 1 +r 608 1 9 1 612 1 +r 608 1 9 1 609 1 +r 608 1 2 1 45 1 +r 608 1 6 1 1093 1 +r 608 1 7 1 578 1 +r 609 1 2 1 603 1 +r 609 1 69 1 611 1 +r 609 1 6 1 610 1 +r 609 1 7 1 608 1 +r 610 1 2 1 10 1 s Experiment Control +r 610 1 115 1 609 1 +r 611 1 2 1 10 1 s Experiment control feature provides generic facilities for controlling the execution of simulation sequences. +r 611 1 1127 1 609 1 +r 612 1 2 1 604 1 +r 612 1 69 1 614 1 +r 612 1 6 1 613 1 +r 612 1 7 1 608 1 +r 613 1 2 1 10 1 s Model Manager +r 613 1 115 1 612 1 +r 614 1 2 1 10 1 s Model management feature provides generic facilities for building models. +r 614 1 1127 1 612 1 +r 615 1 100 1 616 1 +r 615 1 5 1 589 1 +r 615 1 6 1 1102 1 +r 615 1 7 1 578 1 +r 616 1 2 1 102 1 +r 616 1 310 1 615 1 +r 616 1 38 1 602 1 +r 617 1 9 1 627 1 +r 617 1 9 1 623 1 +r 617 1 9 1 622 1 +r 617 1 65 1 621 1 +r 617 1 2 1 53 1 +r 617 1 60 1 619 1 +r 617 1 6 1 618 1 +r 617 1 63 1 620 1 +r 617 1 7 1 57 1 +r 618 1 2 1 10 1 s Workbench-1.0 +r 618 1 115 1 617 1 +r 619 1 2 1 62 1 s 1.0 +r 619 1 1124 1 617 1 +r 620 1 2 1 10 1 s org.simantics.project.WorkbenchResource +r 620 1 1125 1 617 1 +r 621 1 2 1 10 1 s workbench +r 621 1 1126 1 617 1 +r 622 1 171 1 624 1 +r 622 1 5 1 589 1 +r 622 1 6 1 724 1 +r 622 1 7 1 617 1 +r 623 1 9 1 624 1 +r 623 1 2 1 45 1 +r 623 1 6 1 723 1 +r 623 1 7 1 617 1 +r 624 1 2 1 622 1 +r 624 1 69 1 626 1 +r 624 1 6 1 625 1 +r 624 1 7 1 623 1 +r 625 1 2 1 10 1 s Symbol Manager +r 625 1 115 1 624 1 +r 626 1 2 1 10 1 s Symbol management feature provides project facilities for controlling what is shown in the Symbols view. +r 626 1 1127 1 624 1 +r 627 1 3 1 74 1 +r 627 1 4 1 1202 1 +r 627 1 28 1 10 1 +r 627 1 69 1 628 1 +r 627 1 6 1 725 1 +r 627 1 7 1 617 1 +r 628 1 2 1 10 1 s Deprecated. A description of how to publish something to an external site. +r 628 1 1127 1 627 1 +r 629 1 9 1 652 1 +r 629 1 9 1 650 1 +r 629 1 9 1 649 1 +r 629 1 9 1 647 1 +r 629 1 9 1 646 1 +r 629 1 9 1 645 1 +r 629 1 9 1 644 1 +r 629 1 9 1 642 1 +r 629 1 9 1 640 1 +r 629 1 9 1 638 1 +r 629 1 9 1 636 1 +r 629 1 9 1 635 1 +r 629 1 9 1 633 1 +r 629 1 9 1 631 1 +r 629 1 9 1 630 1 +r 629 1 2 1 45 1 +r 629 1 6 1 804 1 +r 629 1 7 1 44 1 +r 630 1 1112 1 662 1 +r 630 1 1112 1 635 1 +r 630 1 172 1 640 1 +r 630 1 172 1 636 1 +r 630 1 172 1 631 1 +r 630 1 5 1 25 1 +r 630 1 6 1 785 1 +r 630 1 7 1 629 1 +r 631 1 100 1 634 1 +r 631 1 100 1 632 1 +r 631 1 5 1 630 1 +r 631 1 6 1 808 1 +r 631 1 7 1 629 1 +r 632 1 2 1 102 1 +r 632 1 310 1 631 1 +r 632 1 38 1 633 1 +r 632 1 39 1 103 1 +r 633 1 3 1 77 1 +r 633 1 1116 1 632 1 +r 633 1 4 1 1203 1 +r 633 1 28 1 11 1 +r 633 1 6 1 788 1 +r 633 1 7 1 629 1 +r 634 1 2 1 102 1 +r 634 1 310 1 631 1 +r 634 1 38 1 635 1 +r 634 1 39 1 103 1 +r 635 1 3 1 77 1 +r 635 1 1116 1 639 1 +r 635 1 1116 1 634 1 +r 635 1 4 1 1204 1 +r 635 1 28 1 630 1 +r 635 1 6 1 796 1 +r 635 1 7 1 629 1 +r 636 1 100 1 639 1 +r 636 1 100 1 637 1 +r 636 1 5 1 630 1 +r 636 1 6 1 799 1 +r 636 1 7 1 629 1 +r 637 1 2 1 102 1 +r 637 1 310 1 636 1 +r 637 1 38 1 638 1 +r 637 1 39 1 103 1 +r 638 1 3 1 77 1 +r 638 1 1116 1 637 1 +r 638 1 4 1 1205 1 +r 638 1 28 1 11 1 +r 638 1 6 1 802 1 +r 638 1 7 1 629 1 +r 639 1 2 1 102 1 +r 639 1 310 1 636 1 +r 639 1 38 1 635 1 +r 639 1 39 1 103 1 +r 640 1 100 1 643 1 +r 640 1 100 1 641 1 +r 640 1 5 1 630 1 +r 640 1 6 1 784 1 +r 640 1 7 1 629 1 +r 641 1 2 1 102 1 +r 641 1 310 1 640 1 +r 641 1 38 1 642 1 +r 641 1 39 1 103 1 +r 642 1 3 1 77 1 +r 642 1 1116 1 641 1 +r 642 1 4 1 1206 1 +r 642 1 28 1 10 1 +r 642 1 6 1 811 1 +r 642 1 7 1 629 1 +r 643 1 2 1 102 1 +r 643 1 310 1 640 1 +r 643 1 38 1 644 1 +r 643 1 39 1 139 1 +r 644 1 3 1 77 1 +r 644 1 1116 1 643 1 +r 644 1 4 1 1207 1 +r 644 1 28 1 646 1 +r 644 1 6 1 810 1 +r 644 1 7 1 629 1 +r 645 1 5 1 140 1 +r 645 1 6 1 809 1 +r 645 1 7 1 629 1 +r 646 1 1112 1 644 1 +r 646 1 5 1 25 1 +r 646 1 6 1 786 1 +r 646 1 7 1 629 1 +r 647 1 100 1 648 1 +r 647 1 5 1 25 1 +r 647 1 6 1 787 1 +r 647 1 7 1 629 1 +r 648 1 2 1 102 1 +r 648 1 310 1 647 1 +r 648 1 38 1 649 1 +r 648 1 39 1 103 1 +r 649 1 3 1 77 1 +r 649 1 1116 1 648 1 +r 649 1 4 1 1208 1 +r 649 1 28 1 12 1 +r 649 1 6 1 795 1 +r 649 1 7 1 629 1 +r 650 1 100 1 651 1 +r 650 1 5 1 25 1 +r 650 1 6 1 801 1 +r 650 1 7 1 629 1 +r 651 1 2 1 102 1 +r 651 1 310 1 650 1 +r 651 1 38 1 652 1 +r 651 1 39 1 103 1 +r 652 1 3 1 77 1 +r 652 1 1116 1 651 1 +r 652 1 4 1 1209 1 +r 652 1 28 1 12 1 +r 652 1 6 1 798 1 +r 652 1 7 1 629 1 +r 653 1 9 1 666 1 +r 653 1 9 1 663 1 +r 653 1 9 1 662 1 +r 653 1 9 1 661 1 +r 653 1 9 1 660 1 +r 653 1 9 1 659 1 +r 653 1 9 1 658 1 +r 653 1 9 1 657 1 +r 653 1 9 1 656 1 +r 653 1 9 1 655 1 +r 653 1 9 1 654 1 +r 653 1 2 1 45 1 +r 653 1 6 1 790 1 +r 653 1 7 1 44 1 +r 654 1 1112 1 659 1 +r 654 1 1112 1 658 1 +r 654 1 5 1 87 1 +r 654 1 6 1 803 1 +r 654 1 7 1 653 1 +r 655 1 3 1 74 1 +r 655 1 4 1 1210 1 +r 655 1 28 1 11 1 +r 655 1 6 1 806 1 +r 655 1 7 1 653 1 +r 656 1 3 1 74 1 +r 656 1 4 1 1211 1 +r 656 1 28 1 11 1 +r 656 1 6 1 791 1 +r 656 1 7 1 653 1 +r 657 1 3 1 74 1 +r 657 1 4 1 1212 1 +r 657 1 28 1 10 1 +r 657 1 6 1 807 1 +r 657 1 7 1 653 1 +r 658 1 3 1 77 1 +r 658 1 1116 1 664 1 +r 658 1 4 1 1213 1 +r 658 1 28 1 654 1 +r 658 1 6 1 794 1 +r 658 1 7 1 653 1 +r 659 1 3 1 77 1 +r 659 1 4 1 1214 1 +r 659 1 28 1 654 1 +r 659 1 6 1 793 1 +r 659 1 7 1 653 1 +r 660 1 3 1 74 1 +r 660 1 4 1 1215 1 +r 660 1 28 1 12 1 +r 660 1 6 1 800 1 +r 660 1 7 1 653 1 +r 661 1 3 1 74 1 +r 661 1 4 1 1216 1 +r 661 1 28 1 12 1 +r 661 1 6 1 805 1 +r 661 1 7 1 653 1 +r 662 1 3 1 77 1 +r 662 1 4 1 1217 1 +r 662 1 28 1 630 1 +r 662 1 6 1 797 1 +r 662 1 7 1 653 1 +r 663 1 100 1 665 1 +r 663 1 100 1 664 1 +r 663 1 5 1 25 1 +r 663 1 6 1 789 1 +r 663 1 7 1 653 1 +r 664 1 2 1 102 1 +r 664 1 310 1 663 1 +r 664 1 38 1 658 1 +r 664 1 39 1 103 1 +r 665 1 2 1 102 1 +r 665 1 310 1 663 1 +r 665 1 38 1 666 1 +r 665 1 39 1 139 1 +r 666 1 3 1 77 1 +r 666 1 1116 1 665 1 +r 666 1 4 1 1218 1 +r 666 1 28 1 1 1 +r 666 1 6 1 792 1 +r 666 1 7 1 653 1 +r 667 1 9 1 712 1 +r 667 1 9 1 709 1 +r 667 1 9 1 704 1 +r 667 1 9 1 694 1 +r 667 1 9 1 685 1 +r 667 1 9 1 675 1 +r 667 1 2 1 177 1 +r 667 1 6 1 668 1 +r 667 1 7 1 669 1 +r 668 1 2 1 10 1 s Types +r 668 1 115 1 667 1 +r 669 1 9 1 670 1 +r 669 1 9 1 667 1 +r 669 1 2 1 53 1 +r 669 1 60 1 673 1 +r 669 1 6 1 672 1 +r 669 1 63 1 674 1 +r 669 1 7 1 57 1 +r 670 1 9 1 715 1 +r 670 1 9 1 702 1 +r 670 1 9 1 701 1 +r 670 1 9 1 692 1 +r 670 1 9 1 684 1 +r 670 1 9 1 682 1 +r 670 1 9 1 681 1 +r 670 1 9 1 680 1 +r 670 1 9 1 679 1 +r 670 1 9 1 678 1 +r 670 1 9 1 677 1 +r 670 1 9 1 676 1 +r 670 1 2 1 180 1 +r 670 1 6 1 671 1 +r 670 1 7 1 669 1 +r 671 1 2 1 10 1 s Relations +r 671 1 115 1 670 1 +r 672 1 2 1 10 1 s Image-1.0 +r 672 1 115 1 669 1 +r 673 1 2 1 62 1 s 1.0 +r 673 1 1124 1 669 1 +r 674 1 2 1 10 1 s org.simantics.diagram.stubs.ImageResource +r 674 1 1125 1 669 1 +r 675 1 1112 1 715 1 +r 675 1 1112 1 676 1 +r 675 1 172 1 704 1 +r 675 1 172 1 694 1 +r 675 1 172 1 685 1 +r 675 1 5 1 25 1 +r 675 1 6 1 823 1 +r 675 1 7 1 667 1 +r 675 1 1111 1 714 1 +r 675 1 1111 1 711 1 +r 676 1 3 1 80 1 +r 676 1 4 1 1219 1 +r 676 1 28 1 675 1 +r 676 1 6 1 819 1 +r 676 1 7 1 670 1 +r 677 1 3 1 74 1 +r 677 1 1116 1 697 1 +r 677 1 1116 1 686 1 +r 677 1 4 1 1220 1 +r 677 1 28 1 11 1 +r 677 1 6 1 813 1 +r 677 1 7 1 670 1 +r 678 1 3 1 74 1 +r 678 1 1116 1 698 1 +r 678 1 1116 1 687 1 +r 678 1 4 1 1221 1 +r 678 1 28 1 11 1 +r 678 1 6 1 817 1 +r 678 1 7 1 670 1 +r 679 1 3 1 74 1 +r 679 1 1116 1 707 1 +r 679 1 1116 1 699 1 +r 679 1 1116 1 690 1 +r 679 1 4 1 1222 1 +r 679 1 28 1 12 1 +r 679 1 6 1 821 1 +r 679 1 7 1 670 1 +r 680 1 3 1 74 1 +r 680 1 1116 1 708 1 +r 680 1 1116 1 700 1 +r 680 1 1116 1 691 1 +r 680 1 4 1 1223 1 +r 680 1 28 1 12 1 +r 680 1 6 1 822 1 +r 680 1 7 1 670 1 +r 681 1 51 1 684 1 +r 681 1 51 1 682 1 +r 681 1 3 1 74 1 +r 681 1 4 1 1224 1 +r 681 1 28 1 22 1 +r 681 1 6 1 815 1 +r 681 1 7 1 670 1 +r 682 1 3 1 681 1 +r 682 1 1116 1 688 1 +r 682 1 4 1 1225 1 +r 682 1 6 1 683 1 +r 682 1 7 1 670 1 +r 683 1 2 1 10 1 s Has RGB Data +r 683 1 115 1 682 1 +r 684 1 3 1 681 1 +r 684 1 1116 1 689 1 +r 684 1 4 1 1226 1 +r 684 1 6 1 812 1 +r 684 1 7 1 670 1 +r 685 1 100 1 691 1 +r 685 1 100 1 690 1 +r 685 1 100 1 689 1 +r 685 1 100 1 688 1 +r 685 1 100 1 687 1 +r 685 1 100 1 686 1 +r 685 1 5 1 675 1 +r 685 1 6 1 825 1 +r 685 1 7 1 667 1 +r 686 1 2 1 102 1 +r 686 1 310 1 685 1 +r 686 1 38 1 677 1 +r 686 1 39 1 103 1 +r 687 1 2 1 102 1 +r 687 1 310 1 685 1 +r 687 1 38 1 678 1 +r 687 1 39 1 103 1 +r 688 1 2 1 102 1 +r 688 1 310 1 685 1 +r 688 1 38 1 682 1 +r 688 1 39 1 103 1 +r 689 1 2 1 102 1 +r 689 1 310 1 685 1 +r 689 1 38 1 684 1 +r 689 1 39 1 139 1 +r 690 1 2 1 102 1 +r 690 1 310 1 685 1 +r 690 1 38 1 679 1 +r 690 1 39 1 139 1 +r 691 1 2 1 102 1 +r 691 1 310 1 685 1 +r 691 1 38 1 680 1 +r 691 1 39 1 139 1 +r 692 1 3 1 77 1 +r 692 1 1116 1 696 1 +r 692 1 4 1 1227 1 +r 692 1 28 1 10 1 +r 692 1 6 1 693 1 +r 692 1 7 1 670 1 +r 693 1 2 1 10 1 s Has SVG Document +r 693 1 115 1 692 1 +r 694 1 100 1 700 1 +r 694 1 100 1 699 1 +r 694 1 100 1 698 1 +r 694 1 100 1 697 1 +r 694 1 100 1 696 1 +r 694 1 5 1 675 1 +r 694 1 6 1 695 1 +r 694 1 7 1 667 1 +r 695 1 2 1 10 1 s SVG Image +r 695 1 115 1 694 1 +r 696 1 2 1 102 1 +r 696 1 310 1 694 1 +r 696 1 38 1 692 1 +r 696 1 39 1 103 1 +r 697 1 2 1 102 1 +r 697 1 310 1 694 1 +r 697 1 38 1 677 1 +r 697 1 39 1 139 1 +r 698 1 2 1 102 1 +r 698 1 310 1 694 1 +r 698 1 38 1 678 1 +r 698 1 39 1 139 1 +r 699 1 2 1 102 1 +r 699 1 310 1 694 1 +r 699 1 38 1 679 1 +r 699 1 39 1 139 1 +r 700 1 2 1 102 1 +r 700 1 310 1 694 1 +r 700 1 38 1 680 1 +r 700 1 39 1 139 1 +r 701 1 3 1 74 1 +r 701 1 1116 1 705 1 +r 701 1 4 1 1228 1 +r 701 1 28 1 11 1 +r 701 1 6 1 814 1 +r 701 1 7 1 670 1 +r 702 1 3 1 74 1 +r 702 1 1116 1 706 1 +r 702 1 4 1 1229 1 +r 702 1 28 1 11 1 +r 702 1 69 1 703 1 +r 702 1 6 1 816 1 +r 702 1 7 1 670 1 +r 703 1 2 1 10 1 s An index from 0..63 to describe the 8x8 2D bit pattern +r 703 1 1127 1 702 1 +r 704 1 100 1 708 1 +r 704 1 100 1 707 1 +r 704 1 100 1 706 1 +r 704 1 100 1 705 1 +r 704 1 5 1 675 1 +r 704 1 6 1 824 1 +r 704 1 7 1 667 1 +r 705 1 2 1 102 1 +r 705 1 310 1 704 1 +r 705 1 38 1 701 1 +r 705 1 39 1 103 1 +r 706 1 2 1 102 1 +r 706 1 310 1 704 1 +r 706 1 38 1 702 1 +r 706 1 39 1 103 1 +r 707 1 2 1 102 1 +r 707 1 310 1 704 1 +r 707 1 38 1 679 1 +r 707 1 39 1 103 1 +r 708 1 2 1 102 1 +r 708 1 310 1 704 1 +r 708 1 38 1 680 1 +r 708 1 39 1 103 1 +r 709 1 27 1 710 1 +r 709 1 5 1 45 1 +r 709 1 6 1 818 1 +r 709 1 7 1 667 1 +r 709 1 1111 1 711 1 +r 710 1 40 1 711 1 +r 710 1 2 1 37 1 +r 710 1 38 1 9 1 +r 710 1 1111 1 709 1 +r 711 1 2 1 33 1 +r 711 1 27 1 709 1 +r 711 1 27 1 675 1 +r 711 1 1118 1 710 1 +r 712 1 27 1 713 1 +r 712 1 5 1 45 1 +r 712 1 6 1 826 1 +r 712 1 7 1 667 1 +r 712 1 1111 1 714 1 +r 713 1 40 1 714 1 +r 713 1 2 1 37 1 +r 713 1 38 1 9 1 +r 713 1 1111 1 712 1 +r 714 1 2 1 33 1 +r 714 1 27 1 712 1 +r 714 1 27 1 675 1 +r 714 1 1118 1 713 1 +r 715 1 3 1 80 1 +r 715 1 4 1 1230 1 +r 715 1 28 1 675 1 +r 715 1 6 1 820 1 +r 715 1 7 1 670 1 +r 716 1 9 1 720 1 +r 716 1 2 1 53 1 +r 716 1 60 1 718 1 +r 716 1 6 1 717 1 +r 716 1 63 1 719 1 +r 716 1 7 1 57 1 +r 717 1 2 1 10 1 s ODE-1.0 +r 717 1 115 1 716 1 +r 718 1 2 1 62 1 s 1.0 +r 718 1 1124 1 716 1 +r 719 1 2 1 10 1 s org.simantics.db.Builtins +r 719 1 1125 1 716 1 +r 720 1 2 1 589 1 +r 720 1 116 1 721 1 +r 720 1 69 1 722 1 +r 720 1 6 1 1110 1 +r 720 1 7 1 716 1 +r 720 1 7 1 582 1 +r 721 1 2 1 10 1 s Ontology Development Project +r 721 1 1131 1 720 1 +r 722 1 2 1 10 1 s A project type for developing new data models. +r 722 1 1127 1 720 1 +r 723 1 2 1 10 1 s Features +r 723 1 115 1 623 1 +r 724 1 2 1 10 1 s SymbolManagerFeature +r 724 1 115 1 622 1 +r 725 1 2 1 10 1 s HasPublishSite +r 725 1 115 1 627 1 +r 726 1 2 1 10 1 s Value +r 726 1 115 1 430 1 +r 727 1 2 1 10 1 s ConnectionJoin +r 727 1 115 1 466 1 +r 728 1 2 1 10 1 s HasSubgroup +r 728 1 115 1 489 1 +r 729 1 2 1 10 1 s StandardModelingRules +r 729 1 115 1 480 1 +r 730 1 2 1 10 1 s IsJoinedBy +r 730 1 115 1 444 1 +r 731 1 2 1 10 1 s InComposite +r 731 1 115 1 448 1 +r 732 1 2 1 10 1 s ConnectionConstraint +r 732 1 115 1 482 1 +r 733 1 2 1 10 1 s HasCardinalityRestriction +r 733 1 115 1 454 1 +r 734 1 2 1 10 1 s IsDefinedBy +r 734 1 115 1 412 1 +r 735 1 2 1 10 1 s HeterogenityConnectionConstraint +r 735 1 115 1 484 1 +r 736 1 2 1 10 1 s DefaultConnectionType +r 736 1 115 1 478 1 +r 737 1 2 1 10 1 s DefaultModelingRules +r 737 1 115 1 479 1 +r 738 1 2 1 10 1 s Composite +r 738 1 115 1 418 1 +r 739 1 2 1 10 1 s Component +r 739 1 115 1 398 1 +r 740 1 2 1 10 1 s BelongsTo +r 740 1 115 1 405 1 +r 741 1 2 1 10 1 s VariableRelation +r 741 1 115 1 427 1 +r 742 1 2 1 10 1 s ConnectionDirection +r 742 1 115 1 457 1 +r 743 1 2 1 10 1 s Expression +r 743 1 115 1 433 1 +r 744 1 2 1 10 1 s SupportsConnectionType +r 744 1 115 1 450 1 +r 745 1 2 1 10 1 s ValueRelation +r 745 1 115 1 437 1 +r 746 1 2 1 10 1 s VariableOf +r 746 1 115 1 429 1 +r 747 1 2 1 10 1 s IsBoundBy +r 747 1 115 1 424 1 +r 748 1 2 1 10 1 s HasModelingRules +r 748 1 115 1 472 1 +r 749 1 2 1 10 1 s Joins +r 749 1 115 1 468 1 +r 750 1 2 1 10 1 s Defines +r 750 1 115 1 414 1 +r 751 1 2 1 10 1 s OutputDirection +r 751 1 115 1 459 1 +r 752 1 2 1 10 1 s OrderedComposite +r 752 1 115 1 421 1 +r 753 1 2 1 10 1 s LiteralVariable +r 753 1 115 1 425 1 +r 754 1 2 1 10 1 s HasConnectionConstraint +r 754 1 115 1 483 1 +r 755 1 2 1 10 1 s HasConnectionType +r 755 1 115 1 452 1 +r 756 1 2 1 10 1 s GroupSubsumption +r 756 1 115 1 487 1 +r 757 1 2 1 10 1 s IsParameterOf +r 757 1 115 1 417 1 +r 758 1 2 1 10 1 s HasLowerBound +r 758 1 115 1 461 1 +r 759 1 2 1 10 1 s ConnectionRelation +r 759 1 115 1 447 1 +r 760 1 2 1 10 1 s ConnectionType +r 760 1 115 1 451 1 +r 761 1 2 1 10 1 s GroupBelongsTo +r 761 1 115 1 407 1 +r 762 1 2 1 10 1 s Binds +r 762 1 115 1 423 1 +r 763 1 2 1 10 1 s IsConnectedTo +r 763 1 115 1 401 1 +r 764 1 2 1 10 1 s HasParameter +r 764 1 115 1 410 1 +r 765 1 2 1 10 1 s SimpleModelingRules +r 765 1 115 1 473 1 +r 766 1 2 1 10 1 s HasAttachmentRelation +r 766 1 115 1 476 1 +r 767 1 2 1 10 1 s ComponentGroup +r 767 1 115 1 486 1 +r 768 1 2 1 10 1 s ComponentType +r 768 1 115 1 399 1 +r 769 1 2 1 10 1 s Connection +r 769 1 115 1 440 1 +r 770 1 2 1 10 1 s Variable +r 770 1 115 1 415 1 +r 771 1 2 1 10 1 s Connects +r 771 1 115 1 442 1 +r 772 1 2 1 10 1 s HasValue +r 772 1 115 1 438 1 +r 773 1 2 1 10 1 s ModelingRules +r 773 1 115 1 470 1 +r 774 1 2 1 10 1 s HasUpperBound +r 774 1 115 1 463 1 +r 775 1 2 1 10 1 s DirectedConnectionRelation +r 775 1 115 1 449 1 +r 776 1 2 1 10 1 s HasConnectionDirection +r 776 1 115 1 465 1 +r 777 1 2 1 10 1 s ConnectionVariable +r 777 1 115 1 445 1 +r 778 1 2 1 10 1 s CardinalityRestriction +r 778 1 115 1 455 1 +r 779 1 2 1 10 1 s AllowsConnectionType +r 779 1 115 1 481 1 +r 780 1 2 1 10 1 s SupportsDirection +r 780 1 115 1 456 1 +r 781 1 2 1 10 1 s HasConnectionJoin +r 781 1 115 1 469 1 +r 782 1 2 1 10 1 s InputDirection +r 782 1 115 1 458 1 +r 783 1 2 1 10 1 s HasVariable +r 783 1 115 1 428 1 +r 784 1 2 1 10 1 s NamedUnit +r 784 1 115 1 640 1 +r 785 1 2 1 10 1 s Unit +r 785 1 115 1 630 1 +r 786 1 2 1 10 1 s UnitConversion +r 786 1 115 1 646 1 +r 787 1 2 1 10 1 s LinearUnitConversion +r 787 1 115 1 647 1 +r 788 1 2 1 10 1 s HasMagnitude +r 788 1 115 1 633 1 +r 789 1 2 1 10 1 s Component +r 789 1 115 1 663 1 +r 790 1 2 1 10 1 s DataTypes +r 790 1 115 1 653 1 +r 791 1 2 1 10 1 s HasMaxLength +r 791 1 115 1 656 1 +r 792 1 2 1 10 1 s HasComponentRelation +r 792 1 115 1 666 1 +r 793 1 2 1 10 1 s HasReturnType +r 793 1 115 1 659 1 +r 794 1 2 1 10 1 s HasComponentType +r 794 1 115 1 658 1 +r 795 1 2 1 10 1 s HasScale +r 795 1 115 1 649 1 +r 796 1 2 1 10 1 s HasBaseUnit +r 796 1 115 1 635 1 +r 797 1 2 1 10 1 s HasUnit_ +r 797 1 115 1 662 1 +r 798 1 2 1 10 1 s HasShift +r 798 1 115 1 652 1 +r 799 1 2 1 10 1 s PowerUnit +r 799 1 115 1 636 1 +r 800 1 2 1 10 1 s HasLowerBound +r 800 1 115 1 660 1 +r 801 1 2 1 10 1 s ShiftedUnitConversion +r 801 1 115 1 650 1 +r 802 1 2 1 10 1 s HasExponent +r 802 1 115 1 638 1 +r 803 1 2 1 10 1 s DataType +r 803 1 115 1 654 1 +r 804 1 2 1 10 1 s Units +r 804 1 115 1 629 1 +r 805 1 2 1 10 1 s HasUpperBound +r 805 1 115 1 661 1 +r 806 1 2 1 10 1 s HasMinLength +r 806 1 115 1 655 1 +r 807 1 2 1 10 1 s HasPattern +r 807 1 115 1 657 1 +r 808 1 2 1 10 1 s ScaledUnit +r 808 1 115 1 631 1 +r 809 1 2 1 10 1 s ProductUnit +r 809 1 115 1 645 1 +r 810 1 2 1 10 1 s HasConversion +r 810 1 115 1 644 1 +r 811 1 2 1 10 1 s HasSymbol +r 811 1 115 1 642 1 +r 812 1 2 1 10 1 s HasAlphaData +r 812 1 115 1 684 1 +r 813 1 2 1 10 1 s HasPixelWidth +r 813 1 115 1 677 1 +r 814 1 2 1 10 1 s HasMatrixType +r 814 1 115 1 701 1 +r 815 1 2 1 10 1 s HasImageData +r 815 1 115 1 681 1 +r 816 1 2 1 10 1 s HasMatrixImageIndex +r 816 1 115 1 702 1 +r 817 1 2 1 10 1 s HasPixelHeight +r 817 1 115 1 678 1 +r 818 1 2 1 10 1 s ImageLibrary +r 818 1 115 1 709 1 +r 819 1 2 1 10 1 s HasImage +r 819 1 115 1 676 1 +r 820 1 2 1 10 1 s HasIcon +r 820 1 115 1 715 1 +r 821 1 2 1 10 1 s HasPhysicalWidth +r 821 1 115 1 679 1 +r 822 1 2 1 10 1 s HasPhysicalHeight +r 822 1 115 1 680 1 +r 823 1 2 1 10 1 s Image +r 823 1 115 1 675 1 +r 824 1 2 1 10 1 s MatrixImage +r 824 1 115 1 704 1 +r 825 1 2 1 10 1 s BitmapImage +r 825 1 115 1 685 1 +r 826 1 2 1 10 1 s IconLibrary +r 826 1 115 1 712 1 +r 827 1 2 1 10 1 s HasType +r 827 1 115 1 30 1 +r 828 1 2 1 10 1 s Value +r 828 1 115 1 111 1 +r 829 1 2 1 10 1 s HasCardinality +r 829 1 115 1 39 1 +r 830 1 2 1 10 1 s DoubleArray +r 830 1 115 1 19 1 +r 831 1 2 1 10 1 s HasSignature +r 831 1 115 1 214 1 +r 832 1 2 1 10 1 s HasElseElement +r 832 1 115 1 297 1 +r 833 1 2 1 10 1 s RequirementDisjunction +r 833 1 115 1 33 1 +r 834 1 2 1 10 1 s CompositePredicate +r 834 1 115 1 255 1 +r 835 1 2 1 10 1 s HasSubstituteForTypeChange +r 835 1 115 1 353 1 +r 836 1 2 1 10 1 s SuperrelationOf +r 836 1 115 1 51 1 +r 837 1 2 1 10 1 s HasSingleInstance +r 837 1 115 1 282 1 +r 838 1 2 1 10 1 s BrowseContext +r 838 1 115 1 228 1 +r 839 1 2 1 10 1 s IntersectionPredicate +r 839 1 115 1 267 1 +r 840 1 2 1 10 1 s CommentOf +r 840 1 115 1 120 1 +r 841 1 2 1 10 1 s Trigger +r 841 1 115 1 272 1 +r 842 1 2 1 10 1 s UnionPredicate +r 842 1 115 1 265 1 +r 843 1 2 1 10 1 s String +r 843 1 115 1 10 1 +r 844 1 2 1 10 1 s Float +r 844 1 115 1 13 1 +r 845 1 2 1 10 1 s HasCondition +r 845 1 115 1 293 1 +r 846 1 2 1 10 1 s PropertyType +r 846 1 115 1 106 1 +r 847 1 2 1 10 1 s Entity +r 847 1 115 1 25 1 +r 848 1 2 1 10 1 s IsSingleInstanceOf +r 848 1 115 1 283 1 +r 849 1 2 1 10 1 s HasRange +r 849 1 115 1 28 1 +r 850 1 2 1 10 1 s HasInstance +r 850 1 115 1 171 1 +r 851 1 2 1 10 1 s IsComposedOf +r 851 1 115 1 83 1 +r 852 1 2 1 10 1 s SubExtentOf +r 852 1 115 1 356 1 +r 853 1 2 1 10 1 s PartOf +r 853 1 115 1 7 1 +r 854 1 2 1 10 1 s HasContextTester +r 854 1 115 1 234 1 +r 855 1 2 1 10 1 s ForType +r 855 1 115 1 235 1 +r 856 1 2 1 10 1 s SomeValuesSatisfy +r 856 1 115 1 41 1 +r 857 1 2 1 10 1 s AppliesThen +r 857 1 115 1 259 1 +r 858 1 2 1 10 1 s TransitiveClosure +r 858 1 115 1 263 1 +r 859 1 2 1 10 1 s HasGeneratedNamePrefix +r 859 1 115 1 241 1 +r 860 1 2 1 10 1 s HasMethod +r 860 1 115 1 216 1 +r 861 1 2 1 10 1 s Includes +r 861 1 115 1 360 1 +r 862 1 2 1 10 1 s ViewpointContribution +r 862 1 115 1 269 1 +r 863 1 2 1 10 1 s TypeClassifier +r 863 1 115 1 349 1 +r 864 1 2 1 10 1 s NameOf +r 864 1 115 1 115 1 +r 865 1 2 1 10 1 s Configuration +r 865 1 115 1 48 1 +r 866 1 2 1 10 1 s SubgraphAdvisor +r 866 1 115 1 346 1 +r 867 1 2 1 10 1 s Extent +r 867 1 115 1 355 1 +r 868 1 2 1 10 1 s Viewpoint +r 868 1 115 1 189 1 +r 869 1 2 1 10 1 s HasIndex +r 869 1 115 1 279 1 +r 870 1 2 1 10 1 s ConditionalList +r 870 1 115 1 291 1 +r 871 1 2 1 10 1 s HasLabel +r 871 1 115 1 116 1 +r 872 1 2 1 10 1 s HasBinaryPredicate +r 872 1 115 1 262 1 +r 873 1 2 1 10 1 s BinaryPredicates +r 873 1 115 1 253 1 +r 874 1 2 1 10 1 s HasName +r 874 1 115 1 6 1 +r 875 1 2 1 10 1 s Requirement +r 875 1 115 1 144 1 +r 876 1 2 1 10 1 s InverseOfIsRelatedTo +r 876 1 115 1 79 1 +r 877 1 2 1 10 1 s HasObject +r 877 1 115 1 56 1 +r 878 1 2 1 10 1 s Assertion +r 878 1 115 1 97 1 +r 879 1 2 1 10 1 s HasDefaultValue +r 879 1 115 1 161 1 +r 880 1 2 1 10 1 s Operation +r 880 1 115 1 286 1 +r 881 1 2 1 10 1 s HasModelledIcon +r 881 1 115 1 229 1 +r 882 1 2 1 10 1 s GenericRelation +r 882 1 115 1 217 1 +r 883 1 2 1 10 1 s TypeLibrary +r 883 1 115 1 177 1 +r 884 1 2 1 10 1 s OrderedSet +r 884 1 115 1 140 1 +r 885 1 2 1 10 1 s RelationApplication +r 885 1 115 1 221 1 +r 886 1 2 1 10 1 s Abstract +r 886 1 115 1 92 1 +r 887 1 2 1 10 1 s Long +r 887 1 115 1 16 1 +r 888 1 2 1 10 1 s EntityType +r 888 1 115 1 311 1 +r 889 1 2 1 10 1 s HasDescription +r 889 1 115 1 69 1 +r 890 1 2 1 10 1 s HasPackageName +r 890 1 115 1 65 1 +r 891 1 2 1 10 1 s HasPredicate +r 891 1 115 1 55 1 +r 892 1 2 1 10 1 s TypeContextTester +r 892 1 115 1 236 1 +r 893 1 2 1 10 1 s HasPrevious +r 893 1 115 1 143 1 +r 894 1 2 1 10 1 s HasTrigger +r 894 1 115 1 275 1 +r 895 1 2 1 10 1 s ModelConfigurator +r 895 1 115 1 170 1 +r 896 1 2 1 10 1 s InversePredicate +r 896 1 115 1 260 1 +r 897 1 2 1 10 1 s EqualityRequirement +r 897 1 115 1 36 1 +r 898 1 2 1 10 1 s Valuation +r 898 1 115 1 237 1 +r 899 1 2 1 10 1 s Double +r 899 1 115 1 12 1 +r 900 1 2 1 10 1 s Ignore +r 900 1 115 1 43 1 +r 901 1 2 1 10 1 s SubgraphExtent +r 901 1 115 1 347 1 +r 902 1 2 1 10 1 s HasMaxCardinality +r 902 1 115 1 317 1 +r 903 1 2 1 10 1 s HasValidNumericalRange +r 903 1 115 1 159 1 +r 904 1 2 1 10 1 s HasDocumentation +r 904 1 115 1 127 1 +r 905 1 2 1 10 1 s Version +r 905 1 115 1 62 1 +r 906 1 2 1 10 1 s Layer0ValidationRule +r 906 1 115 1 345 1 +r 907 1 2 1 10 1 s IsIncludedWith +r 907 1 115 1 361 1 +r 908 1 2 1 10 1 s ConsistsOf +r 908 1 115 1 9 1 +r 909 1 2 1 10 1 s IsAssertionOf +r 909 1 115 1 98 1 +r 910 1 2 1 10 1 s Conjunction +r 910 1 115 1 245 1 +r 911 1 2 1 10 1 s LibraryDeveloper +r 911 1 115 1 169 1 +r 912 1 2 1 10 1 s Property +r 912 1 115 1 24 1 +r 913 1 2 1 10 1 s PropertyOf +r 913 1 115 1 107 1 +r 914 1 2 1 10 1 s HasResourceClass +r 914 1 115 1 63 1 +r 915 1 2 1 10 1 s RootLibrary +r 915 1 115 1 0 0 +r 916 1 2 1 10 1 s PropertyLibrary +r 916 1 115 1 183 1 +r 917 1 2 1 10 1 s HasChangeCode +r 917 1 115 1 240 1 +r 918 1 2 1 10 1 s DependenciesRelation +r 918 1 115 1 280 1 +r 919 1 2 1 10 1 s RelationRequirement +r 919 1 115 1 37 1 +r 920 1 2 1 10 1 s HasRequirement +r 920 1 115 1 27 1 +r 921 1 2 1 10 1 s InverseOf +r 921 1 115 1 4 1 +r 922 1 2 1 10 1 s InstanceOf +r 922 1 115 1 2 1 +r 923 1 2 1 10 1 s Requires +r 923 1 115 1 313 1 +r 924 1 2 1 10 1 s Type +r 924 1 115 1 87 1 +r 925 1 2 1 10 1 s IsOperation +r 925 1 115 1 220 1 +r 926 1 2 1 10 1 s Role +r 926 1 115 1 166 1 +r 927 1 2 1 10 1 s Ontology +r 927 1 115 1 53 1 +r 928 1 2 1 10 1 s IntegerArray +r 928 1 115 1 18 1 +r 929 1 2 1 10 1 s Template +r 929 1 115 1 304 1 +r 930 1 2 1 10 1 s LinkedList +r 930 1 115 1 134 1 +r 931 1 2 1 10 1 s Library +r 931 1 115 1 45 1 +r 932 1 2 1 10 1 s Enumeration +r 932 1 115 1 26 1 +r 933 1 2 1 10 1 s ByteArray +r 933 1 115 1 22 1 +r 934 1 2 1 10 1 s Index +r 934 1 115 1 278 1 +r 935 1 2 1 10 1 s Tag +r 935 1 115 1 90 1 +r 936 1 2 1 10 1 s HasEmail +r 936 1 115 1 71 1 +r 937 1 2 1 10 1 s Relation +r 937 1 115 1 1 1 +r 938 1 2 1 10 1 s BooleanArray +r 938 1 115 1 21 1 +r 939 1 2 1 10 1 s HasMultiplicity +r 939 1 115 1 110 1 +r 940 1 2 1 10 1 s AbstractContextualList +r 940 1 115 1 287 1 +r 941 1 2 1 10 1 s HasAttributeName +r 941 1 115 1 113 1 +r 942 1 2 1 10 1 s IsBrowseContextOf +r 942 1 115 1 233 1 +r 943 1 2 1 10 1 s EvaluatesTo +r 943 1 115 1 314 1 +r 944 1 2 1 10 1 s Projects +r 944 1 115 1 47 1 +r 945 1 2 1 10 1 s SubrelationOf +r 945 1 115 1 3 1 +r 946 1 2 1 10 1 s Disjunction +r 946 1 115 1 247 1 +r 947 1 2 1 10 1 s ViewpointLibrary +r 947 1 115 1 186 1 +r 948 1 2 1 10 1 s URI +r 948 1 115 1 122 1 +r 949 1 2 1 10 1 s HasEntity +r 949 1 115 1 31 1 +r 950 1 2 1 10 1 s URL +r 950 1 115 1 124 1 +r 951 1 2 1 10 1 s PropertyDefinition +r 951 1 115 1 102 1 +r 952 1 2 1 10 1 s ContextTester +r 952 1 115 1 227 1 +r 953 1 2 1 10 1 s ValueRequirement +r 953 1 115 1 155 1 +r 954 1 2 1 10 1 s IsTriggerOf +r 954 1 115 1 274 1 +r 955 1 2 1 10 1 s IntegerRangeUnion +r 955 1 115 1 121 1 +r 956 1 2 1 10 1 s ConcernsRelation +r 956 1 115 1 38 1 +r 957 1 2 1 10 1 s HasViewpointContribution +r 957 1 115 1 230 1 +r 958 1 2 1 10 1 s HasActivation +r 958 1 115 1 277 1 +r 959 1 2 1 10 1 s Function +r 959 1 115 1 212 1 +r 960 1 2 1 10 1 s Inherits +r 960 1 115 1 5 1 +r 961 1 2 1 10 1 s AppliesFirst +r 961 1 115 1 257 1 +r 962 1 2 1 10 1 s Admin +r 962 1 115 1 167 1 +r 963 1 2 1 10 1 s PropagatesTo +r 963 1 115 1 359 1 +r 964 1 2 1 10 1 s Examples +r 964 1 115 1 335 1 +r 965 1 2 1 10 1 s Propagates +r 965 1 115 1 358 1 +r 966 1 2 1 10 1 s HasBrowseContext +r 966 1 115 1 232 1 +r 967 1 2 1 10 1 s AllValuesSatisfy +r 967 1 115 1 40 1 +r 968 1 2 1 10 1 s ModelUser +r 968 1 115 1 73 1 +r 969 1 2 1 10 1 s Constraint +r 969 1 115 1 312 1 +r 970 1 2 1 10 1 s Final +r 970 1 115 1 89 1 +r 971 1 2 1 10 1 s HasProperty +r 971 1 115 1 74 1 +r 972 1 2 1 10 1 s HasVersion +r 972 1 115 1 60 1 +r 973 1 2 1 10 1 s ContextualList +r 973 1 115 1 288 1 +r 974 1 2 1 10 1 s TagLibrary +r 974 1 115 1 190 1 +r 975 1 2 1 10 1 s StringArray +r 975 1 115 1 17 1 +r 976 1 2 1 10 1 s BinaryPredicate +r 976 1 115 1 202 1 +r 977 1 2 1 10 1 s Integer +r 977 1 115 1 11 1 +r 978 1 2 1 10 1 s HasExtent +r 978 1 115 1 357 1 +r 979 1 2 1 10 1 s HasUnit +r 979 1 115 1 126 1 +r 980 1 2 1 10 1 s Negation +r 980 1 115 1 249 1 +r 981 1 2 1 10 1 s TypeRequirement +r 981 1 115 1 35 1 +r 982 1 2 1 10 1 s Activation +r 982 1 115 1 276 1 +r 983 1 2 1 10 1 s RequirementNegation +r 983 1 115 1 34 1 +r 984 1 2 1 10 1 s HasTemplate +r 984 1 115 1 306 1 +r 985 1 2 1 10 1 s HasTextualIssue +r 985 1 115 1 238 1 +r 986 1 2 1 10 1 s EntitySubgraphExtent +r 986 1 115 1 348 1 +r 987 1 2 1 10 1 s HasRelation +r 987 1 115 1 208 1 +r 988 1 2 1 10 1 s RelationClassifier +r 988 1 115 1 351 1 +r 989 1 2 1 10 1 s ValueType +r 989 1 115 1 108 1 +r 990 1 2 1 10 1 s HasValueRequirement +r 990 1 115 1 160 1 +r 991 1 2 1 10 1 s HasComment +r 991 1 115 1 119 1 +r 992 1 2 1 10 1 s OrderedSetElements +r 992 1 115 1 254 1 +r 993 1 2 1 10 1 s KernelDeveloper +r 993 1 115 1 168 1 +r 994 1 2 1 10 1 s TypeBasedList +r 994 1 115 1 289 1 +r 995 1 2 1 10 1 s HasPasswordHash +r 995 1 115 1 52 1 +r 996 1 2 1 10 1 s DocumentTemplate +r 996 1 115 1 132 1 +r 997 1 2 1 10 1 s Users +r 997 1 115 1 46 1 +r 998 1 2 1 10 1 s FunctionalRelation +r 998 1 115 1 42 1 +r 999 1 2 1 10 1 s TextualIssueOf +r 999 1 115 1 239 1 +r 1000 1 2 1 10 1 s HasValidationRule +r 1000 1 115 1 344 1 +r 1001 1 2 1 10 1 s LongArray +r 1001 1 115 1 23 1 +r 1002 1 2 1 10 1 s CardinalityRestriction +r 1002 1 115 1 315 1 +r 1003 1 2 1 10 1 s RelationView +r 1003 1 115 1 226 1 +r 1004 1 2 1 10 1 s Boolean +r 1004 1 115 1 14 1 +r 1005 1 2 1 10 1 s HasDomain +r 1005 1 115 1 29 1 +r 1006 1 2 1 10 1 s HasMinCardinality +r 1006 1 115 1 319 1 +r 1007 1 2 1 10 1 s IsWeaklyRelatedTo +r 1007 1 115 1 8 1 +r 1008 1 2 1 10 1 s Report +r 1008 1 115 1 129 1 +r 1009 1 2 1 10 1 s IsOwnedBy +r 1009 1 115 1 85 1 +r 1010 1 2 1 10 1 s IsViewpointContributionOf +r 1010 1 115 1 231 1 +r 1011 1 2 1 10 1 s User +r 1011 1 115 1 67 1 +r 1012 1 2 1 10 1 s IsDependencyOf +r 1012 1 115 1 82 1 +r 1013 1 2 1 10 1 s FloatArray +r 1013 1 115 1 20 1 +r 1014 1 2 1 10 1 s Literal +r 1014 1 115 1 193 1 +r 1015 1 2 1 10 1 s Singleton +r 1015 1 115 1 284 1 +r 1016 1 2 1 10 1 s RequirementConjunction +r 1016 1 115 1 32 1 +r 1017 1 2 1 10 1 s HasBindingPattern +r 1017 1 115 1 223 1 +r 1018 1 2 1 10 1 s HasElement +r 1018 1 115 1 138 1 +r 1019 1 2 1 10 1 s HasReportFactory +r 1019 1 115 1 128 1 +r 1020 1 2 1 10 1 s AppliesRelation +r 1020 1 115 1 225 1 +r 1021 1 2 1 10 1 s HasNext +r 1021 1 115 1 136 1 +r 1022 1 2 1 10 1 s HasDataType +r 1022 1 115 1 342 1 +r 1023 1 2 1 10 1 s HasPropertyDefinition +r 1023 1 115 1 100 1 +r 1024 1 2 1 10 1 s RelationLibrary +r 1024 1 115 1 180 1 +r 1025 1 2 1 10 1 s SupertypeOf +r 1025 1 115 1 172 1 +r 1026 1 2 1 10 1 s ValidationRule +r 1026 1 115 1 343 1 +r 1027 1 2 1 10 1 s DependsOn +r 1027 1 115 1 80 1 +r 1028 1 2 1 10 1 s IsRelatedTo +r 1028 1 115 1 77 1 +r 1029 1 2 1 10 1 s Number +r 1029 1 115 1 112 1 +r 1030 1 2 1 10 1 s Predicate +r 1030 1 115 1 195 1 +r 1031 1 2 1 10 1 s HasThenElement +r 1031 1 115 1 295 1 +r 1032 1 2 1 10 1 s HasDocumentTemplate +r 1032 1 115 1 131 1 +r 1033 1 2 1 10 1 s Asserts +r 1033 1 115 1 54 1 +r 1034 1 2 1 10 1 s Predicates +r 1034 1 115 1 244 1 +r 1035 1 2 1 10 1 s IsPropertyDefinitionOf +r 1035 1 115 1 310 1 +r 1036 1 2 1 10 1 s AgentServers +r 1036 1 115 1 49 1 +r 1037 1 2 1 10 1 s Byte +r 1037 1 115 1 15 1 +r 1038 1 2 1 10 1 s HasDevsComponent +r 1038 1 115 1 391 1 +r 1039 1 2 1 10 1 s ExperimentLibrary +r 1039 1 115 1 375 1 +r 1040 1 2 1 10 1 s HasActiveExperiment +r 1040 1 115 1 390 1 +r 1041 1 2 1 10 1 s IsActive +r 1041 1 115 1 389 1 +r 1042 1 2 1 10 1 s Run +r 1042 1 115 1 388 1 +r 1043 1 2 1 10 1 s Model +r 1043 1 115 1 374 1 +r 1044 1 2 1 10 1 s HasState +r 1044 1 115 1 382 1 +r 1045 1 2 1 10 1 s State +r 1045 1 115 1 384 1 +r 1046 1 2 1 10 1 s HasInitialState +r 1046 1 115 1 386 1 +r 1047 1 2 1 10 1 s Experiment +r 1047 1 115 1 378 1 +r 1048 1 2 1 10 1 s ModelLibrary +r 1048 1 115 1 371 1 +r 1049 1 2 1 10 1 s HasConfiguration +r 1049 1 115 1 380 1 +r 1050 1 2 1 10 1 s IsConfigurationOf +r 1050 1 115 1 385 1 +r 1051 1 2 1 10 1 s Plugin +r 1051 1 115 1 570 1 +r 1052 1 2 1 10 1 s RequiresVersion +r 1052 1 115 1 562 1 +r 1053 1 2 1 10 1 s UpdateSite +r 1053 1 115 1 565 1 +r 1054 1 2 1 10 1 s FeatureReference +r 1054 1 115 1 574 1 +r 1055 1 2 1 10 1 s RefersToItem +r 1055 1 115 1 560 1 +r 1056 1 2 1 10 1 s PluginReference +r 1056 1 115 1 576 1 +r 1057 1 2 1 10 1 s VersionedItem +r 1057 1 115 1 561 1 +r 1058 1 2 1 10 1 s HasURL +r 1058 1 115 1 556 1 +r 1059 1 2 1 10 1 s HasData +r 1059 1 115 1 563 1 +r 1060 1 2 1 10 1 s HasDependency +r 1060 1 115 1 557 1 +r 1061 1 2 1 10 1 s VersionRange +r 1061 1 115 1 555 1 +r 1062 1 2 1 10 1 s IsDependencyOf +r 1062 1 115 1 559 1 +r 1063 1 2 1 10 1 s Feature +r 1063 1 115 1 569 1 +r 1064 1 2 1 10 1 s VersionedItemReference +r 1064 1 115 1 558 1 +r 1065 1 2 1 10 1 s HasItemIdentifier +r 1065 1 115 1 564 1 +r 1066 1 2 1 10 1 s HasCoefficient +r 1066 1 115 1 514 1 +r 1067 1 2 1 10 1 s Operator +r 1067 1 115 1 535 1 +r 1068 1 2 1 10 1 s ElementExpression +r 1068 1 115 1 543 1 +r 1069 1 2 1 10 1 s Assign +r 1069 1 115 1 546 1 +r 1070 1 2 1 10 1 s HasSource +r 1070 1 115 1 505 1 +r 1071 1 2 1 10 1 s Expression +r 1071 1 115 1 499 1 +r 1072 1 2 1 10 1 s Addition +r 1072 1 115 1 538 1 +r 1073 1 2 1 10 1 s HasElementList +r 1073 1 115 1 542 1 +r 1074 1 2 1 10 1 s SystemOfEquations +r 1074 1 115 1 522 1 +r 1075 1 2 1 10 1 s Element +r 1075 1 115 1 534 1 +r 1076 1 2 1 10 1 s SecondOrderScalarPolynomial +r 1076 1 115 1 526 1 +r 1077 1 2 1 10 1 s HasA +r 1077 1 115 1 529 1 +r 1078 1 2 1 10 1 s HasB +r 1078 1 115 1 531 1 +r 1079 1 2 1 10 1 s HasC +r 1079 1 115 1 533 1 +r 1080 1 2 1 10 1 s HasTarget +r 1080 1 115 1 501 1 +r 1081 1 2 1 10 1 s DoubleToIntegerAssign +r 1081 1 115 1 551 1 +r 1082 1 2 1 10 1 s DoubleAssign +r 1082 1 115 1 550 1 +r 1083 1 2 1 10 1 s Multiplication +r 1083 1 115 1 540 1 +r 1084 1 2 1 10 1 s ScalarPolynomial +r 1084 1 115 1 512 1 +r 1085 1 2 1 10 1 s IntegerAssign +r 1085 1 115 1 549 1 +r 1086 1 2 1 10 1 s Division +r 1086 1 115 1 541 1 +r 1087 1 2 1 10 1 s Number +r 1087 1 115 1 536 1 +r 1088 1 2 1 10 1 s Equation +r 1088 1 115 1 510 1 +r 1089 1 2 1 10 1 s SystemOfExpressions +r 1089 1 115 1 520 1 +r 1090 1 2 1 10 1 s Subtraction +r 1090 1 115 1 539 1 +r 1091 1 2 1 10 1 s HasVariable +r 1091 1 115 1 525 1 +r 1092 1 2 1 10 1 s RequiredByFeature +r 1092 1 115 1 597 1 +r 1093 1 2 1 10 1 s Features +r 1093 1 115 1 608 1 +r 1094 1 2 1 10 1 s ExperimentControlFeature +r 1094 1 115 1 603 1 +r 1095 1 2 1 10 1 s HasFeature +r 1095 1 115 1 587 1 +r 1096 1 2 1 10 1 s ProjectType2 +r 1096 1 115 1 583 1 +r 1097 1 2 1 10 1 s LifecycleFeature +r 1097 1 115 1 591 1 +r 1098 1 2 1 10 1 s Project2 +r 1098 1 115 1 584 1 +r 1099 1 2 1 10 1 s PublishedProjectFeatures +r 1099 1 115 1 582 1 +r 1100 1 2 1 10 1 s HasExtensionId +r 1100 1 115 1 588 1 +r 1101 1 2 1 10 1 s IsIncompatibleWithFeature +r 1101 1 115 1 600 1 +r 1102 1 2 1 10 1 s ModellingDomain +r 1102 1 115 1 615 1 +r 1103 1 2 1 10 1 s RequiresNamespace +r 1103 1 115 1 602 1 +r 1104 1 2 1 10 1 s IsCompatibleWithFeature +r 1104 1 115 1 598 1 +r 1105 1 2 1 10 1 s RequiresFeature +r 1105 1 115 1 596 1 +r 1106 1 2 1 10 1 s ExtensionFeature +r 1106 1 115 1 592 1 +r 1107 1 2 1 10 1 s ModelManagerFeature +r 1107 1 115 1 604 1 +r 1108 1 2 1 10 1 s OntologyRequirementValidationFeature +r 1108 1 115 1 605 1 +r 1109 1 2 1 10 1 s Feature +r 1109 1 115 1 589 1 +r 1110 1 2 1 10 1 s OntologyDevelopmentProject +r 1110 1 115 1 720 1 +r 1111 1 3 1 82 1 +r 1111 1 4 1 27 1 +r 1112 1 3 1 82 1 +r 1112 1 4 1 28 1 +r 1113 1 3 1 82 1 +r 1113 1 4 1 29 1 +r 1114 1 3 1 82 1 +r 1114 1 4 1 30 1 +r 1115 1 3 1 79 1 +r 1115 1 4 1 31 1 +r 1116 1 3 1 79 1 +r 1116 1 4 1 38 1 +r 1117 1 3 1 107 1 +r 1117 1 4 1 39 1 +r 1118 1 3 1 82 1 +r 1118 1 4 1 40 1 +r 1119 1 3 1 82 1 +r 1119 1 4 1 41 1 +r 1120 1 3 1 79 1 +r 1120 1 4 1 43 1 +r 1121 1 3 1 107 1 +r 1121 1 4 1 52 1 +r 1122 1 3 1 79 1 +r 1122 1 4 1 55 1 +r 1123 1 3 1 79 1 +r 1123 1 4 1 56 1 +r 1124 1 3 1 107 1 +r 1124 1 4 1 60 1 +r 1125 1 3 1 107 1 +r 1125 1 4 1 63 1 +r 1126 1 3 1 107 1 +r 1126 1 4 1 65 1 +r 1127 1 3 1 107 1 +r 1127 1 4 1 69 1 +r 1128 1 3 1 107 1 +r 1128 1 4 1 71 1 +r 1129 1 3 1 107 1 +r 1129 1 4 1 110 1 +r 1130 1 3 1 107 1 +r 1130 1 4 1 113 1 +r 1131 1 3 1 107 1 +r 1131 1 4 1 116 1 +r 1132 1 3 1 82 1 +r 1132 1 4 1 126 1 +r 1133 1 3 1 82 1 +r 1133 1 4 1 127 1 +r 1134 1 3 1 82 1 +r 1134 1 4 1 128 1 +r 1135 1 3 1 82 1 +r 1135 1 4 1 131 1 +r 1136 1 3 1 82 1 +r 1136 1 4 1 138 1 +r 1137 1 3 1 107 1 +r 1137 1 4 1 159 1 +r 1138 1 3 1 107 1 +r 1138 1 4 1 160 1 +r 1139 1 3 1 82 1 +r 1139 1 4 1 161 1 +r 1140 1 3 1 82 1 +r 1140 1 4 1 208 1 +r 1141 1 3 1 107 1 +r 1141 1 4 1 214 1 +r 1142 1 3 1 79 1 +r 1142 1 4 1 216 1 +r 1143 1 3 1 107 1 +r 1143 1 4 1 223 1 +r 1144 1 3 1 79 1 +r 1144 1 4 1 225 1 +r 1145 1 3 1 79 1 +r 1145 1 4 1 229 1 +r 1146 1 3 1 79 1 +r 1146 1 4 1 234 1 +r 1147 1 3 1 79 1 +r 1147 1 4 1 235 1 +r 1148 1 3 1 79 1 +r 1148 1 4 1 240 1 +r 1149 1 3 1 107 1 +r 1149 1 4 1 241 1 +r 1150 1 3 1 79 1 +r 1150 1 4 1 257 1 +r 1151 1 3 1 79 1 +r 1151 1 4 1 259 1 +r 1152 1 3 1 79 1 +r 1152 1 4 1 262 1 +r 1153 1 3 1 79 1 +r 1153 1 4 1 277 1 +r 1154 1 3 1 79 1 +r 1154 1 4 1 279 1 +r 1155 1 3 1 79 1 +r 1155 1 4 1 293 1 +r 1156 1 3 1 79 1 +r 1156 1 4 1 295 1 +r 1157 1 3 1 79 1 +r 1157 1 4 1 297 1 +r 1158 1 51 1 1174 1 +r 1158 1 3 1 8 1 +r 1158 1 4 1 306 1 +r 1159 1 3 1 79 1 +r 1159 1 4 1 313 1 +r 1160 1 3 1 79 1 +r 1160 1 4 1 314 1 +r 1161 1 3 1 79 1 +r 1161 1 4 1 317 1 +r 1162 1 3 1 79 1 +r 1162 1 4 1 319 1 +r 1163 1 3 1 143 1 +r 1163 1 4 1 336 1 +r 1164 1 3 1 107 1 +r 1164 1 4 1 342 1 +r 1165 1 3 1 79 1 +r 1165 1 4 1 344 1 +r 1166 1 3 1 82 1 +r 1166 1 4 1 353 1 +r 1167 1 3 1 82 1 +r 1167 1 4 1 382 1 +r 1168 1 3 1 82 1 +r 1168 1 4 1 386 1 +r 1169 1 3 1 107 1 +r 1169 1 4 1 390 1 +r 1170 1 3 1 79 1 +r 1170 1 4 1 391 1 +r 1171 1 3 1 79 1 +r 1171 1 4 1 405 1 +r 1172 1 3 1 79 1 +r 1172 1 4 1 407 1 +r 1173 1 3 1 107 1 +r 1173 1 4 1 438 1 +r 1174 1 3 1 1158 1 +r 1174 1 4 1 448 1 +r 1175 1 3 1 79 1 +r 1175 1 4 1 450 1 +r 1176 1 3 1 79 1 +r 1176 1 4 1 452 1 +r 1177 1 3 1 79 1 +r 1177 1 4 1 454 1 +r 1178 1 3 1 79 1 +r 1178 1 4 1 456 1 +r 1179 1 3 1 107 1 +r 1179 1 4 1 461 1 +r 1180 1 3 1 107 1 +r 1180 1 4 1 463 1 +r 1181 1 3 1 79 1 +r 1181 1 4 1 465 1 +r 1182 1 3 1 79 1 +r 1182 1 4 1 469 1 +r 1183 1 3 1 79 1 +r 1183 1 4 1 472 1 +r 1184 1 3 1 79 1 +r 1184 1 4 1 476 1 +r 1185 1 3 1 79 1 +r 1185 1 4 1 481 1 +r 1186 1 3 1 79 1 +r 1186 1 4 1 483 1 +r 1187 1 3 1 79 1 +r 1187 1 4 1 489 1 +r 1188 1 51 1 1192 1 +r 1188 1 51 1 1191 1 +r 1188 1 51 1 1190 1 +r 1188 1 3 1 79 1 +r 1188 1 4 1 514 1 +r 1189 1 3 1 82 1 +r 1189 1 4 1 525 1 +r 1190 1 3 1 1188 1 +r 1190 1 4 1 529 1 +r 1191 1 3 1 1188 1 +r 1191 1 4 1 531 1 +r 1192 1 3 1 1188 1 +r 1192 1 4 1 533 1 +r 1193 1 3 1 107 1 +r 1193 1 4 1 542 1 +r 1194 1 3 1 107 1 +r 1194 1 4 1 556 1 +r 1195 1 3 1 8 1 +r 1195 1 4 1 560 1 +r 1196 1 3 1 107 1 +r 1196 1 4 1 562 1 +r 1197 1 3 1 82 1 +r 1197 1 4 1 563 1 +r 1198 1 3 1 82 1 +r 1198 1 4 1 564 1 +r 1199 1 3 1 82 1 +r 1199 1 4 1 587 1 +r 1200 1 3 1 107 1 +r 1200 1 4 1 588 1 +r 1201 1 3 1 107 1 +r 1201 1 4 1 602 1 +r 1202 1 3 1 107 1 +r 1202 1 4 1 627 1 +r 1203 1 3 1 79 1 +r 1203 1 4 1 633 1 +r 1204 1 3 1 79 1 +r 1204 1 4 1 635 1 +r 1205 1 3 1 79 1 +r 1205 1 4 1 638 1 +r 1206 1 3 1 79 1 +r 1206 1 4 1 642 1 +r 1207 1 3 1 79 1 +r 1207 1 4 1 644 1 +r 1208 1 3 1 79 1 +r 1208 1 4 1 649 1 +r 1209 1 3 1 79 1 +r 1209 1 4 1 652 1 +r 1210 1 3 1 107 1 +r 1210 1 4 1 655 1 +r 1211 1 3 1 107 1 +r 1211 1 4 1 656 1 +r 1212 1 3 1 107 1 +r 1212 1 4 1 657 1 +r 1213 1 3 1 79 1 +r 1213 1 4 1 658 1 +r 1214 1 3 1 79 1 +r 1214 1 4 1 659 1 +r 1215 1 3 1 107 1 +r 1215 1 4 1 660 1 +r 1216 1 3 1 107 1 +r 1216 1 4 1 661 1 +r 1217 1 3 1 79 1 +r 1217 1 4 1 662 1 +r 1218 1 3 1 79 1 +r 1218 1 4 1 666 1 +r 1219 1 3 1 82 1 +r 1219 1 4 1 676 1 +r 1220 1 3 1 107 1 +r 1220 1 4 1 677 1 +r 1221 1 3 1 107 1 +r 1221 1 4 1 678 1 +r 1222 1 3 1 107 1 +r 1222 1 4 1 679 1 +r 1223 1 3 1 107 1 +r 1223 1 4 1 680 1 +r 1224 1 51 1 1226 1 +r 1224 1 51 1 1225 1 +r 1224 1 3 1 107 1 +r 1224 1 4 1 681 1 +r 1225 1 3 1 1224 1 +r 1225 1 4 1 682 1 +r 1226 1 3 1 1224 1 +r 1226 1 4 1 684 1 +r 1227 1 3 1 79 1 +r 1227 1 4 1 692 1 +r 1228 1 3 1 107 1 +r 1228 1 4 1 701 1 +r 1229 1 3 1 107 1 +r 1229 1 4 1 702 1 +r 1230 1 3 1 82 1 +r 1230 1 4 1 715 1 diff --git a/tests/org.simantics.db.tests/defaultDb/.keep b/tests/org.simantics.db.tests/defaultDb/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros Debug.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros Debug.launch new file mode 100644 index 000000000..d202af734 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros Debug.launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros.launch new file mode 100644 index 000000000..9ca146c2e --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Apros.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics Debug.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics Debug.launch new file mode 100644 index 000000000..10c1642ca --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics Debug.launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics.launch new file mode 100644 index 000000000..3ea466b04 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Simantics.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Debug.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Debug.launch new file mode 100644 index 000000000..c01f856b7 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Debug.launch @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Linux.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Linux.launch new file mode 100644 index 000000000..63f952d2e --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests Linux.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests.launch b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests.launch new file mode 100644 index 000000000..4af223285 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate Layer0 For Tests.launch @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/org.simantics.db.tests/launch/Generate.launch b/tests/org.simantics.db.tests/launch/Generate.launch new file mode 100644 index 000000000..e4203b08e --- /dev/null +++ b/tests/org.simantics.db.tests/launch/Generate.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/PerformanceTests.launch b/tests/org.simantics.db.tests/launch/PerformanceTests.launch new file mode 100644 index 000000000..27fee1e65 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/PerformanceTests.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/PluginTests.launch b/tests/org.simantics.db.tests/launch/PluginTests.launch new file mode 100644 index 000000000..bde35cca6 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/PluginTests.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/RegressionTests.launch b/tests/org.simantics.db.tests/launch/RegressionTests.launch new file mode 100644 index 000000000..fc5e81077 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/RegressionTests.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/RegressionTestsPlugin.launch b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin.launch new file mode 100644 index 000000000..cb98442a6 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin.launch @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/RegressionTestsPlugin2.launch b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin2.launch new file mode 100644 index 000000000..306635d31 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin2.launch @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/RegressionTestsPlugin64.launch b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin64.launch new file mode 100644 index 000000000..d7bdd406e --- /dev/null +++ b/tests/org.simantics.db.tests/launch/RegressionTestsPlugin64.launch @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/StressTests.launch b/tests/org.simantics.db.tests/launch/StressTests.launch new file mode 100644 index 000000000..d11caa4c0 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/StressTests.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/TempTests.launch b/tests/org.simantics.db.tests/launch/TempTests.launch new file mode 100644 index 000000000..d2eb0b9cd --- /dev/null +++ b/tests/org.simantics.db.tests/launch/TempTests.launch @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/launch/TempTestsPlugin.launch b/tests/org.simantics.db.tests/launch/TempTestsPlugin.launch new file mode 100644 index 000000000..485bc8fb8 --- /dev/null +++ b/tests/org.simantics.db.tests/launch/TempTestsPlugin.launch @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/org.simantics.db.tests/run/.keep b/tests/org.simantics.db.tests/run/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/SuiteAPI.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/SuiteAPI.java new file mode 100644 index 000000000..26f44f5a0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/SuiteAPI.java @@ -0,0 +1,28 @@ +package org.simantics.db.tests.api; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.delayedWrite.SuiteDelayedWrite; +import org.simantics.db.tests.api.readGraph.SuiteReadGraph; +import org.simantics.db.tests.api.request.SuiteRequest; +import org.simantics.db.tests.api.story.SuiteStory; +import org.simantics.db.tests.api.support.SuiteSupport; +import org.simantics.db.tests.api.write.SuiteWrite; +import org.simantics.db.tests.common.InitializeDatabaseTest; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + SuiteDelayedWrite.class, + SuiteReadGraph.class, + SuiteRequest.class, + SuiteStory.class, + SuiteSupport.class, + SuiteWrite.class +}) +public class SuiteAPI { + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphExceptionHandling.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphExceptionHandling.java new file mode 100644 index 000000000..61a3e3bf4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphExceptionHandling.java @@ -0,0 +1,38 @@ +package org.simantics.db.tests.api.delayedWrite; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.DelayedWriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * This originated from Apros issue #3296. + * + * @author Tuukka Lehtonen + */ +public class DelayedWriteGraphExceptionHandling extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + try { + DelayedWriteRequest r = new DelayedWriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Should throw an exception / error + graph.claim(null, null, null, null); + } + }; + getSession().sync(r); + } catch (DatabaseException e) { + // Should happen. + } + + // Just to check the database session is still alive. + Resource r = getSession().sync(new org.simantics.db.common.primitiverequest.Resource("http:/")); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java new file mode 100644 index 000000000..9ffb5dd7d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java @@ -0,0 +1,75 @@ +package org.simantics.db.tests.api.delayedWrite; + +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.DelayedWriteRequest; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * This originated from Apros issue #3296. + * + * @author Tuukka Lehtonen + */ +public class DelayedWriteGraphVirtualGraphHandling extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + final VirtualGraphSupport vgs = getSession().getService(VirtualGraphSupport.class); + final VirtualGraph mem = getSession().getService(VirtualGraphSupport.class).getMemoryPersistent("MEM"); + final VirtualGraph ws = getSession().getService(VirtualGraphSupport.class).getWorkspacePersistent("WS"); + + final AtomicReference transientName = new AtomicReference(); + final AtomicReference persistentDescription = new AtomicReference(); + + DelayedWriteRequest r = new DelayedWriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + final Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, null, L0.Entity); + + transientName.set( graph.sync(new WriteResultRequest(mem) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Resource vr = graph.newResource(); + graph.claim(vr, L0.InstanceOf, null, L0.String); + graph.claim(r, L0.HasName, vr); + return vr; + } + }) ); + persistentDescription.set( graph.sync(new WriteResultRequest(ws) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Resource vr = graph.newResource(); + graph.claim(vr, L0.InstanceOf, null, L0.String); + graph.claim(r, L0.HasDescription, vr); + return vr; + } + }) ); + } + }; + getSession().sync(r); + + // Validate that the data was actually written into virtual graphs. + getSession().sync(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + VirtualGraph nameVg = vgs.getGraph(graph, transientName.get()); + VirtualGraph descVg = vgs.getGraph(graph, persistentDescription.get()); + assertEquals(nameVg, mem); + assertEquals(descVg, ws); + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteRequestCancelHandling.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteRequestCancelHandling.java new file mode 100644 index 000000000..12cfb91a4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteRequestCancelHandling.java @@ -0,0 +1,62 @@ +package org.simantics.db.tests.api.delayedWrite; + +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Assert; +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.DelayedWriteRequest; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Checks that throwing CancelTransactionException from within + * {@link DelayedWriteRequest#perform(WriteGraph)} will + *
    + *
  1. Cancel the transaction correctly without getting stuck
  2. + *
  3. Write no data into the database
  4. + *
+ * + * @author Tuukka Lehtonen + */ +public class DelayedWriteRequestCancelHandling extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + final AtomicReference ref = new AtomicReference(); + try { + DelayedWriteRequest r = new DelayedWriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Should throw an exception / error + ref.set(graph.newResource()); + graph.claim(ref.get(), L0.InstanceOf, null, L0.String); + throw new CancelTransactionException("intentional cancel"); + } + }; + getSession().sync(r); + } catch (CancelTransactionException e) { + // Should happen. + } catch (DatabaseException e) { + // Shouldn't happen. + fail("Got DatabaseException " + e + ", should've received CancelTransactionException"); + } + + // Just to check the database session is still alive. + Resource r = getSession().sync(new org.simantics.db.common.primitiverequest.Resource("http:/")); + + fail("No data should've been written", getSession().sync(new UniqueRead() { + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + return graph.hasStatement( ref.get() ); + } + })); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/SuiteDelayedWrite.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/SuiteDelayedWrite.java new file mode 100644 index 000000000..8d7ed0e39 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/SuiteDelayedWrite.java @@ -0,0 +1,27 @@ +package org.simantics.db.tests.api.delayedWrite; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + DelayedWriteGraphExceptionHandling.class, + DelayedWriteGraphVirtualGraphHandling.class, + DelayedWriteRequestCancelHandling.class +}) +public class SuiteDelayedWrite { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/SuiteReadGraph.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/SuiteReadGraph.java new file mode 100644 index 000000000..3dcec6265 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/SuiteReadGraph.java @@ -0,0 +1,296 @@ +package org.simantics.db.tests.api.readGraph; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.readGraph.adapt.AdaptTest3; +import org.simantics.db.tests.api.readGraph.adapt.AdaptTest4; +import org.simantics.db.tests.api.readGraph.adapt.AdaptionFailureTest; +import org.simantics.db.tests.api.readGraph.adaptRelated.AdaptRelatedTest2; +import org.simantics.db.tests.api.readGraph.adaptRelated.AdaptRelatedTest3; +import org.simantics.db.tests.api.readGraph.adaptUnique.AdaptUniqueTest2; +import org.simantics.db.tests.api.readGraph.forEachObject.ForEachObjectTest1; +import org.simantics.db.tests.api.readGraph.forObjectSet.ForObjectSetTest1; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest1; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest2; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest3; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest4; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest5; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest6; +import org.simantics.db.tests.api.readGraph.getAssertedObjects.GetAssertedObjectsTest7; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest1; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest2; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest3; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest4; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest5; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest6; +import org.simantics.db.tests.api.readGraph.getAssertedStatements.GetAssertedStatementsTest7; +import org.simantics.db.tests.api.readGraph.getBuiltin.GetBuiltinTest1; +import org.simantics.db.tests.api.readGraph.getInverse.GetInverseTest1; +import org.simantics.db.tests.api.readGraph.getInverse.GetInverseTest2; +import org.simantics.db.tests.api.readGraph.getInverse.GetInverseTest3; +import org.simantics.db.tests.api.readGraph.getInverse.GetInverseTest4; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest1; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest21; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest22; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest3; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest4; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest5; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest6; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsTest7; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsWithAssertionsTest3; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsWithAssertionsTest6; +import org.simantics.db.tests.api.readGraph.getObjects.GetObjectsWithAssertionsTest7; +import org.simantics.db.tests.api.readGraph.getPossibleResource.GetPossibleResourceTest1; +import org.simantics.db.tests.api.readGraph.getPossibleResource.GetPossibleResourceTest2; +import org.simantics.db.tests.api.readGraph.getPossibleURI.GetPossibleURITest1; +import org.simantics.db.tests.api.readGraph.getPredicates.GetPredicatesTest1; +import org.simantics.db.tests.api.readGraph.getPredicates.GetPredicatesTest2; +import org.simantics.db.tests.api.readGraph.getPredicates.GetPredicatesTest3; +import org.simantics.db.tests.api.readGraph.getPredicates.GetPredicatesTest4; +import org.simantics.db.tests.api.readGraph.getPredicates.GetPredicatesWithAssertionsTest6; +import org.simantics.db.tests.api.readGraph.getPredicates.PredicatePropertiesTest; +import org.simantics.db.tests.api.readGraph.getPrincipalTypes.GetPrincipalTypesTest1; +import org.simantics.db.tests.api.readGraph.getPrincipalTypes.GetPrincipalTypesTest2; +import org.simantics.db.tests.api.readGraph.getPrincipalTypes.GetPrincipalTypesTest3; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest1; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest10; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest2; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest23; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest24; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest25; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest26; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest27; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest28; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest29; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest3; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest4; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest5; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest6; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest7; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest8; +import org.simantics.db.tests.api.readGraph.getRelatedValue.GetRelatedValueTest9; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest1; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest10; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest11; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest12; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest13; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest14; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest2; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest3; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest4; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest5; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest6; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest7; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest8; +import org.simantics.db.tests.api.readGraph.getResource.GetResourceTest9; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest1; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest2; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest21; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest22; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest23; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest3; +import org.simantics.db.tests.api.readGraph.getSingleObject.GetSingleObjectTest3_bak; +import org.simantics.db.tests.api.readGraph.getSingleStatement.GetSingleStatementTest21; +import org.simantics.db.tests.api.readGraph.getSingleStatement.GetSingleStatementTest22; +import org.simantics.db.tests.api.readGraph.getSingleStatement.GetSingleStatementTest23; +import org.simantics.db.tests.api.readGraph.getSingleStatement.GetSingleStatementTest3; +import org.simantics.db.tests.api.readGraph.getSingleType.GetSingleTypeTest1; +import org.simantics.db.tests.api.readGraph.getSingleType.GetSingleTypeTest2; +import org.simantics.db.tests.api.readGraph.getSingleType.GetSingleTypeTest3; +import org.simantics.db.tests.api.readGraph.getSingleType.GetSingleTypeTest7; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest1; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest2; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest3; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest4; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest5; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest6; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsTest7; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsWithAssertionsTest3; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsWithAssertionsTest6; +import org.simantics.db.tests.api.readGraph.getStatements.GetStatementsWithAssertionsTest7; +import org.simantics.db.tests.api.readGraph.getSuperRelations.GetSuperrelationsTest1; +import org.simantics.db.tests.api.readGraph.getSuperRelations.GetSuperrelationsTest2; +import org.simantics.db.tests.api.readGraph.getSuperRelations.GetSuperrelationsTest3; +import org.simantics.db.tests.api.readGraph.getSuperRelations.GetSuperrelationsTest4; +import org.simantics.db.tests.api.readGraph.getSuperTypes.GetSupertypesTest1; +import org.simantics.db.tests.api.readGraph.getSuperTypes.GetSupertypesTest2; +import org.simantics.db.tests.api.readGraph.getSuperTypes.GetSupertypesTest3; +import org.simantics.db.tests.api.readGraph.getSuperTypes.GetSupertypesTest7; +import org.simantics.db.tests.api.readGraph.getTypes.GetTypesTest1; +import org.simantics.db.tests.api.readGraph.getTypes.GetTypesTest2; +import org.simantics.db.tests.api.readGraph.getTypes.GetTypesTest3; +import org.simantics.db.tests.api.readGraph.getTypes.GetTypesTest7; +import org.simantics.db.tests.api.readGraph.getURI.GetURITest1; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest1; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest2; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest22; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest23; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest24; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest25; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest26; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest3; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest4; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest5; +import org.simantics.db.tests.api.readGraph.getValue.GetValueTest6; +import org.simantics.db.tests.api.readGraph.hasStatement.HasStatementTest1; +import org.simantics.db.tests.api.readGraph.hasStatement.HasStatementTest2; +import org.simantics.db.tests.api.readGraph.hasValue.HasValueTest1; +import org.simantics.db.tests.api.readGraph.isInheritedFrom.IsInheritedFromTest1; +import org.simantics.db.tests.api.readGraph.isInstanceOf.IsInstanceOfTest1; +import org.simantics.db.tests.api.readGraph.isSubrelationOf.IsSubrelationOfTest1; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + AdaptionFailureTest.class, + AdaptTest3.class, + AdaptTest4.class, + AdaptRelatedTest2.class, + AdaptRelatedTest3.class, + AdaptUniqueTest2.class, + ForEachObjectTest1.class, + ForObjectSetTest1.class, + GetAssertedObjectsTest1.class, + GetAssertedObjectsTest2.class, + GetAssertedObjectsTest3.class, + GetAssertedObjectsTest4.class, + GetAssertedObjectsTest5.class, + GetAssertedObjectsTest6.class, + GetAssertedObjectsTest7.class, + GetAssertedStatementsTest1.class, + GetAssertedStatementsTest2.class, + GetAssertedStatementsTest3.class, + GetAssertedStatementsTest4.class, + GetAssertedStatementsTest5.class, + GetAssertedStatementsTest6.class, + GetAssertedStatementsTest7.class, + GetBuiltinTest1.class, + GetInverseTest1.class, + GetInverseTest2.class, + GetInverseTest3.class, + GetInverseTest4.class, + GetObjectsTest1.class, + GetObjectsTest21.class, + GetObjectsTest22.class, + GetObjectsTest3.class, + GetObjectsTest4.class, + GetObjectsTest5.class, + GetObjectsTest6.class, + GetObjectsTest7.class, + GetObjectsWithAssertionsTest3.class, + GetObjectsWithAssertionsTest6.class, + GetObjectsWithAssertionsTest7.class, + GetPossibleResourceTest1.class, + GetPossibleResourceTest2.class, + GetPossibleURITest1.class, + GetPredicatesTest1.class, + GetPredicatesTest2.class, + GetPredicatesTest3.class, + GetPredicatesTest4.class, + GetPredicatesWithAssertionsTest6.class, + PredicatePropertiesTest.class, + GetPrincipalTypesTest1.class, + GetPrincipalTypesTest2.class, + GetPrincipalTypesTest3.class, + GetRelatedValueTest1.class, + GetRelatedValueTest10.class, + GetRelatedValueTest2.class, + GetRelatedValueTest23.class, + GetRelatedValueTest24.class, + GetRelatedValueTest25.class, + GetRelatedValueTest26.class, + GetRelatedValueTest27.class, + GetRelatedValueTest28.class, + GetRelatedValueTest29.class, + GetRelatedValueTest3.class, + GetRelatedValueTest4.class, + GetRelatedValueTest5.class, + GetRelatedValueTest6.class, + GetRelatedValueTest7.class, + GetRelatedValueTest8.class, + GetRelatedValueTest9.class, + GetResourceTest1.class, + GetResourceTest10.class, + GetResourceTest11.class, + GetResourceTest12.class, + GetResourceTest13.class, + GetResourceTest14.class, + GetResourceTest2.class, + GetResourceTest3.class, + GetResourceTest4.class, + GetResourceTest5.class, + GetResourceTest6.class, + GetResourceTest7.class, + GetResourceTest8.class, + GetResourceTest9.class, + GetSingleObjectTest1.class, + GetSingleObjectTest2.class, + GetSingleObjectTest21.class, + GetSingleObjectTest22.class, + GetSingleObjectTest23.class, + GetSingleObjectTest3_bak.class, + GetSingleObjectTest3.class, + GetSingleStatementTest21.class, + GetSingleStatementTest22.class, + GetSingleStatementTest23.class, + GetSingleStatementTest3.class, + GetSingleTypeTest1.class, + GetSingleTypeTest2.class, + GetSingleTypeTest3.class, + GetSingleTypeTest7.class, + GetStatementsTest1.class, + GetStatementsTest2.class, + GetStatementsTest3.class, + GetStatementsTest4.class, + GetStatementsTest5.class, + GetStatementsTest6.class, + GetStatementsTest7.class, + GetStatementsWithAssertionsTest3.class, + GetStatementsWithAssertionsTest6.class, + GetStatementsWithAssertionsTest7.class, + GetSuperrelationsTest1.class, + GetSuperrelationsTest2.class, + GetSuperrelationsTest3.class, + GetSuperrelationsTest4.class, + GetSupertypesTest1.class, + GetSupertypesTest2.class, + GetSupertypesTest3.class, + GetSupertypesTest7.class, + GetTypesTest1.class, + GetTypesTest2.class, + GetTypesTest3.class, + GetTypesTest7.class, + GetURITest1.class, + GetValueTest1.class, + GetValueTest2.class, + GetValueTest22.class, + GetValueTest23.class, + GetValueTest24.class, + GetValueTest25.class, + GetValueTest26.class, + GetValueTest3.class, + GetValueTest4.class, + GetValueTest5.class, + GetValueTest6.class, + HasStatementTest1.class, + HasStatementTest2.class, + HasValueTest1.class, + IsInheritedFromTest1.class, + IsInstanceOfTest1.class, + IsSubrelationOfTest1.class +}) +public class SuiteReadGraph { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest3.java new file mode 100644 index 000000000..32f12978c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest3.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adapt; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptTest3 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedTypelessResource(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + String s = graph.adapt(written, String.class); + assertTrue("adapt must never return null", s!=null); + } catch (AdaptionException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest4.java new file mode 100644 index 000000000..7b8befc81 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest4.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adapt; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptTest4 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedTypelessResource(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + + String s = graph + .syncRequest(new ResourceAsyncRead(written) { + @Override + public void perform(AsyncReadGraph graph, + AsyncProcedure procedure) { + graph.forAdapted(resource, String.class, procedure); + } + }); + assertTrue("adapt must never return null", s != null); + } catch (AdaptionException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptionFailureTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptionFailureTest.java new file mode 100644 index 000000000..4fa898fdb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptionFailureTest.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adapt; + +import org.junit.Before; +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.Read; +import org.simantics.db.services.GlobalServiceInitializer; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptionFailureTest extends ExistingDatabaseTest { + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + new GlobalServiceInitializer().initialize(getSession()); + } + + private Resource writeTypeless(Session session) throws DatabaseException { + final Resource[] typeless = { null }; + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource tless = graph.newResource(); + Resource name = graph.newResource(); + graph.claim(name, l0.InstanceOf, null, l0.String); + graph.claimValue(name, "A Typeless Resource"); + graph.claim(tless, l0.HasName, name); + typeless[0] = tless; + } + }); + return typeless[0]; + } + + static abstract class Adapter { + String name; + + public Adapter(String name) { + this.name = name; + } + + public abstract T adapt(ReadGraph graph, Resource r, Class clazz) throws DatabaseException; + + @Override + public String toString() { + return name; + } + } + + private void adaptTester(final Adapter adapter) throws DatabaseException { + final Session session = getSession(); + final Resource typeless = writeTypeless(session); + try { + String s = session.syncRequest(new Read() { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + try { + return adapter.adapt(graph, typeless, String.class); + } catch (AdaptionException e) { + throw e; + } catch (DatabaseException e) { + throw new DatabaseException("AdaptionException expected, got " + e, e); + } + } + }); + + if (s == null) + fail(adapter + " must never return null"); + } catch (AdaptionException e) { + // Failure with AdaptionException is expected + if (DEBUG) + System.out.println("Expected failure message: " + e.getMessage()); + } + } + + @Test + public void testAdapt() throws DatabaseException{ + adaptTester(new Adapter("ReadGraph.adapt") { + @Override + public T adapt(ReadGraph graph, Resource resource, Class clazz) throws DatabaseException { + return graph.adapt(resource, clazz); + } + }); + } + + @Test + public void testAdaptUnique() throws DatabaseException{ + adaptTester(new Adapter("ReadGraph.adaptUnique") { + @Override + public T adapt(ReadGraph graph, Resource resource, Class clazz) throws DatabaseException { + return graph.adaptUnique(resource, clazz); + } + }); + } + + @Test + public void testforAdapted() throws DatabaseException{ + adaptTester(new Adapter("AsyncReadGraph.forAdapted") { + @Override + public T adapt(ReadGraph graph, Resource resource, final Class clazz) throws DatabaseException { + return graph.syncRequest(new ResourceAsyncRead(resource) { + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + graph.forAdapted(resource, clazz, procedure); + } + }); + } + }); + } + + @Test + public void testforUniqueAdapted() throws DatabaseException{ + adaptTester(new Adapter("AsyncReadGraph.forUniqueAdapted") { + @Override + public T adapt(ReadGraph graph, Resource resource, final Class clazz) throws DatabaseException { + return graph.syncRequest(new ResourceAsyncRead(resource) { + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + graph.forUniqueAdapted(resource, clazz, procedure); + } + }); + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest2.java new file mode 100644 index 000000000..f54fc8922 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest2.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adaptRelated; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptRelatedTest2 extends WriteReadTest { + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedConsiststOfString(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.adaptRelated(written, L0.ConsistsOf, String.class)); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest3.java new file mode 100644 index 000000000..572aae34b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptRelated/AdaptRelatedTest3.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adaptRelated; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptRelatedTest3 extends WriteReadTest { + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedTypelessConsistsOf(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.adaptRelated(written, L0.ConsistsOf, String.class)); + } catch (AdaptionException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptUnique/AdaptUniqueTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptUnique/AdaptUniqueTest2.java new file mode 100644 index 000000000..62e7b8ac5 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adaptUnique/AdaptUniqueTest2.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.adaptUnique; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)}, + * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)}, + * AsyncReadGraph.forAdapted fail as expected. + * + *

+ * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617 + * + * @author Tuukka Lehtonen + */ +public class AdaptUniqueTest2 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedTypelessResource(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.adaptUnique(written, String.class)); + } catch (AdaptionException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/common/Ontologies.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/common/Ontologies.java new file mode 100644 index 000000000..1d944007f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/common/Ontologies.java @@ -0,0 +1,326 @@ +package org.simantics.db.tests.api.readGraph.common; + +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.tests.common.Writes; +import org.simantics.layer0.Layer0; + +/* Provides simple ontologies for unit tests of various functionalities of + * ReadGraph and WriteGraph methods. + */ +public class Ontologies { + // 1 + public static Resource typeMultipleSupertype(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + // New type with assertions + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + Resource named1 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named2 = Writes.named(graph, UUID.randomUUID().toString()); + graph.claim(type, L0.SupertypeOf, named1); + graph.claim(type, L0.SupertypeOf, named2); + return type; + + } + + // 2 + public static Resource typeInherited(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + // Create first resource and give it a name + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + graph.claim(type, L0.HasName, string1); + + // Create second resource and give it a name + Resource type2 = graph.newResource(); + Resource string2 = Writes.string(graph, UUID.randomUUID().toString()); + graph.claim(type2, L0.HasName, string2); + + // second resource inherits from first resource + graph.claim(type2, L0.Inherits, type); + return type; + } + + // 3 + public static Resource typeMultipleFunctional(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + Resource string2 = Writes.string(graph, UUID.randomUUID().toString()); + Resource string3 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.HasName, string1); + graph.claim(type, L0.HasName, string2); + graph.claim(type, L0.HasName, string3); + return type; + } + + // 4 + public static Resource typeMultipleInheritance(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + // New type with assertions + Resource type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + Resource type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + Resource type = graph.newResource(); + + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + Resource string2 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type2, L0.InstanceOf, string1); + graph.claim(type3, L0.InstanceOf, string2); + + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + return type; + } + + // 5 + public static Resource typeMultipleInheritanceConsistsOf(Layer0 L0, + WriteGraph graph) throws DatabaseException { + + Resource type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + Resource type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + Resource named1 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named2 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named3 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named4 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named5 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named6 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.ConsistsOf, named1); + graph.claim(type, L0.ConsistsOf, named2); + graph.claim(type2, L0.ConsistsOf, named3); + graph.claim(type2, L0.ConsistsOf, named4); + graph.claim(type3, L0.ConsistsOf, named5); + graph.claim(type3, L0.ConsistsOf, named6); + return type; + } + + // 6 + public static Resource typeConsistsOfInheritance(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + Resource type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + Resource type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + Resource named1 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.ConsistsOf, named1); + graph.claim(type2, L0.ConsistsOf, named1); + graph.claim(type3, L0.ConsistsOf, named1); + return type; + + } + + + public static Resource typeX(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + // New type with assertions + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + Resource named1 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named2 = Writes.named(graph, UUID.randomUUID().toString()); + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert some nonfunctional objects + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, named2)); + + // Assert a functional object + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.HasName, string1)); + return type; + } + + // 7 + public static Resource typeCyclicInheritance(Layer0 L0, WriteGraph graph) + throws DatabaseException { + // Create first resource and give it a name + Resource type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + graph.claim(type1, L0.HasName, string1); + + // Create second resource and give it a name + Resource type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + + Resource string2 = Writes.string(graph, UUID.randomUUID().toString()); + graph.claim(type2, L0.HasName, string2); + + // Create third resource and give it a name + Resource type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + + string2 = Writes.string(graph, UUID.randomUUID().toString()); + graph.claim(type2, L0.HasName, string2); + + // second resource inherits from first resource + graph.claim(type2, L0.Inherits, type1); + // third resource inherits from second resource + graph.claim(type3, L0.Inherits, type2); + // Completing loop: first resource inherits from third resource + graph.claim(type1, L0.Inherits, type3); + return type1; + } + + // assertion3 + public static Resource typeMultipleFunctionalAssertions(Layer0 L0, + WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + Resource string2 = Writes.string(graph, UUID.randomUUID().toString()); + Resource string3 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.HasName, string1)); + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.HasName, string2)); + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.HasName, string3)); + return type; + } + + // assertion6 + public static Resource typeFunctionalAndNonFunctionalAssertions(Layer0 L0, + WriteGraph graph) throws DatabaseException { + + // New type with assertions + Resource type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + Resource named1 = Writes.named(graph, UUID.randomUUID().toString()); + Resource named2 = Writes.named(graph, UUID.randomUUID().toString()); + Resource string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert some nonfunctional objects + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, named2)); + + // Assert a functional object + graph.claim(type, L0.Asserts, + Writes.assertion(graph, L0.HasName, string1)); + return type; + } + + //assertion7 + public static Resource typeCyclicAssertion(Layer0 L0, WriteGraph graph) + throws DatabaseException { + + // New type with assertions + Resource type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + Resource type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + graph.claim(type1, L0.HasName, + Writes.string(graph, UUID.randomUUID().toString())); + + // named1 = Writes.named(graph, UUID.randomUUID().toString()); + // named2 = Writes.named(graph, UUID.randomUUID().toString()); + + // Assert some nonfunctional objects + graph.claim(type1, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, type2)); + graph.claim(type2, L0.Asserts, + Writes.assertion(graph, L0.ConsistsOf, type1)); + + return type1; + } + public static Resource blankInstanceofEntity(Layer0 L0, WriteGraph graph) + throws DatabaseException { + Resource resource = graph.newResource(); + graph.claim(resource, L0.InstanceOf, null, L0.Entity); + return resource; + } + public static Resource relatedTypelessResource(Layer0 L0, WriteGraph graph) + throws DatabaseException { + Resource resource = graph.newResource(); + Resource name = graph.newResource(); + graph.claim(name, L0.InstanceOf, null, L0.String); + graph.claimValue(name, "A Typeless Resource"); + graph.claim(resource, L0.HasName, name); + return resource; + } + public static Resource relatedConsiststOfString(Layer0 L0, WriteGraph graph) + throws DatabaseException { + Resource instance = graph.newResource(); + Resource resource = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.String); + graph.claimValue(instance, "Test String"); + graph.claim(resource, L0.ConsistsOf, instance); + return resource; + } + public static Resource relatedTypelessConsistsOf(Layer0 L0, WriteGraph graph) + throws DatabaseException { + Resource resource1 = graph.newResource(); + Resource resource2 = graph.newResource(); + Resource name = graph.newResource(); + graph.claim(name, L0.InstanceOf, null, L0.String); + graph.claimValue(name, "A Typeless Resource"); + graph.claim(resource1, L0.HasName, name); + graph.claim(resource2, L0.ConsistsOf, resource1); + return resource2; + } + /* Type testing + public static Resource value1(Layer0 L0, WriteGraph graph) throws DatabaseException { + + assertTrue(g.getValue(l0.True)); + try { + g.getValue(l0.Entity); + } catch (DoesNotContainValueException e) { + return; + } + fail("GetValue did not throw DoesNotContainValueException."); + } + + } + public static Resource value2(Layer0 L0, WriteGraph graph) throws DatabaseException { + s.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// g.getValue(null, null); + assertTrue(g.getValue(l0.True, Bindings.BOOLEAN)); + try { + g.getValue(l0.Entity, Bindings.BOOLEAN); + } catch (DoesNotContainValueException e) { + return; + } + fail("GetValue did not throw DoesNotContainValueException."); + } + }); + } + */ +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forEachObject/ForEachObjectTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forEachObject/ForEachObjectTest1.java new file mode 100644 index 000000000..7cd4791d7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forEachObject/ForEachObjectTest1.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.forEachObject; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.AsyncReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class ForEachObjectTest1 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + final Layer0 L0 = Layer0.getInstance(session); + + final Resource res = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Resource part = graph.newResource(); + graph.addLiteral(part, L0.HasName, L0.NameOf, L0.String, "A", Bindings.STRING); + graph.addLiteral(part, L0.HasName, L0.NameOf, L0.String, "B", Bindings.STRING); + return part; + + } + + }); + + final AtomicInteger finished = new AtomicInteger(0); + final AtomicInteger execute = new AtomicInteger(0); + final AtomicInteger exception = new AtomicInteger(0); + final DataContainer throwable = new DataContainer(); + + session.syncRequest(new AsyncReadRequest() { + + @Override + public void run(AsyncReadGraph graph) { + + graph.forEachObject(res, L0.HasName, new AsyncMultiProcedure() { + + @Override + public void finished(AsyncReadGraph graph) { + finished.incrementAndGet(); + } + + @Override + public void execute(AsyncReadGraph graph, Resource result) { + execute.incrementAndGet(); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + exception.incrementAndGet(); + throwable.set(t); + } + + }); + + } + + }); + + if(finished.get() != 1) fail("finished was not 1"); + if(execute.get() != 2) fail("execute was not 2 (was " + execute.get() + ")"); + if(exception.get() != 0) fail("exception was not 0 (was " + exception.get() + ")"); + if(throwable.get() != null) fail("there was a throwable"); + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forObjectSet/ForObjectSetTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forObjectSet/ForObjectSetTest1.java new file mode 100644 index 000000000..1a6a3a0b4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/forObjectSet/ForObjectSetTest1.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.forObjectSet; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncSetListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class ForObjectSetTest1 extends ExistingDatabaseTest { + + private Throwable exception; + private Resource relation; + private int adds = 0; + private int removes = 0; + + @Test + public void testObjectSet() throws Exception { + + Session session = getSession(); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + + relation = graph.newResource(); + graph.claim(relation, b.SubrelationOf, b.IsRelatedTo); + graph.claim(relation, b.InverseOf, relation); + + graph.forObjectSet(graph.getRootLibrary(), relation, new AsyncSetListener() { + + @Override + public void add(AsyncReadGraph graph, Resource result) { + synchronized(this) { + adds++; + } + } + + @Override + public void remove(AsyncReadGraph graph, Resource result) { + synchronized(this) { + removes++; + } + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + exception = t; + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + } + + }); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + // Add + g.claim(g.getRootLibrary(), relation, b.Abstract); + + } + + }); + + assert(adds == 1 && removes == 0); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + // Nop + g.claim(g.getRootLibrary(), relation, b.Abstract); + + } + + }); + + assert(adds == 1 && removes == 0); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + // Remove + g.deny(g.getRootLibrary(), relation, b.Abstract); + + } + + }); + + assert(adds == 1 && removes == 1); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + // Nop + g.deny(g.getRootLibrary(), relation, b.Abstract); + + } + + }); + + assert(adds == 1 && removes == 1); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + // nop + g.claim(g.getRootLibrary(), relation, b.Abstract); + g.deny(g.getRootLibrary(), relation, b.Abstract); + + } + + }); + + assert(adds == 1 && removes == 1); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest1.java new file mode 100644 index 000000000..dcd7ed5c7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest1.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest1 extends WriteReadTest { + + private Resource type; + private Resource named1; + private Resource named2; + private Resource string1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert some nonfunctional objects + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named2)); + + // Assert a functional object + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedObjects(type, L0.ConsistsOf); + assertNotNull("Null not allowed", result); + assert(result.size() == 2); + assert(result.contains(named1)); + assert(result.contains(named2)); + + Collection names = graph.getAssertedObjects(type, L0.HasName); + + assert(names.size() == 1); + assert(names.contains(string1)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest2.java new file mode 100644 index 000000000..0dca6f039 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest2.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest2 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert functional object + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + + // New type with assertions + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, type); + + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert functional object + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedObjects(type2, L0.HasName); + assertNotNull("Null not allowed", result); + assertTrue(result.size() == 1); + assertTrue(result.contains(string2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest3.java new file mode 100644 index 000000000..6ad4ac82d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest3.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert two functional objects + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + try { + assertNotNull("Null not allowed", graph.getAssertedObjects(type, L0.HasName)); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } + + fail("Should throw."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest4.java new file mode 100644 index 000000000..b6c6ccc40 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest4.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest4 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert two functional objects + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection resources = graph.getAssertedObjects(type, L0.HasName); + assertNotNull("Null not allowed", resources); + assertTrue("Must return both objects.", 2 == resources.size()); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest5.java new file mode 100644 index 000000000..60de22ed9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest5.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest5 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource named2; + private Resource named3; + private Resource named4; + private Resource named5; + private Resource named6; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + named3 = Writes.named(graph, UUID.randomUUID().toString()); + named4 = Writes.named(graph, UUID.randomUUID().toString()); + named5 = Writes.named(graph, UUID.randomUUID().toString()); + named6 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named3)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named4)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named5)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named6)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedObjects(type, L0.ConsistsOf); + assertNotNull("Null not allowed", result); + assertTrue(result.contains(named1)); + assertTrue(result.contains(named2)); + assertTrue(result.contains(named3)); + assertTrue(result.contains(named4)); + assertTrue(result.contains(named5)); + assertTrue(result.contains(named6)); + assertTrue(result.size() == 6); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest6.java new file mode 100644 index 000000000..b958706d6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest6.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedObjectsTest6 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource named1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedObjects(type, L0.ConsistsOf); + assertNotNull("Null not allowed", result); + assertTrue(result.contains(named1)); + assertTrue(result.size() == 1); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest7.java new file mode 100644 index 000000000..a2d7bc93b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedObjects/GetAssertedObjectsTest7.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedObjects; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; +//Cyclic assertion +public class GetAssertedObjectsTest7 extends WriteReadTest { + + private Resource type1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeCyclicAssertion(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getAssertedObjects(type1, L0.HasName)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest1.java new file mode 100644 index 000000000..5b3c808c7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest1.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest1 extends WriteReadTest { + + private Resource type; + private Resource named1; + private Resource named2; + private Resource string1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert some nonfunctional objects + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named2)); + + // Assert a functional object + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedStatements(type, L0.ConsistsOf); + assertNotNull("Null not allowed", result); + assertTrue(result.size() == 2); + assertTrue(Tests.contains(result, L0.ConsistsOf, named1)); + assertTrue(Tests.contains(result, L0.ConsistsOf, named2)); + Collection names = graph.getAssertedStatements(type, L0.HasName); + assertTrue(names.size() == 1); + assertTrue(Tests.contains(names, L0.HasName, string1)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest2.java new file mode 100644 index 000000000..9223518a1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest2.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest2 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert functional object + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + + // New type with assertions + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, type); + + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert functional object + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getAssertedStatements(type2, L0.HasName); + assertNotNull("Null not allowed", result); + assertTrue(result.size() == 1); + assertTrue(Tests.contains(result, L0.HasName, string2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest3.java new file mode 100644 index 000000000..13b9f6b06 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest3.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert two functional objects + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + try { + assertNotNull("Null not allowed", graph.getAssertedStatements(type, L0.HasName)); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } + fail("Should throw."); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest4.java new file mode 100644 index 000000000..1ef5381fd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest4.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest4 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + // Assert two functional objects + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.HasName, string1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.HasName, string2)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection stms = graph.getAssertedStatements(type, L0.HasName); + assertNotNull("Null not allowed", stms); + assertTrue("Must return both objects.", 2 == stms.size()); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest5.java new file mode 100644 index 000000000..e8973189c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest5.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest5 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource named2; + private Resource named3; + private Resource named4; + private Resource named5; + private Resource named6; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + named3 = Writes.named(graph, UUID.randomUUID().toString()); + named4 = Writes.named(graph, UUID.randomUUID().toString()); + named5 = Writes.named(graph, UUID.randomUUID().toString()); + named6 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named3)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named4)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named5)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named6)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getAssertedStatements(type, L0.ConsistsOf); + assertNotNull("Null not allowed", results); + assertTrue(Tests.contains(results, L0.ConsistsOf, named1)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named2)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named3)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named4)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named5)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named6)); + assertTrue(results.size() == 6); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest6.java new file mode 100644 index 000000000..c6a15a6fd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest6.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.common.Writes; + +public class GetAssertedStatementsTest6 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource named1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, type2); + graph.claim(type, L0.Inherits, type3); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getAssertedStatements(type, L0.ConsistsOf); + assertNotNull("Null not allowed", result); + assertTrue(Tests.contains(result, type, L0.ConsistsOf, named1)); +// assertTrue(Tests.contains(result, type2, L0.ConsistsOf, named1)); +// assertTrue(Tests.contains(result, type3, L0.ConsistsOf, named1)); + assertTrue(result.size() == 1); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest7.java new file mode 100644 index 000000000..afc42a197 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getAssertedStatements/GetAssertedStatementsTest7.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getAssertedStatements; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +//Cyclic assertion + +@Fails +public class GetAssertedStatementsTest7 extends WriteReadTest { + + private Resource type1; + private Resource type2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + graph.claim(type1, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + // Assert some nonfunctional objects + graph.claim(type1, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, type2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, type1)); + + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getAssertedStatements(type1, L0.ConsistsOf)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getBuiltin/GetBuiltinTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getBuiltin/GetBuiltinTest1.java new file mode 100644 index 000000000..6f3407d30 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getBuiltin/GetBuiltinTest1.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getBuiltin; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetBuiltinTest1 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + //Not implemented + assertTrue(true); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest1.java new file mode 100644 index 000000000..1c5f52f44 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest1.java @@ -0,0 +1,28 @@ +package org.simantics.db.tests.api.readGraph.getInverse; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.Inverse; +import org.simantics.db.exception.NoInverseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.tests.common.Writes; + +/* + * When a resource does not specify L0.InverseOf, getInverse shall throw NoInverseException. + */ +public class GetInverseTest1 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + Resource resource = getSession().syncRequest(Writes.newEmpty()); + + try { + assertNotNull("Null not allowed",getSession().syncRequest(new Inverse(resource))); + } catch (NoInverseException e) { + return; + } + fail("Should throw."); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest2.java new file mode 100644 index 000000000..77f14aeb1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest2.java @@ -0,0 +1,37 @@ +package org.simantics.db.tests.api.readGraph.getInverse; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoInverseException; +import org.simantics.db.testing.base.WriteReadTest; + +/* + * When a resource does not specify L0.InverseOf, getInverse shall throw NoInverseException. + */ +public class GetInverseTest2 extends WriteReadTest { + private Resource relation1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + //Create first resource and give it a name + relation1 = graph.newResource(); + graph.claim(relation1, L0.Inherits, L0.Relation); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getInverse(relation1)); + } catch (NoInverseException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest3.java new file mode 100644 index 000000000..fd9f1451c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest3.java @@ -0,0 +1,49 @@ +package org.simantics.db.tests.api.readGraph.getInverse; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.NoInverseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +/* + * When a resource does not specify L0.InverseOf, getInverse shall throw NoInverseException. + */ +public class GetInverseTest3 extends WriteReadTest { + private Resource relation1; + private Resource relation2; + private Resource relation3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + //Create first resource and give it a name + relation1 = graph.newResource(); + graph.claim(relation1, L0.Inherits, L0.Relation); + relation2 = graph.newResource(); + graph.claim(relation2, L0.Inherits, L0.Relation); + graph.claim(relation2, L0.InverseOf, relation1); + + relation3 = graph.newResource(); + graph.claim(relation3, L0.Inherits, L0.Relation); + graph.claim(relation3, L0.InverseOf, relation1); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getInverse(relation1)); + } catch (NoInverseException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.java new file mode 100644 index 000000000..6d7d241af --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.java @@ -0,0 +1,45 @@ +package org.simantics.db.tests.api.readGraph.getInverse; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoInverseException; +import org.simantics.db.testing.base.WriteReadTest; + +/* + * When a resource does not specify L0.InverseOf, getInverse shall throw NoInverseException. + */ +public class GetInverseTest4 extends WriteReadTest { + private Resource relation1; + private Resource relation2; + private Resource relation3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + //Create first resource and give it a name + relation1 = graph.newResource(); + graph.claim(relation1, L0.Inherits, L0.Relation); + relation2 = graph.newResource(); + graph.claim(relation2, L0.Inherits, L0.Relation); + graph.claim(relation1, L0.InverseOf, relation2); + + relation3 = graph.newResource(); + graph.claim(relation3, L0.Inherits, L0.Relation); + graph.claim(relation1, L0.InverseOf, relation3); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getInverse(relation1)); + } catch (NoInverseException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest1.java new file mode 100644 index 000000000..184d15a78 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest1.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetObjectsTest1 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeMultipleSupertype(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getObjects(written, L0.SupertypeOf); + assertNotNull("Null response", results); + int resultsSize = results.size(); + assertTrue("Wrong number of statements: " + resultsSize, + (resultsSize == 2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest21.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest21.java new file mode 100644 index 000000000..a016ec333 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest21.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetObjectsTest21 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + //written = Ontologies.typeInherited(L0, graph); + Resource rl = graph.getRootLibrary(); + assertTrue(graph.getObjects(rl, rl).isEmpty()); + Collection results = graph.getObjects(rl, L0.ConsistsOf); + assertNotNull("Null response", results); + assertFalse(results.isEmpty()); + for (Resource r : results) { + graph.getRelatedValue(r, L0.HasName); + } + assertTrue(graph.getObjects(rl, L0.Entity).isEmpty()); + assertTrue(graph.getObjects(rl, L0.SubrelationOf).isEmpty()); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest22.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest22.java new file mode 100644 index 000000000..154e07348 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest22.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetObjectsTest22 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "A", Bindings.STRING); + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "B", Bindings.STRING); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getObjects(written, L0.ConsistsOf); + assertNotNull("Null response", results); + assertEquals(2, graph.getObjects(written, L0.HasName).size()); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest3.java new file mode 100644 index 000000000..31c5aa9c7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest3.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetObjectsTest3 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctional(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + // Collection results = + assertNotNull("Null response", graph.getObjects(written, L0.HasName)); + // assertTrue("Invalid results", (graph.isInstanceOf(L0.HasName, + // L0.FunctionalRelation))); + // assertTrue("Wrong number of statements: " + results.size(), + // (results.size() == 1)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception"); + } + fail("Should throw."); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest4.java new file mode 100644 index 000000000..771549eb0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest4.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetObjectsTest4 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "A", Bindings.STRING); + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "B", Bindings.STRING); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + assertEquals(2, graph.getObjects(written, L0.HasName).size()); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest5.java new file mode 100644 index 000000000..4e818abab --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest5.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetObjectsTest5 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleInheritanceConsistsOf(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getObjects(written, L0.ConsistsOf); + assertNotNull("Null response", results); + assertTrue(results.size() == 6); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest6.java new file mode 100644 index 000000000..979470326 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest6.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetObjectsTest6 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeConsistsOfInheritance(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getObjects(written, L0.ConsistsOf); + assertNotNull("Null response", results); + //assertTrue(results.contains(named1)); + assertTrue(results.size() == 1); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest7.java new file mode 100644 index 000000000..3687a1007 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsTest7.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +//Cyclic inheritance + +@Fails +public class GetObjectsTest7 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeCyclicInheritance(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + //Collection names = + assertNotNull("Null response",graph.getObjects(written, L0.HasName)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception"); + } + fail("Should throw"); + //assertTrue(names.size() == 1); + //assertTrue("Wrong number of statements: " + names.size(), Tests.contains(names, L0.HasName, string2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest3.java new file mode 100644 index 000000000..6b2163355 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest3.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetObjectsWithAssertionsTest3 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response", graph.getObjects(written, L0.HasName)); + } catch (ServiceException e) { + return; + } catch (Throwable t) { + fail("Wrong exception was thrown " + + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest6.java new file mode 100644 index 000000000..e43bc9c26 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest6.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetObjectsWithAssertionsTest6 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeFunctionalAndNonFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getObjects(written, L0.ConsistsOf); + assertNotNull(results); + assertTrue("Wrong number of results returned: " + results.size(), (results.size() != 2)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest7.java new file mode 100644 index 000000000..16f233190 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getObjects/GetObjectsWithAssertionsTest7.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getObjects; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +//Cyclic assertion + +@Fails +public class GetObjectsWithAssertionsTest7 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeCyclicAssertion(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response",graph.getObjects(written, L0.ConsistsOf)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest1.java new file mode 100644 index 000000000..2e5b5ba31 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest1.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPossibleResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetPossibleResourceTest1 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Resource r = graph.getPossibleResource("http:/"); + assertNotNull("Null response not allowed", r); + String name = graph.getPossibleRelatedValue(r, L0.HasName); + assertTrue(name == null); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest2.java new file mode 100644 index 000000000..3625467c1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleResource/GetPossibleResourceTest2.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPossibleResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetPossibleResourceTest2 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Resource r = graph.getPossibleResource("http://Projects"); + assertNotNull("Null response not allowed", r); + String name = graph.getPossibleRelatedValue(r, L0.HasName); + assertTrue(name != null); + assertTrue("Projects".equals(name)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleURI/GetPossibleURITest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleURI/GetPossibleURITest1.java new file mode 100644 index 000000000..574b2d615 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPossibleURI/GetPossibleURITest1.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPossibleURI; + +import org.junit.Assert; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.layer0.Layer0; + +public class GetPossibleURITest1 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Assert.assertEquals(Layer0.URIs.HasName, graph.getPossibleURI(L0.HasName)); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest1.java new file mode 100644 index 000000000..94074fe53 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest1.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +/* Each resource has HasLabel set, so a subject has one more predicate than exclipitly set. + * + */ +@Fails +public class GetPredicatesTest1 extends WriteReadTest { + + private Resource type; + private Resource named1; + private Resource named2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + // New type with assertions + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + graph.claim(type, L0.ConsistsOf, named1); + graph.claim(type, L0.ConsistsOf, named2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getPredicates(type); + assertNotNull("Null not allowed", result); + int size = result.size(); + assertTrue("Wrong number of predicates: " + size, + (size == 7)); + //assertTrue(Tests.contains(predicates)); + //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest2.java new file mode 100644 index 000000000..8c2b13bc3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest2.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetPredicatesTest2 extends WriteReadTest { + + private Resource type; + private Resource type2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + //Create first resource and give it a name + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(type, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + //Create second resource and give it a name + type2 = graph.newResource(); + graph.claim(type2, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + //second resource inherits from first resource + graph.claim(type, L0.Inherits, type2); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getPredicates(type); + assertNotNull("Null not allowed", result); + int size = result.size(); + assertTrue("Wrong number of predicates: " + size, + (size == 7)); + //assertTrue(Tests.contains(predicates)); + //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest3.java new file mode 100644 index 000000000..bcfef2908 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest3.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetPredicatesTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + private Resource string3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + string3 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.HasName, string1); + graph.claim(type, L0.HasName, string2); + graph.claim(type, L0.HasName, string3); + + } + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getPredicates(type); + assertNotNull("Null not allowed", result); + int size = result.size(); + assertTrue("Wrong number of predicates: " + size, + (size == 7)); + //assertTrue(Tests.contains(predicates)); + //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2)); + } + /* + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection statements = graph.getStatements(type, L0.HasName); + assertTrue("foo", (graph.isInstanceOf(L0.HasName, L0.FunctionalRelation))); + assertTrue("Wrong number of statements: " + statements.size(), + (statements.size() == 1)); + + } +*/ +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest4.java new file mode 100644 index 000000000..f86264ea8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesTest4.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetPredicatesTest4 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource string1; + private Resource string2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.InstanceOf, type2); + graph.claim(type, L0.InstanceOf, type3); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type2, L0.InstanceOf, string1); + graph.claim(type3, L0.InstanceOf, string2); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getPredicates(type); + assertNotNull("Null not allowed", result); + int size = result.size(); + assertTrue("Wrong number of predicates: " + size, + (size == 3)); + //assertTrue(Tests.contains(predicates)); + //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesWithAssertionsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesWithAssertionsTest6.java new file mode 100644 index 000000000..ae9f47980 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/GetPredicatesWithAssertionsTest6.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import java.util.Collection; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetPredicatesWithAssertionsTest6 extends WriteReadTest { + + private Resource type; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource named2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + //type2 = graph.newResource(); + //graph.claim(type2, L0.Inherits, L0.Entity); + //type3 = graph.newResource(); + //graph.claim(type3, L0.Inherits, L0.Entity); + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + //graph.claim(type, L0.Inherits, type2); + //graph.claim(type, L0.Inherits, type3); + + named1 = Writes.named(graph, UUID.randomUUID().toString()); + named2 = Writes.named(graph, UUID.randomUUID().toString()); + + //graph.claim(type, L0.HasName, named1); + //graph.claim(type, L0.ConsistsOf, named2); + + + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1)); + graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, named2)); + // graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, named1)); + + } + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getPredicates(type); + assertNotNull("Null not allowed", result); + + for (Resource r: result) { + System.out.println("Resrouce: " + NameUtils.getSafeName(graph, r, true)); + //System.out.println(TestingUtils.predicateName(L0, graph, r)); + } + int size = result.size(); + assertTrue("Wrong number of predicates: " + size, + (size == 2)); + System.out.println(graph.isSubrelationOf(L0.Inherits, L0.DependsOn)); + + //assertTrue(Tests.contains(predicates)); + //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2)); + } + + /* + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection consists = graph.getAssertedStatements(type, L0.ConsistsOf); + + assertTrue(Tests.contains(consists, type, L0.ConsistsOf, named1)); + assertTrue(Tests.contains(consists, type2, L0.ConsistsOf, named1)); + assertTrue(Tests.contains(consists, type3, L0.ConsistsOf, named1)); + assertTrue(consists.size() == 3); + } + */ +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/PredicatePropertiesTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/PredicatePropertiesTest.java new file mode 100644 index 000000000..b9b835d4a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPredicates/PredicatePropertiesTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPredicates; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class PredicatePropertiesTest extends WriteReadTest { + + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Resource[] predicates = {L0.Asserts, L0.ConsistsOf, L0.DependsOn, L0.HasDataType, + L0.HasLabel, L0.HasName, L0.HasPredicate, L0.HasValueType, L0.Inherits, + L0.InstanceOf, L0.IsRelatedTo, L0.IsWeaklyRelatedTo, L0.SubrelationOf}; + if (DEBUG) + System.out.println("Is Functional:"); + for (int i=0; i result = graph.getPrincipalTypes(instance1); + assertNotNull("Null not allowed", result); + int resultsSize = result.size(); + assertTrue("Null result.", (result != null)); + assertTrue("Wrong types", ((result.contains(type1) && (result.contains(type2))))); + assertTrue("Wrong number of results: " + resultsSize, + (resultsSize == 2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest2.java new file mode 100644 index 000000000..ca01c438d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest2.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPrincipalTypes; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetPrincipalTypesTest2 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + //graph.claim(type3, L0.Inherits, L0.Entity); + + graph.claim(type3, L0.Inherits, type1); + graph.claim(type3, L0.Inherits, type2); + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection result = graph.getPrincipalTypes(instance1); + assertNotNull("Null not allowed", result); + int resultsSize = result.size(); + assertTrue("Null results.", (result != null)); + assertTrue("Wrong types", (result.contains(type3))); + assertTrue("Wrong number of results: " + resultsSize, + (resultsSize == 1)); + } + /* + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getSupertypes(instance1); + int resultsSize = results.size(); + assertTrue("Null results.", (results != null)); + System.out.println(results.contains(L0.Entity) + " " + results.contains(type3)+ + " " + results.contains(type1) + " " + results.contains(type2)); + //Collection labels = graph.getObjects(type3, L0.HasLabel); + //assertTrue("Wrong type" + labels.toArray()[0], results.contains(type1)); + assertTrue("Wrong number of results: " + resultsSize, + (resultsSize == 2)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named1)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named2)); + + + } + */ + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest3.java new file mode 100644 index 000000000..e9baeef00 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getPrincipalTypes/GetPrincipalTypesTest3.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getPrincipalTypes; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetPrincipalTypesTest3 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection result = graph.getPrincipalTypes(instance1); + assertNotNull("Null not allowed", result); + int resultsSize = result.size(); + assertTrue("Null results.", (result != null)); + assertTrue("Wrong types", (result.contains(type3))); + assertTrue("Wrong number of results: " + resultsSize, + (resultsSize == 1)); + } + /* + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getSupertypes(instance1); + int resultsSize = results.size(); + assertTrue("Null results.", (results != null)); + System.out.println(results.contains(L0.Entity) + " " + results.contains(type3)+ + " " + results.contains(type1) + " " + results.contains(type2)); + //Collection labels = graph.getObjects(type3, L0.HasLabel); + //assertTrue("Wrong type" + labels.toArray()[0], results.contains(type1)); + assertTrue("Wrong number of results: " + resultsSize, + (resultsSize == 2)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named1)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named2)); + + + } + */ + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest1.java new file mode 100644 index 000000000..a35e3519b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest1.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest1 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + assertTrue(graph.getValue(L0.True)); + try { + graph.getRelatedValue(L0.Entity, L0.InstanceOf, Bindings.FLOAT); + } catch (DoesNotContainValueException e) { + return; + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest10.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest10.java new file mode 100644 index 000000000..89d55d936 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest10.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +/** + * Checks that NoSingleResultException is thrown. + */ +public class GetRelatedValueTest10 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.blankInstanceofEntity(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getRelatedValue(written, L0.HasLabel); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest2.java new file mode 100644 index 000000000..eeb6ee6f9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest2.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest2 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertTrue(graph.getRelatedValue(L0.True, L0.InstanceOf, Bindings.BOOLEAN)); + graph.getValue(L0.Entity); + } catch (DoesNotContainValueException e) { + return; + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest23.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest23.java new file mode 100644 index 000000000..3651f3cdd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest23.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetRelatedValueTest23 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedConsiststOfString(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getRelatedValue(written, L0.ConsistsOf, Bindings.STRING)); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest24.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest24.java new file mode 100644 index 000000000..8650de63d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest24.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest24 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + private Resource type; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + + graph.claim(instance, L0.InstanceOf, null, L0.Double); + graph.claimValue(instance, floatVal); + graph.claim(type, L0.ConsistsOf, instance); + + } + @Override + + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getRelatedValue(type, L0.ConsistsOf, Bindings.DOUBLE)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest25.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest25.java new file mode 100644 index 000000000..308b83d76 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest25.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest25 extends WriteReadTest { + + private Resource instance; + private Resource type; + private float val[] = {0.1F, 0.2F}; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.FloatArray); + graph.claimValue(instance, val); + graph.claim(type, L0.ConsistsOf, instance); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + float[] result = graph.getRelatedValue(type, L0.ConsistsOf, Bindings.FLOAT_ARRAY); + assertNotNull("Null not allowed", result); + assertTrue("Invalid result", (result.length==2 && result[0]==val[0] && result[1]==val[1])); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest26.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest26.java new file mode 100644 index 000000000..9a7225eae --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest26.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest26 extends WriteReadTest { + private Resource instance; + private Resource type; + private float val[] = {0.1F, 0.2F}; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.DoubleArray); + graph.claimValue(instance, val); + graph.claim(type, L0.ConsistsOf, instance); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getRelatedValue(type, L0.ConsistsOf, Bindings.DOUBLE_ARRAY)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest27.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest27.java new file mode 100644 index 000000000..9a329fc53 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest27.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest27 extends WriteReadTest { + private Float floatVal1 = 0.1F; + private Float floatVal2 = 0.3F; + + private Resource instance1; + private Resource instance2; + + private Resource type; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance1 = graph.newResource(); + instance2 = graph.newResource(); + type = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, null, L0.Float); + graph.claim(instance2, L0.InstanceOf, null, L0.Float); + + graph.claimValue(instance1, floatVal1); + graph.claimValue(instance2, floatVal2); + + graph.claim(type, L0.ConsistsOf, instance1); + graph.claim(type, L0.ConsistsOf, instance2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(type, L0.ConsistsOf, Bindings.FLOAT)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest28.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest28.java new file mode 100644 index 000000000..40ed2f6b4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest28.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; +//Multiple functional asserted values +public class GetRelatedValueTest28 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(written, L0.HasName, Bindings.STRING)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest29.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest29.java new file mode 100644 index 000000000..e82482878 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest29.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; +//Multiple functional asserted values +public class GetRelatedValueTest29 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(written, L0.HasName, Bindings.STRING)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest3.java new file mode 100644 index 000000000..8c1f290d2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest3.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetRelatedValueTest3 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.relatedConsiststOfString(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(written, L0.ConsistsOf)); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest4.java new file mode 100644 index 000000000..ef6481cb2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest4.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest4 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + private Resource type; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.Double); + graph.claimValue(instance, floatVal); + graph.claim(type, L0.ConsistsOf, instance); + } + @Override + + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(type, L0.ConsistsOf)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest5.java new file mode 100644 index 000000000..404fd9b0b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest5.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest5 extends WriteReadTest { + Resource instance; + Resource type; + float val[] = {0.1F, 0.2F}; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.FloatArray); + graph.claimValue(instance, val); + graph.claim(type, L0.ConsistsOf, instance); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + float[] result = graph.getRelatedValue(type, L0.ConsistsOf); + assertNotNull("Null response not allowed", result); + assertTrue("Invalid result", (result.length==2 && result[0]==val[0] && result[1]==val[1])); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest6.java new file mode 100644 index 000000000..7d531cb39 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest6.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest6 extends WriteReadTest { + private Resource instance; + private Resource type; + private float val[] = {0.1F, 0.2F}; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + type = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.DoubleArray); + graph.claimValue(instance, val); + graph.claim(type, L0.ConsistsOf, instance); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(type, L0.ConsistsOf)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest7.java new file mode 100644 index 000000000..9b8452ce0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest7.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetRelatedValueTest7 extends WriteReadTest { + private Float floatVal1 = 0.1F; + private Float floatVal2 = 0.3F; + + private Resource instance1; + private Resource instance2; + + private Resource type; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance1 = graph.newResource(); + instance2 = graph.newResource(); + type = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, null, L0.Float); + graph.claim(instance2, L0.InstanceOf, null, L0.Float); + + graph.claimValue(instance1, floatVal1); + graph.claimValue(instance2, floatVal2); + + graph.claim(type, L0.ConsistsOf, instance1); + graph.claim(type, L0.ConsistsOf, instance2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(type, L0.ConsistsOf)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest8.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest8.java new file mode 100644 index 000000000..1e8c12955 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest8.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +//Multiple functional asserted values +@Fails +public class GetRelatedValueTest8 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeCyclicAssertion(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(written, L0.HasName)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest9.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest9.java new file mode 100644 index 000000000..ce26eb996 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getRelatedValue/GetRelatedValueTest9.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getRelatedValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; +//Multiple functional asserted values +public class GetRelatedValueTest9 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getRelatedValue(written, L0.HasName)); + } catch (NoSingleResultException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest1.java new file mode 100644 index 000000000..55271734e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest1.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest1 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Resource r = graph.getResource("http:/"); + assertNotNull("Null response not allowed", r); + String name = graph.getPossibleRelatedValue(r, L0.HasName); + assertTrue(name == null); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest10.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest10.java new file mode 100644 index 000000000..1abd753ce --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest10.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest10 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest11.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest11.java new file mode 100644 index 000000000..3591efbe0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest11.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest11 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("aaaa://Projects")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest12.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest12.java new file mode 100644 index 000000000..dcb21467c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest12.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetResourceTest12 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + graph.claim(written, L0.InstanceOf, null, L0.Entity); + graph.claim(written, L0.PartOf, graph.getRootLibrary()); + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "A", Bindings.STRING); + graph.addLiteral(written, L0.HasName, L0.NameOf, L0.String, "B", Bindings.STRING); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://A")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest13.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest13.java new file mode 100644 index 000000000..646c77a1f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest13.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetResourceTest13 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + graph.claim(written, L0.InstanceOf, null, L0.Entity); + graph.claim(written, L0.PartOf, graph.getRootLibrary()); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://A")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest14.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest14.java new file mode 100644 index 000000000..4c8dcb4c2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest14.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetResourceTest14 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource root = graph.getResource("http:/"); + Resource part = graph.newResource(); + graph.claim(part, L0.InstanceOf, null, L0.Entity); + graph.claim(part, L0.PartOf, root); + graph.claim(part, L0.HasName, L0.NameOf, graph.newResource()); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://A")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest2.java new file mode 100644 index 000000000..3d222b525 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest2.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest2 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Resource r = graph.getResource("http://Projects"); + assertNotNull("Null response not allowed", r); + String name = graph.getPossibleRelatedValue(r, L0.HasName); + assertTrue(name != null); + assertTrue("Projects".equals(name)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest3.java new file mode 100644 index 000000000..681d89567 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest3.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetResourceTest3 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Resource r = graph.getResource("http://Configuration/PublishedProjectFeatures"); + assertNotNull("Null response not allowed", r); + String name = graph.getPossibleRelatedValue(r, L0.HasName); + assertTrue(name != null); + assertTrue("PublishedProjectFeatures".equals(name)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest4.java new file mode 100644 index 000000000..ca5af068e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest4.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest4 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + try { + assertNotNull("Null response not allowed", graph.getResource("http://Invalid")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest5.java new file mode 100644 index 000000000..144d5223f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest5.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest5 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("https:/")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest6.java new file mode 100644 index 000000000..d404d5986 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest6.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest6 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://Projects/Pum!")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest7.java new file mode 100644 index 000000000..f1d33248e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest7.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest7 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("http://Raks/Poks")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest8.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest8.java new file mode 100644 index 000000000..474061fac --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest8.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest8 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("15´8´85tr +0i kjos9d0a+ 1´+ 1´000>CX+08ff8F´(F@121´4 ´13´r+9")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest9.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest9.java new file mode 100644 index 000000000..d0da6cdf9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getResource/GetResourceTest9.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getResource; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetResourceTest9 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getResource("////////////////////////////////")); + } catch (ResourceNotFoundException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest1.java new file mode 100644 index 000000000..327a66489 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest1.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleObjectTest1 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getSingleObject(written, L0.HasName); + } catch (NoSingleResultException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest2.java new file mode 100644 index 000000000..1579086e2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest2.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleObjectTest2 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getSingleObject(written, L0.HasProperty); + } catch (NoSingleResultException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest21.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest21.java new file mode 100644 index 000000000..dc742dc88 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest21.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleObjectTest21 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(ass1, L0.InstanceOf, null, L0.Assertion); + graph.claim(ass2, L0.InstanceOf, null, L0.Assertion); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getSingleObject(written, L0.HasName)); + } catch (NoSingleResultException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest22.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest22.java new file mode 100644 index 000000000..da296045c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest22.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleObjectTest22 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(ass1, L0.InstanceOf, null, L0.Assertion); + graph.claim(ass2, L0.InstanceOf, null, L0.Assertion); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getSingleObject(written, L0.HasProperty)); + } catch (NoSingleResultException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest23.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest23.java new file mode 100644 index 000000000..f1e4fb9e1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest23.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class GetSingleObjectTest23 extends WriteReadTest { + private Resource subject1; + private Resource relation1; + private Resource object1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + relation1 = graph.newResource(); + graph.claim(relation1, L0.SubrelationOf, L0.IsRelatedTo); + + //Resource rel2 = graph.newResource(); + //graph.claim(rel2, L0.SubrelationOf, relation1); + + subject1 = graph.newResource(); + graph.claim(subject1, L0.InstanceOf, L0.Entity); + + object1 = graph.newResource(); + Resource o2 = graph.newResource(); + + graph.claim(subject1, relation1, object1); + graph.claim(subject1, relation1, o2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + + Resource result = graph.getSingleObject(subject1, relation1); + assertNotNull("Null not allowed", result); + assertFalse("Wrong object was returned", (object1.equals(result))); + + } catch (NoSingleResultException e) { + //System.out.println("Read transaction threw an expected exception " + // + e); + return; + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + fail("Should throw"); + + /* + * try { + * + * graph.claim(subject1, relation1, relation1); + * + * } catch (Throwable e) { + * fail("Write transaction threw an unknown exception " + e); } + */ + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3.java new file mode 100644 index 000000000..1fc71b9e0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetSingleObjectTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + private Resource string3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + string3 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.HasName, string1); + graph.claim(type, L0.HasName, string2); + graph.claim(type, L0.HasName, string3); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getSingleObject(type, L0.HasName)); + } catch (NoSingleResultException e) { + return; + } catch (Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3_bak.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3_bak.java new file mode 100644 index 000000000..358db430f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3_bak.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleObject; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class GetSingleObjectTest3_bak extends ExistingDatabaseTest { + + @Test + public void testSingleObject() throws Exception { + Session session = getSession(); + + final DataContainer nonfunctionalRelation = new DataContainer(); + final DataContainer subject = new DataContainer(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + + Resource rel = graph.newResource(); + graph.claim(rel, b.SubrelationOf, b.IsRelatedTo); + + Resource rel2 = graph.newResource(); + graph.claim(rel2, b.SubrelationOf, rel); + + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + + Resource o1 = graph.newResource(); +// Resource o2 = graph.newResource(); + + graph.claim(s, rel, o1); +// graph.claim(s, rel, o2); + + nonfunctionalRelation.set(rel); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new Read() { + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getSingleObject(subject.get(), nonfunctionalRelation.get()); + } + }, new ListenerAdapter() { + + @Override + public boolean isDisposed() { + return false; + } + + }); + } catch (NoSingleResultException e) { + System.out.println("Read transaction threw an expected exception " + e); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + if (DEBUG) + System.out.println("################################################"); + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claim(subject.get(), nonfunctionalRelation.get(), nonfunctionalRelation.get()); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest21.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest21.java new file mode 100644 index 000000000..62e5d1d2e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest21.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleStatement; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleStatementTest21 extends WriteReadTest { + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(ass1, L0.InstanceOf, null, L0.Assertion); + graph.claim(ass2, L0.InstanceOf, null, L0.Assertion); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed",graph.getSingleStatement(written, L0.HasName)); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest22.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest22.java new file mode 100644 index 000000000..2f7c0b230 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest22.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleStatement; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSingleStatementTest22 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + Resource type = graph.newResource(); + Resource l1 = graph.newResource(); + Resource l2 = graph.newResource(); + Resource ass1 = graph.newResource(); + Resource ass2 = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + graph.claim(ass1, L0.InstanceOf, null, L0.Assertion); + graph.claim(ass2, L0.InstanceOf, null, L0.Assertion); + graph.claim(type, L0.Asserts, ass1); + graph.claim(type, L0.Asserts, ass2); + graph.claim(ass1, L0.HasPredicate, L0.HasName); + graph.claim(ass1, L0.HasObject, l1); + graph.claim(ass2, L0.HasPredicate, L0.HasName); + graph.claim(ass2, L0.HasObject, l2); + graph.claim(written, L0.InstanceOf, null, type); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getSingleStatement(written, L0.HasProperty)); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } catch(Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest23.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest23.java new file mode 100644 index 000000000..47e979312 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest23.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleStatement; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class GetSingleStatementTest23 extends WriteReadTest { + private Resource subject1; + private Resource relation1; + private Resource object1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + relation1 = graph.newResource(); + graph.claim(relation1, L0.SubrelationOf, L0.IsRelatedTo); + + //Resource rel2 = graph.newResource(); + //graph.claim(rel2, L0.SubrelationOf, relation1); + + subject1 = graph.newResource(); + graph.claim(subject1, L0.InstanceOf, L0.Entity); + + object1 = graph.newResource(); + Resource o2 = graph.newResource(); + + graph.claim(subject1, relation1, object1); + graph.claim(subject1, relation1, o2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + + assertNotNull("Null not allowed", graph.getSingleStatement(subject1, relation1)); + //assertTrue("Wrong object was returned", (object1.equals(object))); + + } catch (NoSingleResultException e) { + //System.out.println("Read transaction threw an expected exception " + // + e); + return; + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + fail("Should throw"); + + /* + * try { + * + * graph.claim(subject1, relation1, relation1); + * + * } catch (Throwable e) { + * fail("Write transaction threw an unknown exception " + e); } + */ + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest3.java new file mode 100644 index 000000000..2f905eda4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleStatement/GetSingleStatementTest3.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleStatement; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetSingleStatementTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + private Resource string3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type = graph.newResource(); + graph.claim(type, L0.Inherits, L0.Entity); + + string1 = Writes.string(graph, UUID.randomUUID().toString()); + string2 = Writes.string(graph, UUID.randomUUID().toString()); + string3 = Writes.string(graph, UUID.randomUUID().toString()); + + graph.claim(type, L0.HasName, string1); + graph.claim(type, L0.HasName, string2); + graph.claim(type, L0.HasName, string3); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed",graph.getSingleStatement(type, L0.HasName)); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } catch (Throwable t) { + fail("Wrong exception was thrown " + t.getClass().getCanonicalName()); + } + fail("No exception was thrown!"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest1.java new file mode 100644 index 000000000..403c8bfff --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest1.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleType; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSingleTypeTest1 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf,type1); + graph.claim(instance1, L0.InstanceOf,type2); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed",graph.getSingleType(instance1)); + } catch (NoSingleResultException e) { + return; + } catch (Throwable t) { + fail("Wrong exception"); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest2.java new file mode 100644 index 000000000..b01bec3a5 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest2.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleType; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSingleTypeTest2 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits,type1); + graph.claim(type3, L0.Inherits,type2); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf,type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Resource result = graph.getSingleType(instance1); + assertNotNull("Null not allowed", result); + assertTrue("Wrong type returned", result.equals(type3)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest3.java new file mode 100644 index 000000000..748a5623f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest3.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleType; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetSingleTypeTest3 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + + + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + Resource result = graph.getSingleType(instance1); + assertNotNull("Null not allowed", result); + assertTrue("Wrong type", result.equals(type3)); + return; + } catch (NoSingleResultException e) { + fail("More than single results"); + } catch (Throwable t) { + fail("Wrong exception: " + t.getClass().getCanonicalName()); + } + fail("Should throw"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest7.java new file mode 100644 index 000000000..708263077 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleType/GetSingleTypeTest7.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSingleType; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +//Cyclic assertion + +@Fails +public class GetSingleTypeTest7 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + graph.claim(type1, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + graph.claim(type1, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type1); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null not allowed", graph.getSingleType(instance1, L0.ConsistsOf)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest1.java new file mode 100644 index 000000000..bef8d02dd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest1.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetStatementsTest1 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeMultipleSupertype(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection statements = graph.getStatements(written, L0.SupertypeOf); + int statementsSize = statements.size(); + assertTrue("Wrong number of statements: " + statementsSize, + (statementsSize == 2)); + //ssertTrue(Tests.contains(statements, L0.SupertypeOf, named1)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named2)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest2.java new file mode 100644 index 000000000..5948c18d8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest2.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetStatementsTest2 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeInherited(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getStatements(written, L0.HasName); + assertTrue("Wrong number of statements: " + results.size(), results.size() == 1); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest3.java new file mode 100644 index 000000000..9cfa67568 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest3.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetStatementsTest3 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleFunctional(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getStatements(written, L0.HasName); + //assertTrue("Invalid results", (graph.isInstanceOf(L0.HasName, L0.FunctionalRelation))); + assertTrue("Wrong number of statements: " + results.size(), + (results.size() == 1)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest4.java new file mode 100644 index 000000000..320b22dfa --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest4.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +//Not usable +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetStatementsTest4 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeMultipleInheritance(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getStatements(written, L0.Inherits); + assertTrue("Wrong number of statements: " + results.size(), + (results.size() == 2)); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest5.java new file mode 100644 index 000000000..6ea68c7db --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest5.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetStatementsTest5 extends WriteReadTest { + + + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written = Ontologies.typeMultipleInheritanceConsistsOf(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getStatements(written, L0.ConsistsOf); + /* + assertTrue(Tests.contains(results, L0.ConsistsOf, named1)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named2)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named3)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named4)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named5)); + assertTrue(Tests.contains(results, L0.ConsistsOf, named6)); + */ + if (DEBUG) + System.out.println("results " + results.size()); + assertTrue("Wrong number of results", results.size() == 2); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest6.java new file mode 100644 index 000000000..774e9fcc8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest6.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +public class GetStatementsTest6 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeConsistsOfInheritance(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Collection results = graph.getStatements(written, L0.ConsistsOf); + + //assertTrue("Wrong result", Tests.contains(results, written, L0.ConsistsOf, named1)); + assertTrue("Wrong number of results", results.size() == 1); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest7.java new file mode 100644 index 000000000..d726eb9cf --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsTest7.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +//Cyclic inheritance + +@Fails +public class GetStatementsTest7 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + + private Resource string1; + private Resource string2; + private Resource string3; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + written=Ontologies.typeCyclicInheritance(L0, graph); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + //Collection names = + graph.getStatements(written, L0.HasName); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception"); + } + fail("Should throw"); + //assertTrue(names.size() == 1); + //assertTrue("Wrong number of statements: " + names.size(), Tests.contains(names, L0.HasName, string2)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest3.java new file mode 100644 index 000000000..51a240c46 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest3.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetStatementsWithAssertionsTest3 extends WriteReadTest { + + private Resource type; + private Resource string1; + private Resource string2; + private Resource string3; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeMultipleFunctionalAssertions(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getStatements(type, L0.HasName); + } catch (ManyObjectsForFunctionalRelationException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest6.java new file mode 100644 index 000000000..d3fc8d860 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest6.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; + +@Fails +public class GetStatementsWithAssertionsTest6 extends WriteReadTest { + + private Resource type; + private Resource named1; + private Resource named2; + private Resource string1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeFunctionalAndNonFunctionalAssertions(L0, graph); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Collection results = graph.getStatements(type, L0.ConsistsOf); + assertTrue("Null returned", (results!=null)); + assertTrue("Wrong number of results returned: " + results.size(), (results.size() == 2)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest7.java new file mode 100644 index 000000000..d06abe181 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getStatements/GetStatementsWithAssertionsTest7.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getStatements; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.api.readGraph.common.Ontologies; +//Cyclic assertion +@Fails +public class GetStatementsWithAssertionsTest7 extends WriteReadTest { + + private Resource type1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + written=Ontologies.typeCyclicAssertion(L0, graph); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getStatements(type1, L0.ConsistsOf); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown " + e.getClass().getCanonicalName()); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest1.java new file mode 100644 index 000000000..e5f35c467 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest1.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperRelations; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSuperrelationsTest1 extends WriteReadTest { + private Resource relation1; + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getSuperrelations(L0.HasName); + int resultsSize = results.size(); + //for (Resource r: results) { + // System.out.println(TestingUtils.predicateName(L0, graph, r)); + //} + assertTrue("Wrong number of relations: " + resultsSize, + (resultsSize == 5)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest2.java new file mode 100644 index 000000000..c49062b02 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest2.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperRelations; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSuperrelationsTest2 extends WriteReadTest { + private Resource relation1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + relation1 = graph.newResource(); + //graph.claim(relation1, L0.InstanceOf, L0.Relation); + + graph.claim(relation1, L0.SubrelationOf, L0.HasName); + + + } + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getSuperrelations(relation1); + int resultsSize = results.size(); + //for (Resource r: results) { + // System.out.println(TestingUtils.predicateName(L0, graph, r)); + //} + + assertTrue("Wrong number of relations" + resultsSize, + (resultsSize == 6)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named1)); + //ssertTrue(Tests.contains(statements, L0.SupertypeOf, named2)); + + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest3.java new file mode 100644 index 000000000..41b75dad2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest3.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperRelations; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSuperrelationsTest3 extends WriteReadTest { + + private Resource relation1; + private Resource relation2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + relation1 = graph.newResource(); + relation2 = graph.newResource(); + + graph.claim(relation1, L0.InstanceOf, L0.Relation); + + graph.claim(relation2, L0.SubrelationOf, relation1); + graph.claim(relation1, L0.SubrelationOf, relation2); + + + } + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + graph.getSuperrelations(relation2); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception was thrown"); + } + fail("Should throw"); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest4.java new file mode 100644 index 000000000..69f808132 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperRelations/GetSuperrelationsTest4.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperRelations; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSuperrelationsTest4 extends WriteReadTest { + private Resource relation1; + private Resource relation2; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + relation1 = graph.newResource(); + relation2 = graph.newResource(); + + graph.claim(relation1, L0.InstanceOf, L0.Relation); + + graph.claim(relation2, L0.SubrelationOf, relation1); + + + } + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getSuperrelations(relation2); + int resultsSize = results.size(); + //for (Resource r: results) { + // System.out.println(TestingUtils.predicateName(L0, graph, r)); + //} + + assertTrue("Wrong number of relations" + resultsSize, + (resultsSize == 1)); + //assertTrue(Tests.contains(statements, L0.SupertypeOf, named1)); + //ssertTrue(Tests.contains(statements, L0.SupertypeOf, named2)); + + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest1.java new file mode 100644 index 000000000..70672a3d6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest1.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; + +@Fails +public class GetSupertypesTest1 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf,type1); + graph.claim(instance1, L0.InstanceOf,type2); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set result = graph.getSupertypes(instance1); + assertNotNull("Null not allowed", result); + assertTrue("Wrong number of results: " + result.size(), (result.size() == 1)); + assertTrue("Wrong types: ", (result.contains(L0.Entity))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest2.java new file mode 100644 index 000000000..1adf657e4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest2.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetSupertypesTest2 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits,type1); + graph.claim(type3, L0.Inherits,type2); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set result = graph.getSupertypes(type3); + assertNotNull("Null not allowed", result); + assertTrue("Wrong number of results: " + result.size(), (result.size() == 3)); + assertTrue("Wrong types: ", (result.contains(type1) && (result.contains(type2) && + (result.contains(L0.Entity))))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest3.java new file mode 100644 index 000000000..ecf772bb3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest3.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +@Fails +public class GetSupertypesTest3 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + + + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set result = graph.getSupertypes(instance1); + assertNotNull("Null not allowed", result); + assertTrue("Wrong number of results: " + result.size(), (result.size() == 1)); + assertTrue("Wrong types: ", + (result.contains(L0.Entity))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest7.java new file mode 100644 index 000000000..80670f09e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSuperTypes/GetSupertypesTest7.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getSuperTypes; + +import java.util.Set; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +//Cyclic assertion + +@Fails +public class GetSupertypesTest7 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + graph.claim(type1, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + graph.claim(type1, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type1); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set result = graph.getSupertypes(instance1); + assertNotNull("Null not allowed", result); + assertTrue("Wrong number of results: " + result.size(), (result.size() == 1)); + assertTrue("Wrong types: ", (result.contains(L0.Entity))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest1.java new file mode 100644 index 000000000..e9cd45d29 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest1.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetTypesTest1 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf,type1); + graph.claim(instance1, L0.InstanceOf,type2); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getTypes(instance1); + + assertTrue("Wrong number of results: " + results.size(), (results.size() == 3)); + assertTrue("Wrong types: ", (results.contains(type1) && (results.contains(type2) && + (results.contains(L0.Entity))))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest2.java new file mode 100644 index 000000000..866d371ed --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest2.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetTypesTest2 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits,type1); + graph.claim(type3, L0.Inherits,type2); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf,type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getTypes(instance1); + + assertTrue("Wrong number of results: " + results.size(), (results.size() == 4)); + assertTrue("Wrong types: ", (results.contains(type1) && (results.contains(type2) && + (results.contains(type3) && (results.contains(L0.Entity)))))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest3.java new file mode 100644 index 000000000..c5363c233 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest3.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getTypes; + +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; + +public class GetTypesTest3 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource type3; + private Resource named1; + private Resource instance1; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + type3 = graph.newResource(); + graph.claim(type3, L0.Inherits, L0.Entity); + + + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + graph.claim(type3, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type3); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getTypes(instance1); + + assertTrue("Wrong number of results: " + results.size(), (results.size() == 2)); + assertTrue("Wrong types: ", (results.contains(type3) && + (results.contains(L0.Entity)))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest7.java new file mode 100644 index 000000000..db27bbda2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getTypes/GetTypesTest7.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getTypes; + +import java.util.Set; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.db.tests.common.Writes; +//Cyclic assertion +public class GetTypesTest7 extends WriteReadTest { + + private Resource type1; + private Resource type2; + private Resource instance1; + + + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + // New type with assertions + type1 = graph.newResource(); + graph.claim(type1, L0.Inherits, L0.Entity); + type2 = graph.newResource(); + graph.claim(type2, L0.Inherits, L0.Entity); + graph.claim(type1, L0.HasName, Writes.string(graph, UUID.randomUUID().toString())); + + graph.claim(type1, L0.Asserts, Writes.assertion(graph, L0.Inherits, type2)); + graph.claim(type2, L0.Asserts, Writes.assertion(graph, L0.Inherits, type1)); + instance1 = graph.newResource(); + graph.claim(instance1, L0.InstanceOf, type1); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Set results = graph.getTypes(instance1); + + assertTrue("Wrong number of results: " + results.size(), (results.size() == 2)); + assertTrue("Wrong types: ", (results.contains(type1) && + (results.contains(L0.Entity)))); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getURI/GetURITest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getURI/GetURITest1.java new file mode 100644 index 000000000..e670c97b1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getURI/GetURITest1.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getURI; + +import org.junit.Assert; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.layer0.Layer0; + +public class GetURITest1 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + Assert.assertEquals(Layer0.URIs.HasName, graph.getURI(L0.HasName)); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest1.java new file mode 100644 index 000000000..7f3d0581a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest1.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest1 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + assertTrue(graph.getValue(L0.True)); + try { + graph.getValue(L0.Entity); + } catch (DoesNotContainValueException e) { + return; + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest2.java new file mode 100644 index 000000000..adbf4f0aa --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest2.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest2 extends WriteReadTest { + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + assertTrue(graph.getValue(L0.True, Bindings.BOOLEAN)); + try { + graph.getValue(L0.Entity); + } catch (DoesNotContainValueException e) { + return; + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest22.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest22.java new file mode 100644 index 000000000..f01482531 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest22.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest22 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + assertTrue(graph. getValue(L0.True, Bindings.BOOLEAN)); + try { + assertNotNull("Null response not allowed", graph.getValue(L0.Entity, Bindings.BOOLEAN)); + } catch (DoesNotContainValueException e) { + return; + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest23.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest23.java new file mode 100644 index 000000000..ef643249e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest23.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest23 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.Float); + graph.claimValue(instance, floatVal); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + Float result = graph.getValue(instance, Bindings.FLOAT); + assertNotNull("Null response not allowed", result); + assertTrue(floatVal.equals(result)); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest24.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest24.java new file mode 100644 index 000000000..ed474d6e1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest24.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest24 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.Double); + graph.claimValue(instance, floatVal); + } + @Override + + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getValue(instance, Bindings.DOUBLE)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest25.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest25.java new file mode 100644 index 000000000..5fd197c7d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest25.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest25 extends WriteReadTest { + + Resource instance; + float val[] = {0.1F, 0.2F}; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.FloatArray); + graph.claimValue(instance, val); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + float[] result = graph.getValue(instance, Bindings.FLOAT_ARRAY); + assertNotNull("Null response not allowed", result); + assertTrue("Invalid result", (result.length==2 && result[0]==val[0] && result[1]==val[1])); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest26.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest26.java new file mode 100644 index 000000000..858aec414 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest26.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest26 extends WriteReadTest { + Resource instance; + float val[] = {0.1F, 0.2F}; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.DoubleArray); + graph.claimValue(instance, val); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getValue(instance, Bindings.DOUBLE_ARRAY)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest3.java new file mode 100644 index 000000000..656bd456a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest3.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest3 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.Float); + graph.claimValue(instance, floatVal); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + Float result = graph.getValue(instance); + assertNotNull("Null response not allowed", result); + assertTrue(floatVal.equals(result)); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest4.java new file mode 100644 index 000000000..fece93c5b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest4.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest4 extends WriteReadTest { + private Float floatVal = 0.1F; + private Resource instance; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.Double); + graph.claimValue(instance, floatVal); + } + @Override + + protected void read(ReadGraph graph) throws DatabaseException { + try { + assertNotNull("Null response not allowed", graph.getValue(instance)); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest5.java new file mode 100644 index 000000000..7db93fc64 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest5.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest5 extends WriteReadTest { + + Resource instance; + float val[] = {0.1F, 0.2F}; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.FloatArray); + graph.claimValue(instance, val); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + float[] result = graph.getValue(instance); + assertNotNull("Null response not allowed", result); + assertTrue("Invalid result", (result.length==2 && result[0]==val[0] && result[1]==val[1])); + } catch (Exception e) { + fail("Exception: " + e.getClass().getCanonicalName()); + } + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest6.java new file mode 100644 index 000000000..47c45d9da --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getValue/GetValueTest6.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.getValue; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.testing.base.WriteReadTest; + +public class GetValueTest6 extends WriteReadTest { + Resource instance; + float val[] = {0.1F, 0.2F}; + @Override + protected void write(WriteGraph graph) throws DatabaseException { + instance = graph.newResource(); + graph.claim(instance, L0.InstanceOf, null, L0.DoubleArray); + graph.claimValue(instance, val); + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + try { + /*float[] val1 = */ + assertNotNull("Null response not allowed", graph.getValue(instance)); + //assertTrue("Invalid result", (val1.length==2 && val1[0]==val[0] && val1[1]==val[1])); + } catch (ServiceException e) { + return; + } catch (Exception e) { + fail("Wrong exception: " + e.getClass().getCanonicalName()); + } + fail("Should throw."); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest1.java new file mode 100644 index 000000000..66ea6eda0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest1.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.hasStatement; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; + +public class HasStatementTest1 extends SimpleBase { + @Test + public void testHasStatement() throws DatabaseException { + final Session s = getSession(); + hasStm1(s); + hasStm2(s); + hasStm3(s); + } + private void hasStm1(Session s) throws DatabaseException { + s.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// assertFalse(g.hasStatement(null)); + assertTrue(g.hasStatement(rl)); + assertTrue(g.hasStatement(l0.Entity)); + assertTrue(g.hasStatement(l0.Relation)); + assertTrue(g.hasStatement(l0.Literal)); + assertTrue(g.hasStatement(l0.True)); + } + }); + } + private void hasStm2(Session s) throws DatabaseException { + s.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// assertFalse(g.hasStatement(null, null)); +// assertFalse(g.hasStatement(rl, null)); + assertFalse(g.hasStatement(rl, rl)); + assertTrue(g.hasStatement(l0.Entity, l0.InstanceOf)); + assertTrue(g.hasStatement(l0.Entity, l0.HasProperty)); + assertFalse(g.hasStatement(l0.Entity, l0.SubrelationOf)); + assertFalse(g.hasStatement(l0.Entity, l0.SuperrelationOf)); + } + }); + } + private void hasStm3(Session s) throws DatabaseException { + s.syncRequest(new ReadRequest() { + @SuppressWarnings("deprecation") + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// assertFalse(g.hasStatement(null, null, null)); + assertFalse(g.hasStatement(rl, rl, rl)); + assertFalse(g.hasStatement(rl, l0.InstanceOf, l0.Property)); + assertTrue(g.hasStatement(rl, l0.InstanceOf, l0.Library)); + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java new file mode 100644 index 000000000..859453acb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.hasStatement; + +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class HasStatementTest2 extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + final AtomicReference broken = new AtomicReference(); + final AtomicReference brokenName1 = new AtomicReference(); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource brokenName = graph.newResource(); + graph.claim(brokenName, L0.InstanceOf, null, L0.Entity); + + Resource name1 = graph.newResource(); + Resource name2 = graph.newResource(); + graph.claim(name1, L0.InstanceOf, null, L0.String); + graph.claim(name2, L0.InstanceOf, null, L0.String); + graph.claimValue(name1, "name1"); + graph.claimValue(name1, "name2"); + graph.claim(brokenName, L0.HasName, L0.NameOf, name1); + graph.claim(brokenName, L0.HasName, L0.NameOf, name2); + + broken.set(brokenName); + brokenName1.set(name1); + } + }); + + try { + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + assertTrue( graph.hasStatement(broken.get()) ); + assertFalse( graph.hasStatement(broken.get(), L0.HasLabel, brokenName1.get()) ); + assertFalse( graph.hasStatement(broken.get(), L0.HasLabel) ); + assertTrue( graph.hasStatement(broken.get(), L0.IsWeaklyRelatedTo, brokenName1.get()) ); + assertTrue( graph.hasStatement(broken.get(), L0.IsWeaklyRelatedTo) ); + assertTrue( graph.hasStatement(broken.get(), L0.HasName, brokenName1.get()) ); + assertTrue( graph.hasStatement(broken.get(), L0.HasName) ); + } + }); + + } catch (DatabaseException t) { + + t.printStackTrace(); + fail("syncRequest(Read) threw unexpected DatabaseException " + t); + + } catch (Throwable t) { + + t.printStackTrace(); + fail("syncRequest(Read) threw unexpected throwable " + t); + + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasValue/HasValueTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasValue/HasValueTest1.java new file mode 100644 index 000000000..628c1e896 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasValue/HasValueTest1.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.hasValue; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; +public class HasValueTest1 extends SimpleBase { + @Test + public void testHasValue() throws DatabaseException { + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// assertFalse(g.hasValue(null)); + assertFalse(g.hasValue(rl)); + assertFalse(g.hasValue(l0.Entity)); + assertFalse(g.hasValue(l0.Boolean)); + assertTrue(g.hasValue(l0.True)); + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInheritedFrom/IsInheritedFromTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInheritedFrom/IsInheritedFromTest1.java new file mode 100644 index 000000000..eec9bc05f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInheritedFrom/IsInheritedFromTest1.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.isInheritedFrom; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; +public class IsInheritedFromTest1 extends SimpleBase { + @Test + public void testInheritedFrom() throws DatabaseException { + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// g.isInheritedFrom(null, null); +// g.isInheritedFrom(rl, null); + assertTrue(g.isInheritedFrom(rl, rl)); + assertFalse(g.isInheritedFrom(rl, l0.Relation)); + assertFalse(g.isInheritedFrom(rl, l0.Entity)); + assertFalse(g.isInheritedFrom(rl, l0.Library)); + assertFalse(g.isInheritedFrom(rl, l0.Ontology)); + assertFalse(g.isInheritedFrom(rl, l0.Relation)); + assertTrue(g.isInheritedFrom(l0.Relation, l0.Relation)); + assertTrue(g.isInheritedFrom(l0.Relation, l0.Entity)); + assertTrue(g.isInheritedFrom(l0.Ontology, l0.Library)); + assertTrue(g.isInheritedFrom(l0.Ontology, l0.Entity)); + assertTrue(g.isInheritedFrom(l0.Library, l0.Entity)); + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInstanceOf/IsInstanceOfTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInstanceOf/IsInstanceOfTest1.java new file mode 100644 index 000000000..bee134c72 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isInstanceOf/IsInstanceOfTest1.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.isInstanceOf; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; +public class IsInstanceOfTest1 extends SimpleBase { + @Test + public void testInstanceOf() throws DatabaseException { + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); +// g.isInstanceOf(null, null); +// g.isInstanceOf(rl, null); + assertFalse(g.isInstanceOf(rl, rl)); + assertFalse(g.isInstanceOf(rl, l0.Relation)); + assertTrue(g.isInstanceOf(rl, l0.Entity)); + assertTrue(g.isInstanceOf(rl, l0.Library)); + assertTrue(g.isInstanceOf(l0.InverseOf, l0.FunctionalRelation)); + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isSubrelationOf/IsSubrelationOfTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isSubrelationOf/IsSubrelationOfTest1.java new file mode 100644 index 000000000..592bf4ca3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/isSubrelationOf/IsSubrelationOfTest1.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.readGraph.isSubrelationOf; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; + +public class IsSubrelationOfTest1 extends SimpleBase { + @Test + public void testSubrelationOf() throws DatabaseException { + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + /* + * Null arguments are not allowed but are not checked. The + * behavior in this case is unspecified and can't be tested. + */ +// assertFalse(g.isSubrelationOf(null, null)); +// assertFalse(g.isSubrelationOf(rl, null)); + // Current implementation doesn't check if argument is relation. + assertTrue(g.isSubrelationOf(rl, rl)); + // By definition returns true if the two resources are equal. + assertTrue(g.isSubrelationOf(l0.Relation, l0.Relation)); + assertFalse(g.isSubrelationOf(rl, l0.Relation)); + assertFalse(g.isSubrelationOf(rl, l0.Entity)); + assertFalse(g.isSubrelationOf(rl, l0.Library)); + assertFalse(g.isSubrelationOf(l0.IsRelatedTo, l0.Relation)); + assertFalse(g.isSubrelationOf(l0.FunctionalRelation, l0.Relation)); + assertTrue(g.isSubrelationOf(l0.InverseOf, l0.DependsOn)); + assertTrue(g.isSubrelationOf(l0.InverseOf, l0.IsRelatedTo)); + assertTrue(g.isSubrelationOf(l0.InverseOf, l0.IsWeaklyRelatedTo)); + assertFalse(g.isSubrelationOf(l0.InverseOf, l0.Relation)); + assertFalse(g.isSubrelationOf(l0.InverseOf, l0.FunctionalRelation)); + assertFalse(g.isSubrelationOf(l0.InverseOf, l0.Relation)); + assertTrue(g.isSubrelationOf(l0.SubrelationOf, l0.DependsOn)); + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/SuiteRequest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/SuiteRequest.java new file mode 100644 index 000000000..3051c2b1a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/SuiteRequest.java @@ -0,0 +1,147 @@ +package org.simantics.db.tests.api.request; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.request.exception.AsyncProcedureExecuteThrows; +import org.simantics.db.tests.api.request.exception.ExceptionInEqualsTest; +import org.simantics.db.tests.api.request.exception.ExceptionInHashCodeTest; +import org.simantics.db.tests.api.request.exception.GraphSyncAsyncReadPassesDatabaseException; +import org.simantics.db.tests.api.request.exception.GraphSyncAsyncReadThrowsRuntimeException; +import org.simantics.db.tests.api.request.exception.GraphSyncReadThrowsDatabaseException; +import org.simantics.db.tests.api.request.exception.GraphSyncReadThrowsNPE; +import org.simantics.db.tests.api.request.exception.GraphSyncReadThrowsNoSingleResultException; +import org.simantics.db.tests.api.request.exception.GraphSyncReadWithProcedureThrowsDatabaseException; +import org.simantics.db.tests.api.request.exception.GraphSyncReadWithProcedureThrowsNPE; +import org.simantics.db.tests.api.request.exception.GraphSyncReadWithProcedureThrowsNPEInExecute; +import org.simantics.db.tests.api.request.exception.GraphSyncReadWithProcedureThrowsNoSingleResultException; +import org.simantics.db.tests.api.request.exception.ListenerExceptions; +import org.simantics.db.tests.api.request.exception.RecoveryFromExceptedState; +import org.simantics.db.tests.api.request.exception.SessionSyncAsyncReadPassesDatabaseException; +import org.simantics.db.tests.api.request.exception.SessionSyncAsyncReadThrowsRuntimeException; +import org.simantics.db.tests.api.request.exception.SessionSyncReadThrowsDatabaseException; +import org.simantics.db.tests.api.request.exception.SessionSyncReadWithProcedureThrowsDatabaseException; +import org.simantics.db.tests.api.request.exception.SessionSyncReadWithProcedureThrowsNPEInExecute; +import org.simantics.db.tests.api.request.exception.SessionSyncWriteThrowsDatabaseException; +import org.simantics.db.tests.api.request.exception.SessionSyncWriteThrowsRuntimeException; +import org.simantics.db.tests.api.request.external.CachingExternalReads; +import org.simantics.db.tests.api.request.external.ExternalRequestTest; +import org.simantics.db.tests.api.request.external.ExternalRequestTest2; +import org.simantics.db.tests.api.request.external.ExternalRequestTest3; +import org.simantics.db.tests.api.request.external.ExternalRequestTest4; +import org.simantics.db.tests.api.request.listening.DisposedListenerTest; +import org.simantics.db.tests.api.request.listening.EqualListenerDisposeTest; +import org.simantics.db.tests.api.request.listening.ObjectsListeningTest; +import org.simantics.db.tests.api.request.listening.QueryResultCompareTest1; +import org.simantics.db.tests.api.request.misc.AsyncTransactionTest; +import org.simantics.db.tests.api.request.misc.CachedQueryDependencies; +import org.simantics.db.tests.api.request.misc.ComplexReadWriteQueryTest; +import org.simantics.db.tests.api.request.misc.GraphSupportTest; +import org.simantics.db.tests.api.request.misc.MultiListenerTest; +import org.simantics.db.tests.api.request.misc.NoneListenerTest; +import org.simantics.db.tests.api.request.misc.NoneListenerTest2; +import org.simantics.db.tests.api.request.misc.RequestParentTest; +import org.simantics.db.tests.api.request.misc.RequestParentTest2; +import org.simantics.db.tests.api.request.misc.RequestParentTest3; +import org.simantics.db.tests.api.request.misc.RequestParentTest4; +import org.simantics.db.tests.api.request.misc.RequestParentTest5; +import org.simantics.db.tests.api.request.misc.RequestParentTest6; +import org.simantics.db.tests.api.request.misc.RequestProcessorTest1; +import org.simantics.db.tests.api.request.misc.RequestQueuingTest; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest2; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest3; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest4; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest5; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest6; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest7; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest8; +import org.simantics.db.tests.api.request.misc.SyncAsyncSyncTest9; +import org.simantics.db.tests.api.request.misc.SyncRequestTest; +import org.simantics.db.tests.api.request.misc.SyncRequestTest2; +import org.simantics.db.tests.api.request.misc.SyncRequestTest3; +import org.simantics.db.tests.api.request.thread.ThreadingTest1; +import org.simantics.db.tests.api.request.thread.ThreadingTest2; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + // exception + AsyncProcedureExecuteThrows.class, + ExceptionInEqualsTest.class, + ExceptionInHashCodeTest.class, + GraphSyncAsyncReadPassesDatabaseException.class, + GraphSyncAsyncReadThrowsRuntimeException.class, + GraphSyncReadThrowsDatabaseException.class, + GraphSyncReadThrowsNoSingleResultException.class, + GraphSyncReadThrowsNPE.class, + GraphSyncReadWithProcedureThrowsDatabaseException.class, + GraphSyncReadWithProcedureThrowsNoSingleResultException.class, + GraphSyncReadWithProcedureThrowsNPE.class, + GraphSyncReadWithProcedureThrowsNPEInExecute.class, + ListenerExceptions.class, + RecoveryFromExceptedState.class, + SessionSyncAsyncReadPassesDatabaseException.class, + SessionSyncAsyncReadThrowsRuntimeException.class, + SessionSyncReadThrowsDatabaseException.class, + SessionSyncReadWithProcedureThrowsDatabaseException.class, + SessionSyncReadWithProcedureThrowsNPEInExecute.class, + SessionSyncWriteThrowsDatabaseException.class, + SessionSyncWriteThrowsRuntimeException.class, + // external + ExternalRequestTest.class, + ExternalRequestTest2.class, + ExternalRequestTest3.class, + ExternalRequestTest4.class, + CachingExternalReads.class, + // listening + DisposedListenerTest.class, + EqualListenerDisposeTest.class, + ObjectsListeningTest.class, + QueryResultCompareTest1.class, + // misc + AsyncTransactionTest.class, + CachedQueryDependencies.class, + ComplexReadWriteQueryTest.class, + GraphSupportTest.class, + MultiListenerTest.class, + NoneListenerTest.class, + NoneListenerTest2.class, + RequestParentTest.class, + RequestParentTest2.class, + RequestParentTest3.class, + RequestParentTest4.class, + RequestParentTest5.class, + RequestParentTest6.class, + RequestProcessorTest1.class, + RequestQueuingTest.class, + SyncAsyncSyncTest.class, + SyncAsyncSyncTest2.class, + SyncAsyncSyncTest3.class, + SyncAsyncSyncTest4.class, + SyncAsyncSyncTest5.class, + SyncAsyncSyncTest6.class, + SyncAsyncSyncTest7.class, + SyncAsyncSyncTest8.class, + SyncAsyncSyncTest9.class, + SyncRequestTest.class, + SyncRequestTest2.class, + SyncRequestTest3.class, + // thread + ThreadingTest1.class, + ThreadingTest2.class +}) +public class SuiteRequest { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/AsyncProcedureExecuteThrows.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/AsyncProcedureExecuteThrows.java new file mode 100644 index 000000000..46a5575c9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/AsyncProcedureExecuteThrows.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.AsyncRequestProcessor; +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.AsyncReadRequest; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class AsyncProcedureExecuteThrows extends ExistingDatabaseTest { + + final RuntimeException exception = new RuntimeException(); + + private Read syncRead(Resource r) { + return new ResourceRead(r) { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getPossibleObject(resource, L0.InstanceOf); + } + + }; + } + + private AsyncRead asyncRead(Resource r) { + return new ResourceAsyncRead(r) { + + @Override + public void perform(AsyncReadGraph graph,AsyncProcedure procedure) { + graph.forPossibleObject(resource, L0.InstanceOf, procedure); + } + + }; + } + + private AsyncProcedure procedure() { + return new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, Resource result) { + throw exception; + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throw new RuntimeException(); + } + + }; + } + + public void syncSync(RequestProcessor processor) { + + try { + + processor.syncRequest(syncRead(L0.Library), procedure()); + fail("No exception was thrown."); + + } catch (DatabaseException e) { + + if(e.getCause() != exception) fail("Wrong exception was thrown."); + + } + + } + + public void syncAsync(RequestProcessor processor) { + + try { + + processor.syncRequest(asyncRead(L0.Library), procedure()); + fail("No exception was thrown."); + + } catch (DatabaseException e) { + + if(e.getCause() != exception) fail("Wrong exception was thrown."); + + } + + } + + public void asyncSync(AsyncRequestProcessor processor) { + + processor.asyncRequest(syncRead(L0.Library), procedure()); + + } + + public void asyncAsync(AsyncRequestProcessor processor) { + + processor.asyncRequest(asyncRead(L0.Library), procedure()); + + } + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new AsyncReadRequest() { + + @Override + public void run(AsyncReadGraph graph) { + asyncSync(graph); + } + + }); + fail("No exception was thrown."); + + } catch (DatabaseException e) { + + if(e.getCause() != exception) fail("Wrong exception was thrown."); + + } + + try { + + session.syncRequest(new AsyncReadRequest() { + + @Override + public void run(AsyncReadGraph graph) { + asyncAsync(graph); + } + + }); + fail("No exception was thrown."); + + } catch (DatabaseException e) { + + if(e.getCause() != exception) fail("Wrong exception was thrown."); + + } + + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + syncSync(graph); + syncAsync(graph); + } + + }); + + syncSync(session); + syncAsync(session); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInEqualsTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInEqualsTest.java new file mode 100644 index 000000000..b8fbe4789 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInEqualsTest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class ExceptionInEqualsTest extends ExistingDatabaseTest { + + boolean exceptionOk = false; + + @Fails + @Test(timeout = 5000) + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + System.out.println("perform"); + return null; + } + + @Override + public boolean equals(Object obj) { + System.out.println("equals"); + throw new NullPointerException(); + } + + }, new ListenerAdapter() { + @Override + public void exception(Throwable e) { + System.out.println("Got exception " + e.getMessage()); + if(e instanceof NullPointerException) + exceptionOk = true; + } + @Override + public boolean isDisposed() { + return false; + } + }); + + } catch (Throwable e) { + + System.out.println("Got exception " + e.getMessage()); + + return; + + } + + if(!exceptionOk) + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInHashCodeTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInHashCodeTest.java new file mode 100644 index 000000000..27dcf858b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ExceptionInHashCodeTest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class ExceptionInHashCodeTest extends ExistingDatabaseTest { + + boolean exceptionOk = false; + + @Fails + @Test(timeout = 5000) + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + System.out.println("perform"); + return null; + } + + @Override + public int hashCode() { + System.out.println("hashCode"); + throw new NullPointerException(); + } + + }, new ListenerAdapter() { + @Override + public void exception(Throwable e) { + System.out.println("Got exception " + e.getMessage()); + if(e instanceof NullPointerException) + exceptionOk = true; + } + @Override + public boolean isDisposed() { + return false; + } + }); + + } catch (Throwable e) { + + fail("Write transaction threw an unknown exception " + e); + + return; + + } + + if(!exceptionOk) + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadPassesDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadPassesDatabaseException.java new file mode 100644 index 000000000..8611c8791 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadPassesDatabaseException.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncAsyncReadPassesDatabaseException extends ExistingDatabaseTest { + + private Exception exception; + + @Test + public void testWriteException() throws Exception { + + Session session = getSession(); + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + try { + + graph.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + exception = new DatabaseException(); + procedure.exception(graph, exception); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + } catch (Throwable e) { + + if(!e.equals(exception)) { + fail("Write transaction threw an unknown exception " + e); + } + + if (DEBUG) + e.printStackTrace(); + + return null; + + } + + fail("Write transaction did not throw an exception."); + + return null; + + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadThrowsRuntimeException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadThrowsRuntimeException.java new file mode 100644 index 000000000..100fa13a2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadThrowsRuntimeException.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncAsyncReadThrowsRuntimeException extends ExistingDatabaseTest { + + private RuntimeException exception; + + @Test + public void testWriteException() throws Exception { + + Session session = getSession(); + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + try { + + graph.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + exception = new IllegalArgumentException(); + throw exception; + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + } catch (Throwable e) { + + if(!(e instanceof DatabaseException)) { + fail("Request did not throw DatabaseException but " + e); + return null; + } + + DatabaseException ex = (DatabaseException)e; + + if(!exception.equals(ex.getCause())) { + fail("Request did not report the correct cause but " + e); + return null; + } + + if (DEBUG) + e.printStackTrace(); + + return null; + + } + + fail("Request did not throw an exception."); + + return null; + + } + + }); + + + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsDatabaseException.java new file mode 100644 index 000000000..1a70a6c81 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsDatabaseException.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncReadThrowsDatabaseException extends ExistingDatabaseTest { + + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + return graph.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + DatabaseException e = new DatabaseException("Test"); + exception = e; + throw e; + } + + }); + + + } + + }); + + } catch(DatabaseException e) { + + if(e != exception) fail("syncRequest did not throw the original exception"); + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNPE.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNPE.java new file mode 100644 index 000000000..5d95c83f0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNPE.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncReadThrowsNPE extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + return graph.syncRequest(new Read() { + + @SuppressWarnings("null") + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + graph = null; + return graph.getBuiltin(ROOT_LIBRARY_URI); + } + + }); + + + } + + }); + + } catch(DatabaseException e) { + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNoSingleResultException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNoSingleResultException.java new file mode 100644 index 000000000..ba5e08013 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadThrowsNoSingleResultException.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class GraphSyncReadThrowsNoSingleResultException extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + return graph.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + return graph.getSingleObject(graph.getRootLibrary(), b.Inherits); + } + + }); + + + } + + }); + + } catch(DatabaseException e) { + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsDatabaseException.java new file mode 100644 index 000000000..c4932ee51 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsDatabaseException.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncReadWithProcedureThrowsDatabaseException extends ExistingDatabaseTest { + + private String failure = null; + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + graph.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + DatabaseException e = new DatabaseException("Test"); + exception = e; + throw e; + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + if(t != exception) failure = "syncRequest did not throw the original exception"; + + if (DEBUG) + t.printStackTrace(); + + } + + @Override + public void execute(Object result) { + + failure = "Execute was called with " + result; + + } + + }); + + return null; + + + } + + }); + + } catch(DatabaseException e) { + + if(e != exception) fail("syncRequest did not throw the original exception"); + if(failure != null) fail(failure); + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPE.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPE.java new file mode 100644 index 000000000..f12df2186 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPE.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncReadWithProcedureThrowsNPE extends ExistingDatabaseTest { + + private String failure = null; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + graph.syncRequest(new Read() { + + @SuppressWarnings("null") + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + graph = null; + return graph.getBuiltin(ROOT_LIBRARY_URI); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + if(!(t instanceof NullPointerException)) failure = "syncRequest did not throw the original exception"; + + if (DEBUG) + t.printStackTrace(); + + } + + @Override + public void execute(Object result) { + + failure = "Execute was called with " + result; + + } + + }); + + return null; + + } + + }); + + } catch(DatabaseException e) { + + if(failure != null) fail(failure); + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPEInExecute.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPEInExecute.java new file mode 100644 index 000000000..31831fa0e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNPEInExecute.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GraphSyncReadWithProcedureThrowsNPEInExecute extends ExistingDatabaseTest { + + private String failure = null; + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + graph.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + return new Object(); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + failure = "Exception in execute was passed to exception handler"; + + } + + @SuppressWarnings("null") + @Override + public void execute(Object result) { + + Object o = null; + o.toString(); + + } + + }); + + return null; + + + } + + }); + + } catch(DatabaseException e) { + + if (DEBUG) + e.printStackTrace(); + if (null == failure) + fail("Exception in exceute was not passed to exception handler."); + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNoSingleResultException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNoSingleResultException.java new file mode 100644 index 000000000..8c49e2f3a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncReadWithProcedureThrowsNoSingleResultException.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class GraphSyncReadWithProcedureThrowsNoSingleResultException extends ExistingDatabaseTest { + + private String failure = null; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + graph.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + return graph.getSingleObject(graph.getRootLibrary(), b.Inherits); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + if(!(t instanceof NoSingleResultException)) failure = "syncRequest did not throw a correct exception"; + + if (DEBUG) + t.printStackTrace(); + + } + + @Override + public void execute(Object result) { + + failure = "Execute was called with " + result; + + } + + }); + + return null; + + } + + }); + + } catch(DatabaseException e) { + + if(failure != null) fail(failure); + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ListenerExceptions.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ListenerExceptions.java new file mode 100644 index 000000000..223fa686c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/ListenerExceptions.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + + +public class ListenerExceptions extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + class R extends ResourceRead { + + public R(Resource r) { + super(r); + } + + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + Integer i = graph.getPossibleRelatedValue(resource, b.HasProperty); + if(i == 2) throw new DatabaseException("Exception2"); + if(i == 4) throw new DatabaseException("Exception45"); + if(i == 5) throw new DatabaseException("Exception45"); + return i; + } + + } + + final Resource literal = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Resource literal = graph.newResource(); + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(literal, b.HasProperty, 1, Bindings.INTEGER); + return literal; + + } + + }); + + final ArrayList results = new ArrayList(); + + session.syncRequest(new R(literal), new Listener() { + + @Override + public void execute(Integer result) { + results.add(result != null ? result.toString() : null); + } + + @Override + public void exception(Throwable t) { + results.add(t.getMessage()); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + class Claim extends WriteRequest { + + private Integer i; + + public Claim(Integer i) { + this.i = i; + } + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(literal, b.HasProperty, i, Bindings.INTEGER); + } + + } + + session.syncRequest(new Claim(2)); + session.syncRequest(new Claim(3)); + session.syncRequest(new Claim(4)); + session.syncRequest(new Claim(5)); + session.syncRequest(new Claim(6)); + + String[] test = new String[] { "1", "Exception2", "3", "Exception45", "Exception45", "6" }; + + assert(Arrays.equals(test, results.toArray(new String[results.size()]))); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/RecoveryFromExceptedState.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/RecoveryFromExceptedState.java new file mode 100644 index 000000000..9a18036d8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/RecoveryFromExceptedState.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class RecoveryFromExceptedState extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final Layer0 L0 = Layer0.getInstance(session); + + final Resource A = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Resource root = graph.getRootLibrary(); + Resource part = graph.newResource(); + graph.claim(part, L0.InstanceOf, null, L0.Entity); + graph.claim(part, L0.PartOf, root); + graph.claimLiteral(part, L0.HasName, "A"); + return part; + + } + + }); + + try { + + /* + * Create the request. Listening is needed to enforce update of the query in subsequent write + */ + session.syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getResource("http://A"); + } + + }, new ListenerAdapter()); + + /* + * Invalidates the request. Request is updated (is has a listener) and enters 'Excepted' state. + */ + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + graph.deny(A); + graph.deny(graph.getRootLibrary(), L0.ConsistsOf, A); + + } + + }); + + /* + * After this write the result is again valid. The request should be updated to 'Ready' state. + */ + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Resource root = graph.getRootLibrary(); + Resource part = graph.newResource(); + graph.claim(part, L0.InstanceOf, null, L0.Entity); + graph.claim(part, L0.PartOf, root); + graph.claimLiteral(part, L0.HasName, "A"); + + } + + }); + + /* + * Validate the situation. + */ + session.syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getResource("http://A"); + } + + }, TransientCacheListener.instance()); + + } catch(ResourceNotFoundException e) { + + fail("getResource threw ResourceNotFoundException"); + + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadPassesDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadPassesDatabaseException.java new file mode 100644 index 000000000..4b3acc7e4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadPassesDatabaseException.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncAsyncReadPassesDatabaseException extends ExistingDatabaseTest { + + private Exception exception; + + @Test + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + exception = new DatabaseException(); + procedure.exception(graph, exception); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + } catch (Throwable e) { + + if(!e.equals(exception)) { + fail("Write transaction threw an unknown exception " + e); + } + + return; + + } + + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadThrowsRuntimeException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadThrowsRuntimeException.java new file mode 100644 index 000000000..bf9d0889a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncAsyncReadThrowsRuntimeException.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncAsyncReadThrowsRuntimeException extends ExistingDatabaseTest { + private RuntimeException exception; + + @Test + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + exception = new IllegalArgumentException(); + throw exception; + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + } catch (Throwable e) { + + if(!(e instanceof DatabaseException)) { + fail("Request did not throw DatabaseException but " + e); + return; + } + + DatabaseException ex = (DatabaseException)e; + + if(!exception.equals(ex.getCause())) { + fail("Request did not report the correct cause but " + e); + return; + } + + if (DEBUG) + e.printStackTrace(); + + return; + + } + + fail("Request did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadThrowsDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadThrowsDatabaseException.java new file mode 100644 index 000000000..5cf896c2e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadThrowsDatabaseException.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncReadThrowsDatabaseException extends ExistingDatabaseTest { + + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + DatabaseException e = new DatabaseException("Test"); + exception = e; + throw e; + + } + + }); + + } catch(DatabaseException e) { + + if(e != exception) fail("syncRequest did not throw the original exception"); + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsDatabaseException.java new file mode 100644 index 000000000..75da38a0f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsDatabaseException.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncReadWithProcedureThrowsDatabaseException extends ExistingDatabaseTest { + + private String failure = null; + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + DatabaseException e = new DatabaseException("Test"); + exception = e; + throw e; + + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + if(t != exception) failure = "syncRequest did not throw the original exception"; + + if (DEBUG) + t.printStackTrace(); + + } + + @Override + public void execute(Object result) { + + failure = "Execute was called with " + result; + + } + + }); + + } catch(DatabaseException e) { + + if(e != exception) fail("syncRequest did not throw the original exception"); + if(failure != null) fail(failure); + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsNPEInExecute.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsNPEInExecute.java new file mode 100644 index 000000000..067564963 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncReadWithProcedureThrowsNPEInExecute.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncReadWithProcedureThrowsNPEInExecute extends ExistingDatabaseTest { + + private String failure = null; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + return new Object(); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + + failure = "Exception in execute was passed to exception handler"; + if (DEBUG) + System.out.println(failure); + } + + @SuppressWarnings("null") + @Override + public void execute(Object result) { + + Object o = null; + o.toString(); + + } + + }); + + } catch(DatabaseException e) { + + if (DEBUG) + e.printStackTrace(); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsDatabaseException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsDatabaseException.java new file mode 100644 index 000000000..a2ac915f9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsDatabaseException.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncWriteThrowsDatabaseException extends ExistingDatabaseTest { + + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + DatabaseException e = new DatabaseException("Test"); + exception = e; + throw e; + + } + + }); + + } catch(DatabaseException e) { + + if(e != exception) fail("syncRequest did not throw the original exception"); + + // Check that the session bookkeeping is still intact for another write transaction. + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + }); + + return; + + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsRuntimeException.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsRuntimeException.java new file mode 100644 index 000000000..bfccd8964 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/SessionSyncWriteThrowsRuntimeException.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.exception; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionSyncWriteThrowsRuntimeException extends ExistingDatabaseTest { + + private Throwable exception; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + RuntimeException e = new RuntimeException("Test"); + exception = e; + throw e; + + } + + }); + + } catch(DatabaseException e) { + + if(e.getCause() != exception) fail("syncRequest did not throw the original exception"); + + // Check that the session bookkeeping is still intact for another write transaction. + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + }); + + return; + } catch(Throwable t) { + + fail("syncRequest threw unexpected throwable " + t); + + } + + fail("syncRequest did not throw"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/CachingExternalReads.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/CachingExternalReads.java new file mode 100644 index 000000000..087dba232 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/CachingExternalReads.java @@ -0,0 +1,69 @@ +package org.simantics.db.tests.api.request.external; + +import junit.framework.Assert; + +import org.junit.Test; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; +import org.simantics.db.testing.cases.FreshDatabaseTest; + +public class CachingExternalReads extends FreshDatabaseTest { + + public static final String RESULT = "Hello World!"; + + static class MyExternalRead implements ExternalRead { + + int registerCount = 0; + + @Override + public void register(ReadGraph graph, Listener procedure) { + if (DEBUG) + System.out.println("register"); + ++registerCount; + procedure.execute(RESULT); + } + + @Override + public void unregistered() { + if (DEBUG) + System.out.println("unregistered"); + } + + public int getRegisterCount() { + return registerCount; + } + }; + + @Test + public void test() throws Exception { + Session session = Simantics.getSession(); + + MyExternalRead read = new MyExternalRead(); + + for(int i=0;i<10;++i) { + session.syncRequest(read, new Listener() { + @Override + public void execute(String result) { + if (DEBUG) + System.out.println("=> " + result); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + } + + Assert.assertEquals(1, read.registerCount); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest.java new file mode 100644 index 000000000..057ec6ec6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.external; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class ExternalRequestTest extends ExistingDatabaseTest { + + private Error exception; + + int counter = 0; + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1); + + final Semaphore s = new Semaphore(-9); + + session.syncRequest(new ExternalRead() { + + @Override + public void register(ReadGraph graph, final Listener procedure) { + + procedure.execute("String" + (counter++)); + + for(int i=1;i<10;i++) { + exec.schedule(new Runnable() { + + @Override + public void run() { + procedure.execute("String" + (counter++)); + } + + }, i*500, TimeUnit.MILLISECONDS); + } + + } + + @Override + public void unregistered() { + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + } + + @Override + public void execute(String result) { + s.release(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + s.acquire(); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest2.java new file mode 100644 index 000000000..e1dd4fdfe --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest2.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.external; + +import java.util.concurrent.Semaphore; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class ExternalRequestTest2 extends ExistingDatabaseTest { + + int COUNT = 50; + + private Error exception; + + int counter = 0; + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + final Semaphore s = new Semaphore(1-COUNT); + + session.syncRequest(new ExternalRead() { + + @Override + public void register(ReadGraph graph, final Listener procedure) { + + for(int i=0;i() { + + @Override + public void exception(Throwable t) { + } + + @Override + public void execute(String result) { + new Exception("execute2 " + result).printStackTrace(); + s.release(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + s.acquire(); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest3.java new file mode 100644 index 000000000..209752143 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest3.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.external; + +import java.util.concurrent.Semaphore; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.request.SingletonPrimitiveRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class ExternalRequestTest3 extends ExistingDatabaseTest { + + private Error exception; + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + final Semaphore s = new Semaphore(-4); + + session.syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + + class Primitive extends SingletonPrimitiveRead { + + @Override + public void register(ReadGraph graph, Listener procedure) { + + procedure.execute(" Appendix 1"); + procedure.execute(" Appendix 2"); + procedure.execute(" Appendix 3"); + procedure.execute(" Appendix 4"); + procedure.execute(" Appendix 5"); + + } + + } + + Layer0 b = Layer0.getInstance(graph); + String base = graph.getRelatedValue(graph.getRootLibrary(), b.HasName); + String appendix = graph.syncRequest(new Primitive()); + return base + appendix; + + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + } + + @Override + public void execute(String result) { + s.release(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + s.acquire(); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest4.java new file mode 100644 index 000000000..f378c5616 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest4.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.external; + +import java.util.HashSet; +import java.util.concurrent.Semaphore; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.request.SingletonPrimitiveRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class ExternalRequestTest4 extends ExistingDatabaseTest { + + private Error exception; + + boolean listenerAlive = true; + + int counter = 0; + HashSet> listeners = new HashSet>(); + + class Primitive extends SingletonPrimitiveRead { + + @Override + public void register(ReadGraph graph, Listener procedure) { + + listeners.add(procedure); + procedure.execute("Result" + counter); + + } + + } + + public void fireNewPrimitive() { + counter++; + for(Listener listener : listeners) listener.execute("Result" + counter); + } + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + final Semaphore s1 = new Semaphore(-6); + final Semaphore s2 = new Semaphore(-6); + + session.syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + String base = graph.getRelatedValue(graph.getRootLibrary(), b.HasName); + String appendix = graph.syncRequest(new Primitive()); + return base + appendix; + + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + } + + @Override + public void execute(String result) { + s1.release(); + } + + @Override + public boolean isDisposed() { + return !listenerAlive; + } + + }); + + fireNewPrimitive(); + fireNewPrimitive(); + fireNewPrimitive(); + + Thread.sleep(500); + + session.syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + String base = graph.getRelatedValue(graph.getRootLibrary(), b.HasName); + String appendix = graph.syncRequest(new Primitive()); + return base + appendix; + + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + } + + @Override + public void execute(String result) { + s2.release(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + fireNewPrimitive(); + fireNewPrimitive(); + fireNewPrimitive(); + + Thread.sleep(500); + listenerAlive = false; + + fireNewPrimitive(); + fireNewPrimitive(); + fireNewPrimitive(); + + s1.acquire(); + s2.acquire(); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/DisposedListenerTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/DisposedListenerTest.java new file mode 100644 index 000000000..ee26b330f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/DisposedListenerTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.listening; + +import java.util.concurrent.Semaphore; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.utils.DataContainer; + +public class DisposedListenerTest extends ExistingDatabaseTest { + + /** + * Performs an asynchronous dummy graph request with a listener that is + * already disposed when the request is first performed. + * + *

+ * The expected outcome is that the request will complete normally, calling + * execute of the listener procedure once and only once. + * + *

+ * The outcome when this test was created was that QueryProcessor would + * crash internally with a NullPointerException. + * + * This problem is fixed by: https://www.simulationsite.net/trac/simantics/changeset/13869 + * + * @throws Exception + */ + @Test + public void testDisposedListener() throws Exception{ + final Session session = getSession(); + + final Semaphore sem = new Semaphore(0); + final DataContainer exc = new DataContainer(); + + session.asyncRequest(new AsyncRead() { + @Override + public int getFlags() { + return 0; + } + @Override + public int threadHash() { + return hashCode(); + } + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + procedure.execute(graph, new Object()); + } + }, new AsyncListenerAdapter() { + @Override + public boolean isDisposed() { + return true; + } + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + System.out.println(getClass().getSimpleName() + ": exception:"); + t.printStackTrace(); + exc.set(t); + sem.release(); + } + @Override + public void execute(AsyncReadGraph graph, Object result) { + if (DEBUG) + System.out.println(getClass().getSimpleName() + ": execute: " + result); + sem.release(); + } + }); + + sem.acquire(); + + Throwable t = exc.get(); + if (t != null) { + if (t instanceof Exception) + throw (Exception) t; + else + throw new Exception(t); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/EqualListenerDisposeTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/EqualListenerDisposeTest.java new file mode 100644 index 000000000..2b30f4d30 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/EqualListenerDisposeTest.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.listening; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class EqualListenerDisposeTest extends ExistingDatabaseTest { + + static class TestRequest extends ResourceAsyncRead { + public TestRequest(Resource resource) { + super(resource); + } + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + Layer0 b; + try { + b = Layer0.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + throw new RuntimeDatabaseException(e); + } + graph.forRelatedValue(resource, b.HasName, procedure); + } + } + + static class TestListener extends AsyncListenerAdapter { + String id; + AtomicInteger execs = new AtomicInteger(); + AtomicBoolean disposed = new AtomicBoolean(false); + public TestListener(String id) { + this.id = id; + } + public int getExecs() { + return execs.get(); + } + public void dispose() { + disposed.set(true); + } + @Override + public boolean isDisposed() { + return disposed.get(); + } + @Override + public void execute(AsyncReadGraph graph, String result) { + int c = execs.incrementAndGet(); + if (DEBUG) + System.out.println("Listener(" + id + ").execute(" + result + "), execution #" + c); + } + @Override + public int hashCode() { + return TestListener.class.hashCode(); + } + @Override + public boolean equals(Object obj) { + return obj instanceof TestListener; + } + } + + Resource testResource; + + @Test + public void testMultipleListeners() throws Exception { + final Session session = getSession(); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + testResource = graph.newResource(); + graph.claim(testResource, b.InstanceOf, null, b.Entity); + graph.claimLiteral(testResource, b.HasName, "Test Entity", Bindings.STRING); + } + }); + + TestListener l1 = new TestListener("L1"); + TestListener l2 = new TestListener("L2"); + session.syncRequest(new TestRequest(testResource), l1); + + assertEquals(l1.getExecs(), 1); + + // Make a modification that should be notified for + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(testResource, b.HasName, "Test Entity (modified name)", Bindings.STRING); + } + }); + + assertEquals(l1.getExecs(), 2); + + // The listener should be fired but not listened to (there is already an equal listener) + session.syncRequest(new TestRequest(testResource), l2); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 1); + + if (DEBUG) + System.out.println("Dispose listener L1"); + l1.dispose(); + + // The listener should be fired and listened to (previous equal listener is disposed) + session.syncRequest(new TestRequest(testResource), l2); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 2); + + if (DEBUG) + System.out.println("Make modification, should fire l2"); + // Make a modification that should be notified for + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(testResource, b.HasName, "Test Entity (modified name 2)", Bindings.STRING); + } + }); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 3); + + if (DEBUG) + System.out.println("Dispose listener L2"); + l2.dispose(); + + if (DEBUG) + System.out.println("Make another modification, should not fire"); + // Make a modification that should be notified for + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(testResource, b.HasName, "Test Entity (even more modified name)", Bindings.STRING); + } + }); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 3); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/ObjectsListeningTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/ObjectsListeningTest.java new file mode 100644 index 000000000..6811ce5f4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/ObjectsListeningTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.listening; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Assert; +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +@Fails +public class ObjectsListeningTest extends ExistingDatabaseTest { + + Resource subject; + Resource subrelation; + AtomicInteger executions = new AtomicInteger(0); + + @Test + public void testDisposedListener() throws Exception { + + final Session session = getSession(); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + subject = graph.newResource(); + subrelation = graph.newResource(); + graph.claim(subrelation, L0.SubrelationOf, L0.HasProperty); + graph.claim(subrelation, L0.SubrelationOf, null, L0.List_Next); + } + + }); + + session.syncRequest(new UniqueRead>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return graph.getObjects(subject, L0.List_Next); + } + + }, new ListenerAdapter>() { + + @Override + public void execute(Collection result) { + executions.incrementAndGet(); + } + + }); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claim(subject, subrelation, graph.newResource()); + } + + }); + + Assert.assertEquals(2, executions.get()); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/QueryResultCompareTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/QueryResultCompareTest1.java new file mode 100644 index 000000000..e0f0ddc79 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/QueryResultCompareTest1.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.listening; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class QueryResultCompareTest1 extends ExistingDatabaseTest { + + @Test + public void testNullArrayCompare() throws Exception { + + final Session session = getSession(); + + final Resource newResource = getSession().syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + }); + + session.syncRequest(new Read() { + @Override + public Resource[] perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + Collection coll = graph.getObjects(newResource, b.ConsistsOf); + if(coll.isEmpty()) return null; + else return coll.toArray(Resource.NONE); + } + }, new ListenerAdapter() { + @Override + public boolean isDisposed() { + return false; + } + }); + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claim(newResource, b.ConsistsOf, graph.newResource()); + } + }); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/AsyncTransactionTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/AsyncTransactionTest.java new file mode 100644 index 000000000..749fbeb76 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/AsyncTransactionTest.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests that read and write locks are implemented correctly. + * + * @author Hannu Niemistö + */ +public class AsyncTransactionTest extends ExistingDatabaseTest { + + int counter = 100; + + public void perform(AsyncReadGraph graph) { + graph.asyncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, + AsyncProcedure procedure) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + procedure.execute(graph, null); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }, new AsyncListener() { + + @Override + public void exception(AsyncReadGraph graph, + Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, Object result) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + --counter; + if(counter > 0) + perform(graph); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + } + + @Test + public void testAsyncTransactions() throws DatabaseException { + Session session = getSession(); + + session.asyncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + AsyncTransactionTest.this.perform(graph); + return null; + } + + }); + session.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(counter > 0) + fail("Finished before read request was completed."); + } + + }); + + try { // This should be done by the framework, but isn't. + int timeout = 101; + while (counter > 0 && --timeout > 0) + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/CachedQueryDependencies.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/CachedQueryDependencies.java new file mode 100644 index 000000000..130629435 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/CachedQueryDependencies.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatement; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class CachedQueryDependencies extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + final ArrayList result = new ArrayList(); + + final Layer0 L0 = Layer0.getInstance(getSession()); + + final Resource root = getSession().syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + + }); + + getSession().syncRequest(new HasStatement(root, L0.ConsistsOf)); + getSession().syncRequest(new HasStatement(root, L0.ConsistsOf), new Listener() { + + @Override + public void execute(Boolean value) { + if(value) result.add("true"); + else result.add("false"); + } + + @Override + public void exception(Throwable t) { + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claim(root, L0.ConsistsOf, root); + } + + }); + + if(!Arrays.equals(result.toArray(new String[0]), new String[] { "false", "true" })) fail("incorrect result " + result); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/ComplexReadWriteQueryTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/ComplexReadWriteQueryTest.java new file mode 100644 index 000000000..644281ad4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/ComplexReadWriteQueryTest.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +/** + * This test uses several threads to write the graph information and queries to react information changes. + * + * @author Marko Luukkainen + * + */ +public class ComplexReadWriteQueryTest extends ExistingDatabaseTest { + + public static int NUM_THREADS = Configuration.get().rwQueryThreds;; + public static int MAX_CHANGES = Configuration.get().rwQueryCount; + + List threads = new ArrayList(); + int changes; // not quite correct but works for me + volatile int endCount = 0; + Thread self = null; + boolean ended = false; + + private synchronized void incChanges() { +// System.out.println("changes = " + changes); + ++changes; + } + + @Test + public void test() throws Exception { + final Resource rootLib = getSession().getRootLibrary(); + for (int i = 0; i < NUM_THREADS; i++) { + getSession().asyncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + //System.out.println("creating test resource"); + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, b.Type); + g.claim(rootLib, b.ConsistsOf, newResource); + String name = getRandomString(); + g.claimLiteral(newResource, b.HasName, name, Bindings.STRING); + NameUpdateThread t = new NameUpdateThread(getSession(),newResource,name); + threads.add(t); + t.start(); + } + }); + } + if (DEBUG) + System.out.println("Created " + NUM_THREADS + " threads."); + self = Thread.currentThread(); + while(!ended) { + int lastChanges = changes; + boolean test = true; + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("Interrupted."); + test = false; + } + if (test && lastChanges == changes) { + end(); + throw new Exception("No changes in ten seconds, probably database has died. changes="+changes); + } + try { + checkException(); + } catch (Exception e) { + end(); + throw e; + } + checkException(); + } + if (DEBUG) + System.out.println("ended, changes = " + changes); + checkException(); + + } + + public void end() { + for (NameUpdateThread t : threads) { + t.dispose(); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + + } + ended = true; + } + + static volatile int threadCount=0; + public class NameUpdateThread extends Thread { + private boolean disposed = false; + private Resource resource; + private String currentName; + private Session session; + //private NameQuery query; + private Listener procedure; + private NameRead nameRead; + public NameUpdateThread(Session session, Resource resource, String name) { + super("RWQueryTest-" + ++threadCount); + this.currentName = name; + this.resource = resource; + this.session = session; + } + + @Override + public void run() { + procedure = new Listener() { + @Override + public void execute(String result) { + NameUpdateThread.this.interrupt(); + } + + @Override + public void exception(Throwable t) { + ComplexReadWriteQueryTest.fail(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + + }; + while(!disposed) { + try { + nameRead = new NameRead(resource); + //System.out.println("creating query"); + session.asyncRequest(new WriteQuery(ComplexReadWriteQueryTest.this) { + @Override + public void run(WriteGraph g) throws Throwable { + g.syncRequest(nameRead, procedure); + } + }); + // sleep until interrupted (if query fails, we still are updating the value) + Thread.sleep(1000000000); + } catch (InterruptedException e) { + } + if(disposed) + return; + updateName(); + } + + + } + + public void updateName() { + session.asyncRequest(new WriteQuery(ComplexReadWriteQueryTest.this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + String graphName = g.getRelatedValue(resource, b.HasName); + if(!graphName.equals(currentName)) { + throw new Exception("Graph contains name " + graphName + " while name was set to " + currentName); + } + currentName = UUID.randomUUID().toString(); + g.claimLiteral(resource, b.HasName, currentName, Bindings.STRING); + if (changes >= MAX_CHANGES) { + dispose(); + return; + } + incChanges(); + // System.out.println("changes="+changes); + //System.out.println("Name change " +procedure.toString()); + } + }); + + } + + public void dispose() { + if (!disposed) { + ++endCount; + if (endCount >= NUM_THREADS) { + ended = true; + if (null != self) + self.interrupt(); + } + } + disposed = true; + } + + } + + public class NameRead implements Read { + private Resource resource; + + public NameRead(Resource resource) { + this.resource = resource; + } + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + String name = graph.getRelatedValue(resource, b.HasName, Bindings.STRING); + return name; + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/GraphSupportTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/GraphSupportTest.java new file mode 100644 index 000000000..d204c89d3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/GraphSupportTest.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class GraphSupportTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + final AtomicInteger runs = new AtomicInteger(0); + + Session session = getSession(); + + final Resource test = session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + }); + + class Request extends ResourceRead> { + + public Request(Resource resource) { + super(resource); + } + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return graph.getObjects(resource, Layer0.getInstance(graph).ConsistsOf); + } + + } + + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + graph.syncRequest(new Request(test), new SyncListener>() { + + @Override + public void execute(ReadGraph graph, Collection result) throws DatabaseException { + + graph.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + runs.incrementAndGet(); + } + + }); + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + } + + @Override + public boolean isDisposed() { + return false; + } + }); + + } + + }); + + assert(runs.get() == 1); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claim(test, Layer0.getInstance(graph).ConsistsOf, graph.newResource()); + } + }); + + assert(runs.get() == 2); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/MultiListenerTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/MultiListenerTest.java new file mode 100644 index 000000000..0a9451e7a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/MultiListenerTest.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class MultiListenerTest extends ExistingDatabaseTest { + + static class TestRequest extends ResourceAsyncRead { + public TestRequest(Resource resource) { + super(resource); + } + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + Layer0 b; + try { + b = Layer0.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + throw new RuntimeDatabaseException(e); + } + graph.forRelatedValue(resource, b.HasName, procedure); + } + } + + static class TestListener extends AsyncListenerAdapter { + String id; + AtomicInteger execs = new AtomicInteger(); + AtomicBoolean disposed = new AtomicBoolean(false); + public TestListener(String id) { + this.id = id; + } + public int getExecs() { + return execs.get(); + } + public void dispose() { + disposed.set(true); + } + @Override + public boolean isDisposed() { + return disposed.get(); + } + @Override + public void execute(AsyncReadGraph graph, String result) { + int c = execs.incrementAndGet(); + if (DEBUG) + System.out.println("Listener(" + id + ").execute(" + result + "), execution #" + c); + } + } + + Resource testResource; + + @Test + public void testMultipleListeners() throws Exception { + final Session session = getSession(); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + testResource = graph.newResource(); + graph.claim(testResource, b.InstanceOf, null, b.Entity); + graph.claimLiteral(testResource, b.HasName, "Test Entity", Bindings.STRING); + } + }); + + TestListener l1 = new TestListener("L1"); + TestListener l2 = new TestListener("L2"); + + if (DEBUG) + System.out.println("Start listening"); + session.syncRequest(new TestRequest(testResource), l1); + session.syncRequest(new TestRequest(testResource), l2); + if (DEBUG) + System.out.println("Listening"); + + assertEquals(l1.getExecs(), 1); + assertEquals(l2.getExecs(), 1); + + if (DEBUG) + System.out.println("Make modification, should fire listeners"); + // Make a modification that should be notified for + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(testResource, b.HasName, "Test Entity (modified name)", Bindings.STRING); + } + }); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 2); + + if (DEBUG) + System.out.println("Dispose listener L1"); + l1.dispose(); + + if (DEBUG) + System.out.println("Make another modification, should fire only listener L2"); + // Make a modification that should be notified for + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(testResource, b.HasName, "Test Entity (even more modified name)", Bindings.STRING); + } + }); + + assertEquals(l1.getExecs(), 2); + assertEquals(l2.getExecs(), 3); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest.java new file mode 100644 index 000000000..256068da7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.Value; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class NoneListenerTest extends ExistingDatabaseTest { + + static AtomicInteger execs = new AtomicInteger(0); + + static class TestListener implements Listener { + @Override + public void execute(String result) { + execs.incrementAndGet(); + } + @Override + public boolean isDisposed() { + return false; + } + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + @Override + public int hashCode() { + return getClass().hashCode(); + } + @Override + public boolean equals(Object obj) { + return getClass().equals(obj.getClass()); + } + } + + @Test + public void test() throws Exception { + + final Session session = getSession(); + + final Resource newResource = session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource result = g.newResource(); + g.claim(result, b.InstanceOf, null, b.Entity); + g.claim(g.getRootLibrary(), b.ConsistsOf, result); + g.claimValue(result, "Test", Bindings.STRING); + return result; + } + }); + + TestListener l1 = new TestListener(); + TestListener l2 = new TestListener(); + + session.syncRequest(new Value(newResource, Bindings.STRING), l1); + session.syncRequest(new Value(newResource, Bindings.STRING), l2); + + assertEquals(execs.get(), 2); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimValue(newResource, "Test2", Bindings.STRING); + } + }); + + assertEquals(execs.get(), 3); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest2.java new file mode 100644 index 000000000..bd0190f39 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/NoneListenerTest2.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class NoneListenerTest2 extends ExistingDatabaseTest { + + static AtomicInteger execs = new AtomicInteger(0); + + static class TestListener implements Listener { + @Override + public void execute(String result) { + execs.incrementAndGet(); + } + @Override + public boolean isDisposed() { + return false; + } + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + @Override + public int hashCode() { + return getClass().hashCode(); + } + @Override + public boolean equals(Object obj) { + return getClass().equals(obj.getClass()); + } + } + + @Test + public void test() throws Exception { + + final Session session = getSession(); + + final Resource newResource = session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource result = g.newResource(); + g.claim(result, b.InstanceOf, null, b.Entity); + g.claim(g.getRootLibrary(), b.ConsistsOf, result); + g.claimValue(result, "Test", Bindings.STRING); + return result; + } + }); + + TestListener l1 = new TestListener(); + TestListener l2 = new TestListener(); + + class TestRead extends ResourceRead { + + public TestRead(Resource r) { + super(r); + } + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getValue(resource, Bindings.STRING); + } + + } + + session.syncRequest(new TestRead(newResource), l1); + session.syncRequest(new TestRead(newResource), l2); + + assertEquals(execs.get(), 2); + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimValue(newResource, "Test2", Bindings.STRING); + } + }); + + assertEquals(execs.get(), 3); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest.java new file mode 100644 index 000000000..f0d2b94dd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Session; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class RequestParentTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements AsyncRead { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + procedure.execute(graph, new Object()); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + } + + final Request request1 = new Request(); + final Request request2 = new Request(); + + session.syncRequest(request1, new AsyncListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Object result) { + graph.asyncRequest(request2); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + Set parents = debug.getParents(request2); + for(CacheEntry parent : parents) { + if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2"); + } + if(!parents.isEmpty())fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest2.java new file mode 100644 index 000000000..d3f837dc4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest2.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class RequestParentTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements Read { + + @Override + public Object perform(ReadGraph graph) { + return new Object(); + } + + } + + final Request request1 = new Request(); + final Request request2 = new Request(); + + session.syncRequest(request1, new AsyncListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Object result) { + graph.asyncRequest(request2); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + Set parents1 = debug.getParents(request1); + Set parents2 = debug.getParents(request2); +// for(CacheEntry parent : parents) { +// if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2"); +// } + if(!parents1.isEmpty()) fail("Request1 should not have parents"); + if(!parents2.isEmpty()) fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest3.java new file mode 100644 index 000000000..2bec7c21e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest3.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Session; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncMultiListener; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.request.AsyncMultiRead; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class RequestParentTest3 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements AsyncMultiRead { + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public void perform(AsyncReadGraph graph, AsyncMultiProcedure callback) { + callback.execute(graph, new Object()); + callback.finished(graph); + } + + } + + final Request request1 = new Request(); + final Request request2 = new Request(); + + session.syncRequest(request1, new AsyncMultiListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Object result) { + graph.asyncRequest(request2); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + }); + + Set parents = debug.getParents(request2); + for(CacheEntry parent : parents) { + if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2"); + } + if(!parents.isEmpty())fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest4.java new file mode 100644 index 000000000..7ae1a8491 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest4.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncMultiListener; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.request.MultiRead; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class RequestParentTest4 extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements MultiRead { + + @Override + public void perform(ReadGraph graph, AsyncMultiProcedure callback) throws DatabaseException { + callback.execute(graph, new Object()); + callback.finished(graph); + } + + } + + final Request request1 = new Request(); + final Request request2 = new Request(); + + session.syncRequest(request1, new AsyncMultiListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Object result) { + graph.asyncRequest(request2); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + }); + + Set parents = debug.getParents(request2); + for(CacheEntry parent : parents) { + if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2"); + } + if(!parents.isEmpty())fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest5.java new file mode 100644 index 000000000..5b261c75c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest5.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncMultiListener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; + +public class RequestParentTest5 extends SimpleBase { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements Read { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + return new Object(); + } + + } + + final Request request = new Request(); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) throws Throwable { + Layer0 l0 = Layer0.getInstance(graph); + graph.forEachObject(rl, l0.InstanceOf, new AsyncMultiListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Resource result) { + graph.asyncRequest(request); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + }); + + } + + }); + + Set parents = debug.getParents(request); + if(!parents.isEmpty())fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest6.java new file mode 100644 index 000000000..34c73424c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest6.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.Set; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.service.QueryDebug; +import org.simantics.db.procedure.AsyncMultiListener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.layer0.Layer0; + +public class RequestParentTest6 extends SimpleBase { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryDebug debug = session.getService(QueryDebug.class); + + class Request implements Read { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + return new Object(); + } + + } + + final Request request = new Request(); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) throws Throwable { + Layer0 l0 = Layer0.getInstance(graph); + graph.forEachObject(rl, l0.InstanceOf, new AsyncMultiListener() { + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + } + + @Override + public void execute(AsyncReadGraph graph, Resource result) { + graph.asyncRequest(request); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + }); + + } + + }); + + Set parents = debug.getParents(request); + if(!parents.isEmpty())fail("Request2 should not have parents"); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestProcessorTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestProcessorTest1.java new file mode 100644 index 000000000..be32a81fb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestProcessorTest1.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.UnaryAsyncRead; +import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.procedure.Listener; +import org.simantics.db.testing.base.WriteReadTest; +import org.simantics.layer0.Layer0; + +public class RequestProcessorTest1 extends WriteReadTest { + + class R1 extends ResourceRead { + + public R1(Resource resource) { + super(resource); + } + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getURI(resource); + } + + } + + class R2 extends ResourceAsyncRead { + + public R2(Resource resource) { + super(resource); + } + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + graph.forURI(resource, procedure); + } + + } + + class R3 extends UnaryRead { + + public R3(Resource resource) { + super(resource); + } + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getURI(parameter); + } + + } + + class R4 extends UnaryAsyncRead { + + public R4(Resource resource) { + super(resource); + } + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + graph.forURI(parameter, procedure); + } + + } + + class R5 extends UniqueRead { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getURI(graph.getRootLibrary()); + } + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + final ArrayList listeners = new ArrayList(); + + final Listener listener = new ListenerAdapter() { + + @Override + public synchronized void execute(String result) { + listeners.add(result); + } + + }; + + assertEquals(Layer0.URIs.ConsistsOf, graph.sync(new R1(L0.ConsistsOf))); + assertEquals(Layer0.URIs.ConsistsOf, graph.sync(new R2(L0.ConsistsOf))); + assertEquals(Layer0.URIs.ConsistsOf, graph.sync(new R3(L0.ConsistsOf))); + assertEquals(Layer0.URIs.ConsistsOf, graph.sync(new R4(L0.ConsistsOf))); + assertEquals("http:/", graph.sync(new R5())); + + graph.sync(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + graph.async(new R1(L0.ConsistsOf), listener); + graph.async(new R2(L0.ConsistsOf), listener); + graph.async(new R3(L0.ConsistsOf), listener); + graph.async(new R4(L0.ConsistsOf), listener); + graph.async(new R5(), listener); + + } + + }); + + assertEquals(listeners.size(), 5); + + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestQueuingTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestQueuingTest.java new file mode 100644 index 000000000..c17e35797 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestQueuingTest.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.service.QueryControl; +import org.simantics.db.service.QueryControl.ControlProcedure; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class RequestQueuingTest extends ExistingDatabaseTest { + + final private static int LOOPS = 10; + + private Object RESULT = new Object(); + private DatabaseException EXCEPTION = new DatabaseException(); + + private AtomicInteger results = new AtomicInteger(0); + private AtomicInteger exceptions = new AtomicInteger(0); + + class A implements AsyncRead { + + private void perform(AsyncReadGraph graph, final AsyncProcedure procedure, final int todo) { + + if(todo == 0) { + + procedure.execute(graph, RESULT); + + } else { + + final QueryControl control = graph.getService(QueryControl.class); + final int current = control.getGraphThread(graph); + final int next = (current + 1) % control.getAmountOfQueryThreads(); + control.schedule(graph, next, new ControlProcedure() { + + public void execute(AsyncReadGraph graph) { + perform(graph, procedure, todo-1); + } + + }); + + } + + + } + + @Override + public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + perform(graph, procedure, 5); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + } + + class B implements Read { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + return graph.syncRequest(new A()); + + } + + } + + class A2 implements AsyncRead { + + private void perform(AsyncReadGraph graph, final AsyncProcedure procedure, final int todo) { + + if(todo == 0) { + + procedure.exception(graph, EXCEPTION); + + } else { + + final QueryControl control = graph.getService(QueryControl.class); + final int current = control.getGraphThread(graph); + final int next = (current + 1) % control.getAmountOfQueryThreads(); + control.schedule(graph, next, new ControlProcedure() { + + public void execute(AsyncReadGraph graph) { + perform(graph, procedure, todo-1); + } + + }); + + } + + + } + + @Override + public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + perform(graph, procedure, 5); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + } + + class B2 implements Read { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + return graph.syncRequest(new A2()); + + } + + } + + class C implements AsyncListener { + + @Override + public void execute(AsyncReadGraph graph, Object result) { + if(RESULT == result) results.incrementAndGet(); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + if(EXCEPTION == throwable) exceptions.incrementAndGet(); + } + + @Override + public boolean isDisposed() { + return false; + } + + } + + @Test + public void test() throws Exception { + + Session session = getSession(); + + session.syncRequest(new Read() { + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + + A a = new A(); + B b = new B(); + A2 a2 = new A2(); + B2 b2 = new B2(); + for(int i=0;i names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) throws Throwable { + + final Layer0 b = Layer0.getInstance(graph); + Collection rs = graph.getObjects(root, b.ConsistsOf); + for(final Resource r : rs) { + + graph.asyncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + + graph.asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(r, b.HasName); + } + + }, procedure); + + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(String result) { + names.remove(result); + } + + }); + + } + + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest2.java new file mode 100644 index 000000000..971a35dd5 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest2.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.procedure.Listener; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ConcurrentSkipListSet names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) throws Throwable { + + final Layer0 b = Layer0.getInstance(graph); + Collection rs = graph.getObjects(root, b.ConsistsOf); + int index = 0; + for(final Resource r : rs) { + + final int i = index++; + + graph.asyncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + + graph.asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(r, b.HasName); + } + + @Override + public String toString() { + return "Read" + i; + } + + }, procedure); + + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(String result) { + names.remove(result); + } + + }); + + } + + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(Object result) { + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest3.java new file mode 100644 index 000000000..a9d14b235 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest3.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.AsyncReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest3 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ConcurrentSkipListSet names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + if (DEBUG) + System.out.println("Root resource is " + root); + + session.syncRequest(new AsyncReadRequest() { + + @Override + public void run(AsyncReadGraph graph) { + + for(final Resource r : resources) { + + graph.asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + return graph.getRelatedValue(r, b.HasName); + } + + @Override + public String toString() { + return "Read " + r.getResourceId(); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(String result) { + names.remove(result); + } + + }); + + } + + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest4.java new file mode 100644 index 000000000..092e74215 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest4.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest4 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ConcurrentSkipListSet names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + final Layer0 b = Layer0.getInstance(getSession()); + + session.syncRequest(new AsyncRead() { + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + + graph.forPossibleObject(root, b.InstanceOf, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + } + + @Override + public void execute(AsyncReadGraph graph, Resource result) { + + procedure.execute(graph, result); + + for(final Resource r : resources) { + + graph.asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(r, b.HasName); + } + + @Override + public String toString() { + return "Read " + r.getResourceId(); + } + + }, new Procedure() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(String result) { + names.remove(result); + } + + }); + + } + + } + + }); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest5.java new file mode 100644 index 000000000..29b682119 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest5.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncSetListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest5 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ConcurrentSkipListSet names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) { + + Layer0 b = Layer0.getInstance(graph); + graph.forObjectSet(root, b.ConsistsOf, new SyncSetListener() { + + @Override + public void add(ReadGraph graph, final Resource resource) throws DatabaseException { + + graph.asyncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.forObjectSet(resource, b.HasName, new SyncSetListener() { + + @Override + public void add(ReadGraph graph, final Resource resource) throws DatabaseException { + + names.remove(graph.getPossibleValue(resource)); + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + } + + @Override + public void remove(ReadGraph graph, Resource result) throws DatabaseException { + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public String toString() { + return "Inner procedure for " + resource.getResourceId(); + } + + }); + + + } + + @Override + public String toString() { + return "Inner request for " + resource.getResourceId(); + } + + }); + + + + } + + @Override + public void remove(ReadGraph graph, Resource result) throws DatabaseException { + } + + @Override + public void exception(ReadGraph graph, Throwable t) { + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public String toString() { + return "Outer procedure for RootLibrary"; + } + + }); + + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest6.java new file mode 100644 index 000000000..3e1d3ff1f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest6.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncSetListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest6 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final ConcurrentSkipListSet names = new ConcurrentSkipListSet(); + final ArrayList resources = new ArrayList(); + final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph graph) { + Layer0 b = Layer0.getInstance(graph); + graph.forObjectSet(root, b.ConsistsOf, new SyncSetListener() { + + @Override + public void add(ReadGraph graph, final Resource resource) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + names.remove(graph.getRelatedValue(resource, b.HasName)); + + } + + @Override + public void remove(ReadGraph graph, Resource result) throws DatabaseException { + } + + @Override + public void exception(ReadGraph graph, Throwable t) { + } + + @Override + public boolean isDisposed() { + return false; + } + }); + + } + + }); + + assert(names.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest7.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest7.java new file mode 100644 index 000000000..f87a58126 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest7.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.adaption.AdaptionService; +import org.simantics.db.common.adaption.SimpleAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.request.Read; +import org.simantics.db.services.adaption.AdaptionService2; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest7 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + AdaptionService2 adaptionService = new AdaptionService2(); + Layer0 b = Layer0.getInstance(session); + adaptionService.addAdapter(b.Entity, String.class, new SimpleAdapter() { + + @Override + public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException { + return "SIMPLE"; + } + + }); + + session.registerService(AdaptionService.class, adaptionService); + + session.syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + +// Assert.isTrue(path.length > 0); +// String[] namePath = new String[path.length]; +// String description = ""; +// int version = 0; +// for (int i = 0; i < namePath.length; i++) { +// String name = g.getRelatedValue(path[i], g.getBuiltins().HasName); +// Assert.isTrue(name != null); +// Assert.isTrue(name.length() > 0); +// namePath[i] = name; +// +// Layer0 b = Layer0.getInstance(g); +// +// if (i == namePath.length - 1) { +// if (g.isInstanceOf(path[i], b.Project2)) { +// version = 2; +// StringBuilder desc = new StringBuilder(); +// boolean first = true; +// for (Resource pf : g.getObjects(path[i], b.HasFeature)) { +// if (!first) { +// desc.append(", "); +// } +// first = false; +// String d = null; +// try { + return graph.adapt(graph.getRootLibrary(), String.class); +// } catch (AdaptionException e) { +// d = GraphUtils.getReadableName(g, pf.get()); +// } +// desc.append(d); +// } +// description = desc.toString(); +// } +// } + + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest8.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest8.java new file mode 100644 index 000000000..9e9d0c370 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest8.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.primitiverequest.ForObjectSet; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncSetListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest8 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final Set expected = new HashSet(); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + + final Layer0 b = Layer0.getInstance(g); + + g.syncRequest(new ForObjectSet(g.getRootLibrary(), b.InstanceOf, new SyncSetListener() { + + @Override + public void add(ReadGraph graph, Resource type) throws DatabaseException { + + graph.syncRequest(new ForObjectSet(type, b.Inherits, new SyncSetListener() { + + @Override + public void add(ReadGraph graph, Resource result) throws DatabaseException { + + expected.remove(graph.getRelatedValue(result, b.HasName, Bindings.STRING)); + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + assert(false); + } + + @Override + public void remove(ReadGraph graph, Resource result) throws DatabaseException { + assert(false); + } + + @Override + public boolean isDisposed() { + return false; + } + + })); + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + assert(false); + } + + @Override + public void remove(ReadGraph graph, Resource result) throws DatabaseException { + assert(false); + } + + @Override + public boolean isDisposed() { + return false; + } + + })); + + } + + }); + + assert(expected.isEmpty()); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest9.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest9.java new file mode 100644 index 000000000..4d6b1fb46 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest9.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.Statement; +import org.simantics.db.common.primitiverequest.PossibleStatement; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncTest9 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + session.syncRequest(new TestReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + + final Layer0 b = Layer0.getInstance(g); + + g.forPossibleObject(g.getRootLibrary(), b.InstanceOf, new SyncListener() { + + @Override + public void execute(ReadGraph graph, Resource type) throws DatabaseException { + + graph.asyncRequest(new PossibleStatement(type, b.InstanceOf), new SyncListener() { + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + } + + @Override + public void execute(ReadGraph graph, Statement result) throws DatabaseException { + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + +// graph.syncRequest(new ForObjectSet(type, b.Inherits, new SyncSetListener() { +// +// @Override +// public void add(ReadGraph graph, Resource result) throws DatabaseException { +// +// System.out.println(GraphUtils.getReadableName(graph, result)); +// +// graph.asyncRequest(new PossibleStatement(result, b.InstanceOf), new SyncListener() { +// +// @Override +// public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { +// } +// +// @Override +// public void execute(ReadGraph graph, Statement result) throws DatabaseException { +// } +// +// @Override +// public boolean isDisposed() { +// return false; +// } +// +// }); +// +// } +// +// @Override +// public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { +// assert(false); +// } +// +// @Override +// public void remove(ReadGraph graph, Resource result) throws DatabaseException { +// assert(false); +// } +// +// @Override +// public boolean isDisposed() { +// return false; +// } +// +// })); + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + throwable.printStackTrace(); + assert(false); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncUtils.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncUtils.java new file mode 100644 index 000000000..4b94e5c38 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncUtils.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.ArrayList; +import java.util.UUID; +import java.util.concurrent.ConcurrentSkipListSet; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +public class SyncAsyncSyncUtils { + + private static final int SIZE = (int)1e4; + + public static Resource createNames(Session session, final ConcurrentSkipListSet names, final ArrayList resources) throws DatabaseException { + + return session.syncRequest(new WriteOnlyResultRequest() { + + @Override + public Resource perform(WriteOnlyGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g.getService(Session.class)); + + Resource root = g.newResource(); + g.claim(root, b.InstanceOf, null, b.Library); + + for(int i=0;i check = new HashSet(); + for(int i=0;i() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + for(int i=0;i() { + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + throwable.printStackTrace(); + } + + @Override + public void execute(ReadGraph graph, String result) throws DatabaseException { + synchronized(check) { + check.remove(index); + if(check.isEmpty()) s.release(); + } + } + + }); + + } + + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + boolean success = s.tryAcquire(DEADLINE, TimeUnit.MILLISECONDS); + assert(success); + + long end = System.nanoTime(); + if (DEBUG) + System.out.println("success in " + 1e-9*(double)(end-start) + " s."); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest2.java new file mode 100644 index 000000000..710183950 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest2.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.HashSet; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.TestCommonPerf; +import org.simantics.layer0.Layer0; + +public class SyncRequestTest2 extends TestCommonPerf { + + private static final int COUNT = 10000; + + private static final int DEADLINE = 1000; + + @Test(timeout=5000) + @Fails + public void test() throws Exception { + + final Session session = getSession(); + final Layer0 b = Layer0.getInstance(session); + + final HashSet check = new HashSet(); + for(int i=0;i() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + + for(int i=0;i() { + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + throwable.printStackTrace(); + } + + @Override + public void execute(ReadGraph graph, String result) throws DatabaseException { + synchronized(check) { + check.remove(index); + if(check.isEmpty()) s.release(); + } + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + boolean success = s.tryAcquire(DEADLINE, TimeUnit.MILLISECONDS); + + long end = System.nanoTime(); + + System.out.println("success or failure in " + 1e-9*(double)(end-start) + " s."); + + assert(success); + + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest3.java new file mode 100644 index 000000000..8a6de86da --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncRequestTest3.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.misc; + +import java.util.HashSet; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.TestCommonPerf; +import org.simantics.layer0.Layer0; + +public class SyncRequestTest3 extends TestCommonPerf { + + private static final int COUNT = 10000; + + private static final int DEADLINE = 1000; + + @Test + public void test() throws Exception { + + final Session session = getSession(); + + final HashSet check = new HashSet(); + for(int i=0;i() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + return graph.getPossibleRelatedValue(rl, l0.HasName); + } + + }, new SyncListener() { + + @Override + public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { + throwable.printStackTrace(); + } + + @Override + public void execute(ReadGraph graph, String result) throws DatabaseException { + synchronized(check) { + check.remove(index); + if(check.isEmpty()) s.release(); + } + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + boolean success = s.tryAcquire(DEADLINE, TimeUnit.MILLISECONDS); + + long end = System.nanoTime(); + + String t = "SyncRequestTest3 finished in " + 1e-9*(double)(end-start) + " s." + + " Limit was < " + (double)DEADLINE / 1000.0 + " s."; + System.out.println(t); + + if (!success) + fail(t); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest1.java new file mode 100644 index 000000000..cac163968 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest1.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.thread; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.QueryControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/* + * This test ensures that synchronous requests are processed in same thread + * + */ +public class ThreadingTest1 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryControl control = session.getService(QueryControl.class); + if(control.getAmountOfQueryThreads() == 1) return; + + int result = session.syncRequest(new Read() { + + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + + final int thread = graph.thread(); + + return graph.syncRequest(new Read() { + + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + + assert(thread == graph.thread()); + + return 1; + + } + + }); + + } + + @Override + public int hashCode() { + return 0; + } + + }, new ListenerAdapter()); + + assert(result == 1); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest2.java new file mode 100644 index 000000000..f3e1cd14a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest2.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.request.thread; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.QueryControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/* + * This test ensures that synchronous requests are processed in same thread + * + */ +public class ThreadingTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + QueryControl control = session.getService(QueryControl.class); + if(control.getAmountOfQueryThreads() == 1) return; + + int result = session.syncRequest(new Read() { + + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + + final int thread = graph.thread(); + + return graph.syncRequest(new Read() { + + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + + assert(thread == graph.thread()); + + return 1; + + } + + }); + + } + + @Override + public int hashCode() { + return 0; + } + + }, new ListenerAdapter()); + + assert(result == 1); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/SuiteStory.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/SuiteStory.java new file mode 100644 index 000000000..7f10a7e9b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/SuiteStory.java @@ -0,0 +1,38 @@ +package org.simantics.db.tests.api.story; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.story.misc.DataModelTest; +//import org.simantics.db.tests.api.story.misc.GenerateStructuralTest; +import org.simantics.db.tests.api.story.misc.QuerySemanticsTest; +import org.simantics.db.tests.api.story.misc.SyntheticModellingTest; +import org.simantics.db.tests.api.story.misc.TextIndexingTest; +import org.simantics.db.tests.api.story.sessionGarbageCollection.CollectDuringWriteAndRead; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + // misc + DataModelTest.class, +// GenerateStructuralTest.class, + QuerySemanticsTest.class, + SyntheticModellingTest.class, + TextIndexingTest.class, + // sessionGarbageCollection + CollectDuringWriteAndRead.class +}) +public class SuiteStory { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/DataModelTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/DataModelTest.java new file mode 100644 index 000000000..2dc011d51 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/DataModelTest.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.story.misc; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * + * @author Marko Luukkainen + * + */ +public class DataModelTest extends ExistingDatabaseTest { + + /** + * Creates new instance and then tries to find it. + * @throws Exception + */ + @Test + public void testCreateInstance() throws Exception{ + Session session = getSession(); + final Resource rootLib = getSession().getRootLibrary(); + final String newInstanceName = "New Instance " + getRandomString(); + + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, newResource); +// comment(g, newResource, "DataModelTest.testCreateInstance"); + } + }); + + checkException(); + + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new Exception("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new Exception("Created resource is not an instance of Type"); + } + }); + + checkException(); + + } + + /** + * Creates new type and new instance of it. Then tries to find the instance and the type, and verifies that inheritance is correct. + * @throws Exception + */ + @Test + public void testCreateInstance2() throws Exception{ + Session session = getSession(); + final Resource rootLib = getSession().getRootLibrary(); + final String random = getRandomString(); + final String newTypeName = "New Type " + random; + final String newInstanceName = "New Instance " + random; + + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Resource newType = g.newResource(); + g.claim(newType, b.InstanceOf, null, b.Type); + g.claim(newType, b.Inherits, b.SupertypeOf, b.Type); + g.claimLiteral(newType, b.HasName, newTypeName); + g.claim(rootLib, b.ConsistsOf, newType); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, newType); + g.claimLiteral(newResource, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, newResource); + Map md = new HashMap(); + md.put("DataModelTest2", "DataModelTest2"); +// fillMetadata(md); + } + + }); + + checkException(); + + session.syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + Resource newType = null; + Resource newInstance = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null == value) + continue; + if (value.equals(newTypeName)) { + newType = r; + } else if (value.equals(newInstanceName)) { + newInstance = r; + } + } + if (newType == null) + throw new Exception("Could not find created type"); + if (newInstance == null) + throw new Exception("Could not find created instance"); + + if (!g.isInstanceOf(newInstance, b.Type)) + throw new Exception("Created resource is not an instance of Type"); + if (!g.isInstanceOf(newInstance, newType)) + throw new Exception("Created resource is not an instance of created type"); + } + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/QuerySemanticsTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/QuerySemanticsTest.java new file mode 100644 index 000000000..3bba394f1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/QuerySemanticsTest.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.story.misc; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; + +public class QuerySemanticsTest { + + Session session; + Layer0 b; + + Resource instance1; + Resource relation1; + Resource type1; + + Resource createRelation(WriteGraph g, String name) throws DatabaseException { + Resource result = g.newResource(); + g.claimLiteral(result, b.HasName, name); + Resource inv = g.newResource(); + g.claim(result, b.SubrelationOf, b.IsRelatedTo); + g.claim(inv, b.SubrelationOf, b.IsRelatedTo); + g.claim(result, b.InverseOf, inv); + return result; + } + + Resource createFunctionalRelation(WriteGraph g, String name) throws DatabaseException { + Resource result = createRelation(g, name); + g.claim(result, b.InstanceOf, b.FunctionalRelation); + return result; + } + + Resource createType(WriteGraph g, String name) throws DatabaseException { + Resource result = g.newResource(); + g.claimLiteral(result, b.HasName, name); + g.claim(result, b.Inherits, b.Entity); + return result; + } + + Resource createInstance(WriteGraph g, String name, Resource type) throws DatabaseException { + Resource result = g.newResource(); + g.claimLiteral(result, b.HasName, name); + g.claim(result, b.InstanceOf, type); + return result; + } + + void assertion(WriteGraph g, Resource type, Resource pred, Resource obj) throws DatabaseException { + Resource assertion = g.newResource(); + g.claim(assertion, b.InstanceOf, b.Assertion); + g.claim(type, b.Asserts, assertion); + g.claim(assertion, b.HasPredicate, pred); + g.claim(assertion, b.HasObject, obj); + } + + @Before + public void setUp() throws Exception { +// SessionFactory factory = new SessionFactory(Configuration.get().host, Configuration.get().port); +// session = factory.create(); + session = Tests.getTestHandler().getSession(); + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + b = Layer0.getInstance(g); + + relation1 = createFunctionalRelation(g, "Relation1"); + type1 = createType(g, "Type1"); + instance1 = createInstance(g, "Instance1", type1); + assertion(g, type1, relation1, b.Double); + g.claim(instance1, relation1, b.Float); + } + + }); + } + + @After + public void tearDown() throws Exception { + LifecycleSupport support = session.getService(LifecycleSupport.class); + support.close(); + } + + @Fails + @Test + public void test() { + try { + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + System.out.println("--- getStatements(relation1) ---------------------"); + for(Statement stat : g.getStatements(instance1, relation1)) { + System.out.println( + NameUtils.getSafeName(g, stat.getSubject()) + " " + + NameUtils.getSafeName(g, stat.getPredicate()) + " " + + NameUtils.getSafeName(g, stat.getObject()) + ); + } + System.out.println("--- getStatements(IsRelatedTo) ---------------------"); + for(Statement stat : g.getStatements(instance1, b.IsRelatedTo)) { + System.out.println( + NameUtils.getSafeName(g, stat.getSubject()) + " " + + NameUtils.getSafeName(g, stat.getPredicate()) + " " + + NameUtils.getSafeName(g, stat.getObject()) + ); + } + System.out.println("--- getObjects(relation1) ---------------------"); + for(Resource r : g.getObjects(instance1, relation1)) { + System.out.println( + NameUtils.getSafeName(g, r) + ); + } + System.out.println("--- getObjects(IsRelatedTo) ---------------------"); + for(Resource r : g.getObjects(instance1, b.IsRelatedTo)) { + System.out.println( + NameUtils.getSafeName(g, r) + ); + } + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/SyntheticModellingTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/SyntheticModellingTest.java new file mode 100644 index 000000000..02ab4a1fd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/SyntheticModellingTest.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.story.misc; + +import gnu.trove.set.hash.THashSet; + +import java.util.ArrayList; +import java.util.Random; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; +import org.simantics.project.ontology.ProjectResource; + +public class SyntheticModellingTest extends ExistingDatabaseTest { + + static int LOOP_COUNT = Configuration.get().modellingLoopCount; + static int OP_COUNT = Configuration.get().modellingOpCount; + Session session; + Resource root; + Layer0 b; + + Resource Component; + Resource Composite; + Resource IsDefinedBy; + Resource Connection; + Resource IsConnected; + Resource IsConnectedTo; + Resource IsConnectedFrom; + + int componentTypeCount = 0; + int componentCount = 0; + int connectionCount = 0; + + static class Component { + Resource resource; + ComponentType type; + } + + static class ComponentType { + Resource resource; + Resource composite; + ArrayList components = new ArrayList(); + ArrayList connections = new ArrayList(); + } + + ArrayList componentTypes = new ArrayList(); + + Random random = new Random(0x12345679); + +// @Override +// protected void setUp() throws Exception { +// SessionFactory factory = new SessionFactory(Configuration.get().host, Configuration.get().port); +// session = factory.create(); +// } +// +// @Override +// protected void tearDown() throws Exception { +// LifecycleSupport support = session.getService(LifecycleSupport.class); +// support.close(); +// } + + class SetUp extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + b = Layer0.getInstance(g); + + ProjectResource PROJ = ProjectResource.getInstance(g); + + root = g.newResource(); + g.claim(root, b.InstanceOf, PROJ.Project); + + Component = g.getResource("http://www.simantics.org/Structural-1.0/Component"); + Composite = g.getResource("http://www.simantics.org/Structural-1.0/Composite"); + IsDefinedBy = g.getResource("http://www.simantics.org/Structural-1.0/IsDefinedBy"); + Connection = g.getResource("http://www.simantics.org/Structural-1.0/Connection"); + IsConnected = g.getResource("http://www.simantics.org/Structural-1.0/IsConnected"); + IsConnectedTo = g.getResource("http://www.simantics.org/Structural-1.0/IsConnectedTo"); + IsConnectedFrom = g.getResource("http://www.simantics.org/Structural-1.0/IsConnectedFrom"); + + } + + } + + class NewComponentType extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + ComponentType componentType = new ComponentType(); + + componentType.resource = g.newResource(); + g.claim(componentType.resource, b.Inherits, Component); + g.claim(root, b.ConsistsOf, componentType.resource); + g.claimLiteral(componentType.resource, b.HasName, "ComponentType" + componentType.resource.getResourceId()); + + componentType.composite = g.newResource(); + g.claim(componentType.composite, b.Inherits, Composite); + g.claim(componentType.resource, IsDefinedBy, componentType.composite); + + componentTypes.add(componentType); + + ++componentTypeCount; + } + + } + + class NewComponent extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + ComponentType componentType = componentTypes.get(random.nextInt(componentTypes.size())); + ComponentType containerType = componentTypes.get(random.nextInt(componentTypes.size())); + + Component component = new Component(); + + component.resource = g.newResource(); + g.claim(component.resource, b.InstanceOf, componentType.resource); + g.claim(containerType.composite, b.ConsistsOf, component.resource); + + g.claimLiteral(component.resource, b.HasName, "Component" + componentType.resource.getResourceId()); + + containerType.components.add(component); + + ++componentCount; + } + + } + + class RemoveComponent extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + ComponentType containerType = componentTypes.get(random.nextInt(componentTypes.size())); + if(containerType.components.isEmpty()) + return; + int cid = random.nextInt(containerType.components.size()); + Component component = containerType.components.get(cid); + THashSet removed = new THashSet(); + for(Resource c : g.getObjects(component.resource, IsConnected)) + if(removed.add(c)) { + g.deny(c); + int id = containerType.connections.indexOf(c); + int last = containerType.connections.size()-1; + if(id < last) + containerType.connections.set(id, containerType.connections.remove(last)); + else + containerType.connections.remove(last); + --connectionCount; + } + g.deny(component.resource); + { + int last = containerType.components.size() - 1; + if(cid < last) + containerType.components.set(cid, containerType.components.remove(last)); + else + containerType.components.remove(last); + } + + --componentCount; + } + + } + + class NewConnection extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + ComponentType containerType = componentTypes.get(random.nextInt(componentTypes.size())); + if(containerType.components.isEmpty()) + return; + + Component c1 = containerType.components.get(random.nextInt(containerType.components.size())); + Component c2 = containerType.components.get(random.nextInt(containerType.components.size())); + + Resource connection = g.newResource(); + g.claim(connection, b.InstanceOf, Connection); + g.claim(c1.resource, IsConnectedTo, connection); + g.claim(c2.resource, IsConnectedFrom, connection); + + containerType.connections.add(connection); + + ++connectionCount; + } + + } + + class RemoveConnection extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + ComponentType containerType = componentTypes.get(random.nextInt(componentTypes.size())); + if(containerType.connections.isEmpty()) + return; + + int id = random.nextInt(containerType.connections.size()); + g.deny(containerType.connections.get(id)); + int last = containerType.connections.size()-1; + if(id < last) + containerType.connections.set(id, containerType.connections.remove(last)); + else + containerType.connections.remove(last); + + --connectionCount; + } + + } + + @Fails + @Test public void test() { + try { + session = getSession(); + session.syncRequest(new SetUp()); + for(int i=0;i<100;++i) + session.syncRequest(new NewComponentType()); + for(int i=0;i 1000) + session.syncRequest(new RemoveComponent()); + else + session.syncRequest(new NewComponent()); + break; + case 3: + session.syncRequest(new NewConnection()); + break; + case 4: + session.syncRequest(new RemoveConnection()); + break; + case 5: + case 6: + case 7: + if(connectionCount > 1000) + session.syncRequest(new RemoveConnection()); + else + session.syncRequest(new NewConnection()); + break; + } + long endTime = System.nanoTime(); + System.out.println((endTime - startTime) * 1e-9 + "s / 1000 operations"); + System.out.println( + componentTypeCount + " user components, " + + componentCount + " components, " + + connectionCount + " connections" + ); + } + } catch (DatabaseException e) { + if (DEBUG) + e.printStackTrace(); + fail("Test failed with: " + e.getMessage()); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/TextIndexingTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/TextIndexingTest.java new file mode 100644 index 000000000..69fb085b2 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/misc/TextIndexingTest.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.story.misc; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +public class TextIndexingTest { + + static String host = Configuration.get().host; + static int port = Configuration.get().port; + static String dataFileName = Configuration.get().textIndexingFile; + Session session; + Text text; + Resource root; + Resource[] relations = new Resource[128]; + + @Before + public void setUp() throws Exception { +// SessionFactory factory = new SessionFactory(host, port); +// session = factory.create(); + session = Tests.getTestHandler().getSession(); + } + + @After + public void tearDown() throws Exception { + LifecycleSupport support = session.getService(LifecycleSupport.class); + support.close(); + } + + class SetUp extends WriteRequest { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + root = g.newResource(); + Layer0 l0 = Layer0.getInstance(g); + for(int i=0;i<128;++i) { + relations[i] = g.newResource(); + Resource inv = g.newResource(); + g.claim(relations[i], l0.InverseOf, inv); + g.claim(relations[i], l0.SubrelationOf, l0.IsRelatedTo); + g.claim(inv, l0.SubrelationOf, l0.IsWeaklyRelatedTo); + } + } + + } + + boolean finished = false; + + class WriteTrie extends WriteRequest { + + int count = 0; + int newWords = 0; + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + try { + + //System.out.println("T"); + byte[] word; + Layer0 b = Layer0.getInstance(g); + long startTime = System.nanoTime(); + while( (word = text.getWord()) != null ) { + + if(word == PEND) + continue; + + Resource cur = root; + for(int i=0;i { + + @Override + protected void run(WriteGraph graph, CollectDuringWriteAndRead environment) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource root = environment.getRoot(); + int listSize = environment.getListSize(); + int index = environment.incrementAndGetIndex(); + + Resource r = ListUtils.create(graph, Collections.emptyList()); + graph.addLiteral(r, L0.HasName, L0.NameOf, L0.String, "" + (index), Bindings.STRING); + graph.claim(root, L0.ConsistsOf, r); + + for(int i=0,index2=0;i<3;i++) { + ArrayList rs = new ArrayList(); + for(int j=0;j { + + @Override + protected void run(WriteGraph graph, CollectDuringWriteAndRead environment) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource root = environment.getRoot(); + int listSize = environment.getListSize(); + int index = environment.incrementAndGetIndex(); + + Resource r = ListUtils.create(graph, Collections.emptyList()); + graph.addLiteral(r, L0.HasName, L0.NameOf, L0.String, "" + (index), Bindings.STRING); + graph.claim(root, L0.ConsistsOf, r); + + for(int i=0,index2=0;i<3;i++) { + ArrayList rs = new ArrayList(); + for(int j=0;j { + + @Override + protected void run(WriteGraph graph, CollectDuringWriteAndRead environment) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource root = environment.getRoot(); + int listSize = environment.getListSize(); + int index = environment.incrementAndGetIndex(); + + Collection lists = graph.getObjects(root, L0.ConsistsOf); + if(lists.size() == 0) return; + + int position = environment.randomNatural() % lists.size(); + + Resource r = CollectionUtils.element(lists, position); + + for(int i=0,index2=0;i<3;i++) { + ArrayList rs = new ArrayList(); + for(int j=0;j[] getFactories() { + return new CommandSpec[] { + CommandSpec.make(AddList.class, 1.0), + CommandSpec.make(RemoveList.class, 1.0), + CommandSpec.make(AppendList.class, 0.5), + CommandSpec.make(Read.class, 0.1), + CommandSpec.make(AddListAndKill.class, 0.02), + CommandSpec.make(Reconnect.class, 0.02), + CommandSpec.make(Kill.class, 0.02) + }; + } + + protected Command[] beforeSequence(CommandSequenceEnvironment environment) throws Exception { + + return new Command[] { + + new Command() { + + @Override + public void run(CommandSequenceEnvironment environment) throws Exception { + + Session s = getSession(); + root = s.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + + }); + for(int i=0;i<10;i++) new AddList().run(CollectDuringWriteAndRead.this); + SessionGarbageCollection.gc(null, s, true, null, 0, 0); + + } + + } + + }; + + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/sessionGarbageCollection/Read.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/sessionGarbageCollection/Read.java new file mode 100644 index 000000000..94e7d1fac --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/sessionGarbageCollection/Read.java @@ -0,0 +1,42 @@ +package org.simantics.db.tests.api.story.sessionGarbageCollection; + +import java.util.Collection; +import java.util.List; + +import org.junit.Assert; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.common.ReadCommand; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.collections.CollectionUtils; + +public class Read extends ReadCommand { + + @Override + protected void run(ReadGraph graph, CollectDuringWriteAndRead environment) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource root = environment.getRoot(); + int size = environment.getListSize(); + + Collection lists = graph.getObjects(root, L0.ConsistsOf); + if(lists.size() == 0) return; + + int position = environment.randomNatural() % lists.size(); + + Resource list = CollectionUtils.element(lists, position); + + List rs = ListUtils.toList(graph, list); + String n = graph.getRelatedValue(list, L0.HasName, Bindings.STRING); + for(int i=0;i { + + @Override + protected void run(WriteGraph graph, CollectDuringWriteAndRead environment) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource root = environment.getRoot(); + + Collection lists = graph.getObjects(root, L0.ConsistsOf); + if(lists.size() == 0) return; + + int position = environment.randomNatural() % lists.size(); + + Resource list = CollectionUtils.element(lists, position); + RemoverUtil.remove(graph, list); + graph.deny(root, L0.ConsistsOf, list); + + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/SuiteSupport.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/SuiteSupport.java new file mode 100644 index 000000000..2ac00b79d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/SuiteSupport.java @@ -0,0 +1,142 @@ +package org.simantics.db.tests.api.support; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.support.clusterBuilder.WriteOrderTest; +import org.simantics.db.tests.api.support.clusterControl.CachedDirectPredicatesWithNoCluster; +import org.simantics.db.tests.api.support.clusterControl.ClaimIntoNewResourceAfterIntermediateClusterCollect; +import org.simantics.db.tests.api.support.clusterControl.ClaimIntoNewResourceAfterIntermediateClusterCollect2; +import org.simantics.db.tests.api.support.clusterControl.CreateAndCollectBigClusterInUpdateTest; +import org.simantics.db.tests.api.support.clusterControl.DenyCollectedResourceTest; +import org.simantics.db.tests.api.support.clusterControl.DenyCollectedResourceTest2; +import org.simantics.db.tests.api.support.clusterControl.DenyCollectedResourceTest3; +import org.simantics.db.tests.api.support.clusterControl.DenyCollectedResourceTest4; +import org.simantics.db.tests.api.support.clusterControl.ObjectsWithNoClusterWithCachedRelationInfo; +import org.simantics.db.tests.api.support.clusterControl.QueryCollectedResourceTest; +import org.simantics.db.tests.api.support.clusterControl.WriteAfterClusterCollectTest; +import org.simantics.db.tests.api.support.clusterControl.WriteAfterClusterCollectTest2; +import org.simantics.db.tests.api.support.clusterControl.WriteAfterClusterCollectTest3; +import org.simantics.db.tests.api.support.clusterControl.WriteIntoCollectedResourceTest; +import org.simantics.db.tests.api.support.clusterControl.WriteIntoCollectedResourceTest2; +import org.simantics.db.tests.api.support.clusterControl.WriteIntoCollectedResourceTest3; +import org.simantics.db.tests.api.support.clusterControl.WriteIntoCollectedResourceTest4; +import org.simantics.db.tests.api.support.clusterControl.WriteNewResourceIntoCollectedCluster; +import org.simantics.db.tests.api.support.managementSupport.FetchChangeSetsTest; +import org.simantics.db.tests.api.support.managementSupport.GetHeadRevisionTest; +import org.simantics.db.tests.api.support.managementSupport.GetMetadataTest; +import org.simantics.db.tests.api.support.queryControl.CleanCollectQueriesTest; +import org.simantics.db.tests.api.support.serialisationSupport.RandomAccessIdTest; +import org.simantics.db.tests.api.support.serialisationSupport.RandomAccessIdTest1; +import org.simantics.db.tests.api.support.transferableGraphSupport.TransferableGraphSupportTest1; +import org.simantics.db.tests.api.support.transferableGraphSupport.TransferableGraphSupportTest2; +import org.simantics.db.tests.api.support.undoRedoSupport.RedoTest1; +import org.simantics.db.tests.api.support.undoRedoSupport.RedoTest2; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest01; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest02; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest03; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest04; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest05; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest06; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest07; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest08; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest09; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest10; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest11; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest12; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest13; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest14; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest15; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest16; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest17; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest18; +import org.simantics.db.tests.api.support.undoRedoSupport.UndoTest20; +import org.simantics.db.tests.api.support.virtualGraphSupport.PersistentSetValueIntoVirtualResourceTest; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphSupportListStatementsTest; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphTest; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphTest2; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphTest3; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphTest5; +import org.simantics.db.tests.api.support.virtualGraphSupport.VirtualGraphTest6; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + // clusterBuilder + WriteOrderTest.class, + // clusterControl + CachedDirectPredicatesWithNoCluster.class, + ClaimIntoNewResourceAfterIntermediateClusterCollect.class, + ClaimIntoNewResourceAfterIntermediateClusterCollect2.class, + CreateAndCollectBigClusterInUpdateTest.class, + DenyCollectedResourceTest.class, + DenyCollectedResourceTest2.class, + DenyCollectedResourceTest3.class, + DenyCollectedResourceTest4.class, + ObjectsWithNoClusterWithCachedRelationInfo.class, + QueryCollectedResourceTest.class, + WriteAfterClusterCollectTest.class, + WriteAfterClusterCollectTest2.class, + WriteAfterClusterCollectTest3.class, + WriteIntoCollectedResourceTest.class, + WriteIntoCollectedResourceTest2.class, + WriteIntoCollectedResourceTest3.class, + WriteIntoCollectedResourceTest4.class, + WriteNewResourceIntoCollectedCluster.class, + // managementSupport + GetHeadRevisionTest.class, + FetchChangeSetsTest.class, + GetMetadataTest.class, + // queryControl + CleanCollectQueriesTest.class, + // serialisationSupport + RandomAccessIdTest.class, + RandomAccessIdTest1.class, + // transferableGraphSupport + TransferableGraphSupportTest1.class, + TransferableGraphSupportTest2.class, + // undoRedoSupport + RedoTest1.class, + RedoTest2.class, + UndoTest01.class, + UndoTest02.class, + UndoTest03.class, + UndoTest04.class, + UndoTest05.class, + UndoTest06.class, + UndoTest07.class, + UndoTest08.class, + UndoTest09.class, + UndoTest10.class, + UndoTest11.class, + UndoTest12.class, + UndoTest13.class, + UndoTest14.class, + UndoTest15.class, + UndoTest16.class, + UndoTest17.class, + UndoTest18.class, + UndoTest20.class, + // virtualGraphSupport + PersistentSetValueIntoVirtualResourceTest.class, + VirtualGraphSupportListStatementsTest.class, + VirtualGraphTest.class, + VirtualGraphTest2.class, + VirtualGraphTest3.class, + VirtualGraphTest5.class, + VirtualGraphTest6.class +}) +public class SuiteSupport { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java new file mode 100644 index 000000000..3cb6fae3e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java @@ -0,0 +1,122 @@ +package org.simantics.db.tests.api.support.clusterBuilder; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.ClusterBuilder; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.service.ClusterBuilder.ResourceHandle; +import org.simantics.db.service.ClusterBuilder.StatementHandle; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class WriteOrderTest extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws DatabaseException { + + Session session = getSession(); + + final Layer0 b = Layer0.getInstance(session); + + final Resource res = session.syncRequest(new WriteOnlyResultRequest() { + + @Override + public Resource perform(WriteOnlyGraph graph) throws DatabaseException { + + ClusterBuilder builder = graph.getService(ClusterBuilder.class); + SerialisationSupport ss = graph.getService(SerialisationSupport.class); + + ResourceHandle hasNameR = builder.resource(b.HasName); + ResourceHandle nameOfR = builder.resource(b.NameOf); + if (DEBUG) + System.out.println("Name of resource is " + nameOfR); + ResourceHandle instanceOfR = builder.resource(b.InstanceOf); + ResourceHandle libraryR = builder.resource(b.Library); + ResourceHandle stringR = builder.resource(b.String); + ResourceHandle consistsOf = builder.resource(b.ConsistsOf); + if (DEBUG) + System.out.println("ConsistsOf resource is " + consistsOf); + ResourceHandle partOf = builder.resource(b.PartOf); + + StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR); + StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR); + if (DEBUG) + System.out.println("Instance of string is " + instanceOfString); + +// ResourceHandle root = builder.newResource(); +// root.addStatement(instanceOf); +// +// ResourceHandle rootLiteral = builder.newResource(); +// rootLiteral.addStatement(instanceOfString); +// rootLiteral.addStatement(nameOf, root); +// rootLiteral.addValue(name, binding); +// root.addStatement(hasName, rootLiteral); + +// System.out.println("root: " + root.resource()); +// System.out.println("literal: " + rootLiteral.resource()); + +// graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding); +// graph.claim(root, b.InstanceOf, null, b.Library); + +// StatementHandle rootPart = builder.newStatement(b.PartOf, root); + + ResourceHandle level1 = builder.newResource(); + level1.addStatement(instanceOf); + level1.addStatement(partOf, level1); +// root.addStatement(consistsOf, level1); +// ResourceHandle level1Literal = builder.newResource(); +// level1Literal.addStatement(instanceOfString); +// level1Literal.addStatement(nameOf, level1); +// level1Literal.addValue(name, binding); + level1.addStatement(hasNameR, level1); + + StatementHandle level1Part = builder.newStatement(partOf, level1); + if (DEBUG) + System.out.println("Level1Part is " + level1Part); + +// System.out.println("root: " + root.resource()); +// System.out.println("literal: " + rootLiteral.resource()); + +// graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding); +// graph.claim(root, b.InstanceOf, null, b.Library); + + return level1.resource(ss); + +// Resource parent = graph.newResource(); +// Resource res = graph.newResource(); +// Resource child = graph.newResource(); +// Resource literal = graph.newResource(); +// graph.claim(parent, L0.ConsistsOf, L0.PartOf, res); +// graph.claim(res, L0.HasName, L0.NameOf, literal); +// graph.claim(res, L0.ConsistsOf, L0.PartOf, child); +// graph.claim(res, L0.InstanceOf, null, L0.Library); +// graph.claim(literal, L0.InstanceOf, null, L0.String); +// graph.claimValue(literal, "A", Bindings.STRING); +// return res; + + } + + }); + + Resource name = session.syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getSingleObject(res, L0.HasName); +// return graph.getRelatedValue(res, L0.HasName); + } + + }); + if (DEBUG) + System.err.println("name: " + name); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CachedDirectPredicatesWithNoCluster.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CachedDirectPredicatesWithNoCluster.java new file mode 100644 index 000000000..19091b518 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CachedDirectPredicatesWithNoCluster.java @@ -0,0 +1,74 @@ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class CachedDirectPredicatesWithNoCluster extends ExistingDatabaseTest { + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + + final Layer0 L0 = Layer0.getInstance(session); + + session.syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + return graph.hasStatement(L0.Entity); + } + + }, new ListenerAdapter()); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + session.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + graph.forHasStatement(L0.Entity, procedure); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }, new AsyncProcedureAdapter() { + + @Override + public void execute(AsyncReadGraph graph, Boolean result) { + if (DEBUG) + System.err.println("exec: " + result); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + if (DEBUG) + System.err.println("exception: " + t); + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect.java new file mode 100644 index 000000000..1d5140c0d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * + * @author Antti Villberg + * + */ +public class ClaimIntoNewResourceAfterIntermediateClusterCollect extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + // Start new cluster + graph.flushCluster(); + + // Create some resources + for(int i=0;i<1000;i++) graph.newResource(); + + // Create and store a resource + Resource target = graph.newResource(); + + // Flush clusters including the one just created + getSession().getService(ClusterControl.class).collectClusters(Integer.MAX_VALUE); + + // Write into the stored resource + graph.claim(target, target, target); + + } + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect2.java new file mode 100644 index 000000000..2b16814c3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ClaimIntoNewResourceAfterIntermediateClusterCollect2.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * + * @author Antti Villberg + * + */ +public class ClaimIntoNewResourceAfterIntermediateClusterCollect2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + // Start new cluster + graph.flushCluster(); + // Create a resource + graph.newResource(); + + } + }); + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + // Create some resources + for(int i=0;i<1000;i++) graph.newResource(); + + // Create and store a resource + Resource target = graph.newResource(); + + // Flush clusters including the one just created + getSession().getService(ClusterControl.class).collectClusters(Integer.MAX_VALUE); + + // Write into the stored resource + graph.claim(target, target, target); + + } + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CreateAndCollectBigClusterInUpdateTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CreateAndCollectBigClusterInUpdateTest.java new file mode 100644 index 000000000..66d80f6ba --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CreateAndCollectBigClusterInUpdateTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.event.ChangeEvent; +import org.simantics.db.event.ChangeListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.GraphChangeListenerSupport; +import org.simantics.db.testing.cases.FreshDatabaseTest; + +public class CreateAndCollectBigClusterInUpdateTest extends FreshDatabaseTest { + + Resource resource1; + Resource resource2; + Resource resource3; + + @Test + public void test() throws Exception{ + + GraphChangeListenerSupport changeListenerSupport = getSession().getService(GraphChangeListenerSupport.class); + changeListenerSupport.addMetadataListener( new ChangeListener() { + + @Override + public void graphChanged(ChangeEvent e) throws DatabaseException { + + // Collect + ClusterControl cc = e.getGraph().getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + + Arrays.equals(testArray(10), (byte[])e.getGraph().getValue(resource1, Bindings.BYTE_ARRAY)); + Arrays.equals(testArray(100000), (byte[])e.getGraph().getValue(resource2, Bindings.BYTE_ARRAY)); + Arrays.equals(testArray(10), (byte[])e.getGraph().getValue(resource3, Bindings.BYTE_ARRAY)); + + } + + } ); + + + getSession().sync(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + g.flushCluster(); + + for(int i=0;i<1000;i++) g.newResource(); + resource1 = g.newResource(); + g.claimValue(resource1, testArray(10), Bindings.BYTE_ARRAY); + + for(int i=0;i<1000;i++) g.newResource(); + resource2 = g.newResource(); + g.claimValue(resource2, testArray(100000), Bindings.BYTE_ARRAY); + + for(int i=0;i<1000;i++) g.newResource(); + resource3 = g.newResource(); + g.claimValue(resource3, testArray(10), Bindings.BYTE_ARRAY); + + } + + }); + + } + + byte[] testArray(int size) { + byte[] result = new byte[size]; + for(int i=0;i + * + */ +public class DenyCollectedResourceTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.deny(rootLib, b.IsRelatedTo, rootLib); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest2.java new file mode 100644 index 000000000..273a3b651 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest2.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class DenyCollectedResourceTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.deny(rootLib, foreign.get(), null, rootLib); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest3.java new file mode 100644 index 000000000..93ba047db --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest3.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class DenyCollectedResourceTest3 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.deny(rootLib, rootLib, null, foreign.get()); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest4.java new file mode 100644 index 000000000..053dc3f0c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/DenyCollectedResourceTest4.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class DenyCollectedResourceTest4 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.denyValue(foreign.get()); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java new file mode 100644 index 000000000..0596f7658 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java @@ -0,0 +1,49 @@ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleObject; +import org.simantics.db.common.procedure.adapter.ListenerAdapter; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class ObjectsWithNoClusterWithCachedRelationInfo extends ExistingDatabaseTest { + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + + final Layer0 L0 = Layer0.getInstance(session); + + // Create resource in new cluster (not 1) + final Resource res = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Resource res = graph.newResource(); + graph.claim(res, L0.HasName, L0.NameOf, res); + return res; + + } + + }); + + // Cache RelationInfo for HasName + session.syncRequest(new PossibleObject(L0.Entity, L0.HasName), new ListenerAdapter()); + + // Flush clusters + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + // Request objects for res, now relationinfo is in cache and res has no cluster + session.syncRequest(new PossibleObject(res, L0.HasName)); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/QueryCollectedResourceTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/QueryCollectedResourceTest.java new file mode 100644 index 000000000..b6671ccbc --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/QueryCollectedResourceTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class QueryCollectedResourceTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + g.claimValue(f, "", Bindings.STRING); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.getValue(foreign.get(), Bindings.STRING); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest.java new file mode 100644 index 000000000..136cdb944 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteAfterClusterCollectTest extends ExistingDatabaseTest { + @Test + public void test() throws Exception{ + +// final Resource rootLib = getRootLibrary(); + final String random = getRandomString(); + + final Resource rootLib = getSession().syncRequest(new WriteOnlyResultRequest() { + @Override + public Resource perform(WriteOnlyGraph g) throws DatabaseException { + Resource rootLib = g.newResource(); + for (int i = 0; i < 1000; i++) { + Layer0 b = Layer0.getInstance(getSession()); + String newInstanceName = random + i; + Resource instance = g.newResource(); + g.claim(instance, b.InstanceOf, null, b.Type); + g.addLiteral(instance, b.HasName, b.NameOf, b.String, newInstanceName, Bindings.STRING); + g.claim(rootLib, b.ConsistsOf, b.PartOf, instance); + } + return rootLib; + } + }); + + checkException(); + + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("Resource=" + r + " name=" + name); + } + } + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + checkException(); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("Resource=" + r + " name=" + name); + String newInstanceName = random; + Resource instance = g.newResource(); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(r, b.ConsistsOf, b.PartOf, instance); + } + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest2.java new file mode 100644 index 000000000..91cce6d33 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest2.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteAfterClusterCollectTest2 extends ExistingDatabaseTest { + private int LOOP = Configuration.get().collectedLoopCount; + @Test + public void test() throws Exception{ + + final String random = getRandomString(); + + final Resource rootLib = getSession().syncRequest(new WriteOnlyResultRequest() { + @Override + public Resource perform(WriteOnlyGraph g) throws DatabaseException { + Resource rootLib = g.newResource(); + for (int i = 0; i < 10; i++) { + for (int j = 0; j < LOOP; j++) { + Layer0 b = Layer0.getInstance(getSession()); + String newInstanceName = random + i; + Resource instance = g.newResource(); + g.claim(instance, b.InstanceOf, null, b.Type); + g.addLiteral(instance, b.HasName, b.NameOf, b.String, newInstanceName, Bindings.STRING); + g.claim(rootLib, b.ConsistsOf, b.PartOf, instance); + g.flushCluster(); + } + } + return rootLib; + } + }); + + checkException(); + + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("Name is " + name); + } + } + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + checkException(); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("Name is " + name); + String newInstanceName = random; + Resource instance = g.newResource(); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(r, b.ConsistsOf, b.PartOf, instance); + } + + } + + }); + + checkException(); + + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("Name is " + name); + } + } + }); + + checkException(); + + support.collectClusters(Integer.MAX_VALUE); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest3.java new file mode 100644 index 000000000..10d311f74 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteAfterClusterCollectTest3.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; + +public class WriteAfterClusterCollectTest3 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource resource = getSession().syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + return g.newResource(); + } + }); + + checkException(); + + getSession().syncRequest(new HasStatementSubject(resource)); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + checkException(); + + getSession().syncRequest(new WriteQuery(this) { + + @Override + public void run(WriteGraph g) throws Throwable { + + g.newResource(); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest.java new file mode 100644 index 000000000..3392c547e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteIntoCollectedResourceTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.claim(rootLib, b.IsRelatedTo, rootLib); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest2.java new file mode 100644 index 000000000..6b252026a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest2.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteIntoCollectedResourceTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.claim(rootLib, foreign.get(), null, rootLib); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest3.java new file mode 100644 index 000000000..8f3238c00 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest3.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteIntoCollectedResourceTest3 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.claim(rootLib, rootLib, null, foreign.get()); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest4.java new file mode 100644 index 000000000..e5467aa01 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteIntoCollectedResourceTest4.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.HasStatementSubject; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteIntoCollectedResourceTest4 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + final DataContainer foreign = new DataContainer(); + + getSession().syncRequest(new HasStatementSubject(rootLib)); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource f = g.newResource(); + g.claim(f, b.InstanceOf, b.Type); + foreign.set(f); + + } + + }); + + ClusterControl support = getSession().getService(ClusterControl.class); + support.collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.claimValue(foreign.get(), "", Bindings.STRING); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteNewResourceIntoCollectedCluster.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteNewResourceIntoCollectedCluster.java new file mode 100644 index 000000000..fa5621c10 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/WriteNewResourceIntoCollectedCluster.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.clusterControl; + +import org.junit.Test; +import org.simantics.db.WriteGraph; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.ClusteringSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteNewResourceIntoCollectedCluster extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final long clusterId = getSession().getService(ClusteringSupport.class).getCluster(getSession().getRootLibrary()); + + getSession().getService(ClusterControl.class).collectClusters(Integer.MAX_VALUE); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.newResource(clusterId); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.java new file mode 100644 index 000000000..e29c669d3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.java @@ -0,0 +1,66 @@ +package org.simantics.db.tests.api.support.managementSupport; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ChangeSet; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class FetchChangeSetsTest extends ExistingDatabaseTest { +// static final boolean DEBUG = true; + static final boolean VERBOSE = false; + @Test + public void test() throws DatabaseException { + final ManagementSupport ms = getSession().getService(ManagementSupport.class); + final long startId = 1; + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.newResource(); + } + }); + final long endId = ms.getHeadRevisionId(); + assertTrue(endId > 0); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + long id = ms.getHeadRevisionId(); + assertTrue(endId == id); + Collection css = ms.fetchChangeSets(g, endId, endId); + int size = 1; + assertEquals("Failed to get change sets.", size, css.size()); + if (DEBUG) + printDebug(css, endId); + } + }); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + long id = ms.getHeadRevisionId(); + assertTrue(endId == id); + Collection css = ms.fetchChangeSets(g, startId, endId); + // Can't be sure that old change sets are preserved. + assertTrue("Failed to get change sets.", css.size() >= 1); + if (DEBUG) + printDebug(css, startId); + } + }); + } + static void printDebug(Collection css, long startId) { + if (!DEBUG) + return; + long id = startId; + for (ChangeSet cs: css) { + System.out.println("cs=" + id); + if (VERBOSE) + System.out.println(cs.toString()); + ++id; + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetHeadRevisionTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetHeadRevisionTest.java new file mode 100644 index 000000000..61c092d3e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetHeadRevisionTest.java @@ -0,0 +1,25 @@ +package org.simantics.db.tests.api.support.managementSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GetHeadRevisionTest extends ExistingDatabaseTest { + @Test + public void test() throws DatabaseException { + final ManagementSupport ms = getSession().getService(ManagementSupport.class); + final long revisionId = ms.getHeadRevisionId(); + assertTrue(revisionId > 0); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + long id = ms.getHeadRevisionId(); + assertTrue(revisionId == id); + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetMetadataTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetMetadataTest.java new file mode 100644 index 000000000..eb00bf3eb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetMetadataTest.java @@ -0,0 +1,83 @@ +package org.simantics.db.tests.api.support.managementSupport; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.UndoMetadata; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class GetMetadataTest extends ExistingDatabaseTest { + // Behavior of commit has been changed. Commits with only CommentMetadata are dropped. + private void addMetadata(WriteGraph wg, String s) throws DatabaseException { + CommentMetadata cm = wg.getMetadata(CommentMetadata.class); + wg.addMetadata(cm.add(s)); + wg.addMetadata(new UndoMetadata(null, false, 0, 0)); + } + @Test + public void test() throws DatabaseException { + final ManagementSupport ms = getSession().getService(ManagementSupport.class); + WriteRequest nop0 = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + addMetadata(graph, "NOP0"); + } + }; + getSession().sync(nop0); + final long endId = ms.getHeadRevisionId(); + + assertTrue(endId > 0); + WriteRequest nop1 = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + addMetadata(graph, "NOP1"); + } + }; + getSession().sync(nop1); + WriteRequest nop2 = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + addMetadata(graph, "NOP2"); + } + }; + getSession().sync(nop2); + final long newId = ms.getHeadRevisionId(); + + assertTrue(endId == newId - 2); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + long id = ms.getHeadRevisionId(); + assertTrue(newId == id); + Collection comments = ms.getMetadata(newId-1, newId, CommentMetadata.class); + assertTrue(comments.size() == 2); + CommentMetadata cm = comments.iterator().next(); + String s = cm.toString(); + // The line feed is added by the add operation. + assertTrue(s.matches("NOP1\n")); + // gitexitOld interface. + Collection comments2 = ms.getMetadata(newId-1, newId, CommentMetadata.class); + assertTrue(comments.size() == 2); + CommentMetadata cm2 = comments2.iterator().next(); + String s2 = cm2.toString(); + // The line feed is added by the add operation. + assertTrue(s2.matches("NOP1\n")); + } + }); + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + long id = ms.getHeadRevisionId(); + assertTrue(newId == id); + Collection comments = ms.getMetadata(1, newId, CommentMetadata.class); + assertTrue(comments.size() > 2); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/queryControl/CleanCollectQueriesTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/queryControl/CleanCollectQueriesTest.java new file mode 100644 index 000000000..51049135e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/queryControl/CleanCollectQueriesTest.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.queryControl; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.service.QueryControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests nothing. Originally tested that there was no fixed queries after flush. + **/ +public class CleanCollectQueriesTest extends ExistingDatabaseTest { + + @Test + public void testWriteException() throws Exception { + + final Session session = getSession(); + QueryControl control = session.getService(QueryControl.class); + int fixed = control.flush(); + if (fixed > 0) + System.out.println(fixed + " fixed queries after flush. 0 would be nice."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest.java new file mode 100644 index 000000000..3a8a794f7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.serialisationSupport; + + +import org.junit.Test; +import org.simantics.db.exception.DatabaseException; + +/** + * Tests for RandomAccessID + */ +public class RandomAccessIdTest extends RandomAccessIdTestCommon { + @Test + public void testRandomAccessId() + throws DatabaseException { + createResourceWithName(); + validateResourceWithName(); + createRandomAccessId(); +// reconnect(); +// validateRandomAccessId(); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest1.java new file mode 100644 index 000000000..16bd57697 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTest1.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.serialisationSupport; + +import org.junit.Test; +import org.simantics.db.exception.DatabaseException; + +/** + * Tests for RandomAccessID + */ +public class RandomAccessIdTest1 extends RandomAccessIdTestCommon { + @Test + public void testRandomAccessId1() + throws Exception { + createResourceWithName(); + validateResourceWithName(); + createRandomAccessId(); + reconnect(); + try { + validateRandomAccessId(); + } catch (DatabaseException e) { + fail("Failed to detect illeal random access id.", e); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTestCommon.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTestCommon.java new file mode 100644 index 000000000..d23da5e12 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/serialisationSupport/RandomAccessIdTestCommon.java @@ -0,0 +1,89 @@ +package org.simantics.db.tests.api.support.serialisationSupport; + +import java.util.Collection; + +import org.junit.Before; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +public class RandomAccessIdTestCommon extends ExistingDatabaseTest { + protected long randomAccessID; + protected Resource resource; + protected final String newName = "New name " + getRandomString(); + protected Resource rl; + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + rl = getSession().getRootLibrary(); + } + protected void createResourceWithName() + throws DatabaseException { + // Create a new resource. + getSession().syncRequest(new WriteQuery(this) { + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Resource instance = g.newResource(); + g.claim(instance, b.InstanceOf, b.Type); + g.claim(rl, b.ConsistsOf, instance); + g.claimLiteral(instance, b.HasName, newName); + }; + }); + checkException(); + } + protected void validateResourceWithName() + throws DatabaseException { + // Find the created resource. + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 l0 = Layer0.getInstance(g); + Collection resources = g.getObjects(rl, l0.ConsistsOf); + Resource found = null; + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, l0.HasName); + if (null != name && name.equals(newName)) { + found = r; + break; + } + } + if (found == null) { + throw new DatabaseException("Cannot find created resource"); + } + resource = found; + } + }); + checkException(); + } + protected void createRandomAccessId() + throws DatabaseException { + // Create random access id for resource. + SerialisationSupport support = getSession().getService(SerialisationSupport.class); + randomAccessID = support.getRandomAccessId(resource); + if (randomAccessID == 0) + throw new DatabaseException("Could not create random access id"); + } + protected void validateRandomAccessId() + throws DatabaseException { + // test that random access id works and the given resource is the instance that we created + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 l0 = Layer0.getInstance(g); + SerialisationSupport support = getSession().getService(SerialisationSupport.class); + Resource res = support.getResource(randomAccessID); + String name = g.getRelatedValue(res, l0.HasName); + if (!name.equals(newName)) { + throw new Exception("Name is different that was written, returned resource is not a correct one!"); + } + } + }); + checkException(); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest1.java new file mode 100644 index 000000000..f3cd5bed8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest1.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.transferableGraphSupport; + +import java.io.IOException; +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.serialization.SerializationException; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.databoard.serialization.SerializerConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.TransferableGraphSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class TransferableGraphSupportTest1 extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + final TransferableGraphSupport support = session.getService(TransferableGraphSupport.class); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(g); + Resource name = g.getSingleObject(g.getRootLibrary(), b.HasName); + Object value = g.getValue(name); + Binding binding = Bindings.STRING; + try { + Serializer serializer = Bindings.getSerializer( binding ); + byte[] data = serializer.serialize(value); + byte[] raw = support.getValue(g, name); + assert(Arrays.equals(data, raw)); + } catch (SerializerConstructionException e) { + throw new Error(e); + } catch (SerializationException e) { + throw new Error(e); + } catch (IOException e) { + throw new Error(e); + } + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest2.java new file mode 100644 index 000000000..b715d6acf --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest2.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.transferableGraphSupport; + +import java.io.IOException; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.serialization.SerializationException; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.databoard.serialization.SerializerConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.TransferableGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class TransferableGraphSupportTest2 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final String value = UUID.randomUUID().toString(); + final TransferableGraphSupport support = session.getService(TransferableGraphSupport.class); + final DataContainer resource = new DataContainer(); + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + + Resource r = graph.newResource(); + resource.set(r); + graph.claim(r, b.InstanceOf, null, b.String); + + try { + Binding binding = Bindings.STRING; + Serializer serializer = Bindings.getSerializer( binding ); + byte[] raw = serializer.serialize(value); + support.setValue(graph, r, null, raw); + } catch (SerializerConstructionException e) { + throw new Error(e); + } catch (SerializationException e) { + throw new Error(e); + } catch (IOException e) { + throw new Error(e); + } + } + }); + } catch (Throwable e) { + e.printStackTrace(); + fail("Write transaction threw an unknown exception " + e); + } + + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + String v = graph.getValue(resource.get()); + assert(v.equals(value)); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest1.java new file mode 100644 index 000000000..0726a1d51 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest1.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class RedoTest1 extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + fail("Could not validate statement. Read transaction threw an unexpected exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(!graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(!graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + fail("Could not validate statement's undo. Read transaction threw an unexpected exception " + e); + } + + support.redo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + fail("Could not validate statement's redo. Read transaction threw an unexpected exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest2.java new file mode 100644 index 000000000..79784ae05 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest2.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class RedoTest2 extends ExistingDatabaseTest { + + @Test + public void testRedo2() throws DatabaseException { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final Resource[] r = new Resource[2]; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + r[0] = g.newResource(); + g.claimValue(r[0], "One", Bindings.STRING); + g.claimValue(r[0], "Two", Bindings.STRING); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + String v = g.getValue(r[0], Bindings.STRING); + if (!v.equals("Two")) + fail("ClaimValue did not work as expected."); + } + }); + + support.undo(session, 1); + support.redo(session, 1); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + String v = g.getValue(r[0], Bindings.STRING); + if (!v.equals("Two")) + fail("ClaimValue did not work as expected."); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest01.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest01.java new file mode 100644 index 000000000..730bb942d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest01.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.Map; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ChangeSetIdentifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of add statement. + */ +public class UndoTest01 extends ExistingDatabaseTest { + + @Test + public void testUndo1() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + try { + support.undo(session, 1); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + assert(!graph.hasStatement(subject.get())); + } + }); + } catch (Throwable e) { + e.printStackTrace(); + fail("Read transaction threw an unexpected exception ", e); + } + + } + +} + +class Context { + private final Session session; + private final UndoRedoSupport support; + Resource r; + Integer value = 0; + Integer oldValue = 0; + Context(Session session, UndoRedoSupport support) { + this.session = session; + this.support = support; + } + void create() throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + r = graph.newResource(); + graph.claim(r, b.InstanceOf, b.Entity); + } + }); + } + void createAndSet() throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + r = graph.newResource(); + graph.claim(r, b.InstanceOf, b.Entity); + graph.claimValue(r, ++value, Bindings.INTEGER); + oldValue = value; + } + }); + } + void add() throws DatabaseException { + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + graph.claimValue(r, ++value, Bindings.INTEGER); + oldValue = value; + } + }); + } catch (Throwable e) { + throw new DatabaseException("Write transaction threw an unknown exception:", e); + } + } + void check() throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Integer i = graph.getPossibleValue(r, Bindings.INTEGER); + if (null == i) { + if (0 != value) + throw new DatabaseException("Failed to verify value."); + } else if (value != i) + throw new DatabaseException("Failed to verify value. Expected " + value + " got " + i + "."); + } + }); + } + void checkStatements() throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + if (!graph.hasStatement(r)) + throw new DatabaseException("Failed to verify statments. Expected statements."); + } + }); + } + void checkNoStatements() throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + if (graph.hasStatement(r)) + throw new DatabaseException("Failed to verify statments. Expected no statements."); + } + }); + } + void addAppend() throws DatabaseException { + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + graph.claimValue(r, ++value, Bindings.INTEGER); + } + }); + } catch (Throwable e) { + throw new DatabaseException("Write transaction threw an unknown exception:", e); + } + } + class ChangeSetIdentifierImpl implements ChangeSetIdentifier { + private final long id; + ChangeSetIdentifierImpl(long id) { + this.id = id; + } + @Override + public long getId() { + return id; + } + + @Override + public Map getMetadata() { + return null; + } + + } + void undo() throws DatabaseException { + support.undo(session, 1); + value -= 1; + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest02.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest02.java new file mode 100644 index 000000000..4a0cc1f10 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest02.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.ListIterator; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Test case description missing! + */ +public class UndoTest02 extends ExistingDatabaseTest { + private boolean DEBUG = false; + @Test + public void testUndo2() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + + final DataContainer subject = new DataContainer(); + final int size = 3; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource l = OrderedSetUtils.create(g, b.Type); + subject.set(l); + for (int i=0; i it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size != count) + fail("Number of ordered set elements doesn't match!"); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Layer0 b = Layer0.getInstance(g); + Resource l = subject.get(); + Resource el = g.newResource(); + g.claim(el, b.InstanceOf, null, b.Type); + OrderedSetUtils.add(g, l, el); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource l = subject.get(); + ListIterator it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size+1 != count) + fail("Number of ordered set elements doesn't match!"); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource l = subject.get(); + ListIterator it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size != count) + fail("Number of ordered set elements doesn't match! expected=" + size + " got=" + count); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest03.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest03.java new file mode 100644 index 000000000..34c61c788 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest03.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.ListIterator; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Test case description missing! + */ +public class UndoTest03 extends ExistingDatabaseTest { + + @Test + public void testUndo3() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + final int size = 3; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource l = OrderedSetUtils.create(g, b.Type); + subject.set(l); + for (int i=0; i it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size != count) + fail("Number of ordered set elements doesn't match!"); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Resource l = subject.get(); + ListIterator a = OrderedSetUtils.iterator(g, l); + Resource el = null; + if (!a.hasNext()) + fail("Number of elements doesn't match!"); + el = a.next(); + OrderedSetUtils.remove(g, l, el); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource l = subject.get(); + ListIterator it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size != count+1) + fail("Number of ordered set elements doesn't match!"); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource l = subject.get(); + ListIterator it = OrderedSetUtils.iterator(g, l); + int count = 0; + while (it.hasNext()) { + Resource r = it.next(); + if (DEBUG) + System.out.println("Resource " + r); + ++count; + } + if (size != count) + fail("Number of ordered set elements doesn't match!"); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest04.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest04.java new file mode 100644 index 000000000..9f2dd6483 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest04.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Test case description missing! + */ +public class UndoTest04 extends ExistingDatabaseTest { + + @Test + public void testUndo4() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + final String value = "value"; + final String newValue = "new value"; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + if (!graph.hasStatement(s)) + fail("Failed to verify modifications (stm)."); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource s = subject.get(); + graph.claimValue(s, newValue); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest05.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest05.java new file mode 100644 index 000000000..a79a88843 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest05.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class UndoTest05 extends ExistingDatabaseTest { + + @Test + public void testUndo5() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + + final DataContainer subject = new DataContainer(); + final String value = "value"; + final String newValue = "new value"; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + if (!graph.hasStatement(s)) + fail("Failed to verify modifications (stm)."); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource s = subject.get(); + graph.claimValue(s, newValue); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + support.undo(session, 2); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getPossibleValue(s, Bindings.STRING); + if (null != t) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest06.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest06.java new file mode 100644 index 000000000..9e88483b3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest06.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.UndoContext; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.UndoContextEx; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Test case description missing! + */ +public class UndoTest06 extends ExistingDatabaseTest { + + @Test + public void testUndo6() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + Context c1 = new Context(session, support); + c1.create(); + c1.check(); + c1.add(); + c1.check(); + c1.add(); + c1.check(); + + c1.undo(); + c1.check(); + c1.undo(); + c1.check(); + + c1.add(); + c1.check(); + c1.add(); + c1.check(); + + Context c2 = new Context(session, support); + c2.create(); + c2.check(); + c2.add(); + c2.check(); + c2.add(); + c2.check(); + +// c1.undo(); +// c1.check(); +// c1.undo(); +// c1.check(); + + c2.undo(); + c2.check(); + c2.undo(); + c2.check(); + } catch (Throwable t) { + fail("Test failed with exception " + t); + } + } + + class Context { + private final Session session; + private final UndoRedoSupport support; + final UndoContext uctx = new UndoContextEx(); + Resource r; + Integer value = 0; + Context(Session session, UndoRedoSupport support) { + this.session = session; + this.support = support; + } + void create() throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + r = graph.newResource(); + graph.claim(r, b.InstanceOf, b.Entity); + } + }); + } + void add() throws DatabaseException { + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + graph.claimValue(r, ++value, Bindings.INTEGER); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + } + void check() throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Integer i = graph.getPossibleValue(r, Bindings.INTEGER); + if (null == i) { + if (0 != value) + fail("Failed to verify value."); + } else if (value != i) + fail("Failed to verify value expected " + value + " got " + i); + } + }); + } + void undo() throws DatabaseException { + support.undo(session, 1); + value -= 1; + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest07.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest07.java new file mode 100644 index 000000000..5ccb552dd --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest07.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Test case description missing! + */ +public class UndoTest07 extends ExistingDatabaseTest { + + @Test + public void testUndo7() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + Context c1 = new Context(session, support); + c1.create(); + c1.check(); + c1.add(); + c1.check(); + c1.addAppend(); + c1.check(); + + c1.undo(); + c1.check(); + + c1.add(); + c1.check(); + c1.addAppend(); + c1.check(); + + Context c2 = new Context(session, support); + c2.create(); + c2.check(); + c2.add(); + c2.check(); + c1.addAppend(); + c2.check(); + + c1.undo(); + c1.check(); + + c2.undo(); + c2.check(); + } catch (Throwable t) { + fail("Test failed with exception " + t); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest08.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest08.java new file mode 100644 index 000000000..fffafbe00 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest08.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Test case description missing! + */ +public class UndoTest08 extends ExistingDatabaseTest { + + @Test + public void testUndo8() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + Context c1 = new Context(session, support); + c1.createAndSet(); + + Context c2 = new Context(session, support); + c2.create(); + c2.check(); + + c1.check(); + c1.checkStatements(); + c1.add(); + c1.check(); + c1.undo(); + c1.check(); + + c2.add(); + c2.check(); + +// c1.add(); +// c1.check(); +// c1.add(); +// c1.check(); + +// c1.undo(); +// c1.check(); +// c1.undo(); +// c1.check(); +// c1.undo(); +// c1.check(); +// c1.checkNoStatements(); + } catch (Throwable t) { + fail("Test failed with exception " + t); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest09.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest09.java new file mode 100644 index 000000000..c85c09567 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest09.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Test case description missing! + */ +public class UndoTest09 extends ExistingDatabaseTest { + + @Test + public void testUndo9() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + UndoTestOrderedSet c1 = new UndoTestOrderedSet(session, support); + List elements = new ArrayList(); + Resource list = c1.create(elements); + c1.check(list, elements); + List elements2 = new ArrayList(); + elements2.addAll(elements); + c1.front(list, elements2); + c1.check(list, elements2); + c1.back(list, elements2); + c1.check(list, elements2); + c1.undo(); + c1.undo(); + c1.check(list, elements); + c1.add(list, elements); + elements2.clear(); + } catch (Throwable t) { + fail("Test failed with exception " + t); + } + } +} + +class UndoTestOrderedSet { + protected final Session session; + protected final UndoRedoSupport support; + protected final boolean DEBUG = Configuration.get().debug; + UndoTestOrderedSet(Session session, UndoRedoSupport support) { + this.session = session; + this.support = support; + } + Resource create(final List els) + throws DatabaseException { + final int size = 3; + final DataContainer subject = new DataContainer(); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Layer0 b = Layer0.getInstance(g); + Resource l = OrderedSetUtils.create(g, b.Type); + subject.set(l); + for (int i=0; i els) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + getFirstLast(g, list, els); + } + }); + } + void front(final Resource list, final List els) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + FirstLast fl = getFirstLast(g, list, els); + if (null == fl.first) + return; + OrderedSetUtils.remove(g, list, fl.last); + OrderedSetUtils.addFirst(g, list, fl.last); + els.remove(fl.last2); + els.add(0, fl.last2); + } + }); + } + void back(final Resource list, final List els) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + FirstLast fl = getFirstLast(g, list, els); + if (null == fl.first) + return; + OrderedSetUtils.remove(g, list, fl.first); + OrderedSetUtils.addAfter(g, list, fl.last, fl.first); + els.remove(fl.first2); + els.add(els.size(), fl.first2); + } + }); + } + void add(final Resource list, final List els) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + FirstLast fl = getFirstLast(g, list, els); + if (null == fl.first) + return; + Layer0 b = Layer0.getInstance(g); + g.flushCluster(); + Resource el = g.newResource(); + g.claim(el, b.InstanceOf, null, b.Type); + OrderedSetUtils.add(g, list, el); + els.add(el); + } + }); + } + void undo() throws DatabaseException { + support.undo(session, 1); + } + class FirstLast { + public Resource first; + public Resource first2; + public Resource last; + public Resource last2; + } + FirstLast getFirstLast(ReadGraph g, Resource list, List els) + throws DatabaseException { + ListIterator it = OrderedSetUtils.iterator(g, list); + int count = 0; + Iterator it2 = els.iterator(); + FirstLast fl = new FirstLast(); + while (it.hasNext()) { + fl.last = it.next(); + if (null == fl.first) + fl.first = fl.last; + if (DEBUG) + System.out.println("Resource " + fl.last + "in list " + list + "."); + fl.last2 = it2.next(); + if (null == fl.first2) + fl.first2 = fl.last2; + if (null == fl.last2 || fl.last2.getResourceId() != fl.last.getResourceId()) + throw new DatabaseException("Error in list element rid=" + fl.last + "."); + ++count; + } + if (els.size() != count) + throw new DatabaseException("Number of ordered set elements doesn't match!"); + if (DEBUG) + System.out.println("" + count + " elements in resource list."); + return fl; + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest10.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest10.java new file mode 100644 index 000000000..306d8baa5 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest10.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Test case description missing! + */ +public class UndoTest10 extends ExistingDatabaseTest { + + @Test + public void testUndo10() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + UndoTestOrderedSet10 c1 = new UndoTestOrderedSet10(session, support); + List elements = new ArrayList(); + Resource list = c1.create(elements); + c1.check(list, elements); + c1.add(list, elements); + List elements2 = new ArrayList(); + elements2.addAll(elements); + c1.front2(list, elements2); + c1.check(list, elements2); + c1.back(list, elements2); + c1.check(list, elements2); + c1.front(list, elements2); + c1.check(list, elements2); + c1.back(list, elements2); + c1.check(list, elements2); + c1.undo(); + c1.undo(); + c1.undo(); + c1.undo(); + c1.check(list, elements); + c1.add(list, elements); + elements2.clear(); + } catch (Throwable t) { + fail("Test failed with exception " + t); + } + } + class UndoTestOrderedSet10 extends UndoTestOrderedSet { + UndoTestOrderedSet10(Session session, UndoRedoSupport support) { + super(session, support); + } + void front2(final Resource list, final List els) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + FirstLast fl = getFirstLast(g, list, els); + if (null == fl.first) + return; + Resource n = OrderedSetUtils.next(g, list, fl.first); + if (n.getResourceId() == fl.first.getResourceId()) + return; + OrderedSetUtils.remove(g, list, n); + OrderedSetUtils.addFirst(g, list, n); + els.add(0, els.remove(1)); + } + }); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest11.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest11.java new file mode 100644 index 000000000..957e6dadc --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest11.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Test case description missing! + */ +public class UndoTest11 extends ExistingDatabaseTest { + + @Test + public void testUndo11() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + UndoTestOrderedSet11 c1 = new UndoTestOrderedSet11(session, support); + List elements = new ArrayList(); + Resource list = c1.create(elements); + List elements2 = new ArrayList(); + elements2.addAll(elements); + c1.modify(list, elements2); + c1.check(list, elements2); + c1.undo(); + c1.check(list, elements); + } catch (Throwable t) { + fail("Test failed with exception ", t); + } + } + class UndoTestOrderedSet11 extends UndoTestOrderedSet { + UndoTestOrderedSet11(Session session, UndoRedoSupport support) { + super(session, support); + } + void modify(final Resource list, final List els) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + FirstLast fl = getFirstLast(g, list, els); + if (null == fl.first) + return; + Resource el = g.newResource(); + OrderedSetUtils.add(g, list, el); + OrderedSetUtils.remove(g, list, el); + } + }); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest12.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest12.java new file mode 100644 index 000000000..d31f2254c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest12.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.utils.DataContainer; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class UndoTest12 extends ExistingDatabaseTest { + + @Test + public void testUndo12() throws DatabaseException { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer r1 = new DataContainer(); + final DataContainer r2 = new DataContainer(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Resource a = g.newResource(); + Resource b = g.newResource(); + r1.set(a); + r2.set(b); + g.claim(a, a, a); + g.deny(a, a, a); + g.claim(a, a, b); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + check(session, r1.get(), r2.get()); + + support.undo(session, 1); + support.redo(session, 1); + + check(session, r1.get(), r2.get()); + + } + void check(Session session, final Resource a, final Resource b) { + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(a, a, a)) + fail("Deny did not work as expected."); + if (!g.hasStatement(a, a, b)) + fail("Add did not work as expected."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest13.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest13.java new file mode 100644 index 000000000..3642783da --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest13.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class UndoTest13 extends ExistingDatabaseTest { + + @Test + public void testUndo13() throws DatabaseException { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final Resource[] r = new Resource[3]; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + r[0] = g.newResource(); + r[1] = g.newResource(); + r[2] = g.newResource(); + g.claim(r[0], r[0], r[0]); + g.deny(r[0], r[0], r[0]); + g.claim(r[0], r[0], r[1]); + g.deny(r[0], r[0], r[1]); + g.claim(r[0], r[0], r[2]); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(r[0], r[0], r[0])) + fail("Deny did not work as expected."); + if (g.hasStatement(r[0], r[0], r[1])) + fail("Deny did not work as expected."); + if (!g.hasStatement(r[0], r[0], r[2])) + fail("Add did not work as expected."); + } + }); + + support.undo(session, 1); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(r[0], r[0], r[0])) + fail("What did not work as expected."); + if (g.hasStatement(r[0], r[0], r[1])) + fail("Deny did not work as expected."); + if (g.hasStatement(r[0], r[0], r[2])) + fail("Add did not work as expected."); + } + }); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest14.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest14.java new file mode 100644 index 000000000..b6cacd475 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest14.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests case where combined operation belongs to two contexts. + */ +public class UndoTest14 extends ExistingDatabaseTest { + + @Test + public void testUndo14() throws DatabaseException { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final Resource[] r = new Resource[2]; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + r[0] = g.newResource(); + g.claim(r[0], r[0], r[0]); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + r[1] = g.newResource(); + g.claim(r[1], r[1], r[1]); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (!g.hasStatement(r[0], r[0], r[0])) + fail("Claim did not work as expected."); + if (!g.hasStatement(r[1], r[1], r[1])) + fail("Claim did not work as expected."); + } + }); + + support.undo(session, 1); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (!g.hasStatement(r[0], r[0], r[0])) + fail("Undo did not work as expected."); + if (g.hasStatement(r[1], r[1], r[1])) + fail("Undo did not work as expected."); + } + }); + + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest15.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest15.java new file mode 100644 index 000000000..ee3de95bc --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest15.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests cases where a non-functional relation uses + * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)} + * with > 1 objects. + * + *

+ * Should throw {@link NoSingleResultException}, at the time of writing this + * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck. + */ +public class UndoTest15 extends ExistingDatabaseTest { + + @Test + public void testUndo15() throws DatabaseException { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final Resource[] r = new Resource[2]; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + r[0] = g.newResource(); + g.claim(r[0], r[0], r[0]); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + r[1] = g.newResource(); + g.deny(r[0], r[0], r[0]); + g.claim(r[0], r[0], r[1]); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(r[0], r[0], r[0])) + fail("Deny did not work as expected."); + if (!g.hasStatement(r[0], r[0], r[1])) + fail("Claim did not work as expected."); + } + }); + // Note that the implementation and interpretation of this operation has changed. + // This used to be undoRevisions but now this is undoOperations. + // Works as expected only for single operations. + support.undo(session, 2); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(r[0], r[0], r[0])) + fail("Undo did not work as expected."); + if (g.hasStatement(r[0], r[0], r[1])) + fail("Undo did not work as expected."); + } + }); + // Note that the implementation and interpretation of this operation has changed. + // Works as expected only for count one. + support.redo(session, 1); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (g.hasStatement(r[0], r[0], r[0])) + fail("Undo did not work as expected."); + if (!g.hasStatement(r[0], r[0], r[1])) + fail("Undo did not work as expected."); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest16.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest16.java new file mode 100644 index 000000000..36330fadc --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest16.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Test case description missing! + */ +public class UndoTest16 extends ExistingDatabaseTest { + private void initValue(byte[] value) { + for (int i=0; i subject = new DataContainer(); + final byte[] value = new byte[100000]; + final byte[] newValue = new byte[200000]; + + try { + initValue(value); + initValue(newValue); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + if (!graph.hasStatement(s)) + fail("Failed to verify modifications (stm)."); + byte[] t = graph.getValue(s, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t, value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource s = subject.get(); + graph.claimValue(s, newValue); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + byte[] t = graph.getValue(s, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t, value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + byte[] t = graph.getPossibleValue(s, Bindings.BYTE_ARRAY); + if (null != t) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest17.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest17.java new file mode 100644 index 000000000..49c101a4b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest17.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of added value with deleted value as previous operation. + */ +public class UndoTest17 extends ExistingDatabaseTest { + + @Test + public void testUndo1() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + final String value = "value"; + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + if (!graph.hasStatement(s)) + fail("Failed to verify modifications (stm)."); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource s = subject.get(); + graph.denyValue(s); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getPossibleValue(s); + if (null != t) + fail("Failed to verify removal of value."); + + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource s = subject.get(); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + support.undo(session, 1); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getPossibleValue(s); + if (null != t) + fail("Failed to verify removal of value."); + + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + } + +} + diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java new file mode 100644 index 000000000..63a2f42a6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of two changes sets with values modified in multiple cluster change sets. + * The binary values will cause two cluster change sets per modification. + * (By the way the above-mentioned behavior will cause serious fragmentation in server + * because the size of cluster change sets are ridiculously small and server does not + * process cluster change sets but stores them as is. The payload is just about the same + * as the bookkeeping structures. TODO: fix the aforementioned fragmentation) + */ +public class UndoTest18 extends ExistingDatabaseTest { + private void initValue(byte[] value) { + for (int i=0; i subject1 = new DataContainer(); + final DataContainer subject2 = new DataContainer(); + final byte[] value10 = new byte[100000]; + final byte[] value20 = new byte[100001]; + final byte[] value11 = new byte[100002]; + final byte[] value21 = new byte[100003]; + + try { + initValue(value10); + initValue(value11); + initValue(value20); + initValue(value21); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = graph.newResource(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value10); + subject1.set(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s2 = graph.newResource(); + graph.claim(s2, b.InstanceOf, b.Entity); + graph.claimValue(s2, value20); + subject2.set(s2); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value10)) + fail("Failed to verify value1."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value20)) + fail("Failed to verify value2."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + graph.newResource(); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = subject1.get(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value11); + subject1.set(s1); + Resource s2 = subject2.get(); + graph.claim(s2, b.InstanceOf, b.Entity); + graph.claimValue(s2, value21); + subject2.set(s2); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value11)) + fail("Failed to verify value11."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value21)) + fail("Failed to verify value21."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + support.undo(session, 2); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value10)) + fail("Failed to verify value1."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value20)) + fail("Failed to verify value2."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + } + +} + diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java new file mode 100644 index 000000000..f22521907 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of deletion of large literal when done twice in sequence. + * This was added because of Bug #4591. + */ +public class UndoTest20 extends ExistingDatabaseTest { + private void initValue(byte[] value) { + for (int i=0; i subject1 = new DataContainer(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = graph.newResource(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value); + subject1.set(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + testUndo(session, value, subject1); + testUndo(session, value, subject1); + } + public void testUndo(final Session session, final byte[] value, final DataContainer subject1) + throws Exception { + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value)) + fail("Failed to verify value."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource s1 = subject1.get(); + graph.denyValue(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getPossibleValue(s1, Bindings.BYTE_ARRAY); + if (null != t1) + fail("Failed to verify delettion of value."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + try { + support.undo(session, 1); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value)) + fail("Failed to verify value1."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/PersistentSetValueIntoVirtualResourceTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/PersistentSetValueIntoVirtualResourceTest.java new file mode 100644 index 000000000..4acace929 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/PersistentSetValueIntoVirtualResourceTest.java @@ -0,0 +1,51 @@ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class PersistentSetValueIntoVirtualResourceTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + VirtualGraphSupport vgs = getSession().getService(VirtualGraphSupport.class); + VirtualGraph vg = vgs.getMemoryPersistent(UUID.randomUUID().toString()); + + final Resource virtual = getSession().syncRequest(new WriteResultRequest(vg) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + }); + + checkException(); + + try { + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimValue(virtual, "Name", Bindings.STRING); + } + }); + } catch (ServiceException e) { + if (DEBUG) + e.printStackTrace(); + return; + } + + fail("Should throw."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphExample.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphExample.java new file mode 100644 index 000000000..90411a97b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphExample.java @@ -0,0 +1,84 @@ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.Statement; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.layer0.Layer0; + +/** + * Not really created into a proper test, more a demonstration that is available + * in the Simantics + * developer wiki. + * + * @author Tuukka Lehtonen + */ +public class VirtualGraphExample { + + public Resource createLibrary(RequestProcessor processor, VirtualGraph vg, final String libraryName) throws DatabaseException { + return processor.syncRequest(new WriteResultRequest(vg) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r, L0.HasName, libraryName); + return r; + } + }); + } + + public void testVirtualGraphs(Session session) throws DatabaseException { + VirtualGraphSupport vgSupport = session.getService(VirtualGraphSupport.class); + VirtualGraph memory = vgSupport.getMemoryPersistent("memory"); + VirtualGraph workspace = vgSupport.getWorkspacePersistent("workspace"); + // NOTICE: resource are created in difference virtual graphs in separate + // transactions through Session.syncRequest. + Resource memResource = createLibrary(session, memory, "memory"); + Resource workspaceResource = createLibrary(session, workspace, "workspace"); + printVirtualGraphs(session); + } + + public void testMultipleVirtualGraphsInSameTransaction(Session session) throws DatabaseException { + final VirtualGraphSupport vgSupport = session.getService(VirtualGraphSupport.class); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph memory = vgSupport.getMemoryPersistent("memory"); + VirtualGraph workspace = vgSupport.getWorkspacePersistent("workspace"); + // NOTICE: resource are created in different virtual graphs in + // the same transaction through WriteGraph.syncRequest + Resource memResource = createLibrary(graph, memory, "memory"); + Resource workspaceResource = createLibrary(graph, workspace, "workspace"); + } + }); + printVirtualGraphs(session); + } + + public void printVirtualGraphs(Session session) throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + VirtualGraphSupport vgSupport = graph.getService(VirtualGraphSupport.class); + for (VirtualGraph vg : vgSupport.listGraphs()) { + for (Statement stm : vgSupport.listStatements(vg)) { + System.out.println("Statement: " + NameUtils.toString(graph, stm)); + } + for (Resource r : vgSupport.listValues(vg)) { + System.out.println("Literal value: " + graph.getValue(r)); + } + } + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphSupportListStatementsTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphSupportListStatementsTest.java new file mode 100644 index 000000000..80182d009 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphSupportListStatementsTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.Collection; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class VirtualGraphSupportListStatementsTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + // Create a new persistent resource + final Resource resource = getSession().syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + return g.newResource(); + } + }); + + VirtualGraphSupport vgs = getSession().getService(VirtualGraphSupport.class); + VirtualGraph vg = vgs.getMemoryPersistent(UUID.randomUUID().toString()); + + // Create some virtual graph + getSession().syncRequest(new WriteRequest(vg) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource virtual = graph.newResource(); + graph.claim(resource, L0.ConsistsOf, virtual); + graph.claimLiteral(virtual, L0.HasName, "Name"); + + } + }); + + checkException(); + + Collection stms = vgs.listStatements(vg); + + assertEquals("Amount of statements.", stms.size(), 5); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java new file mode 100644 index 000000000..4ff12d68f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.TestCleanDb; +import org.simantics.layer0.Layer0; + +public class VirtualGraphTest extends TestCleanDb { + + private Error exception; + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + + final Resource newResource = graph.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource result = graph.newResource(); + graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING); + return result; + + } + + }); + + String rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary")) { + exception = new AssertionError("rootName != 'RootLibrary'"); + throw exception; + } + + VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class); + final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString()); + + graph.syncRequest(new WriteRequest(virtual) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + graph.addLiteral(newResource, L0.HasName, L0.NameOf, L0.String, "RootLibrary2", Bindings.STRING); + + } + + }); + + rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary2")) { + exception = new AssertionError("rootName != 'RootLibrary2'"); + throw exception; + } + + support.discard(virtual); + + rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary")) { + exception = new AssertionError("rootName != 'RootLibrary'"); + throw exception; + } + + } + + }); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest2.java new file mode 100644 index 000000000..2745274d3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest2.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.TestCleanDb; +import org.simantics.layer0.Layer0; + +public class VirtualGraphTest2 extends TestCleanDb { + + private Error exception; + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); + final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString()); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + + final HashSet strings = new HashSet(); + + for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) { + String name = g.getPossibleRelatedValue(r, b.HasName); + strings.add(name); + } + + g.syncRequest(new WriteRequest(virtual) { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + for(int i=0;i<10;i++) { + Resource r = g.newResource(); + String name = "Virtual" + i; + g.claimLiteral(r, b.HasName, name, Bindings.STRING); + strings.add(name); + g.claim(g.getRootLibrary(), b.ConsistsOf, r); + } + + } + + }); + + for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("found " + name); + boolean success = strings.remove(name); + if(!success) { + exception = new AssertionError("encountered unknown string " + name); + throw exception; + } + } + + if(!strings.isEmpty()) { + exception = new AssertionError("some strings were left over " + Arrays.toString(strings.toArray())); + throw exception; + } + + } + + }); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest3.java new file mode 100644 index 000000000..ffa76a1d3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest3.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.TestCleanDb; +import org.simantics.layer0.Layer0; + +public class VirtualGraphTest3 extends TestCleanDb { + + private Error exception; + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + final VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); + final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString()); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + + final HashSet original = new HashSet(); + final HashSet strings = new HashSet(); + + for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (name != null) { + original.add(name); + strings.add(name); + } else if (DEBUG) + System.out.println("Resource " + r + " has no name."); + } + + g.syncRequest(new WriteRequest(virtual) { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Layer0 b = Layer0.getInstance(g); + for(int i=0;i<10;i++) { + Resource r = g.newResource(); + String name = "Virtual" + i; + g.claimLiteral(r, b.HasName, name, Bindings.STRING); + strings.add(name); + g.claim(g.getRootLibrary(), b.ConsistsOf, r); + if (DEBUG) + System.out.println("added " + name + " resource " + r); + } + + } + + }); + + for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("found " + name); + boolean success = strings.remove(name); + if(!success) { + exception = new AssertionError("encountered unknown string " + name); + throw exception; + } + } + + if(!strings.isEmpty()) { + exception = new AssertionError("some strings were left over " + Arrays.toString(strings.toArray())); + throw exception; + } + + support.discard(virtual); + + for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (DEBUG) + System.out.println("found " + name); + boolean success = original.remove(name); + if(!success) { + exception = new AssertionError("encountered unknown string " + name + " resource " + r); + throw exception; + } + } + + if(!original.isEmpty()) { + exception = new AssertionError("some strings were left over " + Arrays.toString(strings.toArray())); + throw exception; + } + + } + + }); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest5.java new file mode 100644 index 000000000..1e267c777 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest5.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.List; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.TestCleanDb; + +public class VirtualGraphTest5 extends TestCleanDb { + + @Test + @Fails + public void test() throws DatabaseException { + + Session session = getSession(); + final VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); + final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString()); + + final Resource list = session.syncRequest(new WriteResultRequest(virtual) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + return graph.newResource(); + } + + }); + + session.syncRequest(new WriteResultRequest(virtual) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Resource element1 = graph.newResource(); + OrderedSetUtils.addFirst(graph, list, element1); + OrderedSetUtils.addFirst(graph, list, graph.newResource()); + OrderedSetUtils.addFirst(graph, list, graph.newResource()); + OrderedSetUtils.remove(graph, list, element1); + //OrderedSetUtils.addFirst(graph, list, graph.newResource()); + return list; + } + + }); + + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + List set = OrderedSetUtils.toList(graph, list); + System.err.println("set=" + set.size()); + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest6.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest6.java new file mode 100644 index 000000000..6b0e618a3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest6.java @@ -0,0 +1,42 @@ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.WriteReadTest; + +public class VirtualGraphTest6 extends WriteReadTest { + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + VirtualGraph virt = support.getMemoryPersistent(UUID.randomUUID().toString()); + + Resource other = graph.syncRequest(new WriteResultRequest(virt) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Resource other = graph.newResource(); + if (DEBUG) + System.err.println("other=" + other); + graph.claim(written, L0.ConsistsOf, L0.PartOf, other); + return other; + } + + }); + + Resource single = graph.getSingleObject(written, L0.ConsistsOf); + if (DEBUG) + System.err.println("single=" + single); + assertNotNull(single); + assertTrue(single.equals(other)); + + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/SuiteWrite.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/SuiteWrite.java new file mode 100644 index 000000000..aa500f4e6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/SuiteWrite.java @@ -0,0 +1,69 @@ +package org.simantics.db.tests.api.write; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.api.write.claim.WriteWithMultipleInverses; +import org.simantics.db.tests.api.write.claimLiteral.WriteUntypedCustomLiteral; +import org.simantics.db.tests.api.write.claimLiteral.WriteUntypedL0Literal; +import org.simantics.db.tests.api.write.claimValue.DataBlobTest; +import org.simantics.db.tests.api.write.claimValue.SetValueTest; +import org.simantics.db.tests.api.write.claimValue.SetValueTest2; +import org.simantics.db.tests.api.write.deny.DenyTest1; +import org.simantics.db.tests.api.write.denyValue.DenyValueTest; +import org.simantics.db.tests.api.write.request.SessionWriteErrorTest; +import org.simantics.db.tests.api.write.request.SessionWriteExceptionTest; +import org.simantics.db.tests.api.write.request.SessionWriteOnlyErrorTest; +import org.simantics.db.tests.api.write.request.WriteCallbackFailureTest; +import org.simantics.db.tests.api.write.request.WriteCancelTest; +import org.simantics.db.tests.api.write.request.WriteCancelTest2; +import org.simantics.db.tests.api.write.request.WriteGraphWriteExceptionTest; +import org.simantics.db.tests.api.write.request.WriteMetadataTest; +import org.simantics.db.tests.api.write.request.WriteOnlyReadTest; +import org.simantics.db.tests.api.write.story.AddStatementTest; +import org.simantics.db.tests.api.write.story.WriteIntoBuiltinResourceTest; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + // claim + WriteWithMultipleInverses.class, + // claimLiteral + WriteUntypedCustomLiteral.class, + WriteUntypedL0Literal.class, + // claimValue + DataBlobTest.class, + SetValueTest.class, + SetValueTest2.class, + // deny + DenyTest1.class, + // denyValue + DenyValueTest.class, + // request + SessionWriteErrorTest.class, + SessionWriteExceptionTest.class, + SessionWriteOnlyErrorTest.class, + WriteCallbackFailureTest.class, + WriteCancelTest.class, + WriteCancelTest2.class, + WriteGraphWriteExceptionTest.class, + WriteMetadataTest.class, + WriteOnlyReadTest.class, + // story + AddStatementTest.class, + WriteIntoBuiltinResourceTest.class +}) +public class SuiteWrite { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claim/WriteWithMultipleInverses.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claim/WriteWithMultipleInverses.java new file mode 100644 index 000000000..6d4d9b107 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claim/WriteWithMultipleInverses.java @@ -0,0 +1,63 @@ +package org.simantics.db.tests.api.write.claim; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +public class WriteWithMultipleInverses extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception{ + + final Collection predicates = getSession().syncRequest(new WriteResultRequest>() { + @Override + public Collection perform(WriteGraph g) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(g); + Collection result = new ArrayList(); + for(int i=0;i<1;i++) { + Resource predicate = g.newResource(); + g.claim(predicate, L0.SubrelationOf, null, L0.IsRelatedTo); + g.claim(predicate, L0.InverseOf, null, L0.IsRelatedTo); + g.claim(predicate, L0.InverseOf, null, L0.IsWeaklyRelatedTo); + g.claim(predicate, L0.InverseOf, null, L0.IsComposedOf); + g.claim(predicate, L0.InverseOf, null, L0.IsDependencyOf); + result.add(predicate); + } + return result; + } + }); + + checkException(); + + try { + getSession().syncRequest(new WriteQuery(this) { + + @Override + public void run(WriteGraph g) throws Throwable { + + for(Resource predicate : predicates) + g.claim(predicate, predicate, predicate); + + } + + }); + + } catch (DatabaseException e) { + return; + } + + fail("Write should throw."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/TestLiteral.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/TestLiteral.java new file mode 100644 index 000000000..ee7db8267 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/TestLiteral.java @@ -0,0 +1,19 @@ +package org.simantics.db.tests.api.write.claimLiteral; + +import java.util.Arrays; + +public class TestLiteral { + + int a = 1; + double b[] = { 1, 2 }; + + public void setA(int a) { + this.a = a; + } + + @Override + public String toString() { + return "TestLiteral " + a + " " + Arrays.toString(b); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedCustomLiteral.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedCustomLiteral.java new file mode 100644 index 000000000..0eecb4ab4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedCustomLiteral.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.claimLiteral; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + + +public class WriteUntypedCustomLiteral extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception { + + Session session = getSession(); + + final Resource literal = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + TestLiteral value = new TestLiteral(); + value.setA(1091); + Resource literal = graph.newResource(); + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(literal, b.HasProperty, value); + return literal; + + } + + }); + + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + TestLiteral l1 = graph.getRelatedValue(literal, b.HasProperty, Bindings.getBindingUnchecked(TestLiteral.class)); + assert(l1 != null); + assert(l1.toString().equals("TestLiteral 1091 [1.0, 2.0]")); + + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedL0Literal.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedL0Literal.java new file mode 100644 index 000000000..bef48e25e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedL0Literal.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.claimLiteral; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + + +public class WriteUntypedL0Literal extends ExistingDatabaseTest { + + @Test + public void test() throws Exception { + + Session session = getSession(); + + final Resource literal = session.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Resource literal = graph.newResource(); + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(literal, b.HasProperty, new String("test")); + return literal; + + } + + }); + + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + String s = graph.getRelatedValue(literal, b.HasProperty); + assert(s != null); + assert(s.equals("test")); + + } + + }); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java new file mode 100644 index 000000000..d80ddc175 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.claimValue; + +import java.util.Collection; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large data array and stores it into the database. + * + * @author Marko Luukkainen + * + */ +public class DataBlobTest extends ExistingDatabaseTest { + + private static int ARRAY_SIZE = 1*1024*1024; // 60*1024*1024; + + @Test + public void testDataBlob() throws Exception{ + final Resource rootLib = getSession().getRootLibrary(); + final String random = UUID.randomUUID().toString(); + final String newInstanceName = "New Instance" + random; + if (DEBUG) + System.out.println("Test start"); + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + byte data[] = new byte[ARRAY_SIZE]; + for (int i = 0; i < data.length; i++) { + data[i] = (byte)(i % 2); + } + Resource instance = g.newResource(); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, instance); + + Resource prop = g.newResource(); + g.claim(prop, b.InstanceOf, b.ByteArray); + g.claimValue(prop, data); + + // Link it to the thing + g.claim(instance, b.HasProperty, prop); + } + }); + + + checkException(); + + if (DEBUG) + System.out.println("Reading stage"); + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + for (Resource p : g.getObjects(r, b.HasProperty)) + if (g.isInstanceOf(p, b.ByteArray)) { + byte[] data = g.getValue(p); + if (data.length != ARRAY_SIZE) + fail("Data blob lenght does not match."); + for (int i = 0; i < data.length; i++) { + if (data[i] != (byte)(i % 2)) + fail("Data blob content does not match."); + } + return; + } + } + } + fail("Data blob not found."); + } + }); + if (DEBUG) + System.out.println("test done"); + checkException(); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest.java new file mode 100644 index 000000000..a5972776f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.claimValue; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; +public class SetValueTest extends SimpleBase { + private static int ARRAY_SIZE; + private final String value = "SetValue" + getRandomString(); + public SetValueTest() { + long max = Runtime.getRuntime().maxMemory() / 4; + if (max>Integer.MAX_VALUE) + max = Integer.MAX_VALUE; + ARRAY_SIZE = Math.min((int)max, 1<<20); + } + @Test + public void testSetValue() throws DatabaseException { + final Session s = getSession(); + setValue(s); + checkValue(s); + final Session s2 = Tests.getTestHandler().getSession(); + try { + checkValue(s2); + } finally { + LifecycleSupport ls = s2.getService(LifecycleSupport.class); + ls.close(); + } + } + private void setValue(Session s) throws DatabaseException { + s.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + byte data[] = new byte[ARRAY_SIZE]; + for (int i = 0; i < data.length; i++) { + data[i] = (byte)(i); + } + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, null, b.Type); + g.claimLiteral(r, b.HasName, value); + g.claim(rl, b.ConsistsOf, r); + Resource rv = g.newResource(); + g.claim(rv, b.InstanceOf, b.ByteArray); + g.claimValue(rv, data); + checkValue(g, rv); + g.claim(r, b.HasProperty, rv); + } + }); + } + private void checkValue(ReadGraph g, Resource rv) + throws DatabaseException { + byte[] data = g.getValue(rv); + if (data.length != ARRAY_SIZE) + fail("Value lenght does not match."); + for (int i = 0; i < data.length; i++) { + if (data[i] != (byte)i) + fail("Value content does not match."); + } + } + private void checkValue(Session s) throws DatabaseException { + s.syncRequest(new Read() { + @Override + public Resource perform(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + String uri = TestBase.ROOT_LIBRARY_URI + "/" + value; + Resource r = g.getResource(uri); + assertTrue(null != r); + for (Resource rv : g.getObjects(r, l0.HasProperty)) { + if (g.isInstanceOf(rv, l0.ByteArray)) { + byte[] data = g.getValue(rv); + if (data.length != ARRAY_SIZE) + fail("Value lenght does not match."); + for (int i = 0; i < data.length; i++) { + if (data[i] != (byte)i) + fail("Value content does not match."); + } + return rv; + } + } + fail("Value not found."); + return null; + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest2.java new file mode 100644 index 000000000..6fc81d24b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/SetValueTest2.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.claimValue; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.base.SimpleBase; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; +public class SetValueTest2 extends SimpleBase { + private static int NV = 258; + private static int VS = (1<<14)-1; + private final String value = "SetValue2" + getRandomString(); + private final byte[] data; + public SetValueTest2() { + data = new byte[VS]; + for (int i = 0; i < data.length; i++) { + data[i] = (byte)(i); + } + } + @Test + public void testSetValue2() throws DatabaseException { + final Session s = getSession(); + setValues(s); + checkValues(s); + final Session s2 = Tests.getTestHandler().getSession(); + try { + checkValues(s2); + } finally { + LifecycleSupport ls = s2.getService(LifecycleSupport.class); + ls.close(); + } + } + private void setValues(Session s) throws DatabaseException { + s.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, null, b.Library); + g.claimLiteral(r, b.HasName, value); + g.claim(rl, b.ConsistsOf, r); + g.flushCluster(); + for (int i=0; i() { + @Override + public Resource perform(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + String uri = TestBase.ROOT_LIBRARY_URI + "/" + value; + Resource r = g.getResource(uri); + assertTrue(null != r); + Collection resources = g.getObjects(r, l0.HasProperty); + int count = 0; + for (Resource rv : resources) { + if (g.isInstanceOf(rv, l0.ByteArray)) { + byte[] data = g.getValue(rv); + if (data.length != VS) + fail("Value lenght does not match."); + for (int i = 0; i < data.length; i++) { + if (data[i] != (byte)i) + fail("Value content does not match."); + } + ++count; + } + } + if (count != NV) + fail("Value count does not match. count=" + count); + return null; + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/deny/DenyTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/deny/DenyTest1.java new file mode 100644 index 000000000..62acb0787 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/deny/DenyTest1.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.deny; + +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.WriteReadTest; + +public class DenyTest1 extends WriteReadTest { + + Resource other; + + @Override + protected void write(WriteGraph graph) throws DatabaseException { + + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + VirtualGraph virt = support.getMemoryPersistent(UUID.randomUUID().toString()); + + final Resource other2 = graph.syncRequest(new WriteResultRequest(virt) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Resource other = graph.newResource(); + graph.claim(written, L0.ConsistsOf, L0.PartOf, other); + return other; + } + + }); + + Resource single = graph.getSingleObject(written, L0.ConsistsOf); + assertNotNull(single); + assertTrue(single.equals(other2)); + + other = graph.newResource(); + graph.claim(written, L0.ConsistsOf, L0.PartOf, other); + + graph.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.deny(written, L0.ConsistsOf, L0.PartOf, other2); + } + + }); + + } + + @Override + protected void read(ReadGraph graph) throws DatabaseException { + + Resource single = graph.getPossibleObject(written, L0.ConsistsOf); + assertNotNull(single); + assertTrue(single.equals(other)); + + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/denyValue/DenyValueTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/denyValue/DenyValueTest.java new file mode 100644 index 000000000..b90347c5f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/denyValue/DenyValueTest.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.denyValue; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; + +public class DenyValueTest extends ExistingDatabaseTest { + + @Test + @Fails + public void test() throws Exception{ + + final Resource r = getSession().syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Resource f = g.newResource(); + g.claimValue(f, "A", Bindings.STRING); + return f; + + } + + }); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + g.denyValue(r); + + } + + }); + + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + + String value = g.getPossibleValue(r, Bindings.STRING); + if(value != null) throw new AssertionError("Value was not removed!"); + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteErrorTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteErrorTest.java new file mode 100644 index 000000000..77da1b7e4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteErrorTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * @author Tuukka Lehtonen + * + */ +public class SessionWriteErrorTest extends ExistingDatabaseTest { + + private Error exception; + + @Test + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + exception = new Error(); + throw exception; + + } + + }); + + } catch (Throwable e) { + + if(e.getCause() != exception) { + fail("Write transaction threw an unknown exception " + e); + } + + // Check that the session bookkeeping is still intact for another write transaction. + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + }); + + return; + + } + + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteExceptionTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteExceptionTest.java new file mode 100644 index 000000000..7b699bda4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteExceptionTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class SessionWriteExceptionTest extends ExistingDatabaseTest { + + private Exception exception; + + @Test + @Fails + public void testWriteException() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + exception = new DatabaseException(); + + } + + }); + + } catch (Throwable e) { + + if(!e.equals(exception)) { + fail("Write transaction threw an unknown exception " + e); + } + + return; + + } + + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteOnlyErrorTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteOnlyErrorTest.java new file mode 100644 index 000000000..21a311455 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/SessionWriteOnlyErrorTest.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * @see #3462 + * + * @author Tuukka Lehtonen + */ +public class SessionWriteOnlyErrorTest extends ExistingDatabaseTest { + + private Error exception; + + @Test + @Fails + public void testWriteOnlyError() throws Exception { + + Session session = getSession(); + + try { + + session.syncRequest(new WriteOnlyRequest() { + + @Override + public void perform(WriteOnlyGraph graph) throws DatabaseException { + + exception = new OutOfMemoryError(); + throw exception; + + } + + }); + + } catch (Throwable e) { + + if(e.getCause() != exception) { + fail("Write transaction threw an unknown exception " + e); + } + + // Check that the session bookkeeping is still intact for another write transaction. + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + }); + session.syncRequest(new WriteOnlyRequest() { + @Override + public void perform(WriteOnlyGraph graph) throws DatabaseException { + } + }); + + return; + + } + + fail("Write transaction did not throw an exception."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCallbackFailureTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCallbackFailureTest.java new file mode 100644 index 000000000..fff066acf --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCallbackFailureTest.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import java.util.concurrent.Semaphore; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Callback; + +/** + * Checks that unexpected write callback failures do not crash the session and + * that the write request results were correctly committed. + * + * @author Tuukka Lehtonen + */ +public class WriteCallbackFailureTest extends ExistingDatabaseTest { + + private static final String AN_ENTITY = "An entity"; + Resource written; + + @Test + public void testFailingWriteCallback() throws DatabaseException{ + final Semaphore sem = new Semaphore(0); + + getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + Resource test = graph.newResource(); + graph.claim(test, b.InstanceOf, null, b.Entity); + Resource name = graph.newResource(); + graph.claim(name, b.InstanceOf, null, b.String); + graph.claimValue(name, AN_ENTITY); + graph.claim(test, b.HasName, name); + + written = test; + } + }, new Callback() { + @Override + public void run(DatabaseException parameter) { + try { + throw new NullPointerException("intentional failure"); + } finally { + sem.release(); + } + } + }); + + try { + sem.acquire(); + } catch (InterruptedException e) { + throw new DatabaseException(e); + } + + // This will block until the previous request has finished. + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + // Ensure that the previously written data exists. + assertTrue(graph.hasStatement(written, b.InstanceOf, b.Entity)); + Resource name = graph.getSingleObject(written, b.HasName); + assertTrue(graph.hasStatement(name, b.InstanceOf, b.String)); + assertTrue(graph.hasStatement(written, b.HasName, name)); + Object value = graph.getValue(name); + assertTrue(value.equals(AN_ENTITY)); + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest.java new file mode 100644 index 000000000..a5933cf67 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Checks that unexpected write callback failures do not crash the session and + * that the write request results were correctly committed. + * + * @author Tuukka Lehtonen + */ +public class WriteCancelTest extends ExistingDatabaseTest { + + private static final String AN_ENTITY = "An entity"; + Resource written; + Resource writtenName; + + @Test + public void testWriteCancel() throws DatabaseException{ + + try { + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + written = graph.newResource(); + writtenName = graph.newResource(); + graph.claim(written, b.InstanceOf, null, b.Entity); + graph.claim(writtenName, b.InstanceOf, null, b.String); + graph.claimValue(writtenName, AN_ENTITY); + graph.claim(written, b.HasName, writtenName); + + //throw new DatabaseException("Intentional write request cancellation by unexpected exception"); + throw new CancelTransactionException("Intentional write request cancellation"); + } + }); + } catch (DatabaseException e) { + if (DEBUG) + e.printStackTrace(); + } + + // Make sure that we can at least start a new transaction after the + // cancelled one, but don't do anything yet. + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + }); + + // Ensure that the previously written data does not exist. + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + assertTrue(!graph.hasStatement(written, b.InstanceOf, b.Entity)); + assertTrue(!graph.hasStatement(written, b.HasName, writtenName)); + assertTrue(!graph.hasStatement(writtenName, b.InstanceOf, b.String)); + assertTrue(!graph.hasValue(writtenName)); + } + }); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest2.java new file mode 100644 index 000000000..d81358e2c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteCancelTest2.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.TransactionSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Checks that asynchronous read requests work correctly with canceled writes + * + * @author Antti Villberg + */ +public class WriteCancelTest2 extends ExistingDatabaseTest { + + private static final int SIZE = 10000; + + Resource[] written = new Resource[SIZE]; + + @Test + public void testWriteCancel2() throws DatabaseException{ + + // First create a set of resources for testing + try { + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if (DEBUG) + System.err.println("a"); + for(int i=0;i ids = getSession().getService(ManagementSupport.class).getChangeSetIdentifiers(Long.MIN_VALUE, Long.MAX_VALUE); + if (DEBUG) + for (ChangeSetIdentifier id : ids) { + System.out.println("CSID: " + id.getId()); + System.out.println(" METADATA: " + id.getMetadata()); + } + + getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource r = graph.newResource(); + graph.claim(root, L0.InstanceOf, L0.Library); + graph.claim(root, L0.ConsistsOf, r); + + TreeMap map = new TreeMap(); + map.put(r, new StructuralChanges.Change[] { new StructuralChanges.ComponentAddition(r) }); + StructuralChanges ch = new StructuralChanges(map); + graph.addMetadata(ch); + } + }); + int count = ids.size(); + ids = getSession().getService(ManagementSupport.class).getChangeSetIdentifiers(Long.MIN_VALUE, Long.MAX_VALUE); + Assert.assertTrue("Metadata not updated.", count < ids.size()); + if (DEBUG) + for (ChangeSetIdentifier id : ids) { + System.out.println("CSID: " + id.getId()); + System.out.println(" METADATA: " + id.getMetadata()); + } + if (DEBUG) { + Thread.sleep(5000); + + ids = getSession().getService(ManagementSupport.class).getChangeSetIdentifiers(Long.MIN_VALUE, Long.MAX_VALUE); + for (ChangeSetIdentifier id : ids) { + System.out.println("CSID: " + id.getId()); + System.out.println(" METADATA: " + id.getMetadata()); + } + } + } + +} + +class StructuralChanges implements Metadata { + + public final @Arguments({Resource.class, Change[].class}) TreeMap modelChanges; + + public StructuralChanges(TreeMap modelChanges) { + this.modelChanges = modelChanges; + } + + public StructuralChanges(Map> _modelChanges) { + this(new TreeMap()); + for(Map.Entry> entry : _modelChanges.entrySet()) { + ArrayList value = entry.getValue(); + modelChanges.put(entry.getKey(), value.toArray(new Change[value.size()])); + } + } + + public static enum ChangeType { + COMPONENT_ADDITION, COMPONENT_REMOVAL, + COMPONENT_MODIFICATION, CONNECTION_CHANGE + } + + @Union({ComponentAddition.class, + ComponentRemoval.class, + ComponentModification.class, + ConnectionChange.class}) + public static interface Change { + ChangeType getType(); + } + + public static class ComponentAddition implements Change { + public final Resource component; + public ComponentAddition(Resource component) { + this.component = component; + } + @Override + public ChangeType getType() { + return ChangeType.COMPONENT_ADDITION; + } + } + + public static class ComponentRemoval implements Change { + public final Resource component; + public final Resource parent; + public ComponentRemoval(Resource component, Resource parent) { + this.component = component; + this.parent = parent; + } + @Override + public ChangeType getType() { + return ChangeType.COMPONENT_REMOVAL; + } + } + + public static class ComponentModification implements Change { + public final Resource component; + public ComponentModification(Resource component) { + this.component = component; + } + @Override + public ChangeType getType() { + return ChangeType.COMPONENT_MODIFICATION; + } + } + + public static class ConnectionChange implements Change { + public final Resource connection; + public ConnectionChange(Resource connection) { + this.connection = connection; + } + @Override + public ChangeType getType() { + return ChangeType.CONNECTION_CHANGE; + } + } + + public Change[] get(Resource model) { + return modelChanges.get(model); + } + + @Override + public byte[] serialise(Session session) { + try { + Databoard databoard = session.getService( Databoard.class ); + Binding binding = databoard.getBinding( StructuralChanges.class ); + Serializer serializer = databoard.getSerializer( binding ); + return serializer.serialize(this); + } catch (Exception e) { + e.printStackTrace(); + if (e instanceof RuntimeDatabaseException) + throw (RuntimeDatabaseException)e; + else + throw new RuntimeDatabaseException("Serialization failed.", e); + } + } + + public static StructuralChanges deserialise(Session session, byte[] input) { + try { + Databoard databoard = session.getService( Databoard.class ); + Binding binding = databoard.getBinding( StructuralChanges.class ); + Serializer serializer = databoard.getSerializer( binding ); + return (StructuralChanges) serializer.deserialize(input); + } catch (Exception e) { + e.printStackTrace(); + if (e instanceof RuntimeDatabaseException) + throw (RuntimeDatabaseException)e; + else + throw new RuntimeDatabaseException("Deserialization failed.", e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteOnlyReadTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteOnlyReadTest.java new file mode 100644 index 000000000..898777d0d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/request/WriteOnlyReadTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.request; + +import java.util.ArrayList; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class WriteOnlyReadTest extends ExistingDatabaseTest { + + final static int ITEM_COUNT = 2; + + @Test + public void testWriteException() throws Exception { + + final Session session = getSession(); + final Layer0 b = Layer0.getInstance(session); + + final ArrayList items = new ArrayList(); + + session.syncRequest(new WriteOnlyRequest() { + + @Override + public void perform(WriteOnlyGraph graph) throws DatabaseException { + + graph.flushCluster(); + for(int i=0;i() { + @Override + public Resource perform(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + + Resource rs = g.getResource(TestBase.ROOT_LIBRARY_URI + "/" + stms); + assertTrue(null != rs); + Collection stmsR = g.getObjects(rs, l0.ConsistsOf); + if (stmsR.size() != NR) + fail("Resource count does not match. count=" + stmsR.size()); + + Resource rt = g.getResource(TestBase.ROOT_LIBRARY_URI + "/" + types); + assertTrue(null != rs); + Collection typesR = g.getObjects(rt, l0.ConsistsOf); + if (typesR.size() != NS) + fail("Types count does not match. count=" + typesR.size()); + + Set typesS = new HashSet(); + for (Resource r : typesR) { + typesS.add(r); + } + for (Resource r : stmsR) { + Collection instances = g.getObjects(r, l0.InstanceOf); + if (instances.size() != NS) + fail("Instance count does not match. count=" + instances.size()); + for (Resource ri : instances) + if (!typesS.contains(ri)) + fail("Instance typet does not match. instance=" + ri); + } + return null; + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/story/WriteIntoBuiltinResourceTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/story/WriteIntoBuiltinResourceTest.java new file mode 100644 index 000000000..1fafff4e0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/story/WriteIntoBuiltinResourceTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.write.story; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class WriteIntoBuiltinResourceTest extends ExistingDatabaseTest { + + @Test + public void test() throws Exception{ + + final Resource rootLib = getSession().getRootLibrary(); + + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + + Layer0 b = Layer0.getInstance(g); + try { + g.claim(rootLib, b.IsRelatedTo, rootLib); + } catch (Throwable t) { + new Exception().printStackTrace(); + } + + } + + }); + + checkException(); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java new file mode 100644 index 000000000..7da5cfe2a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java @@ -0,0 +1,80 @@ +package org.simantics.db.tests.client; + +import org.junit.Test; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.Client; +import org.simantics.db.testing.common.ClientFactory; +import org.simantics.db.tests.common.Configuration; + +public class CallTest extends ExistingDatabaseTest { + private static final int COUNT = Configuration.get().callLoopCount; + private static final int CALL_COUNT = Configuration.get().callCallCount; + private static final int N_THREADS = Configuration.get().callThreadCount; + private CallTestThread[] threads = new CallTestThread[N_THREADS]; + + @Test + @Fails + public void testCall() throws DatabaseException { + for (int i=0; i + * + */ +public class CleanShutdownTest extends TestBase { + private boolean completed = false; + + @Test + @Fails + public void testShutdown() throws Exception { + completed = false; + Thread t = new Thread() { + @Override + public void run() { + try { + Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest.this) { + @Override + public void run(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource instance = g.newResource(); + g.claim(g.getRootLibrary(), b.ConsistsOf, instance); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, "Name"); + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + try { + Tests.killCore(); // kill the core before read transaction + } catch (DatabaseException e1) { + fail("Killing core failed: " + e1.getMessage()); + } + try { + Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + g.getRelatedValue(r, b.HasName); + } + } + }); + } catch (Exception e) { + // this is the correct behavior for this test + } + try { + Tests.closeSession(Tests.getTestHandler().getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + } + completed = true; + } + }; + t.start(); + + for (int i = 0; i < 30; i++) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + + } + if (completed) + break; + } + if (!completed) + throw new Exception("Core did not shutdown in 30 seconds"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java new file mode 100644 index 000000000..6dfff02c8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; +/** + * Tests if session can be closed after core crash. + * @author Marko Luukkainen + * + */ +public class CleanShutdownTest2 extends TestBase { + private boolean completed = false; + @Test + @Fails + public void testShutdown() throws Exception { + completed = false; + Thread t = new Thread() { + @Override + public void run() { + try { + Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest2.this) { + @Override + public void run(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource instance = g.newResource(); + g.claim(g.getRootLibrary(), b.ConsistsOf, instance); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, "Name"); + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + try { + Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + // kill the core in the middle of a read transaction + Tests.killCore(); + for (Resource r : resources) { + g.getRelatedValue(r, b.HasName); + } + } + }); + } catch (Exception e) { + // this is the correct behavior for this test + } + try { + Tests.closeSession(Tests.getTestHandler().getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + } + completed = true; + } + }; + t.start(); + + for (int i = 0; i < 30; i++) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + + } + if (completed) + break; + } + if (!completed) + throw new Exception("Core did not shutdown in 30 seconds"); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest.java new file mode 100644 index 000000000..5d6dfc752 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.event.SessionEvent; +import org.simantics.db.event.SessionListener; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +import fi.vtt.simantics.procore.SessionManagerSource; + +/** + * Tests how server handles multiple simultaneous connections. + * + * @author Marko Luukkainen + * + */ +public class ConnectionTest extends ExistingDatabaseTest { + + private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount; + private static final int THREAD_COUNT = Configuration.get().connectionThreadCount; + private static final int WAIT_TIME = 10; + private static boolean WRITE = false; + + private Throwable error; + private List threads = new ArrayList(); + private volatile int count = 0; // not totally correct code but works for me + public void setError(Throwable error) { + if (this.error == null) { + this.error = error; + for (ConnectionThread t : threads) { + t.dispose(); + } + } + } + + private boolean notDone() { + for (ConnectionThread t : threads) { + if(!t.isDone()) { + return true; + } + } + return false; + } + + /** + * Tests how server can handle multiple simultaneous connections + * @throws Exception + */ + static int sessionClosed = 0; + private synchronized void inc() { + ++sessionClosed; + } + @Test + public void testConnection() throws Exception { + for (int i = 0; i < THREAD_COUNT; i++) { + ConnectionThread t = new ConnectionThread(); + threads.add(t); + t.start(); + } + if (DEBUG) + System.out.println("Created " + THREAD_COUNT + " threads."); + sessionClosed = 0; + SessionManagerSource.getSessionManager().addSessionListener( + new SessionListener() { + @Override + public void sessionClosed(SessionEvent e) { + if (DEBUG) + System.out.println("Session closed s=" + e.getSession()); + if (null != e.getCause()) + e.getCause().printStackTrace(); + else + inc(); + } + + @Override + public void sessionOpened(SessionEvent e) { + if (DEBUG) + System.out.println("Session opened s=" + e.getSession()); + } + + @Override + public void sessionException(SessionEvent e) { + if (DEBUG) + System.out.println("Session exception s=" + e.getSession()); + if (null != e.getCause()) + e.getCause().printStackTrace(); + } + } + ); + // Wait for correct number of closes. + while (RECONNECT_COUNT * THREAD_COUNT != sessionClosed) { + checkException(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("Interrupted."); + } + } + + // Wait for write request to complete + while (notDone()) { + checkException(); + int currentCount = count; + try { + Thread.sleep(WAIT_TIME * 1000); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("Interrupted."); + } + if (DEBUG) + System.out.println(count); + if (count == currentCount) + break; + } + checkException(); + // check success flag + if (error != null) { + throw new Exception("First error was",error); + } + if (notDone()) + throw new Exception("Test was not completed, server did not resepond for " + + WAIT_TIME + " seconds"); + } + + + private class ConnectionThread extends Thread { + private boolean done = false; + private boolean disposed = false; + public ConnectionThread() { + } + @Override + public void run() { + for (int i = 0; i < RECONNECT_COUNT; i++) { + if (disposed) + return; + try { + final Session session = Tests.getTestHandler().getSession(); + final Resource rootLibrary = session.getRootLibrary(); + assertTrue(rootLibrary != null); + final String name = this.getName() + " " + Integer.toString(i); + if (WRITE) { + session.syncRequest(new WriteQuery(ConnectionTest.this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, name); + g.claim(rootLibrary, b.ConsistsOf, newResource); + } + }); + } + Tests.closeSession(session); + } catch (Exception e) { + setError(e); + return; + } + ++count; + } + if (DEBUG) + System.out.println("count=" + count); + done = true; + } + + public boolean isDone() { + return done; + } + + public void dispose() { + disposed = true; + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest1.java new file mode 100644 index 000000000..130f752b9 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest1.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.layer0.Layer0; + +public class ConnectionTest1 extends ExistingDatabaseTest { +// private static final String USERNAME = Configuration.get().username; +// private static final String PASSWORD = Configuration.get().password; + private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount; + + @Test + public void test1() throws DatabaseException { + Session session = null; + for (int i=0; i resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + } + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(); +// } catch (ClassNotFoundException e) { +// throw new DatabaseException("Test failed.", e); + } finally { + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest2.java new file mode 100644 index 000000000..ee210d661 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest2.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.io.IOException; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.event.SessionEvent; +import org.simantics.db.event.SessionListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.impl.Configuration; + +import fi.vtt.simantics.procore.SessionManagerSource; + +public class ConnectionTest2 extends ExistingDatabaseTest { +// private static final String USERNAME = Configuration.get().username; +// private static final String PASSWORD = Configuration.get().password; + private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount; + + private int sessionOpened = 0; + private int sessionClosed = 0; + private synchronized void incOpened() { + ++sessionOpened; + } + private synchronized void incClosed() { + ++sessionClosed; + } + @Test + public void test2() throws DatabaseException { + SessionListener sl = new SessionListener() { + @Override + public void sessionClosed(SessionEvent e) { + if (null != e.getCause()) + fail("Session closed with exception: " + e.getCause().getMessage()); + else + incClosed(); + } + + @Override + public void sessionOpened(SessionEvent e) { + if (null != e.getCause()) + fail("Session opened with exception: " + e.getCause().getMessage()); + else + incOpened(); + } + + @Override + public void sessionException(SessionEvent e) { + if (null == e.getCause()) + fail("Session threw null exception"); + else + fail("Session threw exception: " + e.getCause().getMessage()); + } + }; + try { + SessionManagerSource.getSessionManager().addSessionListener(sl); + for (int i=0; i resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + Tests.closeSession(session); + session = Tests.getTestHandler().getSession(); + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + Tests.closeSession(session); +// } catch (ClassNotFoundException e) { +// throw new DatabaseException("Test failed.", e); + } finally { + Tests.closeSession(session); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest5.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest5.java new file mode 100644 index 000000000..f858c9ce6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ConnectionTest5.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.layer0.Layer0; + +public class ConnectionTest5 extends TestBase { + private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount; + private static final int SAVE_COUNT = Configuration.get().connectionSaveCount; + private static final int INSTANCE_COUNT = Configuration.get().connectionInstanceCount; + private static final boolean SKIP = Configuration.get().skipServerCreation; + private Session session = null; + private final String random = "ConnectionTest5" + TestBase.getRandomString(); + private final String libraryName = "Library" + random; + + @Test + @Fails + public void test5() throws DatabaseException { + if (SKIP) { + System.out.println("This test is not valid for remote server."); + return; + } + // Try to load and register the Driver instance with the driver manager + try { + Class.forName("fi.vtt.simantics.procore.ProCoreDriver"); + } catch (ClassNotFoundException e) { + throw new DatabaseException("Test failed.", e); + } + for (int i=0; i names = new ArrayList(); + for (int i=0; i resources = g.getObjects(rl, l0.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, l0.HasName); + if (null != value && value.equals(libraryName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + } + }); + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(); + } finally { + Tests.closeSession(session); + } + } + private Resource getResourceByNameAndRelation(ReadGraph g, + Resource parent, Resource relation, String name) + throws DatabaseException { + Collection resources = g.getObjects(parent, relation); + Resource newResource = null; + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, l0.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + return newResource; + } + String saveTest(int id) throws DatabaseException { + try { + session = Tests.getTestHandler().getSession(); + final String subLibraryName = "" + id + random; + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource subLibrary = g.newResource(); + g.claim(subLibrary, b.InstanceOf, null, b.Library); + g.claimLiteral(subLibrary, b.HasName, subLibraryName); + Resource library = getResourceByNameAndRelation(g, + g.getRootLibrary(), b.ConsistsOf, libraryName); + assertTrue(null != library); + g.claim(library, b.ConsistsOf, b.PartOf, subLibrary); + for (int j=0; j names) throws DatabaseException { + try { + session = Tests.getTestHandler().getSession(); + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + Resource library = getResourceByNameAndRelation(g, + rl, l0.ConsistsOf, libraryName); + assertTrue(null != library); + for (String libraryName : names) { + Resource subLibrary = getResourceByNameAndRelation(g, + library, l0.ConsistsOf, libraryName); + assertTrue(null != subLibrary); + for (int j=0; j names = new ArrayList(); + for (int i=0; i resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(libraryName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + } + }); + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(); + } catch (DatabaseException e) { + throw e; + } finally { + Tests.closeSession(session); + } + } + private Resource getResourceByNameAndRelation(ReadGraph g, + Resource parent, Resource relation, String name) + throws DatabaseException { + Collection resources = g.getObjects(parent, relation); + Resource newResource = null; + Layer0 b = Layer0.getInstance(g); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + return newResource; + } + private static Resource newResource; + String saveTest(final int id) throws Exception { + try { + session = Tests.getTestHandler().getSession(); + final String newInstanceName = "" + id + newInstanceSuffix; + final String desc = "" + id; + + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, newInstanceName); + Resource library = getResourceByNameAndRelation(g, + g.getRootLibrary(), b.ConsistsOf, libraryName); + assertTrue(null != library); + g.claim(library, b.ConsistsOf, newResource); + g.claimLiteral(newResource, b.HasDescription, desc); + } + }); + + LifecycleSupport ls = session.getService(LifecycleSupport.class); + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource library = getResourceByNameAndRelation(g, + g.getRootLibrary(), b.ConsistsOf, libraryName); + assertTrue(null != library); + Resource newResource = getResourceByNameAndRelation(g, + library, b.ConsistsOf, newInstanceName); + assertTrue(null != newResource); + String s = g.getRelatedValue(newResource, b.HasDescription, Bindings.STRING); + if (!s.equals(desc)) + throw new ValidationException("Value is not correct."); + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + ls.close(); + return newInstanceName; + } catch (DatabaseException e) { + throw e; + } finally { + Tests.closeSession(session); + } + } + void checkTest(final List names) throws Exception { + try { + session = Tests.getTestHandler().getSession(); + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource library = getResourceByNameAndRelation(g, + g.getRootLibrary(), b.ConsistsOf, libraryName); + assertTrue(null != library); + for (String instanceName : names) { + Resource instance = getResourceByNameAndRelation(g, + library, b.ConsistsOf, instanceName); + assertTrue(instance != null); + } + } + }); + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(-1, false); + if (DEBUG) + System.out.println("close done"); + } catch (DatabaseException e) { + throw e; + } finally { + Tests.closeSession(session); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CoreCrashTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CoreCrashTest.java new file mode 100644 index 000000000..2cec94fb8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CoreCrashTest.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.Collection; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.common.ExceptionUtils; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Tests how interface handles Servers crash + * + * @author Marko Luukkainen + * + */ +public class CoreCrashTest extends TestBase { + private static final int WAIT_TIME = 200; + private Throwable error; + @Before + public void setUp() throws Exception { + super.setUp(); + } + + @After + public void tearDown() throws Exception { + try { + Tests.getTestHandler().getServer().stop(); + } catch (Exception e) { + + } + super.tearDown(); + } + @Override + public Session getSession() throws DatabaseException { + return Tests.getTestHandler().getSession(); + } + /** + * Tests how graph interface handles server crash when the crash occurs between transactions + * @throws Exception + */ + public void testCrash() throws Exception { + final String randomName = "Name " + getRandomString(); + + // create something + Tests.getTestHandler().getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource instance = g.newResource(); + g.claim(g.getRootLibrary(), b.ConsistsOf, instance); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, randomName); + } + }); + checkException(); + Tests.killCore(); + + // this should create an error + Tests.getTestHandler().getSession().asyncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + fail("Missing exception after core killed."); + for (Resource r : resources) { + g.getRelatedValue(r, b.HasName); + } + } + }); + + // Wait for read request to complete + for (int i = 0; i < 10; i++) { + try { + Thread.sleep(WAIT_TIME); + } catch (InterruptedException e) { + + } + if (hasException()) + break; + } + if (!hasException()) { + throw new Exception("Connection failure before or during request did not cause an error"); + } + error = getException(); + System.out.println("Connection failure caused an error:\n" + ExceptionUtils.getStackTrace(error) ); + } + + /** + * Tests how graph interface handles server crash when the crash occurs between transactions + * @throws Exception + */ + @Test + @Fails + public void testCrash2() throws Exception { + final String randomName = "Name " + getRandomString(); + + Tests.killCore(); + + // create something + Tests.getTestHandler().getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource instance = g.newResource(); + g.claim(g.getRootLibrary(), b.ConsistsOf, instance); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, randomName); + } + }); + if (!hasException()) { + throw new Exception("Connection failure did not cause an error"); + } + error = getException(); + System.out.println("Connection failure caused an error:\n" + ExceptionUtils.getStackTrace(error)); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTest.java new file mode 100644 index 000000000..6ad2e5fbe --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; +public class JournalTest extends ExistingDatabaseTest { + private static final int N = 10; + private static boolean WRITE = false; + + @Test + public void testJournal() throws DatabaseException{ + write(); + validate(); + } + private void write() + throws DatabaseException { + if (!WRITE) + return; + for (int i=0; i() { + @Override + public Resource perform(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + Resource root = g.getResource(TestBase.ROOT_LIBRARY_URI); + for (Resource r : g.getObjects(root, l0.ConsistsOf)) + if (DEBUG) + System.out.println("Resource " + r); + return null; + } + + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTestFail.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTestFail.java new file mode 100644 index 000000000..acaae7c39 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTestFail.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class JournalTestFail extends ExistingDatabaseTest { + + @Test + @Fails + public void testJournalFail() throws DatabaseException{ + final Session s = getSession(); + s.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + XSupport xs = (XSupport)g.getService(XSupport.class); + xs.corruptCluster(null); + xs.flushCluster(null); + } + }); + if (DEBUG) + System.out.println("Write done."); + s.syncRequest(new Read() { + @Override + public Resource perform(ReadGraph g) throws DatabaseException { + return null; + } + }); + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/RefreshTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/RefreshTest1.java new file mode 100644 index 000000000..ec69c83ae --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/RefreshTest1.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + + +import org.junit.Test; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.TestCommonNoVirtual; +import org.simantics.db.testing.common.Client; +import org.simantics.db.testing.common.ClientFactory; +import org.simantics.db.tests.common.ClientOperations; +import org.simantics.db.tests.common.Configuration; + +public class RefreshTest1 extends TestCommonNoVirtual { + private static final int COUNT = Configuration.get().refreshLoopCount; + + @Test + public void testRefresh1() throws DatabaseException { + if (noVirtual()) + return; + for (int i=0; i out) { + this.notifyAll(); + try { + TransactionClient2.this.wait(); + } catch (InterruptedException e) { + System.out.println("Wait was interruped: " + e); + } + } + } + } + private void startReadTransaction() + throws DatabaseException { + session.asyncRequest(new Read() { + @Override + public Integer perform(ReadGraph graph) throws DatabaseException { + synchronized (TransactionClient2.this) { + TransactionClient2.this.transactionIn(); + if (DEBUG) + System.out.println("DEBUG: Read request begin ok, count= " + in); + while (TransactionClient2.this.transactionKeep()) { + try { + TransactionClient2.this.wait(); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("DEBUG: read request wait interrupted: " + e.getMessage()); + } + } + } + return in; + } + }, new AsyncProcedure() { + @Override + public void execute(AsyncReadGraph graph, Integer result) { + TransactionClient2.this.transactionOut(); + if (DEBUG) + System.out.println("DEBUG: Read request end ok, count= " + result); + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + TransactionClient2.this.transactionOut(); + if (DEBUG) + System.out.println("DEBUG: read request end failed: " + throwable.getMessage()); + } + }); + synchronized (this) { + while (in <= out) { + try { + TransactionClient2.this.wait(); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("DEBUG: read request sleep was interruped: " + e); + } + } + } + } + synchronized boolean transactionKeep() { + return !breakTransaction.get(); + } + synchronized int transactionIn() { + ++in; + this.notify(); + return in; + } + synchronized int transactionOut() { + ++out; + this.notify(); + return out; + } + class TryToKeepWrite implements Runnable { + TryToKeepWrite() { + } + @Override + public void run() { + while (goOn) { + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + synchronized (TransactionClient2.this) { + TransactionClient2.this.transactionIn(); + if (DEBUG) + System.out.println("DEBUG: Write request begin ok, count= " + in); + while (TransactionClient2.this.transactionKeep()) { + try { + TransactionClient2.this.wait(); + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("DEBUG: Write request wait interrupted: " + e.getMessage()); + } + } + } + } + }); + } catch (DatabaseException e) { + System.out.println("Empty sync write failed: " + e.getMessage()); + } finally { + TransactionClient2.this.transactionOut(); + } + while (goOn) + try { + relinquish.acquire(); + break; + } catch (InterruptedException e) { + if (DEBUG) + System.out.println("DEBUG: Relinquish wait interrupted: " + e.getMessage()); + } + if (DEBUG) + System.out.println("DEBUG: Write request end, count= " + out); + } + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest2.java new file mode 100644 index 000000000..bd416d547 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest2.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class TransactionTest2 extends ExistingDatabaseTest { + @Test + public void testTransaction2() + throws DatabaseException { + cancelTest1(); + } + void cancelTest1() throws DatabaseException { + TransactionClientCancel client = new TransactionClientCancel(this); + TransactionClientCancel client2 = new TransactionClientCancel(this); + TransactionClientCancel client3 = null; + try { + Resource r = client.createResource(); + client.validateResource(r); + client.modifyAndCancel(r); + client.validateResource(r); + long rid = client.serializeResource(r); + Resource r2 = client2.deserializeResource(rid); + client2.validateResource(r2); + client3 = new TransactionClientCancel(this); + Resource r3 = client3.deserializeResource(rid); + client3.validateResource(r3); + } finally { + if (null != client) + client.close(); + if (null != client2) + client2.close(); + if (null != client3) + client3.close(); + } + } +} + +class TransactionClientCancel extends TransctionCommon { + private final String message = "Transaction was cancelled."; + private final String value = "value"; + private final String newValue = "new value"; + TransactionClientCancel(ExistingDatabaseTest testCommon) + throws DatabaseException { + super(testCommon); + } + long serializeResource(Resource r) + throws DatabaseException { + SerialisationSupport ss = session.getService(SerialisationSupport.class); + return ss.getRandomAccessId(r); + } + Resource deserializeResource(long rid) + throws DatabaseException { + SerialisationSupport ss = session.getService(SerialisationSupport.class); + return ss.getResource(rid); + } + public Resource createResource() + throws DatabaseException { + return session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, b.Entity); + g.claimValue(r, value); + return r; + } + }); + } + public void modifyAndCancel(final Resource r) + throws DatabaseException { + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.claimValue(r, newValue); + String t = g.getValue(r, Bindings.STRING); + if (!t.equals(newValue)) + throw new ValidationException("Failed to modify value."); + g.flushCluster(r); + throw new CancelTransactionException(message); + } + }); + } catch (CancelTransactionException e) { + if (e.getMessage().equals(message)) + return; + } + } + public void validateResource(final Resource r) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + if (!g.hasStatement(r)) + throw new ValidationException("Failed to verify modifications (stm)."); + String t = g.getValue(r, Bindings.STRING); + if (!t.equals(value)) + throw new ValidationException("Failed to verify modifications (val)."); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest3.java new file mode 100644 index 000000000..4a8f68fd6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest3.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import java.util.Collection; +import java.util.Vector; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class TransactionTest3 extends ExistingDatabaseTest { + @Test + public void testTransaction3() + throws DatabaseException { + addResources(); + } + void addResources() throws DatabaseException { + TransactionTest3Client client = new TransactionTest3Client(this); + Vector resources = new Vector(); + try { + Resource r = client.createResource(); + client.validateResource(r); + resources.add(r); + for (int i=0; i<10; ++i) { + Resource r2 = client.addStatement(r); + client.validateResource(r2); + resources.add(r2); + } + client.validateResource(resources); + } finally { + if (null != client) + client.close(); + } + } +} + +class TransactionTest3Client extends TransctionCommon { + private final String message = "Transaction was cancelled."; +// private final String value = "value"; + private final String newValue = "new value"; + TransactionTest3Client(ExistingDatabaseTest testCommon) + throws DatabaseException { + super(testCommon); + } + long serializeResource(Resource r) + throws DatabaseException { + SerialisationSupport ss = session.getService(SerialisationSupport.class); + return ss.getRandomAccessId(r); + } + Resource deserializeResource(long rid) + throws DatabaseException { + SerialisationSupport ss = session.getService(SerialisationSupport.class); + return ss.getResource(rid); + } + public Resource createResource() + throws DatabaseException { + return session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, b.Entity); + return r; + } + }); + } + public Resource addStatement(final Resource r) + throws DatabaseException { + return session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r2 = g.newResource(); + g.claim(r2, b.InstanceOf, b.Entity); + g.claim(r, b.ConsistsOf, r2); + return r2; + } + }); + } + public void modifyAndCancel(final Resource r) + throws DatabaseException { + try { + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.claimValue(r, newValue); + String t = g.getValue(r, Bindings.STRING); + if (!t.equals(newValue)) + throw new ValidationException("Failed to modify value."); + g.flushCluster(r); + throw new DatabaseException(message); + } + }); + } catch (DatabaseException e) { + if (e.getMessage().equals(message)) + return; + } + } + public void validateResource(final Resource r) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + if (!g.isInstanceOf(r, l0.Entity)) + throw new ValidationException("Failed to verify resource " + r + "."); + } + }); + } + public void validateResource(final Collection resources) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : resources) + if (!g.isInstanceOf(r, l0.Entity)) + throw new ValidationException("Failed to verify resource " + r + "."); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java new file mode 100644 index 000000000..0ada0951f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.client; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +public class TransactionTest4 extends ExistingDatabaseTest { + @Test + @Fails + public void testTransaction4() + throws DatabaseException { + breakConnectionDuringTransaction(); + } + void breakConnectionDuringTransaction() throws DatabaseException { + TransactionTest4Client client = new TransactionTest4Client(this); + try { + client.syntheticBreakDuringCreateResource(); + } catch (Throwable t) { + if (DEBUG) + t.printStackTrace(); + } finally { + if (null != client) + client.close(); + } + TransactionTest4Client client2 = new TransactionTest4Client(this); + try { + client2.readQuery(); + } finally { + if (null != client2) + client2.close(); + } + } +} + +class TransactionTest4Client extends TransctionCommon { + TransactionTest4Client(ExistingDatabaseTest testCommon) + throws DatabaseException { + super(testCommon); + } + public Resource syntheticBreakDuringCreateResource() + throws DatabaseException { + return session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, b.Entity); + session.getService(XSupport.class).flushCluster(r); + try { + Thread.sleep(1000); // millisecond + } catch (InterruptedException e) { + if (DEBUG) + e.printStackTrace(); + } + session.getService(XSupport.class).breakConnection(); + return r; + } + }); + } + public void readQuery() + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + for (Resource r : g.getObjects(rl, l0.ConsistsOf)) + if (DEBUG) + System.out.println("Root library " + rl + " consists of " + r); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/Activator.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/Activator.java new file mode 100644 index 000000000..6bfea53de --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/Activator.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.common; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.db.tests"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/ClientOperations.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/ClientOperations.java new file mode 100644 index 000000000..1aa9aae1c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/common/ClientOperations.java @@ -0,0 +1,235 @@ +package org.simantics.db.tests.common; + +import java.util.Collection; +import java.util.ListIterator; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.impl.ClusterSupport; +import org.simantics.db.impl.ResourceImpl; +import org.simantics.db.testing.common.Client; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +public class ClientOperations { + + public static boolean DEBUG = false; + + public static String createData(Client client) + throws DatabaseException { + final String name = client.getInstanceName(); + client.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, name); + g.claim(g.getRootLibrary(), b.ConsistsOf, newResource); + } + }); + return name; + } + public static void validateData(Client client, final String name) + throws DatabaseException { + client.getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + Layer0 l0 = Layer0.getInstance(g); + Collection resources = g.getObjects(rl, l0.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, l0.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find resource " + name); + } + if (!g.isInstanceOf(newResource, l0.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + } + public static void removeData(Client client, final String name) + throws DatabaseException { +// ++instanceNumber; + client.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(name)) { + newResource = r; + g.deny(g.getRootLibrary(), b.ConsistsOf, newResource); + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find resource " + name); + } + } + }); + } + public static void validateDataRemoved(Client client, final String name) + throws DatabaseException { + client.getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + Layer0 l0 = Layer0.getInstance(g); + Collection resources = g.getObjects(rl, l0.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, l0.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + if (newResource != null) { + throw new ValidationException("Could find resource " + name); + } + } + }); + } + public static String createOrderedSet(Client client, final int size) + throws DatabaseException { + final String name = client.getInstanceName(); + client.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource l = OrderedSetUtils.create(g, b.Type); + g.claimLiteral(l, b.HasName, name); + g.claim(g.getRootLibrary(), b.ConsistsOf, l); + for (int i=0; i resources = g.getObjects(rl, l0.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, l0.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find resource " + name); + } + if (!g.isInstanceOf(newResource, l0.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + ListIterator a = OrderedSetUtils.iterator(g, newResource); + int count = 0; + while (a.hasNext()) { + Resource r = a.next(); + if (DEBUG) + System.out.println("DEBUG: Resource " + r); + ++count; + } + if (size != count) + throw new ValidationException("Number of elements doesn't match!"); + } + }); + } + public static void removeElement(Client client, final String name, final int size) + throws DatabaseException { + client.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find resource " + name); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + ListIterator a = OrderedSetUtils.iterator(g, newResource); + Resource el = null; + while (a.hasNext()) { + el = a.next(); + break; + } + if (el == null) { + if (size != 0) + throw new ValidationException("Number of elements doesn't match!"); + return; + } + OrderedSetUtils.remove(g, newResource, el); + a = OrderedSetUtils.iterator(g, newResource); + int count = 0; + while (a.hasNext()) { + Resource r = a.next(); + if (DEBUG) + System.out.println("DEBUG: Resource " + r); + ++count; + } + if (size != count) + throw new ValidationException("Number of elements doesn't match!"); + } + }); + } + public static void adddElement(Client client, final String name, final int size) + throws DatabaseException { + client.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(name)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find resource " + name); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + for (int i=0; i newEmpty() throws DatabaseException { + return new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + return g.newResource(); + } + }; + } + + public static Resource named(WriteGraph graph, String name) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + + Resource result = graph.newResource(); + graph.claim(result, b.InstanceOf, null, b.Entity); + graph.claimLiteral(result, b.HasName, name, Bindings.STRING); + + return result; + + } + + public static Resource assertion(WriteGraph graph, Resource predicate, Resource object) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + + // Assert nonfunctional items + Resource ass = graph.newResource(); + graph.claim(ass, b.InstanceOf, null, b.Assertion); + graph.claim(ass, b.HasPredicate, predicate); + graph.claim(ass, b.HasObject, object); + + return ass; + + } + + public static Resource string(WriteGraph graph, String string) throws DatabaseException { + + Layer0 b = Layer0.getInstance(graph); + + // Assert nonfunctional items + Resource result = graph.newResource(); + graph.claim(result, b.InstanceOf, null, b.String); + graph.claimValue(result, string); + + return result; + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java new file mode 100644 index 000000000..f9d2cbb4f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java @@ -0,0 +1,125 @@ +package org.simantics.db.tests.performance.java; + +import gnu.trove.list.array.TByteArrayList; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; + +import org.simantics.db.testing.base.TestCommonPerf; + +public class BufferTest extends TestCommonPerf { + + public static void test() throws Exception { + final boolean DEBUG = false; + final int BUFFER_SIZE = 100000000; + final int LOOP_SIZE = BUFFER_SIZE / 10; + { + ByteBuffer b = ByteBuffer.wrap(new byte[BUFFER_SIZE]); + long start = System.nanoTime(); + b.order(ByteOrder.LITTLE_ENDIAN); + for(int i=0;i>> 8); + arr[index++] = (byte)(i & 0xFF); + arr[index++] = (byte)((i >>> 8) & 0xFF); + arr[index++] = (byte)((i >>> 16) & 0xFF); + arr[index++] = (byte)((i >>> 24) & 0xFF); + } + long duration3 = System.nanoTime() - start3; + if (DEBUG) { + System.err.println("took " + 1e-9*duration3); + System.err.println(Arrays.hashCode(arr)); + } + } + { + TByteArrayList list = new TByteArrayList(BUFFER_SIZE); + long start4 = System.nanoTime(); + for(int i=0;i>> 8)); + list.add((byte)(i & 0xFF)); + list.add((byte)((i >>> 8) & 0xFF)); + list.add((byte)((i >>> 16) & 0xFF)); + list.add((byte)((i >>> 24) & 0xFF)); + } + long duration4 = System.nanoTime() - start4; + if (DEBUG) { + System.err.println("took " + 1e-9*duration4); + System.err.println(list.hashCode()); + } + } + { + byte[] arr2 = new byte[BUFFER_SIZE]; + long start5 = System.nanoTime(); + for(int i=0;i>> 8); + } + + static private void writeInt(byte[] bytes, int i) { + bytes[byteIndex++] = (byte)(i & 0xFF); + bytes[byteIndex++] = (byte)((i >>> 8) & 0xFF); + bytes[byteIndex++] = (byte)((i >>> 16) & 0xFF); + bytes[byteIndex++] = (byte)((i >>> 24) & 0xFF); + } + + public static void main(String[] args) { + try { + test(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/CastTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/CastTest.java new file mode 100644 index 000000000..f9355d202 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/CastTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.java; + +import org.simantics.db.testing.base.TestCommonPerf; + +/** + * + */ +public class CastTest extends TestCommonPerf { + + interface A { + + public int getValue(); + + } + + final static class B implements A { + + final private int value; + + public B(int value) { + this.value = value; + } + + @Override + public int getValue() { + return value; + } + + } + + final static class C implements A { + + final private int value; + + public C(int value) { + this.value = value; + } + + @Override + public int getValue() { + return value; + } + + } + + public static int LEN1 = 10000; + public static int LEN2 = 1000000000; + + public void test() throws Exception { + + A a = new B(1); + B b = new B(1); + + int counter = 0; + long start = System.nanoTime(); + for(int i=0;i map2, int i) { + Byte value = map2.get(i); + if(value == null) { + map2.put(i, value); + } + } + + public void test() throws Exception { + + TIntByteHashMap map = new TIntByteHashMap(); + + long start = System.nanoTime(); + for(int i=0;i<12000000;i++) { + byte test = (byte)i; + byte value = map.get(test); + if(value == 0) { + map.put(test, value); + } + } + long duration = System.nanoTime() - start; + System.err.println("took " + 1e-9*duration); + + TIntByteHashMap map2 = new TIntByteHashMap(); + long start2 = System.nanoTime(); + for(int i=0;i<10000000;i++) a(map2, i); + long duration2 = System.nanoTime() - start2; + System.err.println("took " + 1e-9*duration2); + + TreeMap map3 = new TreeMap(); + long start3 = System.nanoTime(); + for(int i=0;i<10000000;i++) { + Byte value = map3.get(i); + if(value == null) { + map3.put(i, value); + } + } + long duration3 = System.nanoTime() - start3; + System.err.println("took " + 1e-9*duration3); + + TreeMap map4 = new TreeMap(); + long start4 = System.nanoTime(); + for(int i=0;i<10000000;i++) b(map4, i); + long duration4 = System.nanoTime() - start4; + System.err.println("took " + 1e-9*duration4); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/SynchronizationTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/SynchronizationTest.java new file mode 100644 index 000000000..f47c61ddc --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/SynchronizationTest.java @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.java; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Semaphore; + +import org.simantics.db.testing.base.TestCommonPerf; + + +/** + * + */ +public class SynchronizationTest extends TestCommonPerf { + +// public void test() throws Exception { +// +// class CounterThread extends Thread { +// +// final private Semaphore start; +// final private AtomicInteger counter; +// final private CountDownLatch latch; +// +// public CounterThread(Semaphore start, CountDownLatch latch, AtomicInteger counter) { +// this.start = start; +// this.counter = counter; +// this.latch = latch; +// } +// +// @Override +// public void run() { +// +// try { +// start.acquire(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// int work = 0; +// for(int i=0;i<10000000;i++) { +// counter.incrementAndGet(); +// for(int j=0;j<100;j++) work++; +// counter.decrementAndGet(); +// } +// +// latch.countDown(); +// +// System.out.println("work=" + work); +// +// } +// +// } +// +// CountDownLatch latch = new CountDownLatch(8); +// AtomicInteger counter = new AtomicInteger(0); +// Semaphore starter = new Semaphore(0); +// +// for(int i=0;i<8;i++) new CounterThread(starter, latch, counter).start(); +// +// Thread.sleep(500); +// +// starter.release(8); +// long start = System.nanoTime(); +// latch.await(); +// long duration = System.nanoTime() - start; +// +// System.out.println("counter=" + counter.get()); +// +// System.out.println("Finished in " + 1e-9*duration + "s."); +// +// } +// +// public void test2() throws Exception { +// +// class CounterThread extends Thread { +// +// final private int index; +// final private Semaphore start; +// final private AtomicIntegerArray counter; +// final private CountDownLatch latch; +// +// public CounterThread(int index, Semaphore start, CountDownLatch latch, AtomicIntegerArray counter) { +// this.index = index; +// this.start = start; +// this.counter = counter; +// this.latch = latch; +// } +// +// @Override +// public void run() { +// +// try { +// start.acquire(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// for(int i=0;i<50000000;i++) { +// counter.incrementAndGet(index); +// } +// +// latch.countDown(); +// +// } +// +// } +// +// CountDownLatch latch = new CountDownLatch(4); +// AtomicIntegerArray counter = new AtomicIntegerArray(4); +// Semaphore starter = new Semaphore(0); +// +// for(int i=0;i<4;i++) new CounterThread(i, starter, latch, counter).start(); +// +// Thread.sleep(500); +// +// starter.release(4); +// long start = System.nanoTime(); +// latch.await(); +// long duration = System.nanoTime() - start; +// +// //System.out.println("counter=" + counter.get()); +// +// System.out.println("[counter=" + counter + "]: Finished in " + 1e-9*duration + "s."); +// +// } +// +// public void test3() throws Exception { +// +// class CounterThread extends Thread { +// +// final private int index; +// final private Semaphore start; +// final private AtomicInteger counter; +// final private CountDownLatch latch; +// +// public CounterThread(int index, Semaphore start, CountDownLatch latch, AtomicInteger counter) { +// this.index = index; +// this.start = start; +// this.counter = counter; +// this.latch = latch; +// } +// +// @Override +// public void run() { +// +// try { +// start.acquire(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// for(int i=0;i<50000000;i++) { +// counter.incrementAndGet(); +// } +// +// latch.countDown(); +// +// } +// +// } +// +// CountDownLatch latch = new CountDownLatch(4); +// AtomicInteger counter = new AtomicInteger(0); +// Semaphore starter = new Semaphore(0); +// +// for(int i=0;i<4;i++) new CounterThread(i, starter, latch, counter).start(); +// +// Thread.sleep(500); +// +// starter.release(4); +// long start = System.nanoTime(); +// latch.await(); +// long duration = System.nanoTime() - start; +// +// //System.out.println("counter=" + counter.get()); +// +// System.out.println("[counter=" + counter + "]: Finished in " + 1e-9*duration + "s."); +// +// } + + public void test4() throws Exception { + + int size = 50000000; + + for(int i=0;i<2;i++) { + runTest3(1, size, 4); + runTest3(2, size, 4); + runTest3(4, size, 4); + runTest3(8, size, 4); + runTest3(16, size, 4); + runTest3(32, size, 4); + runTest3(64, size, 4); + runTest3(128, size, 4); + runTest3(256, size, 4); + runTest3(512, size, 4); + } + + } + + private void runTest3(final int STRIPE, final int size, final int threads) throws Exception { + + final int[] work = new int[STRIPE*threads]; + + class CounterThread extends Thread { + + final private int index; + final private Semaphore start; + final private CountDownLatch latch; + + public CounterThread(int index, Semaphore start, CountDownLatch latch) { + this.index = index; + this.start = start; + this.latch = latch; + } + + @Override + public void run() { + + try { + start.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + int offset = STRIPE*index; + + for(int i=0;i local = new ThreadLocal(); + + class CounterThread extends Thread { + + final private Semaphore start; + final private AtomicInteger counter; + final private CountDownLatch latch; + + public CounterThread(Semaphore start, CountDownLatch latch, AtomicInteger counter) { + this.start = start; + this.counter = counter; + this.latch = latch; + } + + @Override + public void run() { + + local.set(new AtomicInteger()); + + try { + start.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + int work = 0; + for(int i=0;i<1000000;i++) { + for(int j=0;j<100;j++) local.get().incrementAndGet(); + } + + latch.countDown(); + + System.out.println("work=" + work); + + } + + } + + CountDownLatch latch = new CountDownLatch(8); + AtomicInteger counter = new AtomicInteger(0); + Semaphore starter = new Semaphore(0); + + for(int i=0;i<8;i++) new CounterThread(starter, latch, counter).start(); + + Thread.sleep(500); + + starter.release(8); + long start = System.nanoTime(); + latch.await(); + long duration = System.nanoTime() - start; + + System.out.println("counter=" + counter.get()); + + System.out.println("Finished in " + 1e-9*duration + "s."); + + } + + public void test2() throws Exception { + + class CounterThread extends Thread { + + final private Semaphore start; + final private AtomicInteger counter; + final private CountDownLatch latch; + + public CounterThread(Semaphore start, CountDownLatch latch, AtomicInteger counter) { + this.start = start; + this.counter = counter; + this.latch = latch; + } + + @Override + public void run() { + + AtomicInteger ai = new AtomicInteger(); + + try { + start.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + int work = 0; + for(int i=0;i<1000000;i++) { + for(int j=0;j<100;j++) ai.incrementAndGet(); + } + + latch.countDown(); + + System.out.println("work=" + work); + + } + + } + + CountDownLatch latch = new CountDownLatch(8); + AtomicInteger counter = new AtomicInteger(0); + Semaphore starter = new Semaphore(0); + + for(int i=0;i<8;i++) new CounterThread(starter, latch, counter).start(); + + Thread.sleep(500); + + starter.release(8); + long start = System.nanoTime(); + latch.await(); + long duration = System.nanoTime() - start; + + System.out.println("counter=" + counter.get()); + + System.out.println("Finished in " + 1e-9*duration + "s."); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/BtreeTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/BtreeTest.java new file mode 100644 index 000000000..f29bc3aa6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/BtreeTest.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.datatypes.utils.BTreeUtils; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + + +public class BtreeTest extends ExistingDatabaseTest { + + public static final int NODE_SIZE = 10; + public static final int TEN = 10; + public static final int THOUSAND = 1000; + public static final int MILLION = 1000000; + + public static final int KEY_SIZE = TEN * THOUSAND; + + public void test() throws Exception { + + Session session = getSession(); + + VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class); + + long start = System.nanoTime(); + + session.sync(new WriteResultRequest(vgss.getMemoryPersistent(UUID.randomUUID().toString())) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + BTreeUtils bu = BTreeUtils.create(graph, null, NODE_SIZE, false); + for(int i=0;i() { +// +// @Override +// public Resource perform(ReadGraph graph) throws DatabaseException { +// return BtreeUtils.search(graph, tree, 3); +// } +// +// }); +// +// duration = System.nanoTime()-start; +// System.err.println("SEEK SINGLE at " + 1e-9*duration + "s."); +// start = System.nanoTime(); +// +// session.sync(new ReadRequest() { +// +// @Override +// public void run(ReadGraph graph) throws DatabaseException { +// for(int i=0;i(vg) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + return BTreeUtils.create(graph, null, NODE_SIZE, false).getTree(); + + } + + }); + + System.err.println("tree=" + tree); + + for(int i=0;i> values = session.sync(new WriteOnlyResultRequest>>(vg) { + + @Override + public Collection> perform(WriteOnlyGraph graph) throws DatabaseException { + + Collection> values = new ArrayList>(); + for(int i=0;i + * + */ +public class CachedQueryTest extends TestCommonPerf { + + final static int QUERIES = 5000; + final static double TIME = 1.0; + + int counter = 0; + + public void testTransactions() throws Exception { + + Session session = getSession(); + + Read req = new Read() { + + @Override + public Boolean perform(ReadGraph graph) { + return true; + } + + }; + + Procedure proc = new Procedure() { + + @Override + public void execute(Boolean result) { + synchronized(this) { + counter++; + } + } + + public void exception(Throwable t) { + System.out.print("CachedQueryTest request failed: "); + t.printStackTrace(); + } + + }; + + session.syncRequest(req, proc); + + long start = System.nanoTime(); + + for(int i = 0; i < QUERIES ; i++) { + session.syncRequest(req, proc); + } + + if(counter != (QUERIES + 1)) throw new Error("Invalid amount of notifications (got " + counter + ", expexted " + (QUERIES + 1) + ")."); + + checkException(); + + long end = System.nanoTime(); + + double time = (double)(end-start) * (double)(1e-9); + + String t = "CachedQueryTest finished with time " + time + ". Limit was < " + TIME; + System.out.println(t); + if (time > TIME) + fail(t); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/HierarchicalNames.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/HierarchicalNames.java new file mode 100644 index 000000000..18d6ce537 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/HierarchicalNames.java @@ -0,0 +1,978 @@ +package org.simantics.db.tests.performance.read; + +import java.io.IOException; +import java.io.UTFDataFormatException; +import java.nio.charset.Charset; +import java.util.Set; +import java.util.Vector; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.impl.StringBindingDefault; +import org.simantics.databoard.serialization.SerializationException; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.databoard.serialization.impl.ModifiedUTF8StringSerializer; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.RelationInfo; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.AssumptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; +import org.simantics.db.request.Read; +import org.simantics.db.service.ClusterBuilder; +import org.simantics.db.service.ClusterBuilder.ResourceHandle; +import org.simantics.db.service.ClusterBuilder.StatementHandle; +import org.simantics.db.service.DirectQuerySupport; +import org.simantics.db.service.QueryControl; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.tests.performance.read.HierarchicalNames.FastStringSerializer.FastStringSerializer2; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Pair; + +/* + * The model contains: + * -2M resources + * -1M string literals + * -6M statements + */ +public class HierarchicalNames { + + public static class FastStringSerializer extends ModifiedUTF8StringSerializer { + + public static final Charset UTF8 = Charset.forName("utf-8"); + + public static FastStringSerializer INSTANCE = new FastStringSerializer(); + + public FastStringSerializer() { + super(FastStringBinding.INSTANCE); + } + + static byte[] writeUTF(String str) throws IOException { + + int strlen = str.length(); + int utflen = 0; + int c, count = 0; + + /* use charAt instead of copying String to char array */ + for (int i = 0; i < strlen; i++) { + c = str.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + utflen++; + } else if (c > 0x07FF) { + utflen += 3; + } else { + utflen += 2; + } + } + + if (utflen > 65535) + throw new UTFDataFormatException( + "encoded string too long: " + utflen + " bytes"); + + byte[] bytearr = new byte[utflen+2]; + + bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF); + bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF); + + int i=0; + for (i=0; i= 0x0001) && (c <= 0x007F))) break; + bytearr[count++] = (byte) c; + } + + for (;i < strlen; i++){ + c = str.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + bytearr[count++] = (byte) c; + + } else if (c > 0x07FF) { + bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); + bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); + bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); + } else { + bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); + bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); + } + } + return bytearr; + + } + + public static class FastStringSerializer2 extends ModifiedUTF8StringSerializer { + + public static final Charset UTF8 = Charset.forName("utf-8"); + + public static FastStringSerializer2 INSTANCE = new FastStringSerializer2(); + + public FastStringSerializer2() { + super(FastStringBinding.INSTANCE); + } + + static byte[] writeUTF(String str) throws IOException { + + int strlen = str.length(); + int utflen = 0; + int c = 0; + + /* use charAt instead of copying String to char array */ + for (int i = 0; i < strlen; i++) { + c = str.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + utflen++; + } else if (c > 0x07FF) { + utflen += 3; + } else { + utflen += 2; + } + } + + if (utflen > 65535) + throw new UTFDataFormatException( + "encoded string too long: " + utflen + " bytes"); + + int byteIndex = 0; + byte[] bytearr; + + if(utflen < 0x80) { + bytearr = new byte[utflen+1]; + bytearr[byteIndex++] = ((byte)utflen); + } + else { + utflen -= 0x80; + if(utflen < 0x4000) { + bytearr = new byte[utflen+2]; + bytearr[byteIndex++] = (byte)( ((utflen&0x3f) | 0x80) ); + bytearr[byteIndex++] = (byte)( (utflen>>>6) ); + } + else { + utflen -= 0x4000; + if(utflen < 0x200000) { + bytearr = new byte[utflen+3]; + bytearr[byteIndex++] = (byte)( ((utflen&0x1f) | 0xc0) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>5)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>13)&0xff) ); + } + else { + utflen -= 0x200000; + if(utflen < 0x10000000) { + bytearr = new byte[utflen+4]; + bytearr[byteIndex++] = (byte)( ((utflen&0x0f) | 0xe0) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>4)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>12)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>20)&0xff) ); + } + else { + utflen -= 0x10000000; + bytearr = new byte[utflen+5]; + bytearr[byteIndex++] = (byte)( ((utflen&0x07) | 0xf0) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>3)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>11)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>19)&0xff) ); + bytearr[byteIndex++] = (byte)( ((utflen>>>27)&0xff) ); + } + } + } + } + + + int i=0; + for (i=0; i= 0x0001) && (c <= 0x007F))) break; + bytearr[byteIndex++] = (byte)(c); + } + + for (;i < strlen; i++){ + c = str.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + bytearr[byteIndex++] = (byte)( c ); + } else if (c > 0x07FF) { + bytearr[byteIndex++] = (byte)(0xE0 | ((c >> 12) & 0x0F)); + bytearr[byteIndex++] = (byte)(0x80 | ((c >> 6) & 0x3F)); + bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F)); + } else { + bytearr[byteIndex++] = (byte)(0xC0 | ((c >> 6) & 0x1F)); + bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F)); + } + } + + return bytearr; + + } + + @Override + public byte[] serialize(Object obj) throws IOException { + try { + return writeUTF((String)obj); + } catch (IOException e) { + throw new SerializationException(); + } + + } + + } + + + @Override + public byte[] serialize(Object obj) throws IOException { + try { + return writeUTF((String)obj); + } catch (IOException e) { + throw new SerializationException(); + } + + } + +// private static byte bytearr[] = new byte[80]; +// private static char chararr[] = new char[80]; + + public final static String readUTF(byte[] bytearr) throws IOException { + + return "name"; + +// int utflen = (bytearr[0] << 8) + bytearr[1]; +// +// char[] chararr = new char[utflen*2]; +// +// int c, char2, char3; +// int count = 2; +// int chararr_count=0; +// +//// in.readFully(bytearr, 0, utflen); +// +// while (count < utflen + 2) { +// c = (int) bytearr[count] & 0xff; +// if (c > 127) break; +// count++; +// chararr[chararr_count++]=(char)c; +// } +// +// while (count < utflen) { +// c = (int) bytearr[count] & 0xff; +// switch (c >> 4) { +// case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: +// /* 0xxxxxxx*/ +// count++; +// chararr[chararr_count++]=(char)c; +// break; +// case 12: case 13: +// /* 110x xxxx 10xx xxxx*/ +// count += 2; +// if (count > utflen) +// throw new UTFDataFormatException( +// "malformed input: partial character at end"); +// char2 = (int) bytearr[count-1]; +// if ((char2 & 0xC0) != 0x80) +// throw new UTFDataFormatException( +// "malformed input around byte " + count); +// chararr[chararr_count++]=(char)(((c & 0x1F) << 6) | +// (char2 & 0x3F)); +// break; +// case 14: +// /* 1110 xxxx 10xx xxxx 10xx xxxx */ +// count += 3; +// if (count > utflen) +// throw new UTFDataFormatException( +// "malformed input: partial character at end"); +// char2 = (int) bytearr[count-2]; +// char3 = (int) bytearr[count-1]; +// if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) +// throw new UTFDataFormatException( +// "malformed input around byte " + (count-1)); +// chararr[chararr_count++]=(char)(((c & 0x0F) << 12) | +// ((char2 & 0x3F) << 6) | +// ((char3 & 0x3F) << 0)); +// break; +// default: +// /* 10xx xxxx, 1111 xxxx */ +// throw new UTFDataFormatException( +// "malformed input around byte " + count); +// } +// } +// if(chararr_count == 2*utflen) { +// // The number of chars produced may be less than utflen +// return new String(chararr); +// } else { +// // The number of chars produced may be less than utflen +// return new String(chararr, 0, chararr_count); +// } + + } + + @Override + public Object deserialize(byte[] data) throws IOException { + return readUTF(data); + //return new String(data, UTF8); + } + + } + + public static class FastStringBinding extends StringBindingDefault { + + public static FastStringBinding INSTANCE = new FastStringBinding(); + + public FastStringBinding() { + super(Datatypes.STRING); + } + + @Override + public Serializer serializer() { + return FastStringSerializer.INSTANCE; + } + + } + + public static WriteOnlyResultRequest writeOnly(final String name, final int[] sizes) throws DatabaseException { + return writeOnly(name, sizes, null); + } + + public static WriteOnlyResultRequest writeOnly(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException { + + return new WriteOnlyResultRequest(graph) { + + @Override + public Resource perform(WriteOnlyGraph graph) throws DatabaseException { + + //Binding binding = Bindings.STRING; +// Serializer serializer = Bindings.STRING.serializer(); + Serializer serializer = FastStringSerializer2.INSTANCE; + Session session = graph.getService(Session.class); + Layer0 b = Layer0.getInstance(session); + + graph.flushCluster(); + + ClusterBuilder builder = graph.getService(ClusterBuilder.class); + SerialisationSupport ss = graph.getService(SerialisationSupport.class); + + ResourceHandle hasNameR = builder.resource(b.HasName); + ResourceHandle nameOfR = builder.resource(b.NameOf); + ResourceHandle consistsOfR = builder.resource(b.ConsistsOf); + ResourceHandle partOfR = builder.resource(b.PartOf); + ResourceHandle instanceOfR = builder.resource(b.InstanceOf); + ResourceHandle libraryR = builder.resource(b.Library); + ResourceHandle ontologyR = builder.resource(b.Ontology); + ResourceHandle stringR = builder.resource(b.String); + + StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR); + StatementHandle instanceOf2 = builder.newStatement(instanceOfR, ontologyR); + StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR); + + ResourceHandle root = builder.newResource(); + root.addStatement(instanceOf); + + ResourceHandle rootLiteral = builder.newResource(); + rootLiteral.addStatement(instanceOfString); + rootLiteral.addStatement(nameOfR, root); + rootLiteral.addValue(name, serializer); + root.addStatement(hasNameR, rootLiteral); + +// System.out.println("root: " + root.resource()); +// System.out.println("literal: " + rootLiteral.resource()); + + // graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding); + // graph.claim(root, b.InstanceOf, null, b.Library); + + StatementHandle rootPart = builder.newStatement(partOfR, root); + + for(int i=0;i writeOnly2(final String name, final int[] sizes) throws DatabaseException { + return writeOnly2(name, sizes, null); + } + + public static WriteOnlyResultRequest writeOnly2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException { + + return new WriteOnlyResultRequest(graph) { + + @Override + public Resource perform(WriteOnlyGraph graph) throws DatabaseException { + + Binding binding = Bindings.STRING; + + Session session = graph.getService(Session.class); + Layer0 b = Layer0.getInstance(session); + + Resource root = graph.newResource(); + graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding); + graph.claim(root, b.InstanceOf, null, b.Library); + + for(int i=0;i write(final String name, final int[] sizes) throws DatabaseException { + return write(name, sizes, null); + } + + public static WriteResultRequest write(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException { + + return new WriteResultRequest(graph) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Binding binding = Bindings.STRING; + + Session session = graph.getService(Session.class); + Layer0 b = Layer0.getInstance(session); + + Resource root = graph.newResource(); + graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding); + graph.claim(root, b.InstanceOf, null, b.Library); + + for(int i=0;i write2(final String name, final int[] sizes) throws DatabaseException { + return write(name, sizes, null); + } + + public static WriteResultRequest write2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException { + + return new WriteResultRequest(graph) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Binding binding = Bindings.STRING; + + Session session = graph.getService(Session.class); + Layer0 b = Layer0.getInstance(session); + + Resource root = graph.newResource(); + graph.claimLiteral(root, b.HasName, name, binding); + graph.claim(root, b.InstanceOf, null, b.Library); + + for(int i=0;i readSync(final Resource resource) throws DatabaseException { + + return new ReadRequest() { + + private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException { +// System.err.println("child=" + resource); + Layer0 L0 = Layer0.getInstance(graph); + String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING); +// System.err.println("name=" + name); + for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) { + readChildren(graph, child); + } + } + + @Override + public void run(ReadGraph graph) throws DatabaseException { + readChildren(graph, resource); + } + + }; + + } + + public static Read readSync2(final Resource resource) throws DatabaseException { + + return new ReadRequest() { + + private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) { + graph.getPossibleRelatedValue(child, L0.HasName); + readChildren(graph, child); + } + } + + @Override + public void run(ReadGraph graph) throws DatabaseException { + readChildren(graph, resource); + } + + }; + + } + + + final private static boolean VALIDATE = false; + + public static Vector validation = new Vector(); + public static Vector criteria = new Vector(); + + public static void validate() throws AssumptionException { + if(VALIDATE) if(!validation.equals(criteria)) { + for(String s : validation) System.err.println("-'" + s + "'"); + throw new AssumptionException(""); + } + } + + public static Read readAsync(final Resource resource) { + + if(VALIDATE) { + for(int i=0;i<244*64*64;i++) criteria.add("name"); + validation.clear(); + } + + class Process { + + final AsyncMultiProcedure structure; + final AsyncProcedure names; + + Process(ReadGraph graph, Resource resource) { + + final Layer0 L0 = Layer0.getInstance(graph); + final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); + final QueryControl control = graph.getService(QueryControl.class); + + names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, String name) { + if(VALIDATE) validation.add(name); +// System.err.println("af=" + name); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + }); + + structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncMultiProcedure() { + + @Override + public void execute(AsyncReadGraph graph, Resource child) { + if(control.scheduleByCluster(graph, child, this)) { + dqs.forEachObjectCompiled(graph, child, structure); + dqs.forPossibleRelatedValueCompiled(graph, child, names); + } + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + }); + + dqs.forEachObjectCompiled(graph, resource, structure); + dqs.forPossibleRelatedValueCompiled(graph, resource, names); + + } + + } + + return new ReadRequest() { + + @Override + public void run(ReadGraph graph) { + + new Process(graph, resource); + + } + + }; + + } + + public static void readAsyncLoop2(AsyncReadGraph graph, Layer0 L0, Resource resource, AsyncMultiProcedure procedure, AsyncProcedure procedure2) { + graph.forEachObject(resource, L0.ConsistsOf, procedure); + graph.forPossibleRelatedValue(resource, L0.HasName, FastStringBinding.INSTANCE, procedure2); + } + + public static ReadRequest readAsync2(final Resource resource) { + + return new ReadRequest() { + + @Override + public void run(ReadGraph graph) { + + final Layer0 L0 = Layer0.getInstance(graph); + + try { + + final AsyncProcedure names = new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, String name) { + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + }; + + readAsyncLoop2(graph, L0, resource, new AsyncMultiProcedure() { + + @Override + public void execute(AsyncReadGraph graph, Resource child) { + readAsyncLoop2(graph, L0, child, this, names); + } + + @Override + public void finished(AsyncReadGraph graph) { + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + }, names); + + } catch (Exception e) { + + e.printStackTrace(); + + } + + } + + }; + + } + + static int names = 0; + + public static void readAsyncTypesLoop(final DirectQuerySupport dqs, final Layer0 L0, AsyncReadGraph graph, final Resource resource, final RelationInfo consistsOf, final AsyncMultiProcedure procedure, final RelationInfo name, final Serializer serializer, final AsyncProcedure procedure2) { + + dqs.forPossibleType(graph, resource, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, Resource type) { + +// System.err.println("affa"); + + graph.asyncRequest(new TypeSetAndString(type), new AsyncProcedure, String>>() { + + @Override + public void execute(AsyncReadGraph graph, Pair, String> typeInfo) { + + Set types = typeInfo.first; + if(types.contains(L0.Ontology)) { + +// dqs.forPossibleRelatedValue(graph, resource, name, serializer, new AsyncProcedure() { +// +// @Override +// public void execute(AsyncReadGraph graph, String result) { +//// if(names++ % 1000 == 0) System.err.println("names=" + names + "(" + result + ")"); +// } +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// } +// +// }); + + } else if (types.contains(L0.Library)) { + //dqs.forEachObject(graph, resource, consistsOf, procedure); + } + + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + } + + }); + + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + } + + }); + + + } + + public static Read readAsyncTypes(final Resource resource) { + + return new ReadRequest() { + + @Override + public void run(ReadGraph graph) { + + final Layer0 L0 = Layer0.getInstance(graph); + + try { + +// graph.syncRequest(new TypeSetAndString(L0.Library), new TransientCacheListener, String>>()); +// graph.syncRequest(new TypeSetAndString(L0.Ontology), new TransientCacheListener, String>>()); + + final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); + final RelationInfo consistsOf = graph.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + dqs.forRelationInfo(graph, L0.ConsistsOf, procedure); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + final RelationInfo name = graph.syncRequest(new AsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + dqs.forRelationInfo(graph, L0.HasName, procedure); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public int getFlags() { + return 0; + } + + }); + + final Serializer serializer = FastStringSerializer.INSTANCE;//Bindings.getSerializerUnchecked( Bindings.STRING ); + + final AsyncProcedure names = new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, String name) { +// System.out.println("exec: " + name); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + }; + +// readAsyncLoop(dqs, graph, resource, new AsyncMultiProcedure() { +// +// @Override +// public void execute(AsyncReadGraph graph, Resource child) { +// readAsyncTypesLoop(dqs, L0, graph, child, consistsOf, this, name, serializer, names); +// } +// +// @Override +// public void finished(AsyncReadGraph graph) { +// } +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// throwable.printStackTrace(); +// } +// +// }, name, serializer, names); + + } catch (Exception e) { + + e.printStackTrace(); + + } + + } + + }; + + } + + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/LogTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/LogTest.java new file mode 100644 index 000000000..edbe9ef3d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/LogTest.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.datatypes.utils.LogUtils; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + + +public class LogTest extends ExistingDatabaseTest { + + public static final int NODE_SIZE = 2; + public static final int TEN = 10; + public static final int THOUSAND = 1000; + public static final int MILLION = 1000000; + + public static final int KEY_SIZE = TEN * 1000; + + public void test() throws Exception { + + Session session = getSession(); + + VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class); + + long start = System.nanoTime(); + + session.sync(new WriteResultRequest(vgss.getMemoryPersistent(UUID.randomUUID().toString())) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + LogUtils lu = new LogUtils(graph); + Resource log = lu.create(graph, NODE_SIZE, 0); + for(int i=0;i(vg) { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + LogUtils lu = new LogUtils(graph); + return lu.create(graph, NODE_SIZE, 0); + + } + + }); + + for(int i=0;i> values = session.sync(new WriteOnlyResultRequest>>(vg) { + + @Override + public Collection> perform(WriteOnlyGraph graph) throws DatabaseException { + + Collection> values = new ArrayList>(); + for(int i=0;i request) throws DatabaseException { + + long start = System.nanoTime(); + Resource result = getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + return result; + + } + + private void time(String label, Read request) throws DatabaseException { + + long start = System.nanoTime(); + getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + + HierarchicalNames.validate(); + + } + + private void listenTime(String label, Read request) throws DatabaseException { + + long start = System.nanoTime(); + getSession().syncRequest(request, new ListenerAdapter()); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + + } + + private void clearCaches() throws DatabaseException { + + Session session = Tests.getTestHandler().getSession(); + QueryControl cc = session.getService(QueryControl.class); + ClusterControl ccr = session.getService(ClusterControl.class); + cc.flush(); + ccr.collectClusters(ccr.used()); + System.gc(); + System.gc(); + System.gc(); + + } + @Test + public void test() throws Exception { + + Layer0.getInstance(getSession()); + + getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); +// getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease()); + +// System.out.println("wait"); +// Thread.sleep(7000); +// System.out.println("wait done"); + + // First build the test data + Resource root = time("write", HierarchicalNames.writeOnly(name, sizes)); + +// System.out.println("wait"); +// Thread.sleep(3000); +// System.out.println("wait done"); + + // Read everything after write + time("response", HierarchicalNames.readAsync(root)); + +// System.out.println("wait"); +// Thread.sleep(3000); +// System.out.println("wait done"); + + // Clusters are now loaded + time("async", HierarchicalNames.readAsync(root)); + time("async2", HierarchicalNames.readAsync2(root)); +// time("sync", HierarchicalNames.readSync(root)); +// listenTime("listenSync", HierarchicalNames.readSync(root)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesAndTypes.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesAndTypes.java new file mode 100644 index 000000000..6291cba4b --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesAndTypes.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.TransactionPolicyKeep; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.request.WriteOnlyResult; +import org.simantics.db.service.QueryControl; +import org.simantics.db.service.TransactionPolicySupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/* + * + * Some statistics: + * + * == With WriteOnlyGraph === + * + * -Creation of 50M write only resources (50M res, 0 stm) + * -Stream off = 1.88s + * -UpdateTransaction off = 5.11s + * -Creation of 50M write only resources with single instanceof (50M res, 50M stm) + * -Stream off = 5.36s + * -UpdateTransaction off = 16.05s + * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm) + * -Stream off = 12.20s + * -UpdateTransaction off = 39.3s + * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm) + * -Stream off = 31.66s + * -Creation of 50M write only resources full (100M res, 300M stm) + * -Stream off = 43.39s + * + * == With ClusterBuilder == + * + * -Creation of 50M write only resources (50M res, 0 stm) + * -Stream off = 1.62s + * -UpdateTransaction off = 5.07 + * -Creation of 50M write only resources with single instanceof (50M res, 50M stm) + * -Stream off = 3.33s + * -UpdateTransaction off = 14.26s + * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm) + * -Stream off = 6.09s + * -UpdateTransaction off = 32.42s + * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm) + * -Stream off = 23.97s + * -Creation of 50M write only resources full (100M res, 300M stm, 50M literals) + * -Stream off = 27.85s + * + */ +public class ReadHierarchicalNamesAndTypes extends ExistingDatabaseTest { + + final private static String name = "name"; + int[] sizes = { 244, 64, 64 }; + + private Resource time(String label, WriteOnlyResult request) throws DatabaseException { + + long start = System.nanoTime(); + Resource result = getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + return result; + + } + + private void time(String label, Read request) throws DatabaseException { + + long start = System.nanoTime(); + getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + + } + +// private void clearCaches() throws DatabaseException { +// +// Session session = Tests.getTestHandler().getSession(); +// QueryControl cc = session.getService(QueryControl.class); +// ClusterControl ccr = session.getService(ClusterControl.class); +// cc.flush(); +// ccr.collectClusters(ccr.used()); +// System.gc(); +// System.gc(); +// System.gc(); +// +// } + + public void test() throws Exception { + + Layer0.getInstance(getSession()); + + getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); +// getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease()); + + // First build the test data + Resource root = time("write", HierarchicalNames.writeOnly(name, sizes)); + + // Read everything after write + time("response", HierarchicalNames.readAsyncTypes(root)); + + Session session = getSession(); + QueryControl cc = session.getService(QueryControl.class); + cc.flush(); + + System.out.println("wait"); + Thread.sleep(3000); + System.out.println("wait done"); + + // Clusters are now loaded + time("async", HierarchicalNames.readAsyncTypes(root)); +// System.err.println("done"); +// time("async2", HierarchicalNames.readAsync2(root)); +// time("sync", HierarchicalNames.readSync(root)); +// time("sync2", HierarchicalNames.readSync2(root)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesFromVirtualGraph.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesFromVirtualGraph.java new file mode 100644 index 000000000..141dde05a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesFromVirtualGraph.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class ReadHierarchicalNamesFromVirtualGraph extends ExistingDatabaseTest { + + final private static String name = "name"; + int[] sizes = { 244, 64, 64 }; + + public void test() throws Exception { + + Session session = getSession(); + + VirtualGraph graph = session.getService(VirtualGraphSupport.class).getMemoryPersistent(UUID.randomUUID().toString()); + + // First build the test data + long start = System.nanoTime(); + Resource root = session.syncRequest(HierarchicalNames.writeOnly2(name, sizes, graph)); + long duration = System.nanoTime() - start; + System.out.println("write = " + 1e-9*duration); + + start = System.nanoTime(); + session.syncRequest(HierarchicalNames.readAsync(root)); + duration = System.nanoTime() - start; + System.out.println("cold start = " + 1e-9*duration); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TransactionTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TransactionTest.java new file mode 100644 index 000000000..5b84f34f4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TransactionTest.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import java.util.concurrent.CountDownLatch; + +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.TransactionPolicyKeep; +import org.simantics.db.common.TransactionPolicyRelease; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.TransactionPolicySupport; +import org.simantics.db.testing.base.TestCommonPerf; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.testing.common.WriteQuery; + +/** + * Tests for Transaction + * + * @author Marko Luukkainen + * + */ +public class TransactionTest extends TestCommonPerf { + + final int REPEAT_COUNT = 2;//0; + final int REQUEST_COUNT = 50; //0; // 1000; + final int SPEED_LIMIT = 3000; + volatile int counter = 0; + + public void testSyncWriteTransactions() throws DatabaseException { + Session session = Tests.getTestHandler().getSession(); + System.out.println("Transaction policy is release."); + session.registerService(TransactionPolicySupport.class, new TransactionPolicyRelease()); + loopSyncWriteTransactions(session); + session.registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); + System.out.println("Transaction policy is keep."); + loopSyncWriteTransactions(session); + } + public void loopSyncWriteTransactions(Session session) { + double totalTime = 0; + counter = 0; + for (int j = 0; j < REPEAT_COUNT; ++j) { + long start = System.nanoTime(); + for(int i = 0; i < REQUEST_COUNT; ++i) { + try { + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph graph) { + ++counter; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + long end = System.nanoTime(); + double time = (double)(end-start) * (double)(1e-9); + totalTime += time; +// int percent = (int)((j+1) / (double)REPEAT_COUNT * 100); +// System.out.println(percent + " precent done."); + } + if (REPEAT_COUNT * REQUEST_COUNT != counter) + fail("Transaction count does not match. Transaction count was " + counter); + double speed = counter / totalTime; + String t = "Transaction speed was " + speed + " empty synchronous write transactions per second." + + " Limit was > " + SPEED_LIMIT + "."; + System.out.println(t); +// if (speed < SPEED_LIMIT) +// fail(t); + } + + public void testEmptyAsyncWriteTransactions() throws Exception { + final CountDownLatch latch = new CountDownLatch(REPEAT_COUNT * REQUEST_COUNT); + Session session = getSession(); + long start = System.nanoTime(); + for (int i = 0; i < REPEAT_COUNT * REQUEST_COUNT; i++) { + session.asyncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph graph) { + latch.countDown(); + } + }); + } + latch.await(); + long end = System.nanoTime(); + checkException(); +// int oldCounter = 0; +// while (counter != REPEAT_COUNT * REQUEST_COUNT) { +// checkException(); +// oldCounter = counter; +//// Thread.sleep(1000); +// int percent = (int)(counter / (double)(REPEAT_COUNT * REQUEST_COUNT) * 100); +// System.out.println(percent + " precent done."); +// if (oldCounter == counter) +// fail("Too long time betwween two asynchronous transactions."); +// } +// checkException(); + double totalTime = (double)(end-start) * (double)(1e-9); + double speed = REPEAT_COUNT / totalTime * REQUEST_COUNT; + String t = "Transaction speed was " + speed + " empty asynchronous write transactions per second." + + " Limit was > " + SPEED_LIMIT + "."; + System.out.println(t); + if (speed < SPEED_LIMIT) + fail(t); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TypeSetAndString.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TypeSetAndString.java new file mode 100644 index 000000000..b40795eff --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TypeSetAndString.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import java.util.Set; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.CollectionSupport; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Pair; + +public class TypeSetAndString extends ResourceRead, String>> { + + public TypeSetAndString(Resource type) { + super(type); + } + + @Override + public Pair, String> perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + CollectionSupport cs = graph.getService(CollectionSupport.class); + Set types = cs.createSet(); + + types.add(resource); + types.addAll(graph.getSupertypes(resource)); + + final StringBuilder b = new StringBuilder(); + boolean first = true; + for (Resource type : types) { + String name = graph.getPossibleRelatedValue(type, L0.HasName, Bindings.STRING); + if (!first) b.append(" "); + first = false; + } + + return Pair.make(types, b.toString()); + + } + +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteOnlyHierarchicalNames.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteOnlyHierarchicalNames.java new file mode 100644 index 000000000..7a97c0058 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteOnlyHierarchicalNames.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import org.simantics.db.testing.base.ExistingDatabaseTest; + +public class WriteOnlyHierarchicalNames extends ExistingDatabaseTest { + + final private static String name = "name"; + int[] sizes = { 100, 1000, 100 }; + + public void test() throws Exception { + + getSession().syncRequest(HierarchicalNames.writeOnly(name, sizes)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteReadBigLiteral.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteReadBigLiteral.java new file mode 100644 index 000000000..f40a216d1 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/WriteReadBigLiteral.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.performance.read; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.TransactionPolicyKeep; +import org.simantics.db.common.WriteBindings; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.db.request.WriteOnlyResult; +import org.simantics.db.service.TransactionPolicySupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class WriteReadBigLiteral extends ExistingDatabaseTest { + + private static final int _100MB = 100000000; + private static final int _250MB = 250000000; + private static final int _500MB = 500000000; + private static final int _1000MB = 1000000000; + private static final int _2000MB = 2000000000; + + private Resource time(String label, WriteOnlyResult request) throws DatabaseException { + + long start = System.nanoTime(); + Resource result = getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + return result; + + } + + private void time(String label, Read request) throws DatabaseException { + + long start = System.nanoTime(); + getSession().syncRequest(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + + } + + public static WriteOnlyResult writeOnly(final int size, VirtualGraph graph) throws DatabaseException { + + final byte[] literal = new byte[size]; + + return new WriteOnlyResultRequest(graph) { + + @Override + public Resource perform(WriteOnlyGraph graph) throws DatabaseException { + Resource res = graph.newResource(); + graph.claimValue(res, literal, WriteBindings.BYTE_ARRAY); + return res; + } + + }; + + } + + public static Read read(final Resource resource) { + + return new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + byte[] value = graph.getValue(resource, WriteBindings.BYTE_ARRAY); + System.err.println("value: " + value.length); + + } + + }; + + } + + public void test() throws Exception { + + Layer0.getInstance(getSession()); + + getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); + + Resource root = time("write 100MB", writeOnly(_100MB, null)); + time("response 100MB", read(root)); + Resource root2 = time("write 250MB", writeOnly(_250MB, null)); + time("response 250MB", read(root2)); + Resource root3 = time("write 500MB", writeOnly(_500MB, null)); + time("response 500MB", read(root3)); + Resource root4 = time("write 1000MB", writeOnly(_1000MB, null)); + time("response 1000MB", read(root4)); + Resource root5 = time("write 2000MB", writeOnly(_2000MB, null)); + time("response 2000MB", read(root5)); + + +//// System.out.println("wait"); +//// Thread.sleep(3000); +//// System.out.println("wait done"); +// +// // Read everything after write +// time("response", HierarchicalNames.readAsync(root)); +// +//// System.out.println("wait"); +//// Thread.sleep(3000); +//// System.out.println("wait done"); +// +// // Clusters are now loaded +// time("async", HierarchicalNames.readAsync(root)); +//// time("async2", HierarchicalNames.readAsync2(root)); +//// time("sync", HierarchicalNames.readSync(root)); +//// listenTime("listenSync", HierarchicalNames.readSync(root)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/SuiteRegression.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/SuiteRegression.java new file mode 100644 index 000000000..3565e19c3 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/SuiteRegression.java @@ -0,0 +1,72 @@ +package org.simantics.db.tests.regression; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.testing.common.RegressionSuiteRunner; +import org.simantics.db.testing.common.Tests; +import org.simantics.db.tests.regression.bugs.CommentMetadataWriteTest; +import org.simantics.db.tests.regression.bugs.Issue2967Test1; +import org.simantics.db.tests.regression.bugs.Issue3072Test1; +import org.simantics.db.tests.regression.bugs.Issue3108Test1; +import org.simantics.db.tests.regression.bugs.Issue3176Test1; +import org.simantics.db.tests.regression.bugs.Issue3176Test2; +import org.simantics.db.tests.regression.bugs.Issue3176Test3; +import org.simantics.db.tests.regression.bugs.Issue3199Test1; +import org.simantics.db.tests.regression.bugs.Issue3199Test2; +import org.simantics.db.tests.regression.bugs.Issue3420Test1; +import org.simantics.db.tests.regression.bugs.Issue3420Test2; +import org.simantics.db.tests.regression.bugs.Issue4688Test1; +import org.simantics.db.tests.regression.bugs.Issue5432Test1; +import org.simantics.db.tests.regression.bugs.SimanticsBug1659Test1; +import org.simantics.db.tests.regression.bugs.SimanticsBug1659Test2; +import org.simantics.db.tests.regression.bugs.SimanticsBug1659Test3; +import org.simantics.db.tests.regression.bugs.SimanticsBug1893Test1; +import org.simantics.db.tests.regression.bugs.SimanticsBug3114Test; +import org.simantics.db.tests.regression.bugs.SimanticsBug639Test; +import org.simantics.db.tests.regression.bugs.SimanticsFeature4007Test1; +import org.simantics.db.tests.regression.bugs.SyncWriteReadTest1; +import org.simantics.db.tests.regression.bugs.TicketTest646; +import org.simantics.db.tests.regression.bugs.WriteCancelTest3; + +@RunWith(RegressionSuiteRunner.class) +@SuiteClasses({ + CommentMetadataWriteTest.class, + Issue2967Test1.class, + Issue3072Test1.class, + Issue3108Test1.class, + Issue3176Test1.class, + Issue3176Test2.class, + Issue3176Test3.class, + Issue3199Test1.class, + Issue3199Test2.class, + Issue3420Test1.class, + Issue3420Test2.class, + Issue3420Test2.class, + Issue4688Test1.class, + Issue5432Test1.class, + Issue5432Test1.class, + SimanticsBug1659Test1.class, + SimanticsBug1659Test2.class, + SimanticsBug1659Test3.class, + SimanticsBug1893Test1.class, + SimanticsBug3114Test.class, + SimanticsBug639Test.class, + SimanticsFeature4007Test1.class, + SyncWriteReadTest1.class, + TicketTest646.class, + WriteCancelTest3.class, +}) +public class SuiteRegression { + + @BeforeClass + public static void setUp() { + try { + Tests.freshDatabase(); + } catch (Exception e) { + Logger.defaultLogError(e); + } + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/ClusterTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/ClusterTest1.java new file mode 100644 index 000000000..ebf1bd326 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/ClusterTest1.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * Tests that cluster contains guid and modification information. + */ +public class ClusterTest1 extends ExistingDatabaseTest{ + @Test + public void test() throws DatabaseException { + Session session = getSession(); + session.getService(XSupport.class).testCluster(session); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/CommentMetadataWriteTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/CommentMetadataWriteTest.java new file mode 100644 index 000000000..a072fcedb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/CommentMetadataWriteTest.java @@ -0,0 +1,84 @@ +package org.simantics.db.tests.regression.bugs; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.UndoMetadata; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * I found a bug in the database client write requests that caused the following + * to happen: + * + *
    + *
  1. Perform a write request (NOP) which inserts a comment into the metadata + * but does no changes to the database
  2. + *
  3. Perform another request (W) that writes both comment metadata and + * database changes
  4. + *
  5. The database revision history will contain a single new revision with the + * both comments from the NOP and W
  6. + *
+ * + * The expected result is that the database only contains the comment metadata + * written in request W. + * + * @author Tuukka Lehtonen + */ +public class CommentMetadataWriteTest extends ExistingDatabaseTest { + // Behavior of commit has been changed. Commits with only CommentMetadata are dropped. + private void addMetadata(WriteGraph wg, String s) throws DatabaseException { + CommentMetadata cm = wg.getMetadata(CommentMetadata.class); + wg.addMetadata(cm.add(s)); + wg.addMetadata(new UndoMetadata(null, false, 0, 0)); + } + @Test + public void test() throws Exception { + // Perform empty request, write comment + WriteRequest nop = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + addMetadata(graph, "NOP"); + } + }; + getSession().sync(nop); + + // Perform non-empty request, write comment + WriteRequest w = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, L0.String); + graph.claimValue(r, "FOO"); + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("W")); + } + }; + getSession().sync(w); + assertTrue("Metadata from empty requests should not accumulate to following requests", getSession().sync(new UniqueRead() { + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + ManagementSupport ms = graph.getService(ManagementSupport.class); + long cid = ms.getHeadRevisionId(); + Collection comments = ms.getMetadata(cid, cid, CommentMetadata.class); + if (comments.size() != 1) + return false; + CommentMetadata cm = comments.iterator().next(); + String s = cm.toString(); + // The line feed is added by the add operation. + if (!s.matches("W\n")) + return false; + else + return true; + } + })); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java new file mode 100644 index 000000000..b0b96d0bb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import java.util.Collection; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.cases.FreshDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class Issue2967Test1 extends FreshDatabaseTest { + + private int N_RESOURCE = 10000; + private int N_STM = 100; + + @Test + @Fails + public void test() throws DatabaseException { + Session session = getSession(); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + final Resource newResource = graph.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource result = graph.newResource(); + graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING); + Resource root = graph.getRootLibrary(); + graph.claim(root, L0.ConsistsOf, result); + return result; + } + }); + String rootName = graph.getRelatedValue(newResource, L0.HasName); + assertTrue("Failed to set resource name.", rootName.equals("RootLibrary")); + VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class); + final String name = UUID.randomUUID().toString(); + final VirtualGraph virtual = support.getMemoryPersistent(name); + graph.syncRequest(new WriteRequest(virtual) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + for (int i=0; i ok = new DataContainer(); + ok.set(false); + Collection resources = graph.getObjects(newResource, L0.ConsistsOf); + if (resources.size() != N_RESOURCE) + fail("Virtual graph data has changed. Object size mismatch. size=" + resources.size()); + for (Resource r : resources) { + Collection ress = graph.getObjects(r, L0.HasComment); + assertEquals("Virtual graph has changed.", N_STM, ress.size()); + } + graph.syncRequest(new WriteRequest(virtual) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + for (int i=0; i cids = ms.getChangeSetIdentifiers(revision2, revision2); + assertTrue("Failed to get empty change set.", cids.size() == 1); + Map metadata = cids.iterator().next().getMetadata(); + assertTrue("Failed to get metadata.", metadata.size() > 0); + XSupport xs = (XSupport)graph.getService(XSupport.class); + xs.clearMetadataCache(); + Collection cids2 = ms.getChangeSetIdentifiers(revision2, revision2); + assertTrue("Failed to get empty change set.", cids2.size() == 1); + Map metadata2 = cids2.iterator().next().getMetadata(); + assertTrue("Fail ed to get metadata.", metadata2.size() > 0); + } + }); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3108Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3108Test1.java new file mode 100644 index 000000000..2e5dfe34e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3108Test1.java @@ -0,0 +1,103 @@ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyResultRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.AssumptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.InvalidResourceReferenceException; +import org.simantics.db.impl.query.QuerySupport; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.cases.FreshDatabaseTest; + +public class Issue3108Test1 extends FreshDatabaseTest { + private static final boolean DEBUG = false; + static class TestGetResourceId extends WriteRequest { + final int key; + public TestGetResourceId(int clusterIndex, int resourceIndex) { + this.key = (clusterIndex << 16) + resourceIndex; + } + @SuppressWarnings("deprecation") // Using createRandomAccessId to simulate error while loading non existing cluster. + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SerialisationSupport ss = graph.getService(SerialisationSupport.class); + QuerySupport gs = graph.getService(QuerySupport.class); + Resource r = gs.getResource(key); + try { +// This used to throw RuntimeDatabaseException when loading illegal cluster failed +// but now the implementation has changed and this does not try to load cluster. +// long id = r.getResourceId(); +// if (0 == id) +// throw new AssumptionException("Illegal resource returned zero as expected."); + if (DEBUG) + System.out.println("DEBBUG: resource key=" + key + " r="+ r); + ss.getResourceSerializer().createRandomAccessId(r); + } catch (InvalidResourceReferenceException e) { + if (DEBUG) + System.out.println("Catched InvalidResourceReferenceException:" + e.getMessage()); + throw new AssumptionException("Illegal resource threw runtime error.", e); + } + } + } + @Test + public void testIssue3108Test1() throws Exception { + final Session session = getSession(); + // This simulates the situation in Apros bug 4210. + // We have an illegal entry in cluster table and we want to handle it + // gracefully. + boolean exceptionThrown = false; + try { + XSupport xs = (XSupport)session.getService(XSupport.class); + long illegalClusterId1 = 666666; + int clusterIndex = xs.corruptClusterTable(illegalClusterId1); + session.syncRequest(new TestGetResourceId(clusterIndex, 666)); + } catch (Exception e) { + exceptionThrown = true; + if (DEBUG) + System.out.println("Catched Exception as excepected:" + e.getMessage()); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + assertTrue("Failed to throw exception as expected.", exceptionThrown); + // Here we have an illegal resource id without proxy in cluster table. + exceptionThrown = false; + try { + session.syncRequest(new TestGetResourceId(666, 666)); + } catch (AssumptionException e) { + exceptionThrown = true; + if (DEBUG) + System.out.println("Catched AssumptionException as excepected:" + e.getMessage()); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + assertTrue("Failed to throw exception as expected.", exceptionThrown); + // Here we have an illegal resource index with valid cluster proxy. + // Note that in this case the invalid resource index is not reported. + try { + session.syncRequest(new TestGetResourceId(1, 6666)); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + } + static class TestWriteOnly extends WriteOnlyResultRequest { + public long id = 0; + public int key = 0; + @Override + public Long perform(WriteOnlyGraph graph) throws DatabaseException { + graph.flushCluster(); + XSupport xs = (XSupport)graph.getService(XSupport.class); + xs.setClusterStreamOff(true); + Resource r = graph.newResource(); + id = r.getResourceId(); + SerialisationSupport ss = graph.getService(SerialisationSupport.class); + key = ss.getTransientId(id); + xs.setClusterStreamOff(false); + return id; + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java new file mode 100644 index 000000000..ecf0c7779 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ExternalValueSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ExternalValueException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.layer0.Layer0; + +public class Issue3176Test1 extends ExistingDatabaseTest { + static final boolean DEBUG = false; + @Test + public void testRaw() + throws DatabaseException { + try{ + int nBlocks = Configuration.get().i3176BlockCount; + int[] blockSize = { 1024, 0xFFFF, 1<<20 }; + final int LENGTH = blockSize.length; + for (int i=0; i() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Layer0 b = Layer0.getInstance(g); + Resource resource = g.newResource(); + g.claim(resource, b.InstanceOf, b.Entity); + return resource; + } + }); + } + protected void checkLiteralValue(final Resource resource) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(resource, l0.Literal); + // Note that graph.hasValue actually fetches the value from server. + // This is highly inefficient and thus do not use this kind of code! + if (!graph.hasValue(literal)) + throw new DatabaseException("Graph resource " + resource + " has no value."); + } + }); + } + protected void undoModi(final Resource resource, int n) + throws DatabaseException { + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + support.undo(session, n); + } + protected byte[] createBlock(int size, int inc) { + final byte block[] = new byte[size]; + for (int i = 0; i < block.length; ++i) + block[i] = (byte)(i+inc); + return block; + } + protected void removeLiteralValue(final Resource resource) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(resource, l0.Literal); + graph.denyValue(literal); + } + }); + } +} +class RawTest extends Issue3176Test { + private final ExternalValueSupport rds; + RawTest(final Session session, boolean DEBUG, int blockSize, int nBlocks) + throws DatabaseException { + super(session, DEBUG, blockSize, nBlocks); + this.rds = session.getService(ExternalValueSupport.class); + } + void createRaw(final Resource resource, final int inc, int aBlocks) + throws DatabaseException { + if (aBlocks < 0) + aBlocks = N_BLOCKS; + final int T_BLOCKS = aBlocks; + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(resource, b.Literal, new byte[0], Bindings.BYTE_ARRAY); + Resource literal = graph.getSingleObject(resource, b.Literal); + long count = 0; + for (int i=0, j=inc; i newBlocks); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(file, l0.Literal); + RandomAccessBinary rab = graph.getRandomAccessBinary(literal); + try { + rab.position(0); + final int T_BLOCKS = newBlocks < 0 ? N_BLOCKS : newBlocks; + byte[] block = createBlock(BLOCK_SIZE, inc); + for (int i=0; i newBlocks); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(resource, l0.Literal); + ArrayAccessor a = graph.getAccessor(literal); + for (int i=0; i clusterSets = new Vector(); + private final Vector resources = new Vector(); + @Test + public void test() throws DatabaseException { + Session session = getSession(); + init(); + session.syncRequest(new Init()); + session.syncRequest(new InitW()); + session.syncRequest(new Check()); + init(); + session.syncRequest(new InitWO()); + session.syncRequest(new Check()); + init(); + session.syncRequest(new InitWD()); + initDWKraaKraa(session); + session.syncRequest(new Check()); + session.syncRequest(new InitWD2()); + initDWKraaKraa(session); + session.syncRequest(new Check()); + } + private void init() { + resources.clear(); + clusterSets.clear(); + resources.setSize(1<<17); + clusterSets.setSize(14); + if (DEBUG) + System.out.println("Resource count=" + resources.size() + " cluster sets=" + clusterSets.size()); + } + class Init extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + try { + g.newClusterSet(l0.InstanceOf); + } catch (ClusterSetExistException e) { + // Cluster set exist already. No problem. + } + } + } + class InitW extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + Resource oldDefault = g.setClusterSet4NewResource(l0.InstanceOf); + assertTrue(null == oldDefault); + for (int i=0; i clusters = new HashMap(); + for (int i=0; i sortedKeys = new TreeSet(); + for (Map.Entry i : clusters.entrySet()) + sortedKeys.add(i.getKey()); + long sum = 0; + for (long key : sortedKeys) { + int count = clusters.get(key); + if (DEBUG) + System.out.println("cluster=" + key + " count=" + count); + sum += count; + } + if (resources.size() != sum) { + String msg = "Resource count mismatch. expected=" + resources.size() + " realized=" + sum; + if (DEBUG) + System.out.println(msg); + fail(msg); + } + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3420Test2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3420Test2.java new file mode 100644 index 000000000..350fbde2a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3420Test2.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.ClusterSetExistException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.ClusterTraitsBase; +import org.simantics.db.service.ClusteringSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Tests that cluster set can be used to explicitly control clustering. + * Must be called more than once from runner to test that cluster set is persistent. + */ +public class Issue3420Test2 extends ExistingDatabaseTest { +// final boolean DEBUG = true; + final boolean VERBOSE = false; + final int CLUSTER_FILL_SIZE = ClusterTraitsBase.getMaxNumberOfResources(); + final Vector clusterSets = new Vector(); + final Vector resources = new Vector(); + @Test + public void test() throws DatabaseException { + Session session = getSession(); + session.syncRequest(new InitClusterSet()); + session.syncRequest(new Init()); + session.syncRequest(new Modi()); + session.syncRequest(new Check()); + session.syncRequest(new ModiWO()); + session.syncRequest(new Check()); + } + class InitClusterSet extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + String base = "http://Projects/Development%20Project"; + String tail = "Issue3420Test2"; + Resource pl = g.getResource(base); + if (DEBUG) + System.out.println("projects=" + pl); + Resource il = g.getPossibleResource(base + "/" + tail); + try { + g.newClusterSet(pl); + // New cluster set. + assertTrue("Old cluster set data lost.", null == il); + il = g.newResource(); + g.claim(il, l0.InstanceOf, null, l0.Library); + g.claim(il, l0.PartOf, pl); + g.claimLiteral(il, l0.HasName, tail); + } catch (ClusterSetExistException e) { + // Old cluster set. + assertTrue("Missing library resource.", null != il); + } + clusterSets.setSize(2); + clusterSets.set(0, pl); + clusterSets.set(1, il); + } + } + class Init extends ReadRequest { + @Override + public void run(ReadGraph g) throws DatabaseException { + resources.clear(); + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : g.getObjects(clusterSets.get(1), l0.ConsistsOf)) { + if (DEBUG) + if (VERBOSE) + System.out.println("Resource " + r); + resources.add(r); + } + if (DEBUG) + System.out.println("Resource count=" + resources.size()); + } + } + class Modi extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + for (int i=0; i clusters = new HashMap(); + for (int i=0; i sortedKeys = new TreeSet(); + for (Map.Entry i : clusters.entrySet()) + sortedKeys.add(i.getKey()); + long sum = 0; + for (long key : sortedKeys) { + int count = clusters.get(key); + if (DEBUG) + System.out.println("cluster=" + key + " count=" + count); + sum += count; + } + if (resources.size() != sum) { + String msg = "Resource count mismatch. expected=" + resources.size() + " realized=" + sum; + if (DEBUG) + System.out.println(msg); + fail(msg); + } + int n = resources.size() / CLUSTER_FILL_SIZE + 1; + if (n < clusters.size()) { + String msg = "Cluster count mismatch. expected=" + n + " realized=" + clusters.size(); + if (DEBUG) + System.out.println(msg); + fail(msg); + } + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java new file mode 100644 index 000000000..4d82714fa --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ImmutableException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.cases.FreshDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +/** + * Tests that commit which changes only meta data will create revision. + */ +public class Issue3422Test1 extends FreshDatabaseTest { + private Resource testRoot; + @Test + public void test() throws DatabaseException { + Session session = getSession(); + session.syncRequest(new Init()); + session.syncRequest(new Modify()); + } + class Init extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters = cc.flushClusters(); + Layer0 l0 = Layer0.getInstance(g); + g.flushCluster(); // Starts new cluster. + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + testRoot = g.newResource(); + g.claim(testRoot, l0.InstanceOf, l0.Library); + g.claim(rl, l0.ConsistsOf, testRoot); + XSupport xs = (XSupport)g.getService(XSupport.class); + assertFalse("GetImmutable did not work.", xs.getImmutable(testRoot)); + xs.setImmutable(testRoot, true); + assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot)); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters2 = cc.flushClusters(); + assertTrue("Could not relase clusters.", nClusters + 1 == nClusters2); + } + } + class Modify extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters = cc.flushClusters(); + System.out.println("clusters count=" + nClusters); + Layer0 l0 = Layer0.getInstance(getSession()); + XSupport xs = (XSupport)g.getService(XSupport.class); + assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot)); + try { + g.claim(testRoot, l0.InstanceOf, l0.Relation); + } catch (ImmutableException e) { + return; + } + fail("Immutable check did not work."); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue4688Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue4688Test1.java new file mode 100644 index 000000000..f80cb573a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue4688Test1.java @@ -0,0 +1,94 @@ +package org.simantics.db.tests.regression.bugs; + +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ImmutableException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; + + /** + * Tests that setting cluster to immutable after cluster is changed to big works. + * Init request adds immutable cluster to database. + * Modify request checks that it is immutable. + * The tests requires that small cluster is converted to big and that the cluster is fetched from the server. + * + * There was a bug in ProCoreServer which caused changes in immutable state to be discarded when small cluster was converted to big before setting immutable state. + * Refs #4688 (https://www.simantics.org/redmine/issues/4688). Fixes https://www.simulationsite.net/redmine/issues/8866. + */ +public class Issue4688Test1 extends ExistingDatabaseTest { + private final String URI_NAME = "ImmutabaleTest" + getRandomString(); + private final String URI_PATH = TestBase.ROOT_LIBRARY_URI + "/" + URI_NAME; + @Test + public void test() throws DatabaseException { + Session session = getSession(); + session.syncRequest(new Init()); + session.syncRequest(new Modify()); + } + class Init extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters = cc.flushClusters(); + g.flushCluster(); // Starts new cluster. + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + Resource testRoot = g.getPossibleResource(URI_PATH); + assertTrue(URI_PATH + " must not be defined.", null == testRoot); + testRoot = g.newResource(); + g.claim(testRoot, L0.InstanceOf, L0.Library); + g.addLiteral(testRoot, L0.HasName, L0.NameOf, L0.String, URI_NAME, Bindings.STRING); + g.claim(rl, L0.ConsistsOf, testRoot); + XSupport xs = (XSupport)g.getService(XSupport.class); + assertFalse("GetImmutable did not work.", xs.getImmutable(testRoot)); + int size = (1<<14) - 1; + for (int i=0; i<1024; ++i) { + Resource r = g.newResource(); + g.claim(testRoot, L0.Relation, r); + g.claimValue(r, bytes(size), Bindings.BYTE_ARRAY); + } + xs.setImmutable(testRoot, true); + assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot)); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters2 = cc.flushClusters(); + assertTrue("Could not relase clusters.", nClusters + 1 == nClusters2); + } + byte[] bytes(int size) { + byte[] result = new byte[size]; + for(int i=0;i loopCount = new DataContainer(); + DataContainer listenerCount = new DataContainer(); + + @Test + public void testSimanticsBug16591() + throws DatabaseException { + session = getSession(); + session.syncRequest(new Init()); + loopCount.set(-1); + listenerCount.set(0); + int oldCount = 0; + for (int i=0; i() { + + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + return true; + } + }); + if (USE_LISTENER2) { + g.forPossibleObject(rr, l0.InstanceOf, new Listener(loopCount, listenerCount)); + } + if (USE_LISTENER3) { + g.syncRequest(new PossibleObject(rr, l0.InstanceOf), new Listener(loopCount, listenerCount)); + } + } + } + } + } + class Listener implements SyncListener { + final DataContainer loopCount; + final DataContainer listenerCount; + final int me; + boolean disposed = false; + Listener(DataContainer loopCount, DataContainer listenerCount) { + this.loopCount = loopCount; + this.listenerCount = listenerCount; + int value = this.listenerCount.get() + 1; + this.listenerCount.set(value); + this.me = loopCount.get(); + } + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + if (disposed) + return true; + disposed = loopCount.get() != me; + if (disposed) { + int value = this.listenerCount.get() - 1; + this.listenerCount.set(value); + } + return disposed; + } + + } + class Delete extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : g.getObjects(testRoot, l0.ConsistsOf)) { + if (DEBUG) + System.out.println("Deny resource " + r); + g.deny(testRoot, l0.ConsistsOf, r); + } + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test2.java new file mode 100644 index 000000000..5c44a694c --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test2.java @@ -0,0 +1,198 @@ +package org.simantics.db.tests.regression.bugs; + +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.primitiverequest.PossibleObject; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class SimanticsBug1659Test2 extends ExistingDatabaseTest { + static int LOOP_COUNT = 100; + static int CLUSTER_COUNT = 2; + static int RESOURCE_COUNT = 1000; + static boolean DEBUG = false; + static boolean DEBUG_LISTENER = false; + // Use transient listener. + static boolean USE_LISTENER = true; + // Use asynchronous listener. + static boolean USE_LISTENER2 = true; + // Use synchronous listener + static boolean USE_LISTENER3 = true; + Session session; + Resource testRoot; + Resource type; + DataContainer loopCount = new DataContainer(); + DataContainer listenerCount = new DataContainer(); + + @Test + public void testSimanticsBug1659_2() + throws DatabaseException { + session = getSession(); + session.syncRequest(new Init()); + loopCount.set(-1); + listenerCount.set(0); + int oldCount = 0; + for (int i=0; i() { + + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + return true; + } + }); + if (USE_LISTENER2) { + g.forPossibleObject(rr, l0.InstanceOf, new Listener(loopCount, listenerCount)); + } + if (USE_LISTENER3) { + g.syncRequest(new PossibleObject(rr, l0.InstanceOf), new Listener(loopCount, listenerCount)); + } + } + } + } + } + class Listener implements SyncListener { + final DataContainer loopCount; + final DataContainer listenerCount; + final int me; + boolean disposed = false; + Listener(DataContainer loopCount, DataContainer listenerCount) { + this.loopCount = loopCount; + this.listenerCount = listenerCount; + int value = this.listenerCount.get() + 1; + this.listenerCount.set(value); + this.me = loopCount.get(); + } + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + if (disposed) + return true; + disposed = loopCount.get() != me; + if (disposed) { + int value = this.listenerCount.get() - 1; + this.listenerCount.set(value); + } + return disposed; + } + + } + class Delete extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : g.getObjects(testRoot, l0.ConsistsOf)) { + if (DEBUG) + System.out.println("Deny resource " + r); + g.deny(testRoot, l0.ConsistsOf, r); + } + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test3.java new file mode 100644 index 000000000..0abcab280 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test3.java @@ -0,0 +1,82 @@ +package org.simantics.db.tests.regression.bugs; + +import java.util.UUID; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +public class SimanticsBug1659Test3 extends ExistingDatabaseTest { + static int LOOP_COUNT = 10; + static int CLUSTER_COUNT = 20; + static int RESOURCE_COUNT = 10000; + static boolean DEBUG = false; + Session session; + Resource testRoot; + ClusterControl clusterControl; + @Test + public void testSimanticsBug1659_3() + throws DatabaseException { + session = getSession(); + clusterControl = getSession().getService(ClusterControl.class); + session.syncRequest(new Init()); + session.syncRequest(new CreateWriteOnly()); + for (int i=0; i { + MyResourceRead(Resource resource) { + super(resource); + } + @Override + public String perform(ReadGraph g) throws DatabaseException { + if (DEBUG) + System.out.println("MyResourceRead"); + g.getResource("huuhaa"); + return "huuhaa"; + } + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else + return false; + } + } + class MyListener implements Listener { + + @Override + public void execute(String result) { + if (DEBUG) + System.out.println("execute=" + result); + } + + @Override + public void exception(Throwable t) { + if (DEBUG) + System.out.println("exception=" + t.getMessage()); + } + + @Override + public boolean isDisposed() { + return false; + } + + } + class TestRequest extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + for (int i=0; i() { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(newResource, L0.HasName, Bindings.STRING); + } + })); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug639Test.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug639Test.java new file mode 100644 index 000000000..f6a3dd1f8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug639Test.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * @author Tuukka Lehtonen + */ +public class SimanticsBug639Test extends ExistingDatabaseTest { + + public Resource createAssertion(WriteGraph graph, Resource subject, Resource relation, String object) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource assertion = graph.newResource(); + graph.claim(assertion, L0.InstanceOf, null, L0.Assertion); + graph.claim(subject, L0.Asserts, assertion); + graph.claim(assertion, L0.HasPredicate, relation); + Resource value = graph.newResource(); + graph.claim(value, L0.InstanceOf, null, L0.String); + graph.claimValue(value, object); + graph.claim(assertion, L0.HasObject, value); + return assertion; + } + + @Test + public void testTicket646() throws Exception { + + Session session = getSession(); + final DataContainer subject = new DataContainer(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + + createAssertion(graph, s, L0.HasName, "Foo1"); + createAssertion(graph, s, L0.HasName, "Foo2"); + createAssertion(graph, s, L0.HasComment, "Comment1"); + createAssertion(graph, s, L0.HasComment, "Comment2"); + + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource s = subject.get(); + // Just make sure that these don't crash. + assertEquals(graph.getObjects(s, L0.HasComment).size(), 0); + assertEquals(graph.getObjects(s, L0.HasName).size(), 0); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource s = subject.get(); + graph.getRelatedValue(s, L0.HasName, Bindings.STRING); + } + }); + } catch (NoSingleResultException e) { + // Expected + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java new file mode 100644 index 000000000..f92bc2d04 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Tests that using virtual graph during write request does not interfere with + * generation of core change sets. + * + * See https://www.simulationsite.net/redmine/issues/4007. + */ +public class SimanticsFeature4007Test1 extends ExistingDatabaseTest { + @Test + public void testSimanticsFeature4007() throws Exception { + final Session session = getSession(); + final VirtualGraphSupport vgSupport = session.getService(VirtualGraphSupport.class); + final ManagementSupport mg = session.getService(ManagementSupport.class); + long id1 = mg.getHeadRevisionId(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + + Resource r1 = graph.newResource(); + graph.claim(r1, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r1, L0.HasName, "r1"); + + VirtualGraph vg = vgSupport.getWorkspacePersistent("vg"); + graph.syncRequest(new WriteRequest(vg) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r, L0.HasName, "rv"); + } + }); + + Resource r2 = graph.newResource(); + graph.claim(r2, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r2, L0.HasName, "r2"); + } + }); + long id2 = mg.getHeadRevisionId(); + assertTrue(getName() + " failed!", id2 == id1 + 1); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SyncWriteReadTest1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SyncWriteReadTest1.java new file mode 100644 index 000000000..77b437968 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SyncWriteReadTest1.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.Terminator; + +/** + * Tests that sync read within sync write causes exception. + * Currently this tests causes deadlock. + */ +public class SyncWriteReadTest1 extends ExistingDatabaseTest { + final boolean DEBUG = true; + final String resourceName = "r1"; + + private Terminator terminator; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + terminator = new Terminator(3); + } + + @After + @Override + public void tearDown() throws Exception { + terminator.disarm(); + super.tearDown(); + } + + @Test + @Fails + public void testSyncWriteReadTest1() throws Exception { + final Session session = getSession(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + try { + session.sync(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource root = graph.getResource(ROOT_LIBRARY_URI); + assertTrue("Failed to get root library.", null == root); + } + }); + fail("Missing exception during read request."); + } catch (DatabaseException e) { + if (DEBUG) + System.out.println("Catched DatabaseException as expected."); + } + } + }); + } catch (DatabaseException e) { + if (DEBUG) + System.out.println("Catched DatabaseException as excepected:" + e.getMessage()); + return; + } + fail("Sync write failed to throw exception as expected."); + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/TicketTest646.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/TicketTest646.java new file mode 100644 index 000000000..da26749c7 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/TicketTest646.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class TicketTest646 extends ExistingDatabaseTest { + + @Test + @Fails + public void testTicket646() throws Exception { + + Session session = getSession(); + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + final DataContainer subject = new DataContainer(); + final String value = "value"; + final String newValue = "new value"; + final String newValue2 = "new value 2"; + final String newValue3 = "new value 3"; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use any non-functional relation + Layer0 b = Layer0.getInstance(graph); + Resource s = graph.newResource(); + graph.claim(s, b.InstanceOf, b.Entity); + graph.claimValue(s, value); + subject.set(s); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + if (!graph.hasStatement(s)) + fail("Failed to verify modifications (stm)."); + String t = graph.getValue(s, Bindings.STRING); + if (!t.equals(value)) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource s = subject.get(); + graph.claimValue(s, newValue); + graph.claimValue(s, newValue2); + graph.claimValue(s, newValue3); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + + support.undo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getPossibleValue(s, Bindings.STRING); + if (null != t) + fail("Failed to verify modifications (value)."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception " + e); + } + + support.redo(session, 1); + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s = subject.get(); + String t = graph.getPossibleValue(s, Bindings.STRING); + if (null == t) + fail("Failed to verify modifications (value)."); + if (!t.equals(newValue3)) + fail("Failed to verify modifications " + t + " != " + newValue3 + "."); + } + }); + } catch (Throwable e) { + e.printStackTrace(); + fail("Read transaction threw an unexpected exception " + e); + } + + } +} \ No newline at end of file diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/WriteCancelTest3.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/WriteCancelTest3.java new file mode 100644 index 000000000..c84d1c826 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/WriteCancelTest3.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.AssumptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Tests that exception during write causes canceling of changes. + * This tests must be added at least twice in order for the bug to appear. + * Even then the bug is not deterministic. + */ +public class WriteCancelTest3 extends ExistingDatabaseTest { + final String resourceName = "WriteCancelTest3"; + @Test + public void testWriteCancelTest3() throws Exception { + final Session session = getSession(); + boolean exceptionThrown = false; + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + checkThatInstanceDoesNotExist(graph); + Resource r1 = graph.newResource(); + graph.claim(r1, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r1, L0.HasName, resourceName); + Resource root = graph.getResource(ROOT_LIBRARY_URI); + graph.claim(root, L0.ConsistsOf, L0.PartOf, r1); + checkThatInstanceDoesExist(graph); + throw new AssumptionException("Intentional exception during write."); + } + }); + } catch (AssumptionException e) { + exceptionThrown = true; + if (DEBUG) + System.out.println("Catched AssumptionException as excepected:" + e.getMessage()); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + assertTrue("Failed to throw exception as expected.", exceptionThrown); + session.sync(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + checkThatInstanceDoesNotExist(graph); + } + }); + } + private void checkThatInstanceDoesExist(final ReadGraph graph) { + try { + String uri = ROOT_LIBRARY_URI + "/" + resourceName; + Resource r = graph.getResource(uri); + if (null == r) + fail("Uri " + uri + " has not been defined."); + } catch (DatabaseException e) { + fail("Unexpected exception during read request: " + e.getMessage()); + } + } + private void checkThatInstanceDoesNotExist(final ReadGraph graph) { + try { + String uri = ROOT_LIBRARY_URI + "/" + resourceName; + Resource r = graph.getResource(uri); + if (null != r) + fail("Uri " + uri + " has been defined."); + } catch (ResourceNotFoundException e) { + if (DEBUG) + System.out.println("Catched ResourceNotFoundException as expected."); + } catch (DatabaseException e) { + fail("Unexpected exception during read request: " + e.getMessage()); + } + } +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest.java new file mode 100644 index 000000000..91dbc2dd5 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.scalability; + +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +public class CreateManyClustersTest extends ExistingDatabaseTest { + + final static int CLUSTERS = Configuration.get().cachedClusterCount; + + private Throwable exception; + private Resource rootResource = null; + + public void test() throws Exception { + + Session session = getSession(); + + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + rootResource = g.newResource(); + g.claim(g.getRootLibrary(), b.ConsistsOf, rootResource); + } + }); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + + + try { + + Layer0 b = Layer0.getInstance(graph); + + for(int i=0;i resources = g.getObjects(rootLib, b.ConsistsOf); + Resource newType = null; + Resource newInstance[] = new Resource[OUTER_INSTANCE_COUNT]; + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (null == name) + continue; + if (name.equals(newTypeName)) { + newType = r; + } + if (!name.startsWith(random, 0)) + continue; + name = name.substring(random.length()); + int index = 0; + try { + index = Integer.parseInt(name); + } catch (NumberFormatException e) { + continue; // not a number + } + if (index > 0 && index < OUTER_INSTANCE_COUNT+1) { + newInstance[index-1] = r; + } + } + if (newType == null) + throw new Exception("Could not find created type"); + for (int i=0; i + * + */ +public class LargeDataTest extends ExistingDatabaseTest { + + private static int INSTANCE_COUNT = 1000; //100000 + private static int MAX_INSTANCE_COUNT_PER_TRANSACTION = 100; // 1000; + private static boolean OPTIMIZED = false; + + public void testLargeData() throws Exception{ + final Resource rootLib = getSession().getRootLibrary(); + final String random = getRandomString(); + if (DEBUG) + System.out.println("Test start"); + for (int j = 0; j < INSTANCE_COUNT; j += MAX_INSTANCE_COUNT_PER_TRANSACTION) { + final int base = j; + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + for (int i = 0; i < MAX_INSTANCE_COUNT_PER_TRANSACTION; i++) { + String newInstanceName = random + (base+i); + Resource instance = g.newResource(); + if(!OPTIMIZED) { + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, instance); + } else { + Resource invName = g.getInverse(b.HasName); + g.claim(instance, b.HasName, invName, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, b.PartOf, instance); + } + } + + } + }); + if (DEBUG) + System.out.println(j + MAX_INSTANCE_COUNT_PER_TRANSACTION); + } + + checkException(); + if (DEBUG) + System.out.println("Reading stage"); + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + List found = new ArrayList(INSTANCE_COUNT); + for (int i = 0; i < INSTANCE_COUNT; i++) { + found.add(false); + } + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (null == name || !name.startsWith(random, 0)) + continue; + name = name.substring(random.length()); + try { + int i = Integer.parseInt(name); + found.set(i, true); + + } catch (NumberFormatException e) { + continue; // not a number + } + } + for (int i = 0; i < INSTANCE_COUNT; i++) { + if (!found.get(i)) + throw new Exception("Created resource " + i + " cannot be found"); + } + } + }); + if (DEBUG) + System.out.println("test done"); + checkException(); + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeImportTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeImportTest.java new file mode 100644 index 000000000..07990edb6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeImportTest.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.scalability; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; + +public class LargeImportTest extends ExistingDatabaseTest { + + private static final int OUTER_INSTANCE_COUNT = Configuration.get().importOuterCount; // these go to the root library + private static final int INNER_INSTANCE_COUNT = Configuration.get().importInnerCount; // these are for each outer instance + private static Layer0 l0; + + /** + * Creates new type and new instance of it. Then tries to find the instance and the type, and verifies that inheritance is correct. + * @throws Exception + */ + @Test + public void testImport() throws Exception{ + Session session = getSession(); + final Resource rootLib = getSession().getRootLibrary(); + final String random = getRandomString(); + final String newTypeName = "New Type " + random; + session.syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Exception { + l0 = Layer0.getInstance(g); + assert(null != l0.InstanceOf); + assert(null != l0.Type); + assert(null != l0.Inherits); + assert(null != l0.SupertypeOf); + assert(null != l0.HasName); + assert(null != l0.ConsistsOf); + } + }); + session.syncRequest(new WriteOnlyQuery() { + @Override + public void run(WriteOnlyGraph g) throws Throwable { + Resource newType = g.newResource(); + g.claim(newType, l0.InstanceOf, null, l0.Type); + g.claim(newType, l0.Inherits, l0.SupertypeOf, l0.Type); + g.claimValue(newType, newTypeName, Bindings.STRING); + g.claim(rootLib, l0.ConsistsOf, l0.PartOf, newType); + for (int i=0; i resources = g.getObjects(rootLib, l0.ConsistsOf); + Resource newType = null; + Resource newInstance[] = new Resource[OUTER_INSTANCE_COUNT]; + for (Resource r : resources) { + String name = g.getPossibleValue(r, Bindings.STRING); + if (null == name) + continue; + if (name.equals(newTypeName)) { + newType = r; + } + if (!name.startsWith(random, 0)) + continue; + name = name.substring(random.length()); + int index = 0; + try { + index = Integer.parseInt(name); + } catch (NumberFormatException e) { + continue; // not a number + } + if (index > 0 && index < OUTER_INSTANCE_COUNT+1) { + newInstance[index-1] = r; + } + } + if (newType == null) + throw new Exception("Could not find created type"); + for (int i=0; i request) throws DatabaseException { + + long start = System.nanoTime(); + Resource result = getSession().sync(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + return result; + + } + + public void test() throws Exception { + + Layer0.getInstance(getSession()); + + getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); + + time("write", HierarchicalNames.write(name, sizes)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteHierarchicalNames.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteHierarchicalNames.java new file mode 100644 index 000000000..c52ab1ebe --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteHierarchicalNames.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.scalability; + +import org.simantics.db.Resource; +import org.simantics.db.common.TransactionPolicyKeep; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.WriteInterface; +import org.simantics.db.service.TransactionPolicySupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.tests.performance.read.HierarchicalNames; +import org.simantics.layer0.Layer0; + +public class WriteHierarchicalNames extends ExistingDatabaseTest { + + final private static String name = "name"; + + // 512k nodes + int[] sizes = { 122, 64, 64 }; + + private Resource time(String label, WriteInterface request) throws DatabaseException { + + long start = System.nanoTime(); + Resource result = getSession().sync(request); + long duration = System.nanoTime() - start; + System.out.println(label + " = " + 1e-9*duration); + return result; + + } + + public void test() throws Exception { + + Layer0.getInstance(getSession()); + + getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep()); + + time("writeOnly", HierarchicalNames.writeOnly(name, sizes)); + time("writeOnly2", HierarchicalNames.writeOnly2(name, sizes)); + time("write", HierarchicalNames.write(name, sizes)); + time("write2", HierarchicalNames.write2(name, sizes)); + + } + +} diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteOnlyManyClustersTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteOnlyManyClustersTest.java new file mode 100644 index 000000000..25255ce69 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/WriteOnlyManyClustersTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.scalability; + +import java.util.ArrayList; +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteOnlyRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +public class WriteOnlyManyClustersTest extends ExistingDatabaseTest { + + final static int ITEM_COUNT = 4000; + + public void testWriteException() throws Exception { + + final Session session = getSession(); + final Layer0 b = Layer0.getInstance(session); + final ArrayList items = new ArrayList(); + + session.syncRequest(new WriteOnlyRequest() { + + @Override + public void perform(WriteOnlyGraph graph) throws DatabaseException { + + for(int i=0;i resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + String s = g.getRelatedValue(r, b.HasDescription, Bindings.STRING); + if (!s.equals("1111")) + throw new ValidationException("Value is not correct."); + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + int count = 0; + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + count++; + } + } + System.out.println("instance count = " + count); + } + }); + + //LifecycleSupport ls = session.getService(LifecycleSupport.class); + //ls.save(); + //ls.close(); + System.out.println("Ok. No ls.close()"); + System.exit(0); + +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/tests/org.simantics.db.tests/tutorial/HeadlessClientToRunningCore.java b/tests/org.simantics.db.tests/tutorial/HeadlessClientToRunningCore.java new file mode 100644 index 000000000..347be888a --- /dev/null +++ b/tests/org.simantics.db.tests/tutorial/HeadlessClientToRunningCore.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; + + +public class HeadlessClientToRunningCore { + static String newInstanceName ="HeadlessClientTestInstanceName"; + static Session session = null; + public static void main(String[] args) { + try { + session = Tests.getTestHandler().getSession(); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, newInstanceName); + g.claim(g.getRootLibrary(), b.ConsistsOf, newResource); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + int count = 0; + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + count++; + } + } + System.out.println("instance count = " + count); + } + }); + + LifecycleSupport ls = session.getService(LifecycleSupport.class); + ls.close(); + System.out.println("Ok."); + +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/tests/org.simantics.db.tests/tutorial/Local1.java b/tests/org.simantics.db.tests/tutorial/Local1.java new file mode 100644 index 000000000..5b68dbb1a --- /dev/null +++ b/tests/org.simantics.db.tests/tutorial/Local1.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; + + +public class Local1 { + static String newInstanceName ="Local1InstanceName"; + static Session session = null; + public static void main(String[] args) { + try { + session = Tests.getTestHandler().getSession(); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource newResource = g.newResource(); + g.claim(newResource, b.InstanceOf, null, b.Type); + g.claimLiteral(newResource, b.HasName, newInstanceName); + g.claim(g.getRootLibrary(), b.ConsistsOf, newResource); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + Resource newResource = null; + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + newResource = r; + break; + } + } + if (newResource == null) { + throw new ValidationException("Could not find created resource"); + } + if (!g.isInstanceOf(newResource, b.Type)) + throw new ValidationException("Created resource is not an instance of Type"); + } + }); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + int count = 0; + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + count++; + } + } + System.out.println("instance count = " + count); + } + }); + +// LifecycleSupport ls = session.getService(LifecycleSupport.class); +// PublishSynchroniseSupport pss = session.getService(PublishSynchroniseSupport.class); +// pss.publish(); +// ls.close(); + System.out.println("Ok."); +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/tests/org.simantics.db.tests/tutorial/Local2.java b/tests/org.simantics.db.tests/tutorial/Local2.java new file mode 100644 index 000000000..5cc643ec8 --- /dev/null +++ b/tests/org.simantics.db.tests/tutorial/Local2.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.testing.common.Tests; +import org.simantics.layer0.Layer0; + + +public class Local2 { + static String newInstanceName ="Local1InstanceName"; + static Session session = null; + public static void main(String[] args) { + try { + session = Tests.getTestHandler().getSession(); + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + int count = 0; + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + count++; + } + } + System.out.println("instance count = " + count); + } + }); + + LifecycleSupport ls = session.getService(LifecycleSupport.class); +// PublishSynchroniseSupport pss = session.getService(PublishSynchroniseSupport.class); +// pss.synchronize(); + + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + int count = 0; + Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + count++; + } + } + System.out.println("instance count = " + count); + } + }); + + ls.close(); + System.out.println("Ok."); +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/tests/org.simantics.db.tests/tutorial/compile.sh b/tests/org.simantics.db.tests/tutorial/compile.sh new file mode 100644 index 000000000..0acdc3c18 --- /dev/null +++ b/tests/org.simantics.db.tests/tutorial/compile.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#******************************************************************************* +# Copyright (c) 2007, 2010 Association for Decentralized Information Management +# in Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +#******************************************************************************* +DIR=../../org.simantics.db.build/ +for i in ${DIR}/*.jar; do + CLASSPATH=$CLASSPATH:$i; +done +javac -classpath ${CLASSPATH} HeadlessClientToRunningCore.java \ No newline at end of file diff --git a/tests/org.simantics.db.tests/tutorial/run.sh b/tests/org.simantics.db.tests/tutorial/run.sh new file mode 100644 index 000000000..54c00a577 --- /dev/null +++ b/tests/org.simantics.db.tests/tutorial/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#******************************************************************************* +# Copyright (c) 2007, 2010 Association for Decentralized Information Management +# in Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +#******************************************************************************* +DIR=../../org.simantics.db.build/ +for i in ${DIR}/*.jar; do + CLASSPATH=$CLASSPATH:$i; +done +java -classpath ${CLASSPATH} -Djava.library.path=../run/env HeadlessClientToRunningCore