Skip to content

Commit e0202f7

Browse files
authored
Merge pull request #245 from ml054/v4.2
sync with latest java version
2 parents cc28b64 + 43451a6 commit e0202f7

21 files changed

+107
-39
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
@@ -37,6 +37,7 @@ import { AbstractIndexCreationTask } from "./Indexes/AbstractIndexCreationTask";
3737
import { SessionOptions } from "./Session/SessionOptions";
3838
import { DatabaseSmuggler } from "./Smuggler/DatabaseSmuggler";
3939
import { IDisposable } from "../Types/Contracts";
40+
import { StringUtil } from "../Utility/StringUtil";
4041

4142
export abstract class DocumentStoreBase
4243
extends EventEmitter
@@ -113,7 +114,7 @@ export abstract class DocumentStoreBase
113114
: databaseOrCallback as string;
114115

115116
const resultPromise = this.maintenance
116-
.forDatabase(database || this.database)
117+
.forDatabase(this.getEffectiveDatabase(database))
117118
.send(new PutIndexesOperation(...indexesToAdd))
118119
// tslint:disable-next-line:no-empty
119120
.then(() => {});
@@ -360,4 +361,23 @@ export abstract class DocumentStoreBase
360361
protected _assertValidConfiguration(): void {
361362
this.conventions.validate();
362363
}
364+
365+
public getEffectiveDatabase(database: string): string {
366+
return DocumentStoreBase.getEffectiveDatabase(this, database);
367+
}
368+
369+
public static getEffectiveDatabase(store: IDocumentStore, database: string) {
370+
if (!database) {
371+
database = store.database;
372+
}
373+
374+
if (!StringUtil.isNullOrWhitespace(database)) {
375+
return database;
376+
}
377+
378+
throwError("InvalidArgumentException", "Cannot determine database to operate on. " +
379+
"Please either specify 'database' directly as an action parameter " +
380+
"or set the default database to operate on using 'DocumentStore.database' property. " +
381+
"Did you forget to pass 'database' parameter?");
382+
}
363383
}

src/Documents/Identity/HiloMultiDatabaseIdGenerator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IHiloIdGenerator } from "./IHiloIdGenerator";
22
import { HiloMultiTypeIdGenerator } from "./HiloMultiTypeIdGenerator";
33
import { AbstractHiloIdGenerator } from "./AbstractHiloIdGenerator";
44
import { IDocumentStore } from "../IDocumentStore";
5+
import { DocumentStoreBase } from "../DocumentStoreBase";
56

67
export class HiloMultiDatabaseIdGenerator extends AbstractHiloIdGenerator implements IHiloIdGenerator {
78

@@ -10,7 +11,7 @@ export class HiloMultiDatabaseIdGenerator extends AbstractHiloIdGenerator implem
1011
}
1112

1213
public generateDocumentId(dbName: string, entity: object): Promise<string> {
13-
return this._getGeneratorForDatabase(dbName || this._store.database)
14+
return this._getGeneratorForDatabase(DocumentStoreBase.getEffectiveDatabase(this._store, dbName))
1415
.generateDocumentId(entity);
1516
}
1617

src/Documents/Indexes/AbstractIndexCreationTaskBase.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PutIndexesOperation } from "../Operations/Indexes/PutIndexesOperation";
66
import { ErrorFirstCallback } from "../../Types/Callbacks";
77
import { TypeUtil } from "../../Utility/TypeUtil";
88
import { passResultToCallback } from "../../Utility/PromiseUtil";
9+
import { DocumentStoreBase } from "../DocumentStoreBase";
910

