Adding more initial code and first tests on properties.
This commit is contained in:
@@ -27,21 +27,54 @@ 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;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Implements annotated property representations of a given Field instance.
|
||||
*
|
||||
* This object is used to gather information out of properties on objects
|
||||
* that need to be persisted. For example, it supports overriding of the
|
||||
* actual property name by providing custom annotations.
|
||||
*/
|
||||
public class BasicCouchbasePersistentProperty
|
||||
extends AnnotationBasedPersistentProperty<CouchbasePersistentProperty>
|
||||
implements CouchbasePersistentProperty {
|
||||
|
||||
/**
|
||||
* Create a new instance of the BasicCouchbasePersistentProperty class.
|
||||
*
|
||||
* @param field the field of the original reflection.
|
||||
* @param propertyDescriptor the PropertyDescriptor.
|
||||
* @param owner the original owner of the property.
|
||||
* @param simpleTypeHolder the type holder.
|
||||
*/
|
||||
public BasicCouchbasePersistentProperty(Field field,
|
||||
PropertyDescriptor propertyDescriptor, CouchbasePersistentEntity<?> owner,
|
||||
SimpleTypeHolder simpleTypeHolder) {
|
||||
super(field, propertyDescriptor, owner, simpleTypeHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Association.
|
||||
*/
|
||||
@Override
|
||||
protected Association<CouchbasePersistentProperty> createAssociation() {
|
||||
return new Association<CouchbasePersistentProperty>(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field name of the property.
|
||||
*
|
||||
* The field name can be different from the actual property name by using a
|
||||
* custom annotation.
|
||||
*/
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
com.couchbase.spring.core.mapping.Field annotation = getField().
|
||||
getAnnotation(com.couchbase.spring.core.mapping.Field.class);
|
||||
|
||||
return annotation != null && StringUtils.hasText(annotation.value())
|
||||
? annotation.value() : field.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,4 +28,11 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
public interface CouchbasePersistentProperty extends
|
||||
PersistentProperty<CouchbasePersistentProperty> {
|
||||
|
||||
/**
|
||||
* Returns the field name of the property.
|
||||
*
|
||||
* The field name can be different from the actual property name by using a
|
||||
* custom annotation.
|
||||
*/
|
||||
String getFieldName();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
|
||||
/**
|
||||
* Identifies a domain object to be persisted to Couchbase.
|
||||
*/
|
||||
@Persistent
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
public @interface Document {
|
||||
|
||||
}
|
||||
23
src/main/java/com/couchbase/spring/core/mapping/Field.java
Normal file
23
src/main/java/com/couchbase/spring/core/mapping/Field.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.couchbase.spring.core.mapping;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Annotation to define custom metadata for document fields.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Field {
|
||||
|
||||
/**
|
||||
* The key to be used to store the field inside the document.
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user