Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Documents/Conventions/DocumentConventions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ export class DocumentConventions {

private _transformClassCollectionNameToDocumentIdPrefix: (maybeClassCollectionName: string) => string;
private _documentIdGenerator: IdConvention;
private _findIdentityPropertyNameFromCollectionName: (collectionName: string) => string;

private _findCollectionName: (constructorOrTypeChecker: ObjectTypeDescriptor) => string;

private _identityProperty: string;

private _findJsTypeName: (ctorOrTypeChecker: ObjectTypeDescriptor) => string;
private _findJsType: (id: string, doc: object) => ObjectTypeDescriptor;

Expand All @@ -77,8 +78,7 @@ export class DocumentConventions {
public constructor() {
this._readBalanceBehavior = "None";
this._identityPartsSeparator = "/";

this._findIdentityPropertyNameFromCollectionName = () => "id";
this._identityProperty = CONSTANTS.Documents.Metadata.ID_PROPERTY;

this._findJsType = (id: string, doc: object) => {
const metadata = doc[CONSTANTS.Documents.Metadata.KEY];
Expand Down Expand Up @@ -271,6 +271,15 @@ export class DocumentConventions {
this._useOptimisticConcurrency = useOptimisticConcurrency;
}

public get identityProperty() {
return this._identityProperty;
}

public set identityProperty(val) {
this._assertNotFrozen();
this._identityProperty = val;
}

public get findJsType() {
return this._findJsType;
}
Expand Down Expand Up @@ -298,15 +307,6 @@ export class DocumentConventions {
this._findCollectionName = value;
}

public get findIdentityPropertyNameFromCollectionName() {
return this._findIdentityPropertyNameFromCollectionName;
}

public set findIdentityPropertyNameFromCollectionName(value) {
this._assertNotFrozen();
this._findIdentityPropertyNameFromCollectionName = value;
}

public get documentIdGenerator() {
return this._documentIdGenerator;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ export class DocumentConventions {
public getIdentityProperty(documentType: DocumentType): string {
const typeDescriptor = this.getJsTypeByDocumentType(documentType);
return this._registeredIdPropertyNames.get(typeDescriptor)
|| CONSTANTS.Documents.Metadata.ID_PROPERTY;
|| this._identityProperty;
}

public updateFrom(configuration: ClientConfiguration): void {
Expand Down
81 changes: 40 additions & 41 deletions src/Http/RequestExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as os from "os";
import * as BluebirdPromise from "bluebird";
import * as semaphore from "semaphore";
import * as stream from "readable-stream";
import { acquireSemaphore } from "../Utility/SemaphoreUtil";
import { acquireSemaphore, AcquiredSemaphoreContext } from "../Utility/SemaphoreUtil";
import { getLogger, ILogger } from "../Utility/LogUtil";
import { Timer } from "../Primitives/Timer";
import { ServerNode } from "./ServerNode";
Expand Down Expand Up @@ -327,54 +327,53 @@ export class RequestExecutor implements IDisposable {
.then(() => this._nodeSelector.getFastestNode());
}

protected _updateClientConfiguration(): PromiseLike<void> {
if (this._disposed) {
return BluebirdPromise.resolve(null);
}
private async _updateClientConfigurationInternal(): Promise<void> {
const oldDisableClientConfigurationUpdates = this._disableClientConfigurationUpdates;
this._disableClientConfigurationUpdates = true;

const updateClientConfigurationInternal = () => {
const oldDisableClientConfigurationUpdates = this._disableClientConfigurationUpdates;
this._disableClientConfigurationUpdates = true;
try {
if (this._disposed) {
return;
}

return BluebirdPromise.resolve()
.then(() => {
const command = new GetClientConfigurationCommand();
const { currentNode, currentIndex } = this.chooseNodeForRequest(command, null);
await this.execute(command, null, {
chosenNode: currentNode,
nodeIndex: currentIndex,
shouldRetry: false
});

if (this._disposed) {
return;
}
const clientConfigOpResult = command.result;
if (!clientConfigOpResult) {
return;
}

const command = new GetClientConfigurationCommand();
const currentIndexAndNode2: CurrentIndexAndNode = this.chooseNodeForRequest(command, null);
return this.execute(command, null, {
chosenNode: currentIndexAndNode2.currentNode,
nodeIndex: currentIndexAndNode2.currentIndex,
shouldRetry: false
})
.then(() => command.result);
})
.then((clientConfigOpResult: GetClientConfigurationOperationResult) => {
if (!clientConfigOpResult) {
return;
}
this._conventions.updateFrom(clientConfigOpResult.configuration);
this._clientConfigurationEtag = clientConfigOpResult.etag;
} catch (err) {
this._log.error(err, "Error getting client configuration.");
} finally {
this._disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates;
}
}

this._conventions.updateFrom(clientConfigOpResult.configuration);
this._clientConfigurationEtag = clientConfigOpResult.etag;
protected async _updateClientConfiguration(): Promise<void> {
if (this._disposed) {
return;
}

})
.tapCatch(err => this._log.error(err, "Error getting client configuration."))
.finally(() => {
this._disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates;
});
};
let semAcquiredContext: AcquiredSemaphoreContext;

const semAcquiredContext = acquireSemaphore(this._updateClientConfigurationSemaphore);
const result = BluebirdPromise.resolve(semAcquiredContext.promise)
.then(() => updateClientConfigurationInternal())
.finally(() => {
try {
semAcquiredContext = acquireSemaphore(this._updateClientConfigurationSemaphore);
await semAcquiredContext.promise;
await this._updateClientConfigurationInternal();
} finally {
if (semAcquiredContext) {
semAcquiredContext.dispose();
});

return Promise.resolve(result);
}
}
}

public updateTopology(node: ServerNode, timeout: number, forceUpdate: boolean = false): Promise<boolean> {
Expand Down
8 changes: 4 additions & 4 deletions test/Documents/CustomKeyCaseConventionsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("With custom key case conventions set", function () {
s.conventions.findCollectionNameForObjectLiteral = (o) => o["collection"];
s.conventions.entityFieldNameConvention = "camel";
s.conventions.remoteEntityFieldNameConvention = "pascal";
s.conventions.findIdentityPropertyNameFromCollectionName = () => "Id";
s.conventions.identityProperty = "Id";
s.conventions.registerEntityIdPropertyName(Object, "Id");
});

Expand Down Expand Up @@ -129,7 +129,7 @@ describe("With custom key case conventions set", function () {
s.conventions.findCollectionNameForObjectLiteral = (o) => o["collection"];
s.conventions.entityFieldNameConvention = "camel";
s.conventions.remoteEntityFieldNameConvention = "pascal";
s.conventions.findIdentityPropertyNameFromCollectionName = () => "Id";
s.conventions.identityProperty = "Id";
s.conventions.registerEntityIdPropertyName(Object, "Id");
});

Expand Down Expand Up @@ -190,7 +190,7 @@ describe("With custom key case conventions set", function () {
s.conventions.findCollectionNameForObjectLiteral = (o) => o["collection"];
s.conventions.entityFieldNameConvention = "camel";
s.conventions.remoteEntityFieldNameConvention = "pascal";
s.conventions.findIdentityPropertyNameFromCollectionName = () => "Id";
s.conventions.identityProperty = "Id";
s.conventions.registerEntityIdPropertyName(Object, "Id");
});

Expand Down Expand Up @@ -226,7 +226,7 @@ describe("With custom key case conventions set", function () {
s.conventions.findCollectionNameForObjectLiteral = (o) => o["collection"];
s.conventions.entityFieldNameConvention = "camel";
s.conventions.remoteEntityFieldNameConvention = "pascal";
s.conventions.findIdentityPropertyNameFromCollectionName = () => "Id";
s.conventions.identityProperty = "Id";
s.conventions.registerEntityIdPropertyName(Object, "Id");
});

Expand Down