protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException { if (!StringUtils.hasText(basePackage)) { return Collections.emptySet(); } final Set<Class<?>> initialEntitySet = new HashSet<Class<?>>(); if (StringUtils.hasText(basePackage)) { final ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); for (final BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) { initialEntitySet .add(ClassUtils.forName(candidate.getBeanClassName(), DocumentDbConfigurationSupport.class.getClassLoader())); } } return initialEntitySet; }
@Before public void setup() { mappingContext = new DocumentDbMappingContext(); try { mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext) .scan(Persistent.class)); } catch (ClassNotFoundException e) { throw new RuntimeException(e.getMessage()); } dbConverter = new MappingDocumentDbConverter(mappingContext); documentClient = new DocumentClient(documentDbUri, documentDbKey, ConnectionPolicy.GetDefault(), ConsistencyLevel.Session); dbTemplate = new DocumentDbTemplate(documentClient, dbConverter, TEST_DB_NAME); dbTemplate.createCollectionIfNotExists(Person.class.getSimpleName(), null, null); dbTemplate.insert(Person.class.getSimpleName(), TEST_PERSON, null); }
private static Set<String> getInititalEntityClasses(String[] domainPackages) { if (ArrayUtils.isEmpty(domainPackages)) { return null; } ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class)); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); Set<String> classes = new ManagedSet<>(); for (String domainPackage : domainPackages) { if (StringUtils.isBlank(domainPackage)) { continue; } for (BeanDefinition candidate : componentProvider.findCandidateComponents(domainPackage)) { classes.add(candidate.getBeanClassName()); } } return classes; }
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { String basePackage = getMappingBasePackage(); Set<Class<?>> initialEntitySet = new HashSet<Class<?>>(); if (StringUtils.hasText(basePackage)) { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class)); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) { initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(), this.getClass().getClassLoader())); } } return initialEntitySet; }
private Set<Class<?>> getInitialEntitySet(BeanFactory beanFactory) throws ClassNotFoundException { Set<Class<?>> entitySet = new HashSet<Class<?>>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.setEnvironment(this.environment); scanner.setResourceLoader(this.resourceLoader); scanner.addIncludeFilter(new AnnotationTypeFilter(Document.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); for (String basePackage : getMappingBasePackages(beanFactory)) { if (StringUtils.hasText(basePackage)) { for (BeanDefinition candidate : scanner .findCandidateComponents(basePackage)) { entitySet.add(ClassUtils.forName(candidate.getBeanClassName(), this.classLoader)); } } } return entitySet; }
@Override public <T> T persist(T e) { BeanProperty id = ReflectionUtils.getAnnotatedProperty(e, Id.class); if (id == null) { throw new IllegalArgumentException("The bean must have an @Id field"); } List<BeanProperty> persistentProperties = ReflectionUtils .getAnnotatedProperties(e, Persistent.class); Property[] properties = new Property[persistentProperties.size() + 1]; properties[0] = new Property(e.getClass().getName() + ID_SUFFIX, id.getValue()); int i = 1; for (BeanProperty property : persistentProperties) { properties[i] = new Property(property.getName(), property.getValue()); i++; } Node node = template.createNode(properties); index.index(node, e.getClass().getName() + ID_SUFFIX, id.getValue()); return e; }
/** * 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; }
@Bean @ConditionalOnMissingBean public MongoMappingContext mongoMappingContext(BeanFactory beanFactory, ApplicationContext applicationContext) throws ClassNotFoundException { MongoMappingContext context = new MongoMappingContext(); context.setInitialEntitySet(new EntityScanner(applicationContext).scan(Document.class, Persistent.class)); return context; }
@Bean @ConditionalOnMissingBean public MongoMappingContext mongoMappingContext(BeanFactory beanFactory) throws ClassNotFoundException { MongoMappingContext context = new MongoMappingContext(); context.setInitialEntitySet(new EntityScanner(this.applicationContext) .scan(Document.class, Persistent.class)); Class<?> strategyClass = this.properties.getFieldNamingStrategy(); if (strategyClass != null) { context.setFieldNamingStrategy( (FieldNamingStrategy) BeanUtils.instantiate(strategyClass)); } return context; }
@Override protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() { return Arrays.asList(Entity.class, Persistent.class); }
@Override protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { return new EntityScanner(this.applicationContext).scan(Document.class, Persistent.class); }
public static boolean isPersistentField(Field field) { return field.isAnnotationPresent(Persistent.class); }