From d65f58eeaf555232cca7af814bcd8e073cc55499 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 29 Apr 2007 17:47:50 +0000 Subject: Merged in support for derived properties. --- pom.xml | 8 + .../java/com/amazon/carbonado/TestStorables.java | 327 +++++++++++++++++++++ .../com/amazon/carbonado/info/TestDerived.java | 220 ++++++++++++++ .../com/amazon/carbonado/stored/UserAddress.java | 2 +- .../com/amazon/carbonado/stored/WithDerived.java | 69 +++++ .../com/amazon/carbonado/stored/WithDerived2.java | 48 +++ .../amazon/carbonado/stored/WithDerivedChainA.java | 53 ++++ .../amazon/carbonado/stored/WithDerivedChainB.java | 45 +++ .../amazon/carbonado/stored/WithDerivedChainC.java | 45 +++ .../amazon/carbonado/stored/WithDerivedChainD.java | 38 +++ .../amazon/carbonado/stored/WithDerivedCycle.java | 37 +++ .../amazon/carbonado/stored/WithDerivedCycle2.java | 47 +++ .../stored/WithDerivedDoubleObjVersion.java | 45 +++ .../carbonado/stored/WithDerivedFloatVersion.java | 44 +++ .../carbonado/stored/WithDerivedStringVersion.java | 45 +++ .../carbonado/stored/WithDerivedVersion.java | 44 +++ .../amazon/carbonado/stored/WithFunctionIndex.java | 50 ++++ 17 files changed, 1166 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/amazon/carbonado/info/TestDerived.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerived.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerived2.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedChainA.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedChainB.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedChainC.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedChainD.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedCycle.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedCycle2.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedDoubleObjVersion.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedFloatVersion.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedStringVersion.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithDerivedVersion.java create mode 100644 src/test/java/com/amazon/carbonado/stored/WithFunctionIndex.java diff --git a/pom.xml b/pom.xml index 5a476dc..6c2764c 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,14 @@ --> + + org.apache.maven.plugins + maven-surefire-plugin + + -Xmx400M + + + org.apache.maven.plugins maven-project-info-reports-plugin diff --git a/src/test/java/com/amazon/carbonado/TestStorables.java b/src/test/java/com/amazon/carbonado/TestStorables.java index 747ee23..b3824da 100644 --- a/src/test/java/com/amazon/carbonado/TestStorables.java +++ b/src/test/java/com/amazon/carbonado/TestStorables.java @@ -1014,6 +1014,189 @@ public class TestStorables extends TestCase { repo = null; } + public void test_derivedVersion() throws Exception { + Storage storage = getRepository().storageFor(WithDerivedVersion.class); + + WithDerivedVersion s = storage.prepare(); + s.setID(1); + s.setName("john"); + s.setValue(2); + s.insert(); + assertEquals(2, s.getVersion()); + + try { + s.setName("bob"); + s.setValue(2); // dirty the property version derives from + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s.setValue(3); + s.update(); + + try { + s.load(); + s.setName("fred"); + s.setValue(1); + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s = storage.prepare(); + s.setID(1); + s.setName("fred"); + s.setValue(100); + s.update(); + } + + public void test_derivedFloatVersion() throws Exception { + Storage storage = + getRepository().storageFor(WithDerivedFloatVersion.class); + + WithDerivedFloatVersion s = storage.prepare(); + s.setID(1); + s.setName("john"); + s.setValue(2.1f); + s.insert(); + assertEquals(2.1f, s.getVersion()); + + try { + s.setName("bob"); + s.setValue(2.1f); // dirty the property version derives from + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s.setValue(2.12f); + s.update(); + + try { + s.load(); + s.setName("fred"); + s.setValue(1); + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s = storage.prepare(); + s.setID(1); + s.setName("fred"); + s.setValue(100); + s.update(); + + s.setValue(Float.NaN); + s.setName("sara"); + s.update(); + + s.setValue(3.14f); + s.setName("conner"); + s.update(); + } + + public void test_derivedDoubleObjVersion() throws Exception { + Storage storage = + getRepository().storageFor(WithDerivedDoubleObjVersion.class); + + WithDerivedDoubleObjVersion s = storage.prepare(); + s.setID(1); + s.setName("john"); + s.setValue(2.1); + s.insert(); + assertEquals(2.1, s.getVersion()); + + try { + s.setName("bob"); + s.setValue(2.1); // dirty the property version derives from + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s.setValue(2.12); + s.update(); + + try { + s.load(); + s.setName("fred"); + s.setValue(1.0); + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s = storage.prepare(); + s.setID(1); + s.setName("fred"); + s.setValue(100.0); + s.update(); + + s.setValue(Double.NaN); + s.setName("sara"); + s.update(); + + s.setValue(3.14); + s.setName("conner"); + s.update(); + + s.setValue(null); + s.setName("steve"); + s.update(); + + s.setValue(1.5); + s.setName("cathy"); + s.update(); + } + + public void test_derivedStringVersion() throws Exception { + Storage storage = + getRepository().storageFor(WithDerivedStringVersion.class); + + WithDerivedStringVersion s = storage.prepare(); + s.setID(1); + s.setName("john"); + s.setValue("a"); + s.insert(); + assertEquals("a", s.getVersion()); + + try { + s.setName("bob"); + s.setValue("a"); // dirty the property version derives from + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s.setValue("b"); + s.update(); + + try { + s.load(); + s.setName("fred"); + s.setValue("a"); + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + s = storage.prepare(); + s.setID(1); + s.setName("fred"); + s.setValue("c"); + s.update(); + + s.setValue(null); + s.setName("steve"); + s.update(); + + s.setValue("a"); + s.setName("cathy"); + s.update(); + } + public void test_sequences() throws Exception { Storage storage = getRepository().storageFor(StorableSequenced.class); @@ -1198,6 +1381,150 @@ public class TestStorables extends TestCase { } } + public void test_derivedFunctionIndex() throws Exception { + Storage storage = getRepository().storageFor(WithFunctionIndex.class); + + WithFunctionIndex s = storage.prepare(); + s.setID(1); + s.setSum(10); + s.setCount(20); + s.insert(); + + s = storage.prepare(); + s.setID(2); + s.setSum(20); + s.setCount(40); + s.insert(); + + s = storage.prepare(); + s.setID(3); + s.setSum(20); + s.setCount(0); + s.insert(); + + s = storage.prepare(); + s.setID(4); + s.setSum(0); + s.setCount(0); + s.insert(); + + s = storage.prepare(); + s.setID(5); + s.setSum(10); + s.setCount(10); + s.insert(); + + Query query = storage.query("average = ?"); + Query q2 = storage.query("averageObject = ?"); + + assertEquals(2, query.with(0.5).count()); + assertEquals(3, query.with(20.0 / 0).loadOne().getID()); + assertEquals(4, query.with(0.0 / 0).loadOne().getID()); + assertEquals(5, query.with(1.0).loadOne().getID()); + + assertEquals(2, q2.with(0.5).count()); + assertEquals(3, q2.with(20.0 / 0).loadOne().getID()); + assertEquals(4, q2.with(0.0 / 0).loadOne().getID()); + assertEquals(5, q2.with(1.0).loadOne().getID()); + + s = storage.prepare(); + s.setID(5); + s.setSum(2); + s.update(); + + assertEquals(0, query.with(1.0).count()); + assertEquals(5, query.with(0.2).loadOne().getID()); + + s.delete(); + + assertEquals(0, query.with(1.0).count()); + assertEquals(0, query.with(0.2).count()); + } + + public void test_derivedJoinIndex() throws Exception { + Storage aStorage = getRepository().storageFor(WithDerivedChainA.class); + Storage bStorage = getRepository().storageFor(WithDerivedChainB.class); + Storage cStorage = getRepository().storageFor(WithDerivedChainC.class); + Storage dStorage = getRepository().storageFor(WithDerivedChainD.class); + + int aid = 101; + int bid = 201; + int cid = 301; + int did = 401; + + WithDerivedChainD d = dStorage.prepare(); + // Insert later + //d.setDid(did); + //d.setName("dee"); + //d.insert(); + d = dStorage.prepare(); + d.setDid(did + 1); + d.setName("dee2"); + d.insert(); + + WithDerivedChainC c = cStorage.prepare(); + c.setCid(cid); + c.setName("cee"); + c.setDid(did); + c.insert(); + c = cStorage.prepare(); + c.setCid(cid + 1); + c.setName("cee2"); + c.setDid(did + 1); + c.insert(); + + WithDerivedChainB b = bStorage.prepare(); + b.setBid(bid); + b.setName("bee"); + b.setCid(cid); + b.insert(); + b = bStorage.prepare(); + b.setBid(bid + 1); + b.setName("bee2"); + b.setCid(cid + 1); + b.insert(); + + WithDerivedChainA a = aStorage.prepare(); + a.setAid(aid); + a.setName("aye"); + a.setBid(bid); + try { + // Insert fails because d doesn't exist. + a.insert(); + fail(); + } catch (PersistException e) { + } + + d = dStorage.prepare(); + d.setDid(did); + d.setName("dee"); + d.insert(); + + a.insert(); + + a = aStorage.prepare(); + a.setAid(aid + 1); + a.setName("aye2"); + a.setBid(bid + 1); + a.insert(); + + Query aQuery = aStorage.query("DName = ?"); + + assertEquals(101, aQuery.with("dee").loadOne().getAid()); + assertEquals(102, aQuery.with("dee2").loadOne().getAid()); + + a.delete(); + + assertEquals(101, aQuery.with("dee").loadOne().getAid()); + assertNull(aQuery.with("dee2").tryLoadOne()); + + d.setName("dee!!!"); + d.update(); + + assertNull(aQuery.with("dee").tryLoadOne()); + assertEquals(101, aQuery.with("dee!!!").loadOne().getAid()); + } + public void test_joinCache() throws Exception { Storage uaStorage = getRepository().storageFor(UserAddress.class); Storage uiStorage = getRepository().storageFor(UserInfo.class); diff --git a/src/test/java/com/amazon/carbonado/info/TestDerived.java b/src/test/java/com/amazon/carbonado/info/TestDerived.java new file mode 100644 index 0000000..6640f94 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/info/TestDerived.java @@ -0,0 +1,220 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.info; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import com.amazon.carbonado.*; +import com.amazon.carbonado.stored.*; + +/** + * Test cases for introspection of derived properties. + * + * @author Brian S O'Neill + */ +public class TestDerived extends TestCase { + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static TestSuite suite() { + return new TestSuite(TestDerived.class); + } + + public TestDerived(String name) { + super(name); + } + + public void test_simple() { + StorableInfo info = StorableIntrospector.examine(WithDerived.class); + StorableProperty prop = info.getAllProperties().get("upperCaseName"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(1, prop.getDerivedFromProperties().length); + assertEquals("name", prop.getDerivedFromProperties()[0].toString()); + } + + public void test_simpleComposites() { + StorableInfo info = StorableIntrospector.examine(WithDerived.class); + + { + StorableProperty prop = info.getAllProperties().get("IDAndName"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(2, prop.getDerivedFromProperties().length); + assertEquals("ID", prop.getDerivedFromProperties()[0].toString()); + assertEquals("name", prop.getDerivedFromProperties()[1].toString()); + } + + { + StorableProperty prop = info.getAllProperties().get("IDAndUpperCaseName"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(3, prop.getDerivedFromProperties().length); + assertEquals("ID", prop.getDerivedFromProperties()[0].toString()); + assertEquals("upperCaseName", prop.getDerivedFromProperties()[1].toString()); + assertEquals("name", prop.getDerivedFromProperties()[2].toString()); + } + + { + StorableProperty prop = info.getAllProperties().get("longKey"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(4, prop.getDerivedFromProperties().length); + assertEquals("IDAndUpperCaseName", prop.getDerivedFromProperties()[0].toString()); + assertEquals("ID", prop.getDerivedFromProperties()[1].toString()); + assertEquals("upperCaseName", prop.getDerivedFromProperties()[2].toString()); + assertEquals("name", prop.getDerivedFromProperties()[3].toString()); + } + + { + StorableProperty prop = info.getAllProperties().get("anotherLongKey"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(5, prop.getDerivedFromProperties().length); + assertEquals("longKey", prop.getDerivedFromProperties()[0].toString()); + assertEquals("IDAndUpperCaseName", prop.getDerivedFromProperties()[1].toString()); + assertEquals("ID", prop.getDerivedFromProperties()[2].toString()); + assertEquals("upperCaseName", prop.getDerivedFromProperties()[3].toString()); + assertEquals("name", prop.getDerivedFromProperties()[4].toString()); + } + + { + StorableProperty prop = info.getAllProperties().get("yetAnotherLongKey"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + assertEquals(0, prop.getDerivedFromProperties().length); + } + } + + public void test_simpleCycle() { + try { + StorableIntrospector.examine(WithDerivedCycle.class); + fail("Cycle not detected"); + } catch (MalformedTypeException e) { + } + } + + public void test_simpleCycle2() { + try { + StorableIntrospector.examine(WithDerivedCycle2.class); + fail("Cycle not detected"); + } catch (MalformedTypeException e) { + } + } + + public void test_joinNotDoublyLinked() { + try { + StorableInfo info = StorableIntrospector.examine(WithDerived2.class); + fail("Missing double link not detected"); + } catch (MalformedTypeException e) { + } + } + + public void test_joinChainA() { + StorableInfo info = + StorableIntrospector.examine(WithDerivedChainA.class); + + StorableProperty prop = info.getAllProperties().get("DName"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + + assertEquals(4, prop.getDerivedFromProperties().length); + assertEquals("b.c.d.name", prop.getDerivedFromProperties()[0].toString()); + assertEquals("b.c.d", prop.getDerivedFromProperties()[1].toString()); + assertEquals("b.c", prop.getDerivedFromProperties()[2].toString()); + assertEquals("b", prop.getDerivedFromProperties()[3].toString()); + + assertEquals(1, prop.getDerivedToProperties().length); + assertEquals("upperDName", prop.getDerivedToProperties()[0].toString()); + + prop = info.getAllProperties().get("upperDName"); + assertTrue(prop != null); + assertTrue(prop.isDerived()); + + assertEquals(5, prop.getDerivedFromProperties().length); + assertEquals("DName", prop.getDerivedFromProperties()[0].toString()); + assertEquals("b.c.d.name", prop.getDerivedFromProperties()[1].toString()); + assertEquals("b.c.d", prop.getDerivedFromProperties()[2].toString()); + assertEquals("b.c", prop.getDerivedFromProperties()[3].toString()); + assertEquals("b", prop.getDerivedFromProperties()[4].toString()); + + assertEquals(0, prop.getDerivedToProperties().length); + } + + public void test_joinChainB() { + StorableInfo info = + StorableIntrospector.examine(WithDerivedChainB.class); + + StorableProperty prop = info.getAllProperties().get("c"); + assertTrue(prop != null); + assertFalse(prop.isDerived()); + + assertEquals(0, prop.getDerivedFromProperties().length); + + assertEquals(2, prop.getDerivedToProperties().length); + assertEquals("DName.b", prop.getDerivedToProperties()[0].toString()); + assertEquals("upperDName.b", prop.getDerivedToProperties()[1].toString()); + + prop = info.getAllProperties().get("name"); + assertTrue(prop != null); + assertFalse(prop.isDerived()); + + assertEquals(0, prop.getDerivedFromProperties().length); + assertEquals(0, prop.getDerivedToProperties().length); + } + + public void test_joinChainC() { + StorableInfo info = + StorableIntrospector.examine(WithDerivedChainC.class); + + StorableProperty prop = info.getAllProperties().get("d"); + assertTrue(prop != null); + assertFalse(prop.isDerived()); + + assertEquals(0, prop.getDerivedFromProperties().length); + + assertEquals(2, prop.getDerivedToProperties().length); + assertEquals("DName.b.c", prop.getDerivedToProperties()[0].toString()); + assertEquals("upperDName.b.c", prop.getDerivedToProperties()[1].toString()); + + prop = info.getAllProperties().get("name"); + assertTrue(prop != null); + assertFalse(prop.isDerived()); + + assertEquals(0, prop.getDerivedFromProperties().length); + assertEquals(0, prop.getDerivedToProperties().length); + } + + public void test_joinChainD() { + StorableInfo info = + StorableIntrospector.examine(WithDerivedChainD.class); + + StorableProperty prop = info.getAllProperties().get("name"); + assertTrue(prop != null); + assertFalse(prop.isDerived()); + + assertEquals(0, prop.getDerivedFromProperties().length); + + assertEquals(2, prop.getDerivedToProperties().length); + assertEquals("DName.b.c.d", prop.getDerivedToProperties()[0].toString()); + assertEquals("upperDName.b.c.d", prop.getDerivedToProperties()[1].toString()); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/UserAddress.java b/src/test/java/com/amazon/carbonado/stored/UserAddress.java index 466f6eb..bee9683 100644 --- a/src/test/java/com/amazon/carbonado/stored/UserAddress.java +++ b/src/test/java/com/amazon/carbonado/stored/UserAddress.java @@ -62,5 +62,5 @@ public abstract class UserAddress implements Storable { @Nullable @Join(internal="neighborAddressID", external="addressID") public abstract UserAddress getNeighbor() throws FetchException; - public abstract void setNeighbor(UserAddress address) throws FetchException; + public abstract void setNeighbor(UserAddress address); } diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerived.java b/src/test/java/com/amazon/carbonado/stored/WithDerived.java new file mode 100644 index 0000000..d5cc69a --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerived.java @@ -0,0 +1,69 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerived implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Derived(from="name") + public String getUpperCaseName() { + String name = getName(); + if (name != null) { + name = name.toUpperCase(); + } + return name; + } + + @Derived(from={"ID", "name"}) + public String getIDAndName() { + return String.valueOf(getID()) + ':' + getName(); + } + + @Derived(from={"ID", "upperCaseName"}) + public String getIDAndUpperCaseName() { + return String.valueOf(getID()) + ':' + getUpperCaseName(); + } + + @Derived(from={"IDAndUpperCaseName"}) + public String getLongKey() { + return getIDAndUpperCaseName(); + } + + @Derived(from={"longKey", "ID", "name", "upperCaseName", "IDAndUpperCaseName"}) + public String getAnotherLongKey() { + return getLongKey(); + } + + @Derived + public String getYetAnotherLongKey() { + return getAnotherLongKey(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerived2.java b/src/test/java/com/amazon/carbonado/stored/WithDerived2.java new file mode 100644 index 0000000..1ece0a2 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerived2.java @@ -0,0 +1,48 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("key") +public abstract class WithDerived2 implements Storable { + public abstract int getKey(); + public abstract void setKey(int id); + + public abstract int getId(); + public abstract void setId(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Join + public abstract StorableTestBasic getBasic() throws FetchException; + public abstract void setBasic(StorableTestBasic basic); + + // This is an error because "basic" isn't doubly joined. + @Derived(from="basic.intProp") + public int getIntProp() throws FetchException, Exception { + return getBasic().getIntProp(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedChainA.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainA.java new file mode 100644 index 0000000..77d82ef --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainA.java @@ -0,0 +1,53 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("aid") +@Indexes(@Index("DName")) +public abstract class WithDerivedChainA implements Storable { + public abstract int getAid(); + public abstract void setAid(int id); + + public abstract int getBid(); + public abstract void setBid(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Join + public abstract WithDerivedChainB getB() throws FetchException; + public abstract void setB(WithDerivedChainB b); + + @Derived(from="b.c.d.name") + public String getDName() throws FetchException { + return getB().getC().getD().getName(); + } + + @Derived(from="DName") + public String getUpperDName() throws FetchException { + return getDName().toUpperCase(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedChainB.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainB.java new file mode 100644 index 0000000..85c8de3 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainB.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("bid") +public abstract class WithDerivedChainB implements Storable { + public abstract int getBid(); + public abstract void setBid(int id); + + public abstract int getCid(); + public abstract void setCid(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Join + public abstract WithDerivedChainC getC() throws FetchException; + public abstract void setC(WithDerivedChainC c); + + @Join + public abstract Query getAQuery() throws FetchException; +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedChainC.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainC.java new file mode 100644 index 0000000..ea1713e --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainC.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("cid") +public abstract class WithDerivedChainC implements Storable { + public abstract int getCid(); + public abstract void setCid(int id); + + public abstract int getDid(); + public abstract void setDid(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Join + public abstract WithDerivedChainD getD() throws FetchException; + public abstract void setD(WithDerivedChainD d); + + @Join + public abstract Query getBQuery() throws FetchException; +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedChainD.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainD.java new file mode 100644 index 0000000..5d10480 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedChainD.java @@ -0,0 +1,38 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("did") +public abstract class WithDerivedChainD implements Storable { + public abstract int getDid(); + public abstract void setDid(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Join + public abstract Query getCQuery() throws FetchException; +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle.java new file mode 100644 index 0000000..022375d --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle.java @@ -0,0 +1,37 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedCycle implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + @Derived(from="selfCycle") + public String getSelfCycle() { + return null; + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle2.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle2.java new file mode 100644 index 0000000..fb09989 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedCycle2.java @@ -0,0 +1,47 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedCycle2 implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + @Derived(from="b") + public String getA() { + return getB(); + } + + @Derived(from="c") + public String getB() { + return getC(); + } + + @Derived(from="a") + public String getC() { + return getA(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedDoubleObjVersion.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedDoubleObjVersion.java new file mode 100644 index 0000000..d4efb1e --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedDoubleObjVersion.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedDoubleObjVersion implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Nullable + public abstract Double getValue(); + public abstract void setValue(Double value); + + @Derived + @Version + public Double getVersion() { + return getValue(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedFloatVersion.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedFloatVersion.java new file mode 100644 index 0000000..df3c135 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedFloatVersion.java @@ -0,0 +1,44 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedFloatVersion implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract String getName(); + public abstract void setName(String name); + + public abstract float getValue(); + public abstract void setValue(float value); + + @Derived + @Version + public float getVersion() { + return getValue(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedStringVersion.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedStringVersion.java new file mode 100644 index 0000000..73ab504 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedStringVersion.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedStringVersion implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract String getName(); + public abstract void setName(String name); + + @Nullable + public abstract String getValue(); + public abstract void setValue(String value); + + @Derived + @Version + public String getVersion() { + return getValue(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithDerivedVersion.java b/src/test/java/com/amazon/carbonado/stored/WithDerivedVersion.java new file mode 100644 index 0000000..9c0d15a --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithDerivedVersion.java @@ -0,0 +1,44 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +public abstract class WithDerivedVersion implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract String getName(); + public abstract void setName(String name); + + public abstract int getValue(); + public abstract void setValue(int value); + + @Derived + @Version + public int getVersion() { + return getValue(); + } +} diff --git a/src/test/java/com/amazon/carbonado/stored/WithFunctionIndex.java b/src/test/java/com/amazon/carbonado/stored/WithFunctionIndex.java new file mode 100644 index 0000000..ad5c5db --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithFunctionIndex.java @@ -0,0 +1,50 @@ +/* + * Copyright 2007 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.amazon.carbonado.stored; + +import com.amazon.carbonado.*; + +/** + * + * + * @author Brian S O'Neill + */ +@PrimaryKey("ID") +@Indexes({@Index("average"), @Index("averageObject")}) +public abstract class WithFunctionIndex implements Storable { + public abstract int getID(); + public abstract void setID(int id); + + public abstract int getSum(); + public abstract void setSum(int sum); + + public abstract int getCount(); + public abstract void setCount(int count); + + @Derived + public double getAverage() { + return ((double) getSum()) / getCount(); + } + + @Derived + @Nullable + public Double getAverageObject() { + return ((double) getSum()) / getCount(); + } +} -- cgit v1.2.3