├── .gitignore ├── _config.yml ├── .travis.yml ├── .settings ├── org.eclipse.m2e.core.prefs └── org.eclipse.core.resources.prefs ├── .project ├── checkstyle.java.header ├── src ├── main │ └── java │ │ └── com │ │ └── jmethods │ │ └── catatumbo │ │ ├── indexers │ │ ├── package-info.java │ │ ├── UpperCaseStringIndexer.java │ │ └── LowerCaseStringIndexer.java │ │ ├── mappers │ │ ├── package-info.java │ │ ├── StringMapper.java │ │ ├── LongMapper.java │ │ ├── DoubleMapper.java │ │ ├── CharArrayMapper.java │ │ ├── BooleanMapper.java │ │ ├── ByteArrayMapper.java │ │ ├── BigDecimalMapper.java │ │ ├── KeyMapper.java │ │ └── CharMapper.java │ │ ├── package-info.java │ │ ├── impl │ │ ├── package-info.java │ │ ├── KeyMetadata.java │ │ ├── ParentKeyMetadata.java │ │ ├── StorageStrategy.java │ │ ├── EmbeddableMetadata.java │ │ ├── ExternalListenerMetadata.java │ │ ├── InternalListenerMetadata.java │ │ └── EntityListenerType.java │ │ ├── DatastoreCursor.java │ │ ├── EntityQueryRequest.java │ │ ├── stats │ │ ├── StatKind.java │ │ ├── StatKindNs.java │ │ ├── StatTotalNs.java │ │ ├── StatCompositeIndex.java │ │ ├── StatTotal.java │ │ └── StatCompositeIndexNs.java │ │ ├── Ignore.java │ │ ├── ParentKey.java │ │ ├── KeyQueryRequest.java │ │ ├── ExcludeSuperclassListeners.java │ │ ├── Unmodeled.java │ │ ├── ProjectionQueryRequest.java │ │ ├── Key.java │ │ ├── Indexer.java │ │ ├── PreDelete.java │ │ ├── PreUpdate.java │ │ ├── PostDelete.java │ │ ├── PostInsert.java │ │ ├── PostUpdate.java │ │ ├── PostUpsert.java │ │ ├── PreInsert.java │ │ ├── PreUpsert.java │ │ ├── UnsupportedConstructionStrategyException.java │ │ ├── PropertyOverrides.java │ │ ├── DefaultQueryResponseMetadata.java │ │ ├── PostLoad.java │ │ ├── TransactionalTask.java │ │ ├── Imploded.java │ │ ├── Exploded.java │ │ ├── ExcludeDefaultListeners.java │ │ ├── PropertyIndexer.java │ │ ├── PropertyOverride.java │ │ └── Mapper.java └── test │ └── java │ └── com │ └── jmethods │ └── catatumbo │ ├── entities │ ├── DeviceType.java │ ├── Color.java │ ├── UserId.java │ ├── WrappedIntegerId.java │ ├── Cow.java │ ├── Pet.java │ ├── GlobalCalculatorEntity.java │ ├── Cat.java │ ├── Lion.java │ ├── WildAnimal.java │ ├── BadBuilderEntity1.java │ ├── FarmAnimal.java │ ├── ExternalCalculatorEntity.java │ ├── GenericLongId.java │ ├── ExternalCalculatorEntity2.java │ ├── ExternalCalculatorEntity4.java │ ├── NoSetterMethodEntity.java │ ├── BadBuilderEntity2.java │ ├── NoGetterMethodEntity.java │ ├── CharField.java │ ├── ShortField.java │ ├── ShortObject.java │ ├── CharObject.java │ ├── ExternalCalculatorEntity3.java │ ├── FloatField.java │ ├── FloatObject.java │ ├── DoubleField.java │ ├── DoubleObject.java │ ├── IntegerField.java │ ├── ByteArrayField.java │ ├── IntegerObject.java │ ├── WrappedLongId.java │ ├── BooleanField.java │ ├── BooleanObject.java │ ├── LongId2.java │ ├── NoSuitableMapperEntity.java │ ├── CharArrayField.java │ ├── CustomTypeEntity.java │ ├── WrappedStringId.java │ ├── GenericListField.java │ ├── WrappedIntegerIdEntity.java │ ├── StringId2.java │ ├── Dog.java │ ├── LongListField.java │ ├── EnumField.java │ ├── StringListField.java │ ├── DateField.java │ ├── UnindexedByteArrayField.java │ ├── LongField.java │ ├── CalendarField.java │ ├── LongObject.java │ ├── WrappedLongObjectId.java │ ├── KeyListField.java │ ├── InternalCalculatorEntity.java │ ├── UnindexedStringField.java │ ├── OptionalVersion.java │ ├── TaskName.java │ ├── NoDefaultConstrctorEntity.java │ ├── EmbeddedList.java │ ├── LocalDateField.java │ ├── LocalTimeField.java │ ├── BadBuilderEntity4.java │ ├── LocalDateTimeField.java │ ├── ZonedDateTimeField.java │ ├── OffsetDateTimeField.java │ ├── OptionalCreatedTimestamp.java │ ├── Animal.java │ ├── NoSetterMethodEntity2.java │ └── BadBuilderEntity3.java │ ├── listeners │ ├── BadInternalListener4.java │ ├── BadInternalListener3.java │ ├── BadInternalListener1.java │ ├── BadInternalListener2.java │ ├── BadExternalListener1.java │ ├── BadExternalListener3.java │ ├── GoodExternalListener1.java │ ├── AnimalListener.java │ ├── FarmAnimalListener.java │ └── BadExternalListener2.java │ ├── mappers │ └── AllTests.java │ ├── indexers │ └── AllTests.java │ ├── impl │ └── AllTests.java │ ├── TenantTest.java │ ├── CustomTypeTest.java │ └── IndexerFactoryTest.java └── .classpath /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | dist: trusty 3 | after_success: 4 | - mvn clean test jacoco:report coveralls:report 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | catatumbo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /checkstyle.java.header: -------------------------------------------------------------------------------- 1 | ^/\*$ 2 | ^ \* Copyright \d\d\d\d Sai Pullabhotla\.$ 3 | ^ \*$ 4 | ^ \* Licensed under the Apache License, Version 2\.0 \(the "License"\);$ 5 | ^ \* you may not use this file except in compliance with the License\.$ 6 | ^ \* You may obtain a copy of the License at$ 7 | ^ \*$ 8 | ^ \* http://www.apache.org/licenses/LICENSE-2\.0$ 9 | ^ \*$ 10 | ^ \* Unless required by applicable law or agreed to in writing, software$ 11 | ^ \* distributed under the License is distributed on an "AS IS" BASIS,$ 12 | ^ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.$ 13 | ^ \* See the License for the specific language governing permissions and$ 14 | ^ \* limitations under the License\.$ 15 | ^ \*/$ -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/indexers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains various indexers for indexing the entity properties. 19 | */ 20 | 21 | package com.jmethods.catatumbo.indexers; -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains various mappers for mapping model fields to entity properties and vice versa. 19 | */ 20 | 21 | package com.jmethods.catatumbo.mappers; -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains the public API for mapping and persisting model objects to the Google Cloud 19 | * Datastore and vice versa. 20 | */ 21 | 22 | package com.jmethods.catatumbo; -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/DeviceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public enum DeviceType { 24 | 25 | DESKTOP, TABLET, SMARTPHONE; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Color.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public enum Color { 24 | 25 | WHITE, BLACK, RED, YELLOW, PURPLE, GOLD, SILVER, BLUE, PINK; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/UserId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public class UserId extends GenericLongId { 24 | 25 | /** 26 | * @param value 27 | */ 28 | public UserId(long value) { 29 | super(value); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains the implementation classes for the Catatumbo API. All classes in this 19 | * package are internal to the functioning of the API and you should never use any of these classes 20 | * directly in your application's code. 21 | * 22 | */ 23 | 24 | package com.jmethods.catatumbo.impl; -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadInternalListener4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadInternalListener4 { 28 | 29 | @PreInsert 30 | private void beforeInsert() { 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WrappedIntegerId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public class WrappedIntegerId { 24 | 25 | private int value; 26 | 27 | public WrappedIntegerId(int value) { 28 | this.value = value; 29 | } 30 | 31 | public int getValue() { 32 | return value; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadInternalListener3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadInternalListener3 { 28 | 29 | @PreInsert 30 | public static void beforeInsert() { 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadInternalListener1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadInternalListener1 { 28 | 29 | @PreInsert 30 | public void beforeInsert(Object obj) { 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadInternalListener2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadInternalListener2 { 28 | 29 | @PreInsert 30 | public int beforeInsert() { 31 | return 0; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadExternalListener1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.PostInsert; 20 | 21 | /** 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | public class BadExternalListener1 { 26 | 27 | @PostInsert 28 | public void afterInsert(Object obj) { 29 | System.out.printf("Object %s of type %s inserted\n", obj, obj.getClass().getName()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/mappers/AllTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | import org.junit.runners.Suite.SuiteClasses; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @RunWith(Suite.class) 28 | @SuiteClasses({ DecimalMapperTest.class, FloatMapperTest.class, OffsetDateTimeMapperTest.class, 29 | ZonedDateTimeMapperTest.class }) 30 | public class AllTests { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/DatastoreCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * Defines a contract for Datastore Cursors. Cursors are used to indicate the starting/ending point 21 | * of a result set. 22 | * 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | public interface DatastoreCursor { 27 | 28 | /** 29 | * Returns the encoded value of this cursor as a String. 30 | * 31 | * @return the encoded value of this cursor. 32 | */ 33 | String getEncoded(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/indexers/AllTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.indexers; 18 | 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | import org.junit.runners.Suite.SuiteClasses; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @RunWith(Suite.class) 28 | @SuiteClasses({ LowerCaseStringIndexerTest.class, LowerCaseStringListIndexerTest.class, 29 | UpperCaseStringIndexerTest.class, UpperCaseStringListIndexerTest.class }) 30 | public class AllTests { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Cow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class Cow extends FarmAnimal { 28 | 29 | @PreInsert 30 | public void insertingCow() { 31 | if (value.trim().length() > 0) { 32 | value += "->"; 33 | } 34 | value += Cow.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Pet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.MappedSuperClass; 20 | import com.jmethods.catatumbo.PreInsert; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @MappedSuperClass 27 | public class Pet extends Animal { 28 | @PreInsert 29 | public void insertingPet() { 30 | if (value.trim().length() > 0) { 31 | value += "->"; 32 | } 33 | value += Pet.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadExternalListener3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.EntityListener; 20 | import com.jmethods.catatumbo.PreInsert; 21 | import com.jmethods.catatumbo.PreUpdate; 22 | import com.jmethods.catatumbo.PreUpsert; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @EntityListener 29 | public class BadExternalListener3 { 30 | 31 | @PreInsert 32 | @PreUpdate 33 | @PreUpsert 34 | public void beforePersist() { 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/EntityQueryRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * QueryRequest implementation for running full entity queries. 21 | * 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | public class EntityQueryRequest extends BaseQueryRequest { 26 | 27 | /** 28 | * Creates a new instance of EntityQueryRequest. 29 | * 30 | * @param query 31 | * the GQL query string 32 | */ 33 | public EntityQueryRequest(String query) { 34 | super(query); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistics by Kind, across all namespaces. 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_KIND) 30 | public class StatKind extends StatKindBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = 2549703734475617627L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/KeyMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | /** 22 | * Objects of this class contain the metadata about an entity's full key. 23 | * 24 | * @author Sai Pullabhotla 25 | */ 26 | public class KeyMetadata extends FieldMetadata { 27 | 28 | /** 29 | * Creates a new instance of KeyMetadata. 30 | * 31 | * @param field 32 | * the field. 33 | */ 34 | public KeyMetadata(Field field) { 35 | super(field); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatKindNs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistics by Kind, in a specific namespace. 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_KIND_NS) 30 | public class StatKindNs extends StatKindBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = -8766112901529363944L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Ignore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Specifies that an entity field should be ignored by the EntityManager when saving or loading the 26 | * entities. 27 | * 28 | * @author Sai Pullabhotla 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.FIELD) 32 | public @interface Ignore { 33 | // Simple marker. 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatTotalNs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistic entity that contains summary of a namespace. 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_TOTAL_NS) 30 | public class StatTotalNs extends StatTotalBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = -5834153984732391563L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/ParentKeyMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | /** 22 | * Objects of this class contain the metadata about parent key of an entity. 23 | * 24 | * @author Sai Pullabhotla 25 | */ 26 | public class ParentKeyMetadata extends KeyMetadata { 27 | 28 | /** 29 | * Creates a new instance of ParentKeyMetadata. 30 | * 31 | * @param field 32 | * the field 33 | */ 34 | public ParentKeyMetadata(Field field) { 35 | super(field); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/impl/AllTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | import org.junit.runners.Suite.SuiteClasses; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @RunWith(Suite.class) 28 | @SuiteClasses({ EntityIntrospectorTest.class, ExternalListenerIntrospectorTest.class, 29 | InternalListenerIntrospectorTest.class, IntrospectionUtilsTest.class, LRUCacheTest.class, 30 | MarshallerTest.class, UnmarshallerTest.class }) 31 | public class AllTests { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatCompositeIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistic entity for composite indexes. 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_COMPOSITE_INDEX) 30 | public class StatCompositeIndex extends StatCompositeIndexBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = 7142034196925336326L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/StorageStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import com.jmethods.catatumbo.Embedded; 20 | 21 | /** 22 | * Storage strategies for {@link Embedded} fields. 23 | * 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | public enum StorageStrategy { 28 | 29 | /** 30 | * The object tree of {@link Embedded} field is exploded into individual properties. 31 | */ 32 | EXPLODED, 33 | 34 | /** 35 | * The object tree of {@link Embedded} field is stored in a single property as an Embedded Entity. 36 | */ 37 | IMPLODED; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatTotal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistic entity that contains summary of the Datastore usage (all namespaces). 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_TOTAL) 30 | public class StatTotal extends StatTotalBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = -8279421156053694066L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/GlobalCalculatorEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | 21 | /** 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | @Entity 26 | public class GlobalCalculatorEntity extends CalculatorEntity { 27 | 28 | /** 29 | * 30 | */ 31 | public GlobalCalculatorEntity() { 32 | super(); 33 | } 34 | 35 | /** 36 | * @param operand1 37 | * @param operand2 38 | */ 39 | public GlobalCalculatorEntity(long operand1, long operand2) { 40 | super(operand1, operand2); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/EmbeddableMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import com.jmethods.catatumbo.Embeddable; 20 | 21 | /** 22 | * Objects of this class contain metadata of an {@link Embeddable} class. 23 | * 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | public class EmbeddableMetadata extends MetadataBase { 28 | 29 | /** 30 | * Creates a new instance of EmbeddableMetadata. 31 | * 32 | * @param clazz 33 | * the Embeddable class 34 | */ 35 | public EmbeddableMetadata(Class clazz) { 36 | super(clazz); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/ExternalListenerMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | /** 20 | * Metadata of an EntityListener. 21 | * 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | public class ExternalListenerMetadata extends AbstractListenerMetadata { 26 | 27 | /** 28 | * Creates a new instance of ExternalListenerMetadata. 29 | * 30 | * @param listenerClass 31 | * the listener class to which this metadata belongs. 32 | */ 33 | public ExternalListenerMetadata(Class listenerClass) { 34 | super(listenerClass); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/stats/StatCompositeIndexNs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.stats; 18 | 19 | import java.io.Serializable; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | 23 | /** 24 | * Statistic entity for namespace specific composite index. 25 | * 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity(kind = StatConstants.STAT_COMPOSITE_INDEX_NS) 30 | public class StatCompositeIndexNs extends StatCompositeIndexBase implements Serializable { 31 | 32 | /** 33 | * Serial version UID 34 | */ 35 | private static final long serialVersionUID = -2593351832953284028L; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/GoodExternalListener1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.EntityListener; 20 | import com.jmethods.catatumbo.PostLoad; 21 | import com.jmethods.catatumbo.PreInsert; 22 | import com.jmethods.catatumbo.PreUpdate; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @EntityListener 29 | public class GoodExternalListener1 { 30 | 31 | @PreInsert 32 | @PreUpdate 33 | public void preInsert(Object obj) { 34 | 35 | } 36 | 37 | @PostLoad 38 | public void afterLoad(Object entity) { 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/ParentKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Fields annotated as ParentKey hold the parent key information, if any. Only one 26 | * field can be annotated with this annotation in a given Entity. 27 | * 28 | * @author Sai Pullabhotla 29 | */ 30 | @Target(ElementType.FIELD) 31 | @Retention(RetentionPolicy.RUNTIME) 32 | public @interface ParentKey { 33 | // Marker 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Cat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.ExcludeDefaultListeners; 21 | import com.jmethods.catatumbo.PreInsert; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | @ExcludeDefaultListeners 29 | public class Cat extends Pet { 30 | 31 | @PreInsert 32 | public void insertingCat() { 33 | if (value.trim().length() > 0) { 34 | value += "->"; 35 | } 36 | value += Cat.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Lion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.ExcludeDefaultListeners; 21 | import com.jmethods.catatumbo.PreInsert; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | @ExcludeDefaultListeners 29 | public class Lion extends WildAnimal { 30 | @PreInsert 31 | public void insertingLion() { 32 | if (value.trim().length() > 0) { 33 | value += "->"; 34 | } 35 | value += Lion.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/InternalListenerMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | /** 20 | * Metadata of listeners defined in an entity or mapped super class. 21 | * 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | public class InternalListenerMetadata extends AbstractListenerMetadata { 26 | 27 | /** 28 | * Creates a new instance of InternalListenerMetadata. 29 | * 30 | * @param listenerClass 31 | * the listener class to which this metadata belongs. 32 | */ 33 | public InternalListenerMetadata(Class listenerClass) { 34 | super(listenerClass); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WildAnimal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.ExcludeSuperclassListeners; 20 | import com.jmethods.catatumbo.MappedSuperClass; 21 | import com.jmethods.catatumbo.PreInsert; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @MappedSuperClass 28 | @ExcludeSuperclassListeners 29 | public class WildAnimal extends Animal { 30 | @PreInsert 31 | public void insertingWildAnimal() { 32 | if (value.trim().length() > 0) { 33 | value += "->"; 34 | } 35 | value += WildAnimal.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/KeyQueryRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * An implementation of {@link QueryRequest} for executing key-only queries. Key-only queries must 21 | * only have __key__ in the SELECT list of fields, with optional WHERE or ORDER BY 22 | * clauses. 23 | * 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | public class KeyQueryRequest extends BaseQueryRequest { 28 | 29 | /** 30 | * Creates a new instance of KeyQueryRequest. 31 | * 32 | * @param query 33 | * the query 34 | */ 35 | public KeyQueryRequest(String query) { 36 | super(query); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/ExcludeSuperclassListeners.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.TYPE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Specifies that the execution of listeners defined in the super class should be excluded. This 27 | * annotation can be specified on an {@link Entity} or {@link MappedSuperClass}. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | @Retention(RUNTIME) 33 | @Target(TYPE) 34 | public @interface ExcludeSuperclassListeners { 35 | // Marker 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Unmodeled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import java.util.Map; 24 | 25 | /** 26 | * NOT IMPLEMENTED YET. A {@link Map} field in an entity can be annotated with this annotation to 27 | * hold all unmodeled (or custom) fields. Only one field can have this annotation in a given entity. 28 | * 29 | * @author Sai Pullabhotla 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.FIELD) 33 | public @interface Unmodeled { 34 | // Marker 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/ProjectionQueryRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * An implementation of {@link QueryRequest} to execute projection queries. Projection queries are 21 | * used for retrieving a subset of entity's properties instead of retrieving all of them. 22 | * 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | public class ProjectionQueryRequest extends BaseQueryRequest { 27 | 28 | /** 29 | * Creates a new instance of ProjectionQueryRequest. 30 | * 31 | * @param query 32 | * the GQL projection query 33 | */ 34 | public ProjectionQueryRequest(String query) { 35 | super(query); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/TenantTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNull; 21 | 22 | import org.junit.Test; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | public class TenantTest { 29 | 30 | @Test 31 | public void test1() { 32 | assertNull(Tenant.getNamespace()); 33 | } 34 | 35 | @Test 36 | public void test2() { 37 | String oldNamespace = Tenant.getNamespace(); 38 | Tenant.setNamespace(Thread.currentThread().getName()); 39 | assertEquals(Thread.currentThread().getName(), Tenant.getNamespace()); 40 | Tenant.setNamespace(oldNamespace); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/AnimalListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.EntityListener; 20 | import com.jmethods.catatumbo.PreInsert; 21 | import com.jmethods.catatumbo.entities.Animal; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @EntityListener 28 | public class AnimalListener { 29 | 30 | @PreInsert 31 | public void beforeInsert(Animal animal) { 32 | String value = animal.getValue(); 33 | if (value.trim().length() > 0) { 34 | value += "->"; 35 | } 36 | value += AnimalListener.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 37 | animal.setValue(value); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Key.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Fields annotated with this annotation in an Entity hold the full key of the entity. Full key 26 | * includes the ancestor paths and the key of the entity. Only one field can be annotated as Key in 27 | * a given entity. The type of field must be {@link DatastoreKey}. 28 | * 29 | * @author Sai Pullabhotla 30 | */ 31 | @Target(ElementType.FIELD) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | public @interface Key { 34 | // Markers 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BadBuilderEntity1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadBuilderEntity1 { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private String name; 33 | 34 | public BadBuilderEntity1(String name) { 35 | this.name = name; 36 | } 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @return the name 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Indexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import com.google.cloud.datastore.Value; 20 | 21 | /** 22 | * Contract for building secondary indexes for entity properties. An implementation of Indexer must 23 | * have a public default (a.k.a no-argument) constructor. 24 | * 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | public interface Indexer { 29 | 30 | /** 31 | * Returns indexed value for the given input. 32 | * 33 | * @param input 34 | * the input, this is the output from the {@link Mapper} that is associated with the 35 | * entity's field. 36 | * @return the indexed value 37 | */ 38 | Value index(Value input); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/FarmAnimal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.EntityListeners; 20 | import com.jmethods.catatumbo.MappedSuperClass; 21 | import com.jmethods.catatumbo.PreInsert; 22 | import com.jmethods.catatumbo.listeners.FarmAnimalListener; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @MappedSuperClass 29 | @EntityListeners(FarmAnimalListener.class) 30 | public class FarmAnimal extends Animal { 31 | @PreInsert 32 | public void insertingWildAnimal() { 33 | if (value.trim().length() > 0) { 34 | value += "->"; 35 | } 36 | value += FarmAnimal.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/FarmAnimalListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.EntityListener; 20 | import com.jmethods.catatumbo.PreInsert; 21 | import com.jmethods.catatumbo.entities.FarmAnimal; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @EntityListener 28 | public class FarmAnimalListener { 29 | 30 | @PreInsert 31 | public void beforeInsert(FarmAnimal farmAnimal) { 32 | String value = farmAnimal.getValue(); 33 | if (value.trim().length() > 0) { 34 | value += "->"; 35 | } 36 | value += FarmAnimalListener.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 37 | farmAnimal.setValue(value); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ExternalCalculatorEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.EntityListeners; 21 | import com.jmethods.catatumbo.listeners.Adder; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | @EntityListeners(Adder.class) 29 | public class ExternalCalculatorEntity extends CalculatorEntity { 30 | 31 | /** 32 | * 33 | */ 34 | public ExternalCalculatorEntity() { 35 | super(); 36 | } 37 | 38 | /** 39 | * @param operand1 40 | * @param operand2 41 | */ 42 | public ExternalCalculatorEntity(long operand1, long operand2) { 43 | super(operand1, operand2); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/GenericLongId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public class GenericLongId { 24 | 25 | private long value; 26 | 27 | public GenericLongId(long value) { 28 | this.value = value; 29 | } 30 | 31 | /** 32 | * @return the value 33 | */ 34 | public long getValue() { 35 | return value; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) { 41 | return true; 42 | } 43 | if (obj != null && !(obj instanceof GenericLongId)) { 44 | return false; 45 | } 46 | GenericLongId that = (GenericLongId) obj; 47 | return this.value == that.value; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PreDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * before deleting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PreDelete { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PreUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * before updating an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PreUpdate { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PostDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * after deleting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PostDelete { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PostInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * after inserting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PostInsert { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PostUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * after updating an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PostUpdate { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PostUpsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * after upserting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PostUpsert { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PreInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * before inserting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PreInsert { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PreUpsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * before upserting an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | * @see EntityListeners 31 | * @see EntityListener 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(METHOD) 38 | public @interface PreUpsert { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/UnsupportedConstructionStrategyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * An exception to indicate that a persistence class does not have a supported 21 | * construction/instantiation mechanism. 22 | * 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | public class UnsupportedConstructionStrategyException extends EntityManagerException { 27 | 28 | /** 29 | * Serial version UID 30 | */ 31 | private static final long serialVersionUID = -1012347475989414105L; 32 | 33 | /** 34 | * Creates a new instance of {@code UnsupportedConstructionStrategyException}. 35 | * 36 | * @param message 37 | * the message 38 | */ 39 | public UnsupportedConstructionStrategyException(String message) { 40 | super(message); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ExternalCalculatorEntity2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.EntityListeners; 21 | import com.jmethods.catatumbo.listeners.Adder; 22 | import com.jmethods.catatumbo.listeners.Multiplier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | @EntityListeners({ Adder.class, Multiplier.class }) 30 | public class ExternalCalculatorEntity2 extends CalculatorEntity { 31 | 32 | /** 33 | * 34 | */ 35 | public ExternalCalculatorEntity2() { 36 | super(); 37 | } 38 | 39 | /** 40 | * @param operand1 41 | * @param operand2 42 | */ 43 | public ExternalCalculatorEntity2(long operand1, long operand2) { 44 | super(operand1, operand2); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ExternalCalculatorEntity4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.EntityListeners; 21 | import com.jmethods.catatumbo.listeners.Adder; 22 | import com.jmethods.catatumbo.listeners.Multiplier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | @EntityListeners({ Adder.class, Multiplier.class }) 30 | public class ExternalCalculatorEntity4 extends CalculatorEntity { 31 | 32 | /** 33 | * 34 | */ 35 | public ExternalCalculatorEntity4() { 36 | super(); 37 | } 38 | 39 | /** 40 | * @param operand1 41 | * @param operand2 42 | */ 43 | public ExternalCalculatorEntity4(long operand1, long operand2) { 44 | super(operand1, operand2); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/NoSetterMethodEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | public class NoSetterMethodEntity { 29 | 30 | @Identifier 31 | private long id; 32 | 33 | @Property 34 | private String name; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the name 53 | */ 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PropertyOverrides.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.TYPE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used to override mappings of properties. Typically used if the entity contains {@link Embedded} 27 | * objects or inherits a {@link MappedSuperClass}. This annotation must be applied to an 28 | * {@link Entity} only. 29 | * 30 | * @author Sai Pullabhotla 31 | * 32 | */ 33 | @Retention(RUNTIME) 34 | @Target(TYPE) 35 | public @interface PropertyOverrides { 36 | 37 | /** 38 | * One or more property overrides. 39 | * 40 | * @return the property overrides 41 | */ 42 | PropertyOverride[] value(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BadBuilderEntity2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadBuilderEntity2 { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private String name; 33 | 34 | public BadBuilderEntity2(String name) { 35 | 36 | } 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @return the name 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | // Non-static - error 53 | public Builder newBuilder() { 54 | return new Builder(); 55 | } 56 | 57 | public static class Builder { 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/DefaultQueryResponseMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * Default implementation of {@link QueryResponseMetadata} interface. 21 | * 22 | * @author Matthew Tso 23 | */ 24 | public class DefaultQueryResponseMetadata implements QueryResponseMetadata { 25 | 26 | /** 27 | * The query state metadata value. 28 | */ 29 | private QueryResponseMetadata.QueryState queryState; 30 | 31 | /** 32 | * Creates a new instance of @code{DefaultQueryResponseMetadata}. 33 | * 34 | * @param queryState 35 | * the query execution state 36 | */ 37 | public DefaultQueryResponseMetadata(QueryResponseMetadata.QueryState queryState) { 38 | this.queryState = queryState; 39 | } 40 | 41 | @Override 42 | public QueryResponseMetadata.QueryState getQueryState() { 43 | return queryState; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/NoGetterMethodEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | public class NoGetterMethodEntity { 29 | 30 | @Identifier 31 | private long id; 32 | 33 | @Property 34 | private String name; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @param name 53 | * the name to set 54 | */ 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PostLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used for annotating a method as an entity listener method. The annotated method will be invoked 27 | * after loading an entity. This annotation can be applied to a method within an {@link Entity}, 28 | * {@link MappedSuperClass} or an {@link EntityListener}. 29 | * 30 | *