1011
export abstract class AbstractIndexCreationTaskBase {
1112

@@ -114,8 +115,8 @@ export abstract class AbstractIndexCreationTaskBase {
114115
const oldConventions = this.conventions;
115116

116117
try {
117-
const databaseForConventions = database || store.database;
118-
this.conventions = conventions || this.conventions || store.getRequestExecutor(databaseForConventions).conventions;
118+
database = DocumentStoreBase.getEffectiveDatabase(store, database);
119+
this.conventions = conventions || this.conventions || store.getRequestExecutor(database).conventions;
119120

120121
const indexDefinition = this.createIndexDefinition();
121122
indexDefinition.name = this.getIndexName();
@@ -128,7 +129,7 @@ export abstract class AbstractIndexCreationTaskBase {
128129
indexDefinition.priority = this.priority;
129130
}
130131

131-
await store.maintenance.forDatabase(database || store.database)
132+
await store.maintenance.forDatabase(database)
132133
.send(new PutIndexesOperation(indexDefinition));
133134
} finally {
134135
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/Session/DocumentSessionRevisionsBase.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {ForceRevisionStrategy} from "./ForceRevisionStrategy";
2-
import {throwError} from "../../Exceptions";
3-
import {TypeUtil} from "../../Utility/TypeUtil";
4-
import {StringUtil} from "../../Utility/StringUtil";
5-
import {AdvancedSessionExtensionBase} from "./AdvancedSessionExtensionBase";
1+
import { ForceRevisionStrategy } from "./ForceRevisionStrategy";
2+
import { throwError } from "../../Exceptions";
3+
import { TypeUtil } from "../../Utility/TypeUtil";
4+
import { StringUtil } from "../../Utility/StringUtil";
5+
import { AdvancedSessionExtensionBase } from "./AdvancedSessionExtensionBase";
66

77
export class DocumentSessionRevisionsBase extends AdvancedSessionExtensionBase {
88
forceRevisionCreationFor<T extends object>(entity: T)

src/Documents/Session/GraphDocumentQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class GraphDocumentQuery<T extends object> extends AbstractDocumentQuery<
7979
const rawQuery = queryRawQueryOrBuilder;
8080
return this._withInternal(alias, documentType, this.session.advanced.rawQuery(rawQuery, documentType) as unknown as AbstractDocumentQuery<TOther, any>);
8181
} else if (queryRawQueryOrBuilder instanceof DocumentQuery) {
82-
//TODO: ParameterPrefix = $"w{WithTokens.Count}p
82+
this.parameterPrefix = "w" + this._withTokens.length + "p";
8383
const documentQuery = queryRawQueryOrBuilder;
8484
return this._withInternal(alias, documentQuery.getQueryType(), documentQuery);
8585
} else {

src/Documents/Session/Tokens/FromToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { QueryToken } from "./QueryToken";
22
import { throwError } from "../../../Exceptions";
3-
import {StringUtil} from "../../../Utility/StringUtil";
3+
import { StringUtil } from "../../../Utility/StringUtil";
44

55
export class FromToken extends QueryToken {
66

src/Documents/Subscriptions/DocumentSubscriptions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class DocumentSubscriptions implements IDisposable {
7171
throwError("InvalidArgumentException", "Cannot create a subscription if the script is null");
7272
}
7373

74-
const requestExecutor = this._store.getRequestExecutor(database || this._store.database);
74+
const requestExecutor = this._store.getRequestExecutor(this._store.getEffectiveDatabase(database));
7575

7676
const command = new CreateSubscriptionCommand(this._store.conventions, options);
7777
await requestExecutor.execute(command);
@@ -291,7 +291,7 @@ export class DocumentSubscriptions implements IDisposable {
291291
* It downloads a list of all existing subscriptions in a database.
292292
*/
293293
public async getSubscriptions(start: number, take: number, database?: string): Promise<SubscriptionState[]> {
294-
const requestExecutor = this._store.getRequestExecutor(database || this._store.database);
294+
const requestExecutor = this._store.getRequestExecutor(this._store.getEffectiveDatabase(database));
295295

296296
const command = new GetSubscriptionsCommand(start, take);
297297
await requestExecutor.execute(command);
@@ -313,7 +313,7 @@ export class DocumentSubscriptions implements IDisposable {
313313
* Delete a subscription.
314314
*/
315315
public async delete(name: string, database?: string): Promise<void> {
316-
const requestExecutor = this._store.getRequestExecutor(database || this._store.database);
316+
const requestExecutor = this._store.getRequestExecutor(this._store.getEffectiveDatabase(database));
317317

318318
const command = new DeleteSubscriptionCommand(name);
319319
return requestExecutor.execute(command);
@@ -337,7 +337,7 @@ export class DocumentSubscriptions implements IDisposable {
337337
throwError("InvalidArgumentException", "SubscriptionName cannot be null");
338338
}
339339

340-
const requestExecutor = this._store.getRequestExecutor(database || this._store.database);
340+
const requestExecutor = this._store.getRequestExecutor(this._store.getEffectiveDatabase(database));
341341

342342
const command = new GetSubscriptionStateCommand(subscriptionName);
343343
await requestExecutor.execute(command);
@@ -366,7 +366,7 @@ export class DocumentSubscriptions implements IDisposable {
366366
* Force server to close current client subscription connection to the server
367367
*/
368368
public async dropConnection(name: string, database?: string): Promise<void> {
369-
const requestExecutor = this._store.getRequestExecutor(database || this._store.database);
369+
const requestExecutor = this._store.getRequestExecutor(this._store.getEffectiveDatabase(database));
370370

371371
const command = new DropSubscriptionConnectionCommand(name);
372372
return requestExecutor.execute(command);
@@ -376,15 +376,15 @@ export class DocumentSubscriptions implements IDisposable {
376376
public async enable(name: string, database: string)
377377
public async enable(name: string, database?: string) {
378378
const operation = new ToggleOngoingTaskStateOperation(name, "Subscription", false);
379-
await this._store.maintenance.forDatabase(database || this._store.database)
379+
await this._store.maintenance.forDatabase(this._store.getEffectiveDatabase(database))
380380
.send(operation);
381381
}
382382

383383
public async disable(name: string)
384384
public async disable(name: string, database: string)
385385
public async disable(name: string, database?: string) {
386386
const operation = new ToggleOngoingTaskStateOperation(name, "Subscription", true);
387-
await this._store.maintenance.forDatabase(database || this._store.database)
387+
await this._store.maintenance.forDatabase(this._store.getEffectiveDatabase(database))
388388
.send(operation);
389389
}
390390
}

src/Documents/Subscriptions/SubscriptionWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class SubscriptionWorker<T extends object> implements IDisposable {
6868
}
6969

7070
this._store = documentStore;
71-
this._dbName = dbName || documentStore.database;
71+
this._dbName = documentStore.getEffectiveDatabase(dbName);
7272
}
7373

7474
public dispose(): void {
@@ -151,7 +151,7 @@ export class SubscriptionWorker<T extends object> implements IDisposable {
151151

152152
this._ensureParser();
153153

154-
const databaseName = this._dbName || this._store.database;
154+
const databaseName = this._store.getEffectiveDatabase(this._dbName);
155155

156156
const parameters = {
157157
database: databaseName,

0 commit comments

Comments
 (0)