DeleteExtWorkExecutor(Workspace workspace) { super( workspace ); managedType = workspace.getEntitiesInIndexManager().iterator().next(); builder = workspace.getDocumentBuilder( managedType ); idIsNumeric = isIdNumeric( builder ); }
UpdateExtWorkExecutor(Workspace workspace, AddWorkExecutor addDelegate) { super( null, null ); this.workspace = workspace; this.addDelegate = addDelegate; this.managedType = workspace.getEntitiesInIndexManager().iterator().next(); this.builder = workspace.getDocumentBuilder( managedType ); this.idIsNumeric = DeleteWorkExecutor.isIdNumeric( builder ); }
UpdateExtWorkExecutor(Workspace workspace, AddWorkExecutor addDelegate) { super( null, null ); this.workspace = workspace; this.addDelegate = addDelegate; this.managedType = workspace.getEntitiesInIndexManager().iterator().next(); this.builder = workspace.getDocumentBuilder( managedType ); this.idIsNumeric = DeleteWorkExecutor.isIdNumeric( builder ); }
DeleteExtWorkExecutor(Workspace workspace) { super( workspace ); managedType = workspace.getEntitiesInIndexManager().iterator().next(); builder = workspace.getDocumentBuilder( managedType ); idIsNumeric = isIdNumeric( builder ); }
public ClusteredCacheQueryImpl(QueryDefinition queryDefinition, ExecutorService asyncExecutor, AdvancedCache<?, ?> cache, KeyTransformationHandler keyTransformationHandler, IndexedTypeMap<CustomTypeMetadata> metadata) { super(queryDefinition, cache, keyTransformationHandler); if (metadata != null) { this.queryDefinition.setIndexedType(metadata.keySet().iterator().next().getPojoType()); this.queryDefinition.setSortableField(metadata.values().iterator().next().getSortableFields()); } this.invoker = new ClusteredQueryInvoker(cache, asyncExecutor); }
private Loader getSingleEntityLoader() { final QueryLoader queryLoader = new QueryLoader(); queryLoader.init( session, extendedIntegrator, getObjectInitializer(), timeoutManager ); queryLoader.setEntityType( targetedEntities.iterator().next().getPojoType() ); return queryLoader; }
private DocumentBuilderIndexedEntity getDocumentBuilder(IndexedTypeIdentifier entityType, ExtendedSearchIntegrator extendedIntegrator) { IndexedTypeSet indexedEntities = extendedIntegrator.getIndexedTypesPolymorphic( entityType.asTypeSet() ); if ( indexedEntities.size() > 0 ) { return extendedIntegrator.getIndexBinding( indexedEntities.iterator().next() ).getDocumentBuilder(); } else { return null; } }
/** * Returns the given type itself if it is indexed, otherwise the first found indexed sub-type. * * @param entityType the type of interest * @param factory search factory * @return the given type itself if it is indexed, otherwise the first found indexed sub-type or {@code null} if * neither the given type nor any of its sub-types are indexed */ private IndexedTypeIdentifier getIndexBoundType(IndexedTypeIdentifier entityType, ExtendedSearchIntegrator factory) { if ( factory.getIndexBinding( entityType ) != null ) { return entityType; } IndexedTypeSet indexedSubTypes = factory.getIndexedTypesPolymorphic( entityType.asTypeSet() ); if ( !indexedSubTypes.isEmpty() ) { return indexedSubTypes.iterator().next(); } return null; }
/** * Returns the given type itself if it is indexed, otherwise the first found indexed sub-type. * * @param entityType the type of interest * @param factory search factory * @return the given type itself if it is indexed, otherwise the first found indexed sub-type or {@code null} if * neither the given type nor any of its sub-types are indexed */ private IndexedTypeIdentifier getIndexBoundType(IndexedTypeIdentifier entityType, ExtendedSearchIntegrator factory) { if ( factory.getIndexBinding( entityType ) != null ) { return entityType; } IndexedTypeSet indexedSubTypes = factory.getIndexedTypesPolymorphic( entityType.asTypeSet() ); if ( !indexedSubTypes.isEmpty() ) { return indexedSubTypes.iterator().next(); } return null; }
private void assertIsDoubleSet(IndexedTypeSet typeSet) { Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypeSets.empty() ); Assert.assertFalse( typeSet.isEmpty() ); Assert.assertEquals( 2, typeSet.size() ); Iterator<IndexedTypeIdentifier> iterator = typeSet.iterator(); Assert.assertTrue( iterator.hasNext() ); iterator.next(); // increment once iterator.next(); // increment twice Assert.assertFalse( iterator.hasNext() ); iterator.forEachRemaining( l -> Assert.fail( "should never happen" ) ); //no more elements Set<Class<?>> pojosSet = typeSet.toPojosSet(); Assert.assertTrue( pojosSet.contains( TYPE_A.getPojoType() ) ); Assert.assertTrue( pojosSet.contains( TYPE_B.getPojoType() ) ); Assert.assertEquals( 2, pojosSet.size() ); }
private Loader getCriteriaLoader() { if ( targetedEntities.size() > 1 ) { throw new SearchException( "Cannot mix criteria and multiple entity types" ); } Class entityType = targetedEntities.size() == 0 ? null : targetedEntities.iterator().next().getPojoType(); if ( criteria instanceof CriteriaImpl ) { String targetEntity = ( (CriteriaImpl) criteria ).getEntityOrClassName(); if ( entityType == null ) { ServiceManager serviceManager = extendedIntegrator.getServiceManager(); try { ClassLoaderService classLoaderService = serviceManager.getClassLoaderService(); entityType = classLoaderService.classForName( targetEntity ); } catch (ClassLoadingException e) { throw new SearchException( "Unable to load entity class from criteria: " + targetEntity, e ); } } else { if ( !entityType.getName().equals( targetEntity ) ) { throw new SearchException( "Criteria query entity should match query entity" ); } } } QueryLoader queryLoader = new QueryLoader(); queryLoader.init( session, extendedIntegrator, getObjectInitializer(), timeoutManager ); queryLoader.setEntityType( entityType ); queryLoader.setCriteria( criteria ); return queryLoader; }
private void assertIsEmpty(IndexedTypeSet typeSet) { Assert.assertTrue( "Verify the singleton optimisation applies", typeSet == IndexedTypeSets.empty() ); Assert.assertTrue( typeSet.isEmpty() ); Assert.assertEquals( 0, typeSet.size() ); typeSet.iterator().forEachRemaining( l -> Assert.fail( "should never happen" ) ); Assert.assertEquals( 0, typeSet.toPojosSet().size() ); }
private void assertIsSingletonSet(IndexedTypeSet typeSet, Class<?> someType, boolean recursive) { Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypeSets.empty() ); Assert.assertFalse( typeSet.isEmpty() ); Assert.assertEquals( 1, typeSet.size() ); Iterator<IndexedTypeIdentifier> iterator = typeSet.iterator(); Assert.assertTrue( iterator.hasNext() ); IndexedTypeIdentifier firstElement = iterator.next(); // increment once Assert.assertFalse( iterator.hasNext() ); iterator.forEachRemaining( l -> Assert.fail( "should never happen" ) ); //no more elements Set<Class<?>> pojosSet = typeSet.toPojosSet(); Assert.assertTrue( pojosSet.contains( someType ) ); Assert.assertEquals( 1, pojosSet.size() ); IndexedTypeSet typeSet2 = firstElement.asTypeSet(); if ( recursive ) { assertIsSingletonSet( typeSet2, someType, false ); } Assert.assertEquals( typeSet2, typeSet2 ); Assert.assertEquals( firstElement.getPojoType(), someType ); }
@Test public void testGetIndexedTypeSingleIndexedType() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchMapping mapping = new SearchMapping(); mapping .entity( Foo.class ).indexed() .property( "id", FIELD ).documentId() ; cfg.setProgrammaticMapping( mapping ); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeSet indexedClasses = si.getIndexedTypeIdentifiers(); assertEquals( "Wrong number of indexed entities", 1, indexedClasses.size() ); assertTrue( indexedClasses.iterator().next().equals( new PojoIndexedTypeIdentifier( Foo.class ) ) ); }