Skip to content

Commit c180a0d

Browse files
authored
Merge pull request #246 from ml054/v5.0
V5.0
2 parents eb89bd9 + c7e140c commit c180a0d

24 files changed

+318
-48
lines changed

src/Documents/DocumentStore.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ export class DocumentStore extends DocumentStoreBase {
189189
public getRequestExecutor(database?: string): RequestExecutor {
190190
this.assertInitialized();
191191

192-
if (!database) {
193-
database = this.database;
194-
}
192+
database = this.getEffectiveDatabase(database);
195193

196194
const databaseLower = database.toLowerCase();
197195

@@ -239,7 +237,7 @@ export class DocumentStore extends DocumentStoreBase {
239237
requestTimeout(timeoutInMs: number, database?: string): IDisposable {
240238
this.assertInitialized();
241239

242-
database = database || this.database;
240+
database = this.getEffectiveDatabase(database);
243241

244242
if (!database) {
245243
throwError("InvalidOperationException", "Cannot use requestTimeout without a default database defined " +
@@ -415,6 +413,6 @@ export class DocumentStore extends DocumentStoreBase {
415413
public bulkInsert(database?: string): BulkInsertOperation {
416414
this.assertInitialized();
417415

418-
return new BulkInsertOperation(database || this.database, this);
416+
return new BulkInsertOperation(this.getEffectiveDatabase(database), this);
419417
}
420418
}

src/Documents/DocumentStoreBase.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { DatabaseSmuggler } from "./Smuggler/DatabaseSmuggler";
3636
import { IDisposable } from "../Types/Contracts";
3737
import { TimeSeriesOperations } from "./TimeSeries/TimeSeriesOperations";
3838
import { IAbstractIndexCreationTask } from "./Indexes/IAbstractIndexCreationTask";
39+
import { StringUtil } from "../Utility/StringUtil";
3940

4041
export abstract class DocumentStoreBase
4142
extends EventEmitter
@@ -91,7 +92,7 @@ export abstract class DocumentStoreBase
9192
const indexesToAdd = IndexCreation.createIndexesToAdd(tasks, this.conventions);
9293

9394
await this.maintenance
94-
.forDatabase(database || this.database)
95+
.forDatabase(this.getEffectiveDatabase(database))
9596
.send(new PutIndexesOperation(...indexesToAdd));
9697
}
9798

@@ -343,4 +344,23 @@ export abstract class DocumentStoreBase
343344
protected _assertValidConfiguration(): void {
344345
this.conventions.validate();
345346
}
347+
348+
public getEffectiveDatabase(database: string): string {
349+
return DocumentStoreBase.getEffectiveDatabase(this, database);
350+
}
351+
352+
public static getEffectiveDatabase(store: IDocumentStore, database: string) {
353+
if (!database) {
354+
database = store.database;
355+
}
356+
357+
if (!StringUtil.isNullOrWhitespace(database)) {
358+
return database;
359+
}
360+
361+
throwError("InvalidArgumentException", "Cannot determine database to operate on. " +
362+
"Please either specify 'database' directly as an action parameter " +
363+
"or set the default database to operate on using 'DocumentStore.database' property. " +
364+
"Did you forget to pass 'database' parameter?");
365+
}
346366
}

src/Documents/Identity/MultiDatabaseHiLoIdGenerator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MultiTypeHiLoIdGenerator } from "./MultiTypeHiLoIdGenerator";
22
import { DocumentStore } from "../DocumentStore";
33
import { IRavenObject } from "../../Types/IRavenObject";
4+
import { DocumentStoreBase } from "../DocumentStoreBase";
45

56
export class MultiDatabaseHiLoIdGenerator {
67

@@ -13,7 +14,7 @@ export class MultiDatabaseHiLoIdGenerator {
1314
}
1415

1516
public generateDocumentId(database: string, entity: object): Promise<string> {
16-
return this._getGeneratorForDatabase(database || this._store.database)
17+
return this._getGeneratorForDatabase(DocumentStoreBase.getEffectiveDatabase(this._store, database))
1718
.generateDocumentId(entity);
1819
}
1920

src/Documents/Indexes/AbstractIndexCreationTaskBase.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { IDocumentStore } from "../IDocumentStore";
55
import { PutIndexesOperation } from "../Operations/Indexes/PutIndexesOperation";
66
import { AbstractCommonApiForIndexes } from "./AbstractCommonApiForIndexes";
77
import { IAbstractIndexCreationTask } from "./IAbstractIndexCreationTask";
8+
import { DocumentStoreBase } from "../DocumentStoreBase";
89

910
export abstract class AbstractIndexCreationTaskBase<TIndexDefinition extends IndexDefinition>
1011
extends AbstractCommonApiForIndexes implements IAbstractIndexCreationTask {
11-
12-
12+
1313
/**
1414
* Creates the index definition.
1515
*/
@@ -47,8 +47,8 @@ export abstract class AbstractIndexCreationTaskBase<TIndexDefinition extends Ind
4747
const oldConventions = this.conventions;
4848

4949
try {
50-
const databaseForConventions = database || store.database;
51-
this.conventions = conventions || this.conventions || store.getRequestExecutor(databaseForConventions).conventions;
50+
database = DocumentStoreBase.getEffectiveDatabase(store, database);
51+
this.conventions = conventions || this.conventions || store.getRequestExecutor(database).conventions;
5252

5353
const indexDefinition = this.createIndexDefinition();
5454
indexDefinition.name = this.getIndexName();
@@ -61,7 +61,7 @@ export abstract class AbstractIndexCreationTaskBase<TIndexDefinition extends Ind
6161
indexDefinition.priority = this.priority;
6262
}
6363

64-
await store.maintenance.forDatabase(database || store.database)
64+
await store.maintenance.forDatabase(database)
6565
.send(new PutIndexesOperation(indexDefinition));
6666
} finally {
6767
this.conventions = oldConventions;

src/Documents/Operations/OperationExecutor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DocumentType } from "../DocumentAbstractions";
1515
import { PatchResult } from "./PatchResult";
1616
import { IDocumentStore } from "../IDocumentStore";
1717
import { StatusCodes } from "../../Http/StatusCode";
18+
import { StringUtil } from "../../Utility/StringUtil";
1819

1920
export class OperationExecutor {
2021

@@ -27,7 +28,7 @@ export class OperationExecutor {
2728
public constructor(store: DocumentStoreBase, databaseName?: string) {
2829
this._store = store;
2930
this._databaseName = databaseName ? databaseName : store.database;
30-
if (this._databaseName) {
31+
if (!StringUtil.isNullOrWhitespace(this._databaseName)) {
3132
this._requestExecutor = store.getRequestExecutor(this._databaseName);
3233
} else {
3334
throwError("InvalidOperationException",

src/Documents/Queries/Facets/AggregationQueryBase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export abstract class AggregationQueryBase {
4343
return (this._session as DocumentSession)
4444
.addLazyOperation(
4545
new LazyAggregationQueryOperation(
46-
this._session.conventions,
46+
this._session,
4747
this._query,
4848
this,
4949
(queryResult: QueryResult) =>
@@ -65,6 +65,8 @@ export abstract class AggregationQueryBase {
6565
results[facetResult.name] = facetResult;
6666
}
6767

68+
this._session.registerIncludes(queryResult.includes);
69+
6870
QueryOperation.ensureIsAcceptable(
6971
queryResult, this._query.waitForNonStaleResults, this._duration, this._session);
7072

src/Documents/Queries/Suggestions/SuggestionQueryBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export abstract class SuggestionQueryBase {
5454

5555
return (this._session as DocumentSession).addLazyOperation(
5656
new LazySuggestionQueryOperation(
57-
this._session.conventions,
57+
this._session,
5858
this._query,
5959
result => this._invokeAfterQueryExecuted(result),
6060
(result) => this._processResults(result)

src/Documents/Session/AbstractDocumentQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
428428

429429
const clazz = this._conventions.getJsTypeByDocumentType(this._clazz);
430430
return new LazyQueryOperation<T>(
431-
this._theSession.conventions,
431+
this._theSession,
432432
this._queryOperation,
433433
this,
434434
clazz);
@@ -2157,7 +2157,7 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
21572157
const clazz = this._conventions.getJsTypeByDocumentType(this._clazz);
21582158
const lazyQueryOperation =
21592159
new LazyQueryOperation<T>(
2160-
this._theSession.conventions,
2160+
this._theSession,
21612161
this._queryOperation,
21622162
this,
21632163
clazz);

src/Documents/Session/IDocumentQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface IDocumentQuery<T extends object>
7474
* If the field is not stored in index, value will come from document directly.
7575
*/
7676
selectFields<TProjection extends object>(
77-
queryData: QueryData, projectionClass: DocumentType<TProjection>): IDocumentQuery<TProjection>; //TODO: update in 4.2 as well
77+
queryData: QueryData, projectionClass: DocumentType<TProjection>): IDocumentQuery<TProjection>;
7878

7979
/**
8080
* Selects a Time Series Aggregation based on

src/Documents/Session/Operations/Lazy/LazyAggregationQueryOperation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ import { GetRequest } from "../../../Commands/MultiGet/GetRequest";
77
import { GetResponse } from "../../../Commands/MultiGet/GetResponse";
88
import { FacetQueryCommand } from "../../../Commands/FacetQueryCommand";
99
import { stringToReadable } from "../../../../Utility/StreamUtil";
10+
import { InMemoryDocumentSessionOperations } from "../../InMemoryDocumentSessionOperations";
1011

1112
export class LazyAggregationQueryOperation implements ILazyOperation {
1213

13-
private readonly _conventions: DocumentConventions;
14+
private readonly _session: InMemoryDocumentSessionOperations;
1415
private readonly _indexQuery: IndexQuery;
1516
private readonly _parent: AggregationQueryBase;
1617
private readonly _processResults:
1718
(queryResult: QueryResult) => FacetResultObject;
1819

1920
public constructor(
20-
conventions: DocumentConventions,
21+
session: InMemoryDocumentSessionOperations,
2122
indexQuery: IndexQuery,
2223
parent: AggregationQueryBase,
2324
processResults: (queryResult: QueryResult) => FacetResultObject) {
24-
this._conventions = conventions;
25+
this._session = session;
2526
this._indexQuery = indexQuery;
2627
this._processResults = processResults;
2728
this._parent = parent;
@@ -32,7 +33,7 @@ export class LazyAggregationQueryOperation implements ILazyOperation {
3233
request.url = "/queries";
3334
request.method = "POST";
3435
request.query = "?queryHash=" + this._indexQuery.getQueryHash();
35-
request.body = writeIndexQuery(this._conventions, this._indexQuery);
36+
request.body = writeIndexQuery(this._session.conventions, this._indexQuery);
3637
return request;
3738
}
3839

@@ -72,7 +73,7 @@ export class LazyAggregationQueryOperation implements ILazyOperation {
7273
}
7374

7475
const result = await FacetQueryCommand.parseQueryResultResponseAsync(
75-
stringToReadable(response.result), this._conventions, false);
76+
stringToReadable(response.result), this._session.conventions, false);
7677
this._handleResponse(result);
7778
}
7879

0 commit comments

Comments
 (0)