summaryrefslogtreecommitdiff
path: root/src/test/java/com/amazon
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-07-20 06:25:27 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-07-20 06:25:27 +0000
commited2af862bd5ac610a0ff7666afb824f29eb67306 (patch)
tree6a8833bf634d09c18fbcb1e69d8153a8fa5fc03e /src/test/java/com/amazon
parent58b7d9479070c41656c730a45625adcfcaf27b14 (diff)
Support BigInteger and BigDecimal property types.
Diffstat (limited to 'src/test/java/com/amazon')
-rw-r--r--src/test/java/com/amazon/carbonado/TestStorables.java75
-rw-r--r--src/test/java/com/amazon/carbonado/stored/WithBigDecimal.java39
-rw-r--r--src/test/java/com/amazon/carbonado/stored/WithBigInteger.java39
3 files changed, 153 insertions, 0 deletions
diff --git a/src/test/java/com/amazon/carbonado/TestStorables.java b/src/test/java/com/amazon/carbonado/TestStorables.java
index a6bab16..f630193 100644
--- a/src/test/java/com/amazon/carbonado/TestStorables.java
+++ b/src/test/java/com/amazon/carbonado/TestStorables.java
@@ -18,6 +18,9 @@
package com.amazon.carbonado;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
@@ -3013,6 +3016,78 @@ public class TestStorables extends TestCase {
*/
}
+ public void test_BigInteger() throws Exception {
+ Storage<WithBigInteger> storage = getRepository().storageFor(WithBigInteger.class);
+
+ WithBigInteger s = storage.prepare();
+ s.setId(1);
+ BigInteger bi = new BigInteger("123456789012345678901234567890");
+ s.setNumber(bi);
+ s.insert();
+
+ s = storage.prepare();
+ s.setId(1);
+ s.load();
+ assertEquals(bi, s.getNumber());
+
+ s = storage.prepare();
+ s.setId(2);
+ s.setNumber(null);
+ s.insert();
+
+ s.load();
+ assertEquals(null, s.getNumber());
+
+ Query<WithBigInteger> query = storage.query("number = ?");
+
+ s = query.with(null).loadOne();
+ assertEquals(2, s.getId());
+ assertEquals(null, s.getNumber());
+
+ s = query.with(bi).loadOne();
+ assertEquals(1, s.getId());
+ assertEquals(bi, s.getNumber());
+
+ s = query.with(BigInteger.ZERO).tryLoadOne();
+ assertEquals(null, s);
+ }
+
+ public void test_BigDecimal() throws Exception {
+ Storage<WithBigDecimal> storage = getRepository().storageFor(WithBigDecimal.class);
+
+ WithBigDecimal s = storage.prepare();
+ s.setId(1);
+ BigDecimal bd = new BigDecimal("12345678901234567890.1234567890");
+ s.setNumber(bd);
+ s.insert();
+
+ s = storage.prepare();
+ s.setId(1);
+ s.load();
+ assertEquals(bd, s.getNumber());
+
+ s = storage.prepare();
+ s.setId(2);
+ s.setNumber(null);
+ s.insert();
+
+ s.load();
+ assertEquals(null, s.getNumber());
+
+ Query<WithBigDecimal> query = storage.query("number = ?");
+
+ s = query.with(null).loadOne();
+ assertEquals(2, s.getId());
+ assertEquals(null, s.getNumber());
+
+ s = query.with(bd).loadOne();
+ assertEquals(1, s.getId());
+ assertEquals(bd, s.getNumber());
+
+ s = query.with(BigDecimal.ZERO).tryLoadOne();
+ assertEquals(null, s);
+ }
+
private void assertUninitialized(boolean expected, Storable storable, String... properties) {
for (String property : properties) {
assertEquals(expected, storable.isPropertyUninitialized(property));
diff --git a/src/test/java/com/amazon/carbonado/stored/WithBigDecimal.java b/src/test/java/com/amazon/carbonado/stored/WithBigDecimal.java
new file mode 100644
index 0000000..cb9ffe8
--- /dev/null
+++ b/src/test/java/com/amazon/carbonado/stored/WithBigDecimal.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 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 java.math.BigDecimal;
+
+import com.amazon.carbonado.*;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+@PrimaryKey("id")
+@Indexes(@Index("number"))
+public interface WithBigDecimal extends Storable {
+ int getId();
+ void setId(int id);
+
+ @Nullable
+ BigDecimal getNumber();
+ void setNumber(BigDecimal number);
+}
diff --git a/src/test/java/com/amazon/carbonado/stored/WithBigInteger.java b/src/test/java/com/amazon/carbonado/stored/WithBigInteger.java
new file mode 100644
index 0000000..f789782
--- /dev/null
+++ b/src/test/java/com/amazon/carbonado/stored/WithBigInteger.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 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 java.math.BigInteger;
+
+import com.amazon.carbonado.*;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+@PrimaryKey("id")
+@Indexes(@Index("number"))
+public interface WithBigInteger extends Storable {
+ int getId();
+ void setId(int id);
+
+ @Nullable
+ BigInteger getNumber();
+ void setNumber(BigInteger number);
+}