当前位置: 首页>>代码示例>>Java>>正文


Java MappingException类代码示例

本文整理汇总了Java中org.springframework.data.mapping.model.MappingException的典型用法代码示例。如果您正苦于以下问题:Java MappingException类的具体用法?Java MappingException怎么用?Java MappingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MappingException类属于org.springframework.data.mapping.model包,在下文中一共展示了MappingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeInternal

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
public void writeInternal(final Object entity,
                          final Document targetDocument,
                          final DocumentDbPersistentEntity<?> entityInformation) {
    if (entity == null) {
        return;
    }

    if (entityInformation == null) {
        throw new MappingException("no mapping metadata for entity type: " + entity.getClass().getName());
    }

    final ConvertingPropertyAccessor accessor = getPropertyAccessor(entity);
    final DocumentDbPersistentProperty idProperty = entityInformation.getIdProperty();

    if (idProperty != null) {
        targetDocument.setId((String) accessor.getProperty(idProperty));
    }

    for (final Field field : entity.getClass().getDeclaredFields()) {
        if (null != idProperty && field.getName().equals(idProperty.getName())) {
            continue;
        }
        targetDocument.set(field.getName(),
                accessor.getProperty(entityInformation.getPersistentProperty(field.getName())));
    }
}
 
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:27,代码来源:MappingDocumentDbConverter.java

