From 2788104f0d67a114dff0d0e82e72b5593e811cc7 Mon Sep 17 00:00:00 2001 From: Michael Nitschinger Date: Mon, 17 Dec 2012 13:46:20 +0100 Subject: [PATCH] Initial Classes (not working) for mapping usage. --- pom.xml | 5 ++ .../spring/core/CouchbaseFactory.java | 31 +++++++++ .../convert/AbstractCouchbaseConverter.java | 47 +++++++++++++ .../core/convert/CouchbaseConverter.java | 36 ++++++++++ .../spring/core/convert/CouchbaseWriter.java | 29 ++++++++ .../convert/MappingCouchbaseConverter.java | 68 +++++++++++++++++++ .../BasicCouchbasePersistentEntity.java | 52 ++++++++++++++ .../BasicCouchbasePersistentProperty.java | 47 +++++++++++++ .../mapping/CouchbasePersistentEntity.java | 30 ++++++++ .../mapping/CouchbasePersistentProperty.java | 31 +++++++++ 10 files changed, 376 insertions(+) create mode 100644 src/main/java/com/couchbase/spring/core/CouchbaseFactory.java create mode 100644 src/main/java/com/couchbase/spring/core/convert/AbstractCouchbaseConverter.java create mode 100644 src/main/java/com/couchbase/spring/core/convert/CouchbaseConverter.java create mode 100644 src/main/java/com/couchbase/spring/core/convert/CouchbaseWriter.java create mode 100644 src/main/java/com/couchbase/spring/core/convert/MappingCouchbaseConverter.java create mode 100644 src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentEntity.java create mode 100644 src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentProperty.java create mode 100644 src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentEntity.java create mode 100644 src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentProperty.java diff --git a/pom.xml b/pom.xml index ca2642b3..940ad405 100644 --- a/pom.xml +++ b/pom.xml @@ -67,5 +67,10 @@ 3.1.3.RELEASE test + + org.springframework.data + spring-data-commons-core + 1.4.0.RELEASE + diff --git a/src/main/java/com/couchbase/spring/core/CouchbaseFactory.java b/src/main/java/com/couchbase/spring/core/CouchbaseFactory.java new file mode 100644 index 00000000..43acd95f --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/CouchbaseFactory.java @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core; + +import com.couchbase.client.CouchbaseClient; + +public interface CouchbaseFactory { + + CouchbaseClient getDb(); + +} diff --git a/src/main/java/com/couchbase/spring/core/convert/AbstractCouchbaseConverter.java b/src/main/java/com/couchbase/spring/core/convert/AbstractCouchbaseConverter.java new file mode 100644 index 00000000..fbe325e1 --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/convert/AbstractCouchbaseConverter.java @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.convert; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.GenericConversionService; + +public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, + InitializingBean { + + protected final GenericConversionService conversionService; + + public AbstractCouchbaseConverter( + GenericConversionService conversionService) { + this.conversionService = conversionService; + } + + public ConversionService getConversionService() { + return conversionService; + } + + public void afterPropertiesSet() throws Exception { + + } + +} diff --git a/src/main/java/com/couchbase/spring/core/convert/CouchbaseConverter.java b/src/main/java/com/couchbase/spring/core/convert/CouchbaseConverter.java new file mode 100644 index 00000000..927c40f6 --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/convert/CouchbaseConverter.java @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.convert; + +import com.couchbase.spring.core.mapping.CouchbasePersistentEntity; +import com.couchbase.spring.core.mapping.CouchbasePersistentProperty; +import org.springframework.data.convert.EntityConverter; +import org.springframework.data.convert.EntityReader; + +public interface CouchbaseConverter extends + EntityConverter, + CouchbasePersistentProperty, Object, Object>, + CouchbaseWriter, + EntityReader { + +} diff --git a/src/main/java/com/couchbase/spring/core/convert/CouchbaseWriter.java b/src/main/java/com/couchbase/spring/core/convert/CouchbaseWriter.java new file mode 100644 index 00000000..7611c807 --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/convert/CouchbaseWriter.java @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.convert; + +import org.springframework.data.convert.EntityWriter; + +public interface CouchbaseWriter extends EntityWriter { + +} \ No newline at end of file diff --git a/src/main/java/com/couchbase/spring/core/convert/MappingCouchbaseConverter.java b/src/main/java/com/couchbase/spring/core/convert/MappingCouchbaseConverter.java new file mode 100644 index 00000000..786c069d --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/convert/MappingCouchbaseConverter.java @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.convert; + +import com.couchbase.spring.core.CouchbaseFactory; +import com.couchbase.spring.core.mapping.CouchbasePersistentEntity; +import com.couchbase.spring.core.mapping.CouchbasePersistentProperty; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.convert.support.ConversionServiceFactory; +import org.springframework.data.mapping.context.MappingContext; + +public class MappingCouchbaseConverter extends AbstractCouchbaseConverter + implements ApplicationContextAware { + + protected ApplicationContext applicationContext; + protected final MappingContext, + CouchbasePersistentProperty> mappingContext; + + @SuppressWarnings("deprecation") + public MappingCouchbaseConverter(CouchbaseFactory couchbaseFactory, + MappingContext, + CouchbasePersistentProperty> mappingContext) { + super(ConversionServiceFactory.createDefaultConversionService()); + + this.mappingContext = mappingContext; + } + + public MappingContext, + CouchbasePersistentProperty> getMappingContext() { + return mappingContext; + } + + public R read(Class type, Object s) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void write(Object t, Object s) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + this.applicationContext = applicationContext; + } + +} diff --git a/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentEntity.java b/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentEntity.java new file mode 100644 index 00000000..23d80321 --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentEntity.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.mapping; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.expression.BeanFactoryAccessor; +import org.springframework.context.expression.BeanFactoryResolver; +import org.springframework.data.mapping.model.BasicPersistentEntity; +import org.springframework.data.util.TypeInformation; +import org.springframework.expression.spel.support.StandardEvaluationContext; + +public class BasicCouchbasePersistentEntity + extends BasicPersistentEntity + implements CouchbasePersistentEntity, ApplicationContextAware { + + private final StandardEvaluationContext context; + + public BasicCouchbasePersistentEntity(TypeInformation typeInformation) { + super(typeInformation); + + this.context = new StandardEvaluationContext(); + } + + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + context.addPropertyAccessor(new BeanFactoryAccessor()); + context.setBeanResolver(new BeanFactoryResolver(applicationContext)); + context.setRootObject(applicationContext); + } +} diff --git a/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentProperty.java b/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentProperty.java new file mode 100644 index 00000000..94e711ea --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/mapping/BasicCouchbasePersistentProperty.java @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.mapping; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import org.springframework.data.mapping.Association; +import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; +import org.springframework.data.mapping.model.SimpleTypeHolder; + + +public class BasicCouchbasePersistentProperty + extends AnnotationBasedPersistentProperty + implements CouchbasePersistentProperty { + + public BasicCouchbasePersistentProperty(Field field, + PropertyDescriptor propertyDescriptor, CouchbasePersistentEntity owner, + SimpleTypeHolder simpleTypeHolder) { + super(field, propertyDescriptor, owner, simpleTypeHolder); + } + + @Override + protected Association createAssociation() { + return new Association(this, null); + } + +} diff --git a/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentEntity.java b/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentEntity.java new file mode 100644 index 00000000..26d7c56a --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentEntity.java @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.mapping; + +import org.springframework.data.mapping.PersistentEntity; + +public interface CouchbasePersistentEntity extends + PersistentEntity { + +} diff --git a/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentProperty.java b/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentProperty.java new file mode 100644 index 00000000..df9e7223 --- /dev/null +++ b/src/main/java/com/couchbase/spring/core/mapping/CouchbasePersistentProperty.java @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.core.mapping; + +import org.springframework.data.mapping.PersistentProperty; + + +public interface CouchbasePersistentProperty extends + PersistentProperty { + +}