31 | * Note that PostLoad callback is NOT invoked for projection queries. 32 | *

33 | * 34 | * @see EntityListeners 35 | * @see EntityListener 36 | * 37 | * @author Sai Pullabhotla 38 | * 39 | */ 40 | @Retention(RUNTIME) 41 | @Target(METHOD) 42 | public @interface PostLoad { 43 | // Marker 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/CharField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class CharField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private char sex; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the sex 51 | */ 52 | public char getSex() { 53 | return sex; 54 | } 55 | 56 | /** 57 | * @param sex 58 | * the sex to set 59 | */ 60 | public void setSex(char sex) { 61 | this.sex = sex; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ShortField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class ShortField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private short age; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the age 51 | */ 52 | public short getAge() { 53 | return age; 54 | } 55 | 56 | /** 57 | * @param age 58 | * the age to set 59 | */ 60 | public void setAge(short age) { 61 | this.age = age; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ShortObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class ShortObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Short age; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the age 51 | */ 52 | public Short getAge() { 53 | return age; 54 | } 55 | 56 | /** 57 | * @param age 58 | * the age to set 59 | */ 60 | public void setAge(Short age) { 61 | this.age = age; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/CharObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class CharObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Character sex; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the sex 51 | */ 52 | public Character getSex() { 53 | return sex; 54 | } 55 | 56 | /** 57 | * @param sex 58 | * the sex to set 59 | */ 60 | public void setSex(Character sex) { 61 | this.sex = sex; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ExternalCalculatorEntity3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.EntityListeners; 21 | import com.jmethods.catatumbo.ExcludeDefaultListeners; 22 | import com.jmethods.catatumbo.listeners.Adder; 23 | import com.jmethods.catatumbo.listeners.Multiplier; 24 | 25 | /** 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity 30 | @EntityListeners({ Adder.class, Multiplier.class }) 31 | @ExcludeDefaultListeners 32 | public class ExternalCalculatorEntity3 extends CalculatorEntity { 33 | 34 | /** 35 | * 36 | */ 37 | public ExternalCalculatorEntity3() { 38 | super(); 39 | } 40 | 41 | /** 42 | * @param operand1 43 | * @param operand2 44 | */ 45 | public ExternalCalculatorEntity3(long operand1, long operand2) { 46 | super(operand1, operand2); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/FloatField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class FloatField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private float area; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the area 51 | */ 52 | public float getArea() { 53 | return area; 54 | } 55 | 56 | /** 57 | * @param area 58 | * the area to set 59 | */ 60 | public void setArea(float area) { 61 | this.area = area; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/FloatObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class FloatObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Float area; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the area 51 | */ 52 | public Float getArea() { 53 | return area; 54 | } 55 | 56 | /** 57 | * @param area 58 | * the area to set 59 | */ 60 | public void setArea(Float area) { 61 | this.area = area; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/DoubleField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class DoubleField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private double area; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the area 51 | */ 52 | public double getArea() { 53 | return area; 54 | } 55 | 56 | /** 57 | * @param area 58 | * the area to set 59 | */ 60 | public void setArea(double area) { 61 | this.area = area; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/DoubleObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class DoubleObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Double area; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the area 51 | */ 52 | public Double getArea() { 53 | return area; 54 | } 55 | 56 | /** 57 | * @param area 58 | * the area to set 59 | */ 60 | public void setArea(Double area) { 61 | this.area = area; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/IntegerField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class IntegerField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private int count; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the count 51 | */ 52 | public int getCount() { 53 | return count; 54 | } 55 | 56 | /** 57 | * @param count 58 | * the count to set 59 | */ 60 | public void setCount(int count) { 61 | this.count = count; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ByteArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class ByteArrayField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private byte[] salt; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the salt 51 | */ 52 | public byte[] getSalt() { 53 | return salt; 54 | } 55 | 56 | /** 57 | * @param salt 58 | * the salt to set 59 | */ 60 | public void setSalt(byte[] salt) { 61 | this.salt = salt; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/TransactionalTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | /** 20 | * Interface for Callbacks to run Datastore operations within a Transaction. 21 | * 22 | * @author Sai Pullabhotla 23 | * @param 24 | * the result type of this {@code TransactionalTask}. 25 | * @see EntityManager#executeInTransaction(TransactionalTask) 26 | * 27 | */ 28 | @FunctionalInterface 29 | public interface TransactionalTask { 30 | 31 | /** 32 | * Executes the task. After the execute method finishes normally, the transaction will be 33 | * committed by the {@link EntityManager}. If the execute method throws any exception, the 34 | * transaction will be rolled back. 35 | * 36 | * @param transaction 37 | * the transaction to read from/write to the Cloud Datastore. 38 | * @return the result of execution 39 | */ 40 | T execute(DatastoreTransaction transaction); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/IntegerObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class IntegerObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Integer count; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the count 51 | */ 52 | public Integer getCount() { 53 | return count; 54 | } 55 | 56 | /** 57 | * @param count 58 | * the count to set 59 | */ 60 | public void setCount(Integer count) { 61 | this.count = count; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WrappedLongId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public class WrappedLongId { 24 | 25 | private long value; 26 | 27 | public WrappedLongId(long value) { 28 | this.value = value; 29 | } 30 | 31 | public long getValue() { 32 | return value; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | StringBuilder builder = new StringBuilder(); 38 | builder.append("WrappedLongId [value=").append(value).append("]"); 39 | return builder.toString(); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) { 45 | return true; 46 | } 47 | if (obj == null || !this.getClass().equals(obj.getClass())) { 48 | return false; 49 | } 50 | WrappedLongId that = (WrappedLongId) obj; 51 | return this.value == that.value; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BooleanField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BooleanField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private boolean awesome; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the awesome 51 | */ 52 | public boolean isAwesome() { 53 | return awesome; 54 | } 55 | 56 | /** 57 | * @param awesome 58 | * the awesome to set 59 | */ 60 | public void setAwesome(boolean awesome) { 61 | this.awesome = awesome; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BooleanObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BooleanObject { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Boolean awesome; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the awesome 51 | */ 52 | public Boolean getAwesome() { 53 | return awesome; 54 | } 55 | 56 | /** 57 | * @param awesome 58 | * the awesome to set 59 | */ 60 | public void setAwesome(Boolean awesome) { 61 | this.awesome = awesome; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LongId2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class LongId2 { 28 | 29 | @Identifier(autoGenerated = false) 30 | private long id; 31 | 32 | private String field1; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the field1 51 | */ 52 | public String getField1() { 53 | return field1; 54 | } 55 | 56 | /** 57 | * @param field1 58 | * the field1 to set 59 | */ 60 | public void setField1(String field1) { 61 | this.field1 = field1; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/NoSuitableMapperEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.net.URL; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class NoSuitableMapperEntity { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private URL url; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the url 53 | */ 54 | public URL getUrl() { 55 | return url; 56 | } 57 | 58 | /** 59 | * @param url 60 | * the url to set 61 | */ 62 | public void setUrl(URL url) { 63 | this.url = url; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/CharArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class CharArrayField { 28 | @Identifier 29 | private long id; 30 | 31 | private char[] password; 32 | 33 | /** 34 | * @return the id 35 | */ 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | /** 41 | * @param id 42 | * the id to set 43 | */ 44 | public void setId(long id) { 45 | this.id = id; 46 | } 47 | 48 | /** 49 | * @return the password 50 | */ 51 | public char[] getPassword() { 52 | return password; 53 | } 54 | 55 | /** 56 | * @param password 57 | * the password to set 58 | */ 59 | public void setPassword(char[] password) { 60 | this.password = password; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/CustomTypeEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class CustomTypeEntity { 28 | @Identifier 29 | private Long id; 30 | 31 | private byte byteField; 32 | 33 | /** 34 | * @return the id 35 | */ 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | /** 41 | * @param id 42 | * the id to set 43 | */ 44 | public void setId(Long id) { 45 | this.id = id; 46 | } 47 | 48 | /** 49 | * @return the byteField 50 | */ 51 | public byte getByteField() { 52 | return byteField; 53 | } 54 | 55 | /** 56 | * @param byteField 57 | * the byteField to set 58 | */ 59 | public void setByteField(byte byteField) { 60 | this.byteField = byteField; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WrappedStringId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | /** 20 | * @author Sai Pullabhotla 21 | * 22 | */ 23 | public class WrappedStringId { 24 | 25 | private String value; 26 | 27 | public WrappedStringId(String value) { 28 | this.value = value; 29 | } 30 | 31 | public String getValue() { 32 | return value; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | StringBuilder builder = new StringBuilder(); 38 | builder.append("WrappedStringId [value=").append(value).append("]"); 39 | return builder.toString(); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) { 45 | return true; 46 | } 47 | if (obj == null || !this.getClass().equals(obj.getClass())) { 48 | return false; 49 | } 50 | WrappedStringId that = (WrappedStringId) obj; 51 | return this.value == that.value; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/CustomTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import com.jmethods.catatumbo.custommappers.ByteMapper; 25 | import com.jmethods.catatumbo.entities.CustomTypeEntity; 26 | 27 | /** 28 | * @author Sai Pullabhotla 29 | * 30 | */ 31 | 32 | public class CustomTypeTest { 33 | 34 | private static EntityManager em = null; 35 | 36 | @BeforeClass 37 | public static void setUpBeforeClass() throws Exception { 38 | MapperFactory.getInstance().setDefaultMapper(byte.class, new ByteMapper()); 39 | em = TestUtils.getEntityManager(); 40 | } 41 | 42 | @Test 43 | public void testInsert() { 44 | CustomTypeEntity entity = new CustomTypeEntity(); 45 | entity.setByteField((byte) 65); 46 | entity = em.insert(entity); 47 | assertEquals((byte) 65, entity.getByteField()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/GenericListField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.List; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class GenericListField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private List items; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the items 53 | */ 54 | public List getItems() { 55 | return items; 56 | } 57 | 58 | /** 59 | * @param items 60 | * the items to set 61 | */ 62 | public void setItems(List items) { 63 | this.items = items; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WrappedIntegerIdEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class WrappedIntegerIdEntity { 28 | 29 | @Identifier 30 | private WrappedIntegerId id; 31 | 32 | private String name; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public WrappedIntegerId getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(WrappedIntegerId id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the name 51 | */ 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | /** 57 | * @param name 58 | * the name to set 59 | */ 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/StringId2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class StringId2 { 28 | @Identifier(autoGenerated = false) 29 | private String id; 30 | private String greetings; 31 | 32 | /** 33 | * @return the id 34 | */ 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | /** 40 | * @param id 41 | * the id to set 42 | */ 43 | public void setId(String id) { 44 | this.id = id; 45 | } 46 | 47 | /** 48 | * @return the greetings 49 | */ 50 | public String getGreetings() { 51 | return greetings; 52 | } 53 | 54 | /** 55 | * @param greetings 56 | * the greetings to set 57 | */ 58 | public void setGreetings(String greetings) { 59 | this.greetings = greetings; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Imploded.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Specifies that the {@link Embedded} object of an {@link Entity} should be stored using the 27 | * Imploded strategy. With Imploded strategy, the {@link Embedded} object of an entity is stored in 28 | * a single field as an Embedded Entity in the Datastore. This annotation can be added to any 29 | * {@link Embedded} field of an {@link Entity} or {@link MappedSuperClass}. Having this annotation 30 | * on a nested Embedded object will not have any effect as the storage strategy is enforced at the 31 | * entity level. 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(FIELD) 38 | public @interface Imploded { 39 | // Markers 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Dog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.ExcludeDefaultListeners; 21 | import com.jmethods.catatumbo.ExcludeSuperclassListeners; 22 | import com.jmethods.catatumbo.PostInsert; 23 | import com.jmethods.catatumbo.PreInsert; 24 | 25 | /** 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity 30 | @ExcludeSuperclassListeners 31 | @ExcludeDefaultListeners 32 | public class Dog extends Pet { 33 | 34 | @PreInsert 35 | public void insertingDog() { 36 | if (value.trim().length() > 0) { 37 | value += "->"; 38 | } 39 | value += Dog.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 40 | } 41 | 42 | @PostInsert 43 | public void dogInserted() { 44 | if (value.trim().length() > 0) { 45 | value += "->"; 46 | } 47 | value += Dog.class.getSimpleName() + "." + PostInsert.class.getSimpleName(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LongListField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.List; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class LongListField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private List numbers; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the list 53 | */ 54 | public List getNumbers() { 55 | return numbers; 56 | } 57 | 58 | /** 59 | * @param numbers 60 | * the list to set 61 | */ 62 | public void setNumbers(List numbers) { 63 | this.numbers = numbers; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/StringMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.NullValue; 20 | import com.google.cloud.datastore.StringValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | 25 | /** 26 | * An implementation of {@link Mapper} for mapping String types to/from the Cloud Datastore. 27 | * 28 | * @author Sai Pullabhotla 29 | * 30 | */ 31 | public class StringMapper implements Mapper { 32 | 33 | @Override 34 | public ValueBuilder toDatastore(Object input) { 35 | if (input == null) { 36 | return NullValue.newBuilder(); 37 | } 38 | return StringValue.newBuilder((String) input); 39 | } 40 | 41 | @Override 42 | public Object toModel(Value input) { 43 | if (input instanceof NullValue) { 44 | return null; 45 | } 46 | return ((StringValue) input).get(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/EnumField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class EnumField { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private Size size; 33 | 34 | public enum Size { 35 | SMALL, MEDIUM, LARGE, EXTRA_LARGE; 36 | } 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @param id 47 | * the id to set 48 | */ 49 | public void setId(long id) { 50 | this.id = id; 51 | } 52 | 53 | /** 54 | * @return the size 55 | */ 56 | public Size getSize() { 57 | return size; 58 | } 59 | 60 | /** 61 | * @param size 62 | * the size to set 63 | */ 64 | public void setSize(Size size) { 65 | this.size = size; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/StringListField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.List; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class StringListField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private List hobbies; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the list 53 | */ 54 | public List getHobbies() { 55 | return hobbies; 56 | } 57 | 58 | /** 59 | * @param hobbies 60 | * the list to set 61 | */ 62 | public void setHobbies(List hobbies) { 63 | this.hobbies = hobbies; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Exploded.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Indicates that the {@link Embedded} object of an entity should be stored using the Exploded 27 | * strategy. With Exploded strategy, the {@link Embedded} object, and nested embedded objects, if 28 | * any, are exploded into separate properties when stored into the Datastore. This annotation can 29 | * exist on any {@link Embedded} field of an {@link Entity} or {@link MappedSuperClass}. Annotating 30 | * a nested Embedded field with this annotation will not have any effect as the storage strategy is 31 | * enforced at the Entity level. 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | @Retention(RUNTIME) 37 | @Target(FIELD) 38 | public @interface Exploded { 39 | // Marker 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/DateField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.Date; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class DateField { 30 | @Identifier 31 | private long id; 32 | private Date creationDate; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the creationDate 51 | */ 52 | public Date getCreationDate() { 53 | return creationDate; 54 | } 55 | 56 | /** 57 | * @param creationDate 58 | * the creationDate to set 59 | */ 60 | public void setCreationDate(Date creationDate) { 61 | this.creationDate = creationDate; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/ExcludeDefaultListeners.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.TYPE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Specifies that any default listeners registered with the {@link EntityManager} should be 27 | * excluded. This annotation can be specified on an {@link Entity} or a {@link MappedSuperClass}. 28 | * 29 | *

30 | * If this annotation is defined on an {@link Entity}, default listeners are skipped for various 31 | * life cycle events of that entity. If this annotation is defined on a {@link MappedSuperClass}, 32 | * default listeners are skipped for all entities extending that {@link MappedSuperClass}. 33 | *

34 | * 35 | * @author Sai Pullabhotla 36 | * 37 | */ 38 | @Retention(RUNTIME) 39 | @Target(TYPE) 40 | public @interface ExcludeDefaultListeners { 41 | // Marker 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/LongMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.LongValue; 20 | import com.google.cloud.datastore.NullValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | 25 | /** 26 | * An implementation of {@link Mapper} for mapping primitive and wrapper and Long types to/from the 27 | * Cloud Datastore. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | public class LongMapper implements Mapper { 33 | 34 | @Override 35 | public ValueBuilder toDatastore(Object input) { 36 | if (input == null) { 37 | return NullValue.newBuilder(); 38 | } 39 | return LongValue.newBuilder((long) input); 40 | } 41 | 42 | @Override 43 | public Object toModel(Value input) { 44 | if (input instanceof NullValue) { 45 | return null; 46 | } 47 | return ((LongValue) input).get(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PropertyIndexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used to specify the Indexer to use for a given property/field of an entity. This annotation can 27 | * be applied to any field of an {@link Entity}, {@link MappedSuperClass} or {@link Embeddable}. The 28 | * specified indexer must be able to handle the indexing of value returned by the field's 29 | * {@link Mapper}. 30 | * 31 | * @author Sai Pullabhotla 32 | * 33 | */ 34 | @Retention(RUNTIME) 35 | @Target(FIELD) 36 | public @interface PropertyIndexer { 37 | /** 38 | * Returns the indexer class. The specified class must have a public default (or no-argument 39 | * constructor). 40 | * 41 | * @return the indexer class. 42 | */ 43 | Class value(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/PropertyOverride.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static java.lang.annotation.ElementType.TYPE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used to override mapping of a property. This annotation must be specified on the top-level entity 27 | * to override any properties of {@link Embedded} objects or a {@link MappedSuperClass}. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | @Retention(RUNTIME) 33 | @Target(TYPE) 34 | public @interface PropertyOverride { 35 | 36 | /** 37 | * The name of the property whose mapping is to be overridden. 38 | * 39 | * @return name of the property whose mapping is to be overridden. 40 | */ 41 | String name(); 42 | 43 | /** 44 | * The override mapping information. 45 | * 46 | * @return override mapping information. 47 | */ 48 | Property property(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/DoubleMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.DoubleValue; 20 | import com.google.cloud.datastore.NullValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | 25 | /** 26 | * An implementation of {@link Mapper} for mapping primitive and wrapper double types to/from Cloud 27 | * Datastore. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | public class DoubleMapper implements Mapper { 33 | 34 | @Override 35 | public ValueBuilder toDatastore(Object input) { 36 | if (input == null) { 37 | return NullValue.newBuilder(); 38 | } 39 | return DoubleValue.newBuilder((double) input); 40 | } 41 | 42 | @Override 43 | public Object toModel(Value input) { 44 | if (input instanceof NullValue) { 45 | return null; 46 | } 47 | return ((DoubleValue) input).get(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/UnindexedByteArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | public class UnindexedByteArrayField { 29 | 30 | @Identifier 31 | private long id; 32 | 33 | @Property(indexed = false) 34 | private byte[] junk; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the salt 53 | */ 54 | public byte[] getJunk() { 55 | return junk; 56 | } 57 | 58 | /** 59 | * @param salt 60 | * the salt to set 61 | */ 62 | public void setJunk(byte[] salt) { 63 | this.junk = salt; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/CharArrayMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.NullValue; 20 | import com.google.cloud.datastore.StringValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | 25 | /** 26 | * An implementation of {@link Mapper} for mapping char arrays to/from Cloud Datastore. 27 | * 28 | * @author Sai Pullabhotla 29 | * 30 | */ 31 | public class CharArrayMapper implements Mapper { 32 | 33 | @Override 34 | public ValueBuilder toDatastore(Object input) { 35 | if (input == null) { 36 | return NullValue.newBuilder(); 37 | } 38 | return StringValue.newBuilder(new String((char[]) input)); 39 | } 40 | 41 | @Override 42 | public Object toModel(Value input) { 43 | if (input instanceof NullValue) { 44 | return null; 45 | } 46 | return ((StringValue) input).get().toCharArray(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/BooleanMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.BooleanValue; 20 | import com.google.cloud.datastore.NullValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | 25 | /** 26 | * An implementation of {@link Mapper} for mapping primitive and wrapper boolean types to/from Cloud 27 | * Datastore. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | public class BooleanMapper implements Mapper { 33 | 34 | @Override 35 | public ValueBuilder toDatastore(Object input) { 36 | if (input == null) { 37 | return NullValue.newBuilder(); 38 | } 39 | return BooleanValue.newBuilder((boolean) input); 40 | } 41 | 42 | @Override 43 | public Object toModel(Value input) { 44 | if (input instanceof NullValue) { 45 | return null; 46 | } 47 | return ((BooleanValue) input).get(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LongField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class LongField { 28 | 29 | @Identifier 30 | private long id; 31 | private long distanceFromEarth; 32 | 33 | /** 34 | * @return the id 35 | */ 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | /** 41 | * @param id 42 | * the id to set 43 | */ 44 | public void setId(long id) { 45 | this.id = id; 46 | } 47 | 48 | /** 49 | * @return the distanceFromEarth 50 | */ 51 | public long getDistanceFromEarth() { 52 | return distanceFromEarth; 53 | } 54 | 55 | /** 56 | * @param distanceFromEarth 57 | * the distanceFromEarth to set 58 | */ 59 | public void setDistanceFromEarth(long distanceFromEarth) { 60 | this.distanceFromEarth = distanceFromEarth; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/IndexerFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | import org.junit.Test; 22 | 23 | import com.jmethods.catatumbo.indexers.LowerCaseStringIndexer; 24 | import com.jmethods.catatumbo.indexers.UpperCaseStringListIndexer; 25 | 26 | /** 27 | * @author Sai Pullabhotla 28 | * 29 | */ 30 | public class IndexerFactoryTest { 31 | 32 | @Test 33 | public void testGetIndexer_LowerCaseStringIndexer() { 34 | Indexer i1 = IndexerFactory.getInstance().getIndexer(LowerCaseStringIndexer.class); 35 | Indexer i2 = IndexerFactory.getInstance().getIndexer(LowerCaseStringIndexer.class); 36 | assertTrue(i1 == i2); 37 | } 38 | 39 | @Test 40 | public void testGetIndexer_UpperCaseSringListIndexer() { 41 | Indexer i1 = IndexerFactory.getInstance().getIndexer(UpperCaseStringListIndexer.class); 42 | Indexer i2 = IndexerFactory.getInstance().getIndexer(UpperCaseStringListIndexer.class); 43 | assertTrue(i1 == i2); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/CalendarField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.Calendar; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class CalendarField { 30 | @Identifier 31 | private long id; 32 | private Calendar creationDate; 33 | 34 | /** 35 | * @return the id 36 | */ 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * @param id 43 | * the id to set 44 | */ 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | /** 50 | * @return the creationDate 51 | */ 52 | public Calendar getCreationDate() { 53 | return creationDate; 54 | } 55 | 56 | /** 57 | * @param creationDate 58 | * the creationDate to set 59 | */ 60 | public void setCreationDate(Calendar creationDate) { 61 | this.creationDate = creationDate; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LongObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class LongObject { 28 | 29 | @Identifier 30 | private long id; 31 | private Long distanceFromEarth; 32 | 33 | /** 34 | * @return the id 35 | */ 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | /** 41 | * @param id 42 | * the id to set 43 | */ 44 | public void setId(long id) { 45 | this.id = id; 46 | } 47 | 48 | /** 49 | * @return the distanceFromEarth 50 | */ 51 | public Long getDistanceFromEarth() { 52 | return distanceFromEarth; 53 | } 54 | 55 | /** 56 | * @param distanceFromEarth 57 | * the distanceFromEarth to set 58 | */ 59 | public void setDistanceFromEarth(Long distanceFromEarth) { 60 | this.distanceFromEarth = distanceFromEarth; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/WrappedLongObjectId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * @author Sai Pullabhotla 23 | * 24 | */ 25 | public class WrappedLongObjectId { 26 | 27 | private Long value; 28 | 29 | public WrappedLongObjectId(Long value) { 30 | this.value = value; 31 | } 32 | 33 | public Long getValue() { 34 | return value; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | StringBuilder builder = new StringBuilder(); 40 | builder.append("WrappedLongObjectId [value=").append(value).append("]"); 41 | return builder.toString(); 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) { 47 | return true; 48 | } 49 | if (obj == null || !this.getClass().equals(obj.getClass())) { 50 | return false; 51 | } 52 | WrappedLongObjectId that = (WrappedLongObjectId) obj; 53 | return Objects.equals(this.value, that.value); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/KeyListField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.List; 20 | 21 | import com.jmethods.catatumbo.DatastoreKey; 22 | import com.jmethods.catatumbo.Entity; 23 | import com.jmethods.catatumbo.Identifier; 24 | 25 | /** 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity 30 | public class KeyListField { 31 | 32 | @Identifier 33 | private long id; 34 | 35 | private List tags; 36 | 37 | /** 38 | * @return the id 39 | */ 40 | public long getId() { 41 | return id; 42 | } 43 | 44 | /** 45 | * @param id 46 | * the id to set 47 | */ 48 | public void setId(long id) { 49 | this.id = id; 50 | } 51 | 52 | /** 53 | * @return the tags 54 | */ 55 | public List getTags() { 56 | return tags; 57 | } 58 | 59 | /** 60 | * @param tags 61 | * the tags to set 62 | */ 63 | public void setTags(List tags) { 64 | this.tags = tags; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/impl/EntityListenerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.impl; 18 | 19 | import com.jmethods.catatumbo.EntityListeners; 20 | import com.jmethods.catatumbo.EntityManager; 21 | 22 | /** 23 | * Enumeration of entity listener types. 24 | * 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | public enum EntityListenerType { 29 | 30 | /** 31 | * Default (aka Global) Listener. These type of listeners are registered with the 32 | * {@link EntityManager} using {@link EntityManager#setDefaultListeners(Class...)} and these 33 | * listeners will be executed for all types of Entities managed by the {@link EntityManager}. 34 | */ 35 | DEFAULT, 36 | 37 | /** 38 | * External Listener. These type of listeners are specified on the Entity class or 39 | * MappedSuperClass using the {@link EntityListeners} annotations. 40 | */ 41 | EXTERNAL, 42 | 43 | /** 44 | * Internal Listeners. These type of listeners are defined within the Entity or MappedSuperClass. 45 | */ 46 | INTERNAL; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/InternalCalculatorEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.PreDelete; 21 | import com.jmethods.catatumbo.PreInsert; 22 | import com.jmethods.catatumbo.PreUpdate; 23 | import com.jmethods.catatumbo.PreUpsert; 24 | 25 | /** 26 | * @author Sai Pullabhotla 27 | * 28 | */ 29 | @Entity 30 | public class InternalCalculatorEntity extends CalculatorEntity { 31 | 32 | /** 33 | * 34 | */ 35 | public InternalCalculatorEntity() { 36 | super(); 37 | } 38 | 39 | /** 40 | * @param operand1 41 | * @param operand2 42 | */ 43 | public InternalCalculatorEntity(long operand1, long operand2) { 44 | super(operand1, operand2); 45 | } 46 | 47 | @PreInsert 48 | @PreUpdate 49 | @PreUpsert 50 | @PreDelete 51 | public void beforeEvent() { 52 | setSum(getOperand1() + getOperand2()); 53 | setProduct(getOperand1() * getOperand2()); 54 | setDifference(getOperand1() - getOperand2()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/ByteArrayMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.Blob; 20 | import com.google.cloud.datastore.BlobValue; 21 | import com.google.cloud.datastore.NullValue; 22 | import com.google.cloud.datastore.Value; 23 | import com.google.cloud.datastore.ValueBuilder; 24 | import com.jmethods.catatumbo.Mapper; 25 | 26 | /** 27 | * An implementation of {@link Mapper} for mapping byte array types to/from Cloud Datastore. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | public class ByteArrayMapper implements Mapper { 33 | 34 | @Override 35 | public ValueBuilder toDatastore(Object input) { 36 | if (input == null) { 37 | return NullValue.newBuilder(); 38 | } 39 | return BlobValue.newBuilder(Blob.copyFrom((byte[]) input)); 40 | } 41 | 42 | @Override 43 | public Object toModel(Value input) { 44 | if (input instanceof NullValue) { 45 | return null; 46 | } 47 | return ((BlobValue) input).get().toByteArray(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/UnindexedStringField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | public class UnindexedStringField { 29 | @Identifier 30 | private long id; 31 | 32 | @Property(indexed = false) 33 | private String hugeString; 34 | 35 | /** 36 | * @return the id 37 | */ 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | /** 43 | * @param id 44 | * the id to set 45 | */ 46 | public void setId(long id) { 47 | this.id = id; 48 | } 49 | 50 | /** 51 | * @return the hugeString 52 | */ 53 | public String getHugeString() { 54 | return hugeString; 55 | } 56 | 57 | /** 58 | * @param hugeString 59 | * the hugeString to set 60 | */ 61 | public void setHugeString(String hugeString) { 62 | this.hugeString = hugeString; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo; 18 | 19 | import com.google.cloud.datastore.Value; 20 | import com.google.cloud.datastore.ValueBuilder; 21 | 22 | /** 23 | * Contract for mapping model values to/from Cloud Datastore. 24 | * 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | public interface Mapper { 29 | 30 | /** 31 | * Maps the given Model object to native Cloud Datastore value. 32 | * 33 | * @param input 34 | * the input to map 35 | * @return the equivalent native value 36 | * @throws MappingException 37 | * if the input is not compatible. 38 | */ 39 | public ValueBuilder toDatastore(Object input); 40 | 41 | /** 42 | * Maps the given native Cloud Datastore value to equivalent model object. 43 | * 44 | * @param input 45 | * the native Cloud Datastore value 46 | * @return the equivalent model object 47 | * @throws MappingException 48 | * if the input is not compatible. 49 | */ 50 | public Object toModel(Value input); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/BigDecimalMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import java.math.BigDecimal; 20 | 21 | import com.google.cloud.datastore.DoubleValue; 22 | import com.google.cloud.datastore.NullValue; 23 | import com.google.cloud.datastore.Value; 24 | import com.google.cloud.datastore.ValueBuilder; 25 | import com.jmethods.catatumbo.Mapper; 26 | 27 | /** 28 | * An implementation of {@link Mapper} for mapping BigDecimal types to/from Cloud Datastore. 29 | * 30 | * @author Sai Pullabhotla 31 | * 32 | */ 33 | public class BigDecimalMapper implements Mapper { 34 | 35 | @Override 36 | public ValueBuilder toDatastore(Object input) { 37 | if (input == null) { 38 | return NullValue.newBuilder(); 39 | } 40 | return DoubleValue.newBuilder(((BigDecimal) input).doubleValue()); 41 | } 42 | 43 | @Override 44 | public Object toModel(Value input) { 45 | if (input instanceof NullValue) { 46 | return null; 47 | } 48 | return BigDecimal.valueOf(((DoubleValue) input).get()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/OptionalVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | import com.jmethods.catatumbo.Version; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class OptionalVersion { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | @Version 35 | @Property(optional = true) 36 | private long version; 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @param id 47 | * the id to set 48 | */ 49 | public void setId(long id) { 50 | this.id = id; 51 | } 52 | 53 | /** 54 | * @return the version 55 | */ 56 | public long getVersion() { 57 | return version; 58 | } 59 | 60 | /** 61 | * @param version 62 | * the version to set 63 | */ 64 | public void setVersion(long version) { 65 | this.version = version; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/TaskName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity(kind = "Task") 27 | public class TaskName { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private String name; 33 | 34 | /** 35 | * Creates a new instance of TaskName. 36 | */ 37 | public TaskName() { 38 | // @ToDo Auto-generated constructor stub 39 | } 40 | 41 | /** 42 | * @return the id 43 | */ 44 | public long getId() { 45 | return id; 46 | } 47 | 48 | /** 49 | * @param id 50 | * the id to set 51 | */ 52 | public void setId(long id) { 53 | this.id = id; 54 | } 55 | 56 | /** 57 | * @return the name 58 | */ 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | /** 64 | * @param name 65 | * the name to set 66 | */ 67 | public void setName(String name) { 68 | this.name = name; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/listeners/BadExternalListener2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.listeners; 18 | 19 | import com.jmethods.catatumbo.EntityListener; 20 | import com.jmethods.catatumbo.PostDelete; 21 | import com.jmethods.catatumbo.PostInsert; 22 | import com.jmethods.catatumbo.PostUpdate; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @EntityListener 29 | public class BadExternalListener2 { 30 | 31 | @PostInsert 32 | public void afterInsert(Object obj) { 33 | System.out.printf("Object %s of type %s inserted\n", obj, obj.getClass().getName()); 34 | } 35 | 36 | @PostUpdate 37 | public void afterUpdate(Object obj) { 38 | System.out.printf("Object %s of type %s updated\n", obj, obj.getClass().getName()); 39 | } 40 | 41 | @PostDelete 42 | public void afterDelete(Object obj) { 43 | System.out.printf("Object %s of type %s deleted\n", obj, obj.getClass().getName()); 44 | } 45 | 46 | @PostInsert 47 | public void afterInsert2(Object obj) { 48 | System.out.printf("Object %s of type %s inserted\n", obj, obj.getClass().getName()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/NoDefaultConstrctorEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | import com.jmethods.catatumbo.Property; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @Entity 28 | public class NoDefaultConstrctorEntity { 29 | 30 | @Identifier 31 | private long id; 32 | 33 | @Property 34 | private String name; 35 | 36 | /** 37 | * 38 | */ 39 | private NoDefaultConstrctorEntity(String name) { 40 | this.name = name; 41 | } 42 | 43 | /** 44 | * @return the id 45 | */ 46 | public long getId() { 47 | return id; 48 | } 49 | 50 | /** 51 | * @param id 52 | * the id to set 53 | */ 54 | public void setId(long id) { 55 | this.id = id; 56 | } 57 | 58 | /** 59 | * @return the name 60 | */ 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | /** 66 | * @param name 67 | * the name to set 68 | */ 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/EmbeddedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.Objects; 22 | 23 | import com.jmethods.catatumbo.Embeddable; 24 | import com.jmethods.catatumbo.Property; 25 | 26 | @Embeddable 27 | public class EmbeddedList { 28 | 29 | @Property(indexed = false) 30 | private List list; 31 | 32 | public List getList() { 33 | return list; 34 | } 35 | 36 | public void setList(List list) { 37 | this.list = list; 38 | } 39 | 40 | public static EmbeddedList getSample1() { 41 | EmbeddedList embeddedList = new EmbeddedList(); 42 | embeddedList.setList(Arrays.asList(new String[] { "One", "Two", "Three" })); 43 | return embeddedList; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) { 49 | return true; 50 | } 51 | if (!this.getClass().equals(obj.getClass())) { 52 | return false; 53 | } 54 | EmbeddedList that = (EmbeddedList) obj; 55 | return Objects.equals(this.list, that.list); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LocalDateField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.time.LocalDate; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class LocalDateField { 30 | @Identifier 31 | private long id; 32 | 33 | private LocalDate birthDate; 34 | 35 | /** 36 | * @return the id 37 | */ 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | /** 43 | * @param id 44 | * the id to set 45 | */ 46 | public void setId(long id) { 47 | this.id = id; 48 | } 49 | 50 | /** 51 | * @return the birthDate 52 | */ 53 | public LocalDate getBirthDate() { 54 | return birthDate; 55 | } 56 | 57 | /** 58 | * @param birthDate 59 | * the birthDate to set 60 | */ 61 | public void setBirthDate(LocalDate birthDate) { 62 | this.birthDate = birthDate; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "LocalDateField [id=" + id + ", birthDate=" + birthDate + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LocalTimeField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.time.LocalTime; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class LocalTimeField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private LocalTime startTime; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the startTime 53 | */ 54 | public LocalTime getStartTime() { 55 | return startTime; 56 | } 57 | 58 | /** 59 | * @param startTime 60 | * the startTime to set 61 | */ 62 | public void setStartTime(LocalTime startTime) { 63 | this.startTime = startTime; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "LocalTimeField [id=" + id + ", startTime=" + startTime + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BadBuilderEntity4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadBuilderEntity4 { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private String name; 33 | 34 | public BadBuilderEntity4(String name) { 35 | 36 | } 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @return the name 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public static Builder newBuilder() { 53 | return new Builder(); 54 | } 55 | 56 | public static class Builder { 57 | private long id; 58 | 59 | private String name; 60 | 61 | /** 62 | * @param name 63 | * the name to set 64 | */ 65 | public void setName(String name) { 66 | this.name = name; 67 | } 68 | 69 | public BadBuilderEntity4 build() { 70 | return new BadBuilderEntity4(name); 71 | } 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/LocalDateTimeField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.time.LocalDateTime; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class LocalDateTimeField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private LocalDateTime timestamp; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the timestamp 53 | */ 54 | public LocalDateTime getTimestamp() { 55 | return timestamp; 56 | } 57 | 58 | /** 59 | * @param timestamp 60 | * the timestamp to set 61 | */ 62 | public void setTimestamp(LocalDateTime timestamp) { 63 | this.timestamp = timestamp; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "LocalDateTimeField [id=" + id + ", timestamp=" + timestamp + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/ZonedDateTimeField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.time.ZonedDateTime; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class ZonedDateTimeField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private ZonedDateTime timestamp; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the timestamp 53 | */ 54 | public ZonedDateTime getTimestamp() { 55 | return timestamp; 56 | } 57 | 58 | /** 59 | * @param timestamp 60 | * the timestamp to set 61 | */ 62 | public void setTimestamp(ZonedDateTime timestamp) { 63 | this.timestamp = timestamp; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "ZonedDateTimeField [id=" + id + ", timestamp=" + timestamp + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/indexers/UpperCaseStringIndexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.indexers; 18 | 19 | import java.util.Locale; 20 | 21 | import com.google.cloud.datastore.NullValue; 22 | import com.google.cloud.datastore.StringValue; 23 | import com.google.cloud.datastore.Value; 24 | import com.google.cloud.datastore.ValueType; 25 | import com.jmethods.catatumbo.Indexer; 26 | import com.jmethods.catatumbo.IndexingException; 27 | 28 | /** 29 | * An implementation of {@link Indexer} interface for creating indexes in upper case. This indexer 30 | * assumes that the value being indexed is of type String. Any other type will result in 31 | * ClassCastException. 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | public class UpperCaseStringIndexer implements Indexer { 37 | 38 | @Override 39 | public Value index(Value input) { 40 | if (input.getType() == ValueType.NULL) { 41 | return NullValue.of(); 42 | } 43 | try { 44 | String str = ((StringValue) input).get(); 45 | return StringValue.of(str.toUpperCase(Locale.ENGLISH)); 46 | } catch (Exception exp) { 47 | throw new IndexingException(exp); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/OffsetDateTimeField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import java.time.OffsetDateTime; 20 | 21 | import com.jmethods.catatumbo.Entity; 22 | import com.jmethods.catatumbo.Identifier; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class OffsetDateTimeField { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | private OffsetDateTime timestamp; 35 | 36 | /** 37 | * @return the id 38 | */ 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * @param id 45 | * the id to set 46 | */ 47 | public void setId(long id) { 48 | this.id = id; 49 | } 50 | 51 | /** 52 | * @return the timestamp 53 | */ 54 | public OffsetDateTime getTimestamp() { 55 | return timestamp; 56 | } 57 | 58 | /** 59 | * @param timestamp 60 | * the timestamp to set 61 | */ 62 | public void setTimestamp(OffsetDateTime timestamp) { 63 | this.timestamp = timestamp; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "OffsetDateTimeField [id=" + id + ", timestamp=" + timestamp + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/OptionalCreatedTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.CreatedTimestamp; 20 | import com.jmethods.catatumbo.Entity; 21 | import com.jmethods.catatumbo.Identifier; 22 | import com.jmethods.catatumbo.Property; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class OptionalCreatedTimestamp { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | @CreatedTimestamp 35 | @Property(optional = true) 36 | private long creationTimestamp; 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @param id 47 | * the id to set 48 | */ 49 | public void setId(long id) { 50 | this.id = id; 51 | } 52 | 53 | /** 54 | * @return the version 55 | */ 56 | public long getCreationTimestamp() { 57 | return creationTimestamp; 58 | } 59 | 60 | /** 61 | * @param creationTimestamp 62 | * the version to set 63 | */ 64 | public void setCreationTimestamp(long creationTimestamp) { 65 | this.creationTimestamp = creationTimestamp; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/indexers/LowerCaseStringIndexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.indexers; 18 | 19 | import java.util.Locale; 20 | 21 | import com.google.cloud.datastore.NullValue; 22 | import com.google.cloud.datastore.StringValue; 23 | import com.google.cloud.datastore.Value; 24 | import com.google.cloud.datastore.ValueType; 25 | import com.jmethods.catatumbo.Indexer; 26 | import com.jmethods.catatumbo.IndexingException; 27 | 28 | /** 29 | * An implementation of {@link Indexer} interface for creating indexes in lower case. This indexer 30 | * assumes that the value being indexed is of type String. Any other type will result in an 31 | * {@link IndexingException}. 32 | * 33 | * @author Sai Pullabhotla 34 | * 35 | */ 36 | public class LowerCaseStringIndexer implements Indexer { 37 | 38 | @Override 39 | public Value index(Value input) { 40 | if (input.getType() == ValueType.NULL) { 41 | return NullValue.of(); 42 | } 43 | try { 44 | String str = ((StringValue) input).get(); 45 | return StringValue.of(str.toLowerCase(Locale.ENGLISH)); 46 | } catch (Exception exp) { 47 | throw new IndexingException(exp); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/KeyMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.KeyValue; 20 | import com.google.cloud.datastore.NullValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.DatastoreKey; 24 | import com.jmethods.catatumbo.DefaultDatastoreKey; 25 | import com.jmethods.catatumbo.Mapper; 26 | 27 | /** 28 | * An implementation of {@link Mapper} for mapping Key types to/from the Cloud Datastore. 29 | * 30 | * @author Sai Pullabhotla 31 | * 32 | */ 33 | public class KeyMapper implements Mapper { 34 | 35 | @Override 36 | public ValueBuilder toDatastore(Object input) { 37 | if (input == null) { 38 | return NullValue.newBuilder(); 39 | } 40 | DatastoreKey datastoreKey = (DatastoreKey) input; 41 | return KeyValue.newBuilder(datastoreKey.nativeKey()); 42 | } 43 | 44 | @Override 45 | public Object toModel(Value input) { 46 | if (input instanceof NullValue) { 47 | return null; 48 | } 49 | KeyValue keyValue = (KeyValue) input; 50 | return new DefaultDatastoreKey(keyValue.get()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/jmethods/catatumbo/mappers/CharMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.mappers; 18 | 19 | import com.google.cloud.datastore.NullValue; 20 | import com.google.cloud.datastore.StringValue; 21 | import com.google.cloud.datastore.Value; 22 | import com.google.cloud.datastore.ValueBuilder; 23 | import com.jmethods.catatumbo.Mapper; 24 | import com.jmethods.catatumbo.MappingException; 25 | 26 | /** 27 | * An implementation of {@link Mapper} for mapping Char type to/from Cloud Datastore. 28 | * 29 | * @author Sai Pullabhotla 30 | * 31 | */ 32 | public class CharMapper implements Mapper { 33 | 34 | @Override 35 | public ValueBuilder toDatastore(Object input) { 36 | if (input == null) { 37 | return NullValue.newBuilder(); 38 | } 39 | return StringValue.newBuilder(String.valueOf((char) input)); 40 | } 41 | 42 | @Override 43 | public Object toModel(Value input) { 44 | if (input instanceof NullValue) { 45 | return null; 46 | } 47 | String str = ((StringValue) input).get(); 48 | if (str.length() != 1) { 49 | throw new MappingException(String.format("Unable to convert %s to char", str)); 50 | } 51 | return str.charAt(0); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/Animal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Identifier; 20 | import com.jmethods.catatumbo.MappedSuperClass; 21 | import com.jmethods.catatumbo.PreInsert; 22 | 23 | /** 24 | * @author Sai Pullabhotla 25 | * 26 | */ 27 | @MappedSuperClass 28 | public class Animal { 29 | 30 | @Identifier 31 | private long id; 32 | 33 | protected String value = ""; 34 | 35 | /** 36 | * @return the id 37 | */ 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | /** 43 | * @param id 44 | * the id to set 45 | */ 46 | public void setId(long id) { 47 | this.id = id; 48 | } 49 | 50 | /** 51 | * @return the value 52 | */ 53 | public String getValue() { 54 | return value; 55 | } 56 | 57 | /** 58 | * @param value 59 | * the value to set 60 | */ 61 | public void setValue(String value) { 62 | this.value = value; 63 | } 64 | 65 | @PreInsert 66 | public void insertingAnimal() { 67 | if (value.trim().length() > 0) { 68 | value += "->"; 69 | } 70 | value += Animal.class.getSimpleName() + "." + PreInsert.class.getSimpleName(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/NoSetterMethodEntity2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Embedded; 20 | import com.jmethods.catatumbo.Entity; 21 | import com.jmethods.catatumbo.Identifier; 22 | import com.jmethods.catatumbo.Property; 23 | 24 | /** 25 | * @author Sai Pullabhotla 26 | * 27 | */ 28 | @Entity 29 | public class NoSetterMethodEntity2 { 30 | 31 | @Identifier 32 | private long id; 33 | 34 | @Property 35 | private String name; 36 | 37 | @Embedded 38 | protected Address address; 39 | 40 | /** 41 | * @return the id 42 | */ 43 | public long getId() { 44 | return id; 45 | } 46 | 47 | /** 48 | * @param id 49 | * the id to set 50 | */ 51 | public void setId(long id) { 52 | this.id = id; 53 | } 54 | 55 | /** 56 | * @return the name 57 | */ 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | /** 63 | * @param name 64 | * the name to set 65 | */ 66 | public void setName(String name) { 67 | this.name = name; 68 | } 69 | 70 | /** 71 | * @return the address 72 | */ 73 | public Address getAddress() { 74 | return address; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/jmethods/catatumbo/entities/BadBuilderEntity3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sai Pullabhotla. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.jmethods.catatumbo.entities; 18 | 19 | import com.jmethods.catatumbo.Entity; 20 | import com.jmethods.catatumbo.Identifier; 21 | 22 | /** 23 | * @author Sai Pullabhotla 24 | * 25 | */ 26 | @Entity 27 | public class BadBuilderEntity3 { 28 | 29 | @Identifier 30 | private long id; 31 | 32 | private String name; 33 | 34 | public BadBuilderEntity3(String name) { 35 | 36 | } 37 | 38 | /** 39 | * @return the id 40 | */ 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | /** 46 | * @return the name 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public static Builder newBuilder() { 53 | return new Builder(); 54 | } 55 | 56 | public static class Builder { 57 | private long id; 58 | 59 | private String name; 60 | 61 | /** 62 | * @param id 63 | * the id to set 64 | */ 65 | public void setId(long id) { 66 | this.id = id; 67 | } 68 | 69 | /** 70 | * @param name 71 | * the name to set 72 | */ 73 | public void setName(String name) { 74 | this.name = name; 75 | } 76 | 77 | } 78 | 79 | } 80 | --------------------------------------------------------------------------------