Adding more initial code and first tests on properties.

This commit is contained in:
Michael Nitschinger
2012-12-17 15:52:12 +01:00
parent 2788104f0d
commit f242499554
5 changed files with 201 additions and 1 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}

View File

@@ -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 {
}

View 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 "";
}