org.springframework.data.annotation.Persistent Java Examples

The following examples show how to use org.springframework.data.annotation.Persistent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CosmosConfigurationSupport.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException {
    if (!StringUtils.hasText(basePackage)) {
        return Collections.emptySet();
    }

    final Set<Class<?>> initialEntitySet = new HashSet<>();

    if (StringUtils.hasText(basePackage)) {
        final ClassPathScanningCandidateComponentProvider componentProvider =
                new ClassPathScanningCandidateComponentProvider(false);

        componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

        for (final BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
            final String className = candidate.getBeanClassName();
            Assert.notNull(className, "Bean class name is null.");

            initialEntitySet
                    .add(ClassUtils.forName(className, CosmosConfigurationSupport.class.getClassLoader()));
        }
    }

    return initialEntitySet;
}
 
Example #2
Source File: SpELCosmosDBAnnotationIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Test
public void testDatabaseOperationsOnDynamicallyNamedCollection() throws ClassNotFoundException {
  final CosmosDBConfig dbConfig = CosmosDBConfig.builder(dbUri, dbKey, TestConstants.DB_NAME).build();
  final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);

  cosmosEntityInformation = new CosmosEntityInformation<>(SpELPropertyStudent.class);
  final CosmosMappingContext dbContext = new CosmosMappingContext();
  dbContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

  final ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
  final MappingCosmosConverter mappingConverter = new MappingCosmosConverter(dbContext, objectMapper);
  staticTemplate = new CosmosTemplate(dbFactory, mappingConverter, TestConstants.DB_NAME);
  
  staticTemplate.createContainerIfNotExists(cosmosEntityInformation);

  final SpELPropertyStudent insertedRecord = 
          staticTemplate.insert(cosmosEntityInformation.getContainerName(), TEST_PROPERTY_STUDENT, null);
  assertNotNull(insertedRecord);
  
  final SpELPropertyStudent readRecord = 
          staticTemplate.findById(TestConstants.DYNAMIC_PROPERTY_COLLECTION_NAME,
                  insertedRecord.getId(), SpELPropertyStudent.class);
  assertNotNull(readRecord);
}
 
Example #3
Source File: CosmosAnnotationIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Before
public void setUp() throws ClassNotFoundException {
    if (!initialized) {
        final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);

        roleInfo = new CosmosEntityInformation<>(Role.class);
        sampleInfo = new CosmosEntityInformation<>(TimeToLiveSample.class);
        final CosmosMappingContext dbContext = new CosmosMappingContext();

        dbContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

        final MappingCosmosConverter mappingConverter = new MappingCosmosConverter(dbContext, null);

        cosmosTemplate = new CosmosTemplate(cosmosDbFactory, mappingConverter, dbConfig.getDatabase());
        initialized = true;
    }
    collectionRole = cosmosTemplate.createContainerIfNotExists(roleInfo);

    collectionSample = cosmosTemplate.createContainerIfNotExists(sampleInfo);

    cosmosTemplate.insert(roleInfo.getContainerName(), TEST_ROLE, null);
}
 
Example #4
Source File: ReactiveCosmosTemplatePartitionIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Before
public void setUp() throws ClassNotFoundException {
    if (!initialized) {
        final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);

        final CosmosMappingContext mappingContext = new CosmosMappingContext();
        personInfo =
            new CosmosEntityInformation<>(PartitionPerson.class);
        containerName = personInfo.getContainerName();

        mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

        final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext,
            null);
        cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
        cosmosTemplate.createContainerIfNotExists(personInfo).block();

        initialized = true;
    }
    cosmosTemplate.insert(TEST_PERSON).block();
}
 
Example #5
Source File: CosmosTemplatePartitionIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Before
public void setUp() throws ClassNotFoundException {
    if (!initialized) {
        final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);
        final CosmosMappingContext mappingContext = new CosmosMappingContext();

        personInfo = new CosmosEntityInformation<>(PartitionPerson.class);
        mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

        final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext, null);

        cosmosTemplate = new CosmosTemplate(cosmosDbFactory, dbConverter, dbConfig.getDatabase());
        containerName = personInfo.getContainerName();

        cosmosTemplate.createContainerIfNotExists(personInfo);
        initialized = true;
    }

    cosmosTemplate.insert(PartitionPerson.class.getSimpleName(), TEST_PERSON,
            new PartitionKey(TEST_PERSON.getLastName()));
}
 
Example #6
Source File: CosmosTemplateIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Before
public void setUp() throws ClassNotFoundException {
    if (!initialized) {
        final CosmosDbFactory cosmosDbFactory = new CosmosDbFactory(dbConfig);

        final CosmosMappingContext mappingContext = new CosmosMappingContext();
        personInfo = new CosmosEntityInformation<>(Person.class);
        containerName = personInfo.getContainerName();

        mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

        final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext,
            null);
        cosmosTemplate = new CosmosTemplate(cosmosDbFactory, cosmosConverter, dbConfig.getDatabase());
        cosmosTemplate.createContainerIfNotExists(personInfo);
        initialized = true;
    }

    insertedPerson = cosmosTemplate.insert(Person.class.getSimpleName(), TEST_PERSON, null);
}
 
Example #7
Source File: ReactiveCosmosTemplateIT.java    From spring-data-cosmosdb with MIT License 6 votes vote down vote up
@Before
public void setUp() throws ClassNotFoundException {
    if (!initialized) {
        cosmosKeyCredential = new CosmosKeyCredential(dbConfig.getKey());
        final CosmosDbFactory dbFactory = new CosmosDbFactory(dbConfig);

        final CosmosMappingContext mappingContext = new CosmosMappingContext();
        personInfo = new CosmosEntityInformation<>(Person.class);
        containerName = personInfo.getContainerName();

        mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));

        final MappingCosmosConverter dbConverter =
            new MappingCosmosConverter(mappingContext, null);
        cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
        cosmosTemplate.createContainerIfNotExists(personInfo).block().container();
        initialized = true;
    }

    insertedPerson = cosmosTemplate.insert(TEST_PERSON,
        new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON))).block();
}
 
Example #8
Source File: AbstractCrateConfiguration.java    From spring-data-crate with Apache License 2.0 6 votes vote down vote up
/**
 * Scans the mapping base package for classes annotated with {@link Table}.
 * 
 * @see #getMappingBasePackage()
 * @return
 * @throws ClassNotFoundException
 */
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {

	String basePackage = getMappingBasePackage();
	Set<Class<?>> initialEntitySet = new HashSet<>();

	if (hasText(basePackage)) {
		ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
		componentProvider.addIncludeFilter(new AnnotationTypeFilter(Table.class));
		componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

		for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
			initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(), AbstractCrateConfiguration.class.getClassLoader()));
		}
	}

	return initialEntitySet;
}
 
Example #9
Source File: BeihuMongoDataAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public MongoMappingContext mongoMappingContext(MongoCustomConversions conversions)
		throws ClassNotFoundException {
	MongoMappingContext context = new MongoMappingContext();
	context.setInitialEntitySet(new EntityScanner(this.applicationContext)
			.scan(Document.class, Persistent.class));
	Class<?> strategyClass = this.beihuMongoProperties.getFieldNamingStrategy();
	if (strategyClass != null) {
		context.setFieldNamingStrategy(
				(FieldNamingStrategy) BeanUtils.instantiateClass(strategyClass));
	}
	context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
	return context;
}
 
Example #10
Source File: ReflectionUtils.java    From spring-data-simpledb with MIT License 4 votes vote down vote up
public static boolean isPersistentField(Field field) {
	return field.isAnnotationPresent(Persistent.class);
}