@Test public void testBrowseByNameCaseInsensitive() { String name = "CamelCase"; String version = "version"; try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.register(db); Component component = createComponent(bucket, GROUP, name, version); entityAdapter.addEntity(db, component); verify(componentEntityAdapterExtension).writeFields(any(ODocument.class), any(Component.class)); List<Component> components1 = Lists.newArrayList(entityAdapter.browseByNameCaseInsensitive(db, "camelcase", Collections.singleton(bucket), null)); assertThat(components1, hasSize(1)); assertThat(components1.get(0).name(), is(name)); assertThat(components1.get(0).version(), is(version)); List<Component> components2 = Lists.newArrayList(entityAdapter.browseByNameCaseInsensitive(db, "CAMELCASE", Collections.singleton(bucket), null)); assertThat(components2, hasSize(1)); assertThat(components2.get(0).name(), is(name)); assertThat(components2.get(0).version(), is(version)); verify(componentEntityAdapterExtension, times(2)).readFields(any(ODocument.class), any(Component.class)); } }
public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db, final String name, @Nullable final Iterable<Bucket> buckets, @Nullable final String querySuffix) { checkNotNull(name); String whereClause = " where (ci_name = :name)"; StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause); addBucketConstraints(whereClause, buckets, query); if (querySuffix != null) { query.append(' ').append(querySuffix); } Map<String, Object> parameters = ImmutableMap.of("name", name); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return transform(db.command(new OCommandSQL(query.toString())).execute(parameters)); }
ComponentEntityAdapter extends MetadataNodeEntityAdapter<Component> { public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db, final String name, @Nullable final Iterable<Bucket> buckets, @Nullable final String querySuffix) { checkNotNull(name); String whereClause = " where (ci_name = :name)"; StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause); addBucketConstraints(whereClause, buckets, query); if (querySuffix != null) { query.append(' ').append(querySuffix); } Map<String, Object> parameters = ImmutableMap.of("name", name); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return transform(db.command(new OCommandSQL(query.toString())).execute(parameters)); } }
ComponentEntityAdapter extends MetadataNodeEntityAdapter<Component> { public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db, final String name, @Nullable final Iterable<Bucket> buckets, @Nullable final String querySuffix) { checkNotNull(name); String whereClause = " where (ci_name = :name)"; StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause); addBucketConstraints(whereClause, buckets, query); if (querySuffix != null) { query.append(' ').append(querySuffix); } Map<String, Object> parameters = ImmutableMap.of("name", name); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return transform(db.command(new OCommandSQL(query.toString())).execute(parameters)); } @Inject  ComponentEntityAdapter(final BucketEntityAdapter bucketEntityAdapter,
                                final ComponentFactory componentFactory,
                                final Set<ComponentEntityAdapterExtension> componentEntityAdapterExtensions); }
ComponentEntityAdapter extends MetadataNodeEntityAdapter<Component> { public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db, final String name, @Nullable final Iterable<Bucket> buckets, @Nullable final String querySuffix) { checkNotNull(name); String whereClause = " where (ci_name = :name)"; StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause); addBucketConstraints(whereClause, buckets, query); if (querySuffix != null) { query.append(' ').append(querySuffix); } Map<String, Object> parameters = ImmutableMap.of("name", name); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return transform(db.command(new OCommandSQL(query.toString())).execute(parameters)); } @Inject  ComponentEntityAdapter(final BucketEntityAdapter bucketEntityAdapter,
                                final ComponentFactory componentFactory,
                                final Set<ComponentEntityAdapterExtension> componentEntityAdapterExtensions); Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db,
                                                         final String name,
                                                         @Nullable final Iterable<Bucket> buckets,
                                                         @Nullable final String querySuffix); boolean exists(final ODatabaseDocumentTx db,
                        @Nullable final String group,
                        final String name,
                        @Nullable final String version,
                        final Bucket bucket); @Override boolean sendEvents(); @Override EntityEvent newEvent(final ODocument document, final EventKind eventKind); @Override String eventAffinity(final ODocument document); @Override boolean resolveConflicts(); }
ComponentEntityAdapter extends MetadataNodeEntityAdapter<Component> { public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db, final String name, @Nullable final Iterable<Bucket> buckets, @Nullable final String querySuffix) { checkNotNull(name); String whereClause = " where (ci_name = :name)"; StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause); addBucketConstraints(whereClause, buckets, query); if (querySuffix != null) { query.append(' ').append(querySuffix); } Map<String, Object> parameters = ImmutableMap.of("name", name); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return transform(db.command(new OCommandSQL(query.toString())).execute(parameters)); } @Inject  ComponentEntityAdapter(final BucketEntityAdapter bucketEntityAdapter,
                                final ComponentFactory componentFactory,
                                final Set<ComponentEntityAdapterExtension> componentEntityAdapterExtensions); Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db,
                                                         final String name,
                                                         @Nullable final Iterable<Bucket> buckets,
                                                         @Nullable final String querySuffix); boolean exists(final ODatabaseDocumentTx db,
                        @Nullable final String group,
                        final String name,
                        @Nullable final String version,
                        final Bucket bucket); @Override boolean sendEvents(); @Override EntityEvent newEvent(final ODocument document, final EventKind eventKind); @Override String eventAffinity(final ODocument document); @Override boolean resolveConflicts(); static final String DB_CLASS; static final String P_GROUP; static final String P_VERSION; static final String P_CI_NAME; static final String I_BUCKET_GROUP_NAME_VERSION; static final String I_GROUP_NAME_VERSION_INSENSITIVE; }