示例2: doWithPersistentProperty

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Override
public void doWithPersistentProperty(SolrPersistentProperty property) {

	if (property.isDynamicProperty()) {

		if (!property.isMap()) {
			throw new MappingException(String.format(DYNAMIC_PROPERTY_NOT_A_MAP, property.getName(),
					property.getFieldName()));
		}

		if (!property.containsWildcard()) {
			throw new MappingException(String.format(DYNAMIC_PROPERTY_NOT_CONTAINING_WILDCARD, property.getName(),
					property.getFieldName()));
		}
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:17,代码来源:SimpleSolrPersistentEntity.java

示例3: SimpleCratePersistentProperty

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
public SimpleCratePersistentProperty(Field field, PropertyDescriptor propertyDescriptor, 
									 PersistentEntity<?, CratePersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
	super(field, propertyDescriptor, owner, simpleTypeHolder);
	
	this.fieldNamingStrategy = INSTANCE;

	String fieldName = getFieldName();
	
	if(RESERVED_ID_FIELD_NAME.equals(fieldName)) {				
		throw new MappingException(format(RESERVED_ID, fieldName, owner.getType()));
	}
	
	if(RESERVED_VESRION_FIELD_NAME.equals(fieldName)) {				
		throw new MappingException(format(RESERVED_VERSION, fieldName, owner.getType()));
	}
	
	if(startsWithIgnoreCase(fieldName, "_")) {
		throw new MappingException(format(STARTS_WITH_UNDERSCORE, fieldName, owner.getType()));
	}
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:21,代码来源:SimpleCratePersistentProperty.java

示例4: findById

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Override
public <T> T findById(Object id, Class<T> entityClass, String tableName) {
	
	notNull(id);
	
	if(!isIdPropertyDefined(entityClass)) {
		throw new MappingException(format("Entity '%s' has no id property defined", entityClass.getName()));
	}
	
	List<T> dbEntity = execute(new SelectAction(entityClass, tableName, id),
   						 	   new ReadDbHandler<T>(entityClass));
	if(dbEntity.isEmpty()) {
		logger.info("No row found with id '{}'", id);
		return null;
	}else {
		return dbEntity.iterator().next();
	}
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:19,代码来源:CrateTemplate.java

示例5: shouldNotWriteForMapWithComplexKeys

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Test(expected=MappingException.class)
public void shouldNotWriteForMapWithComplexKeys() {
	
	String[][] nested = new String[1][1];
	nested[0] = new String[]{"STRING"};
	
	NestedArrays compleKey = new NestedArrays();
	compleKey.nested = nested;
	
	Map<NestedArrays, String> map = new HashMap<MappingCrateConverterTest.NestedArrays, String>();
	map.put(compleKey, "ComplexKey");
	
	MapWithComplexKey entity = new MapWithComplexKey();
	entity.map = map;
	
	converter.write(entity, new CrateDocument());
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:18,代码来源:MappingCrateConverterTest.java

示例6: returnPropertyIfBetterIdPropertyCandidateOrNull

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
/**
 * Returns the given property if it is a better candidate for the id
 * property than the current id property.
 * 
 * @param property
 *            the new id property candidate, will never be {@literal null}.
 * @return the given id property or {@literal null} if the given property is
 *         not an id property.
 */
protected DynamoDBPersistentProperty returnPropertyIfBetterIdPropertyCandidateOrNull(DynamoDBPersistentProperty property) {

	if (!property.isIdProperty()) {
		return null;
	}

	if (getIdProperty() != null) {

		if (getIdProperty().isCompositeIdProperty() && property.isHashKeyProperty()) {
			// Do nothing - favour id annotated properties over hashkey
			return null;
		} else if (getIdProperty().isHashKeyProperty() && property.isCompositeIdProperty()) {
			return property;
		} else {
			throw new MappingException(String.format("Attempt to add id property %s but already have property %s registered "
					+ "as id. Check your mapping configuration!", property.getField(), getIdProperty().getField()));
		}
	}

	return property;
}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:31,代码来源:DynamoDBPersistentEntityImpl.java

示例7: getIdField

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
public static Field getIdField(Class<?> clazz) {
	Field idField = null;

	for(Field f : ReflectionUtils.getDeclaredFieldsInHierarchy(clazz)) {
		// named id or annotated with Id
		if(f.getName().equals(FIELD_NAME_DEFAULT_ID) || f.getAnnotation(Id.class) != null) {
			if(idField != null) {
				throw new MappingException("Multiple id fields detected for class " + clazz.getName());
			}
			idField = f;
		}

	}

	return idField;
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:17,代码来源:MetadataParser.java

示例8: getEntityInformation

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T, ID extends Serializable> SpannerEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
                                                                                          RepositoryInformation information) {
  SpannerPersistentEntity<?> entity = mappingContext.getPersistentEntity(domainClass);

  if (entity == null) {
    throw new MappingException(
        String.format("Could not lookup mapping metadata for domain class %s!", domainClass.getName()));
  }

  BasicSpannerPersistentEntity<T> persistentEntity = (BasicSpannerPersistentEntity<T>) mappingContext.getPersistentEntity(domainClass);
  return new MappingSpannerEntityInformation<T, ID>(persistentEntity);
}
 
开发者ID:saturnism,项目名称:spring-data-spanner,代码行数:14,代码来源:SpannerRepositoryFactory.java

示例9: MappingTarantoolEntityInformation

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
public MappingTarantoolEntityInformation(TarantoolPersistentEntity<T> entity) {
    super(entity);

    if(!entity.hasIdProperty()) {

        throw new MappingException(
                String.format("Entity %s requires to have an explicit id field. Did you forget to provide one using @Id?",
                        entity.getName())
        );
    }
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:12,代码来源:MappingTarantoolEntityInformation.java

示例10: throwsMappingExceptionWhenNoIdPropertyPresent

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
/**
 * @see DATAREDIS-425
 */
@Test(expected = MappingException.class)
@SuppressWarnings("unchecked")
public void throwsMappingExceptionWhenNoIdPropertyPresent() {

    when(entity.hasIdProperty()).thenReturn(false);
    when(entity.getType()).thenReturn((Class<T>) ConversionTestEntities.Person.class);
    new MappingTarantoolEntityInformation<>(entity);
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:12,代码来源:MappingTarantoolEntityInformationUnitTests.java

示例11: get

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
public String get(int typeCode) throws MappingException {
    final String result = defaults.get(typeCode);
    if (result == null) {
        throw new MappingException("No Dialect mapping for JDBC type: " + typeCode);
    }
    return result;
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:8,代码来源:TypeMappings.java

示例12: onBeforeConvert

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Override
public void onBeforeConvert(final Object source) {
	ReflectionUtils.doWithFields(source.getClass(),
			new ReflectionUtils.FieldCallback() {

				public void doWith(Field field)
						throws IllegalArgumentException,
						IllegalAccessException {
					ReflectionUtils.makeAccessible(field);

					if (field.isAnnotationPresent(DBRef.class)
							&& field.isAnnotationPresent(CascadeSave.class)) {
						final Object fieldValue = field.get(source);

						DbRefFieldCallback callback = new DbRefFieldCallback();

						ReflectionUtils.doWithFields(fieldValue.getClass(),
								callback);

						if (!callback.isIdFound()) {
							throw new MappingException(
									"Cannot perform cascade save on child object without id set");
						}

						if (Collection.class.isAssignableFrom(field
								.getType())) {
							Collection<?> models = (Collection<?>) fieldValue;
							for (Object model : models) {
								mongoOperations.save(model);
							}
						} else {
							mongoOperations.save(fieldValue);
						}
					}
				}
			});
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:38,代码来源:CascadingMongoEventListener.java

示例13: getEntityInformation

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Override
public <T, ID extends Serializable> MyBatisEntityInformation<T, ID> getEntityInformation(final Class<T> domainClass) {
    final Object mapper = mapperProvider.getMapper(domainClass);
    if (mapper == null) {
        throw new MappingException(
                String.format("Could not lookup mapping metadata for domain class %s!", domainClass.getName()));
    }
    return new MappingMyBatisEntityInformation<>(domainClass);
}
 
开发者ID:create1st,项目名称:spring-boot-starter-mybatis,代码行数:10,代码来源:MyBatisRepositoryFactory.java

示例14: testDeleteSingleWithException

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
@Test(expectedExceptions = DawgIllegalArgumentException.class)
public void testDeleteSingleWithException() {
    HouseRestController controller = new HouseRestController();
    ReflectionTestUtils.setField(controller, "serverUtils", utils);

    HouseService mockService = EasyMock.createMock(HouseService.class);
    mockService.deleteStbById((String) EasyMock.anyObject());
    EasyMock.expectLastCall().andThrow(new MappingException(""));
    EasyMock.replay(mockService);
    ReflectionTestUtils.setField(controller, "service", mockService);

    String id = "id";
    controller.deleteSingle(id);
}
 
开发者ID:Comcast,项目名称:dawg,代码行数:15,代码来源:HouseRestControllerTest.java

示例15: assertUniqueness

import org.springframework.data.mapping.model.MappingException; //导入依赖的package包/类
private void assertUniqueness(SolrPersistentProperty property) {

			if (property.isScoreProperty()) {

				if (scoreProperty != null) {
					throw new MappingException(String.format(AMBIGUOUS_FIELD_MAPPING, property.getFieldName(),
							scoreProperty.getFieldName()));
				}

				scoreProperty = property;
			}
		}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:13,代码来源:SimpleSolrPersistentEntity.java


注:本文中的org.springframework.data.mapping.model.MappingException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。