|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2020 "Neo4j," |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { newError } from '../../error' |
| 21 | +import BoltProtocolV1 from '../bolt-protocol-v1' |
| 22 | +import BoltProtocolV2 from '../bolt-protocol-v2' |
| 23 | +import BoltProtocolV3 from '../bolt-protocol-v3' |
| 24 | +import BoltProtocolV4x0 from '../bolt-protocol-v4x0' |
| 25 | +import BoltProtocolV4x1 from '../bolt-protocol-v4x1' |
| 26 | +import BoltProtocolV4x2 from '../bolt-protocol-v4x2' |
| 27 | +import BoltProtocolV4x3 from '../bolt-protocol-v4x3' |
| 28 | +import { Chunker } from '../chunking' |
| 29 | +import Connection from '../connection' |
| 30 | + |
| 31 | +/** |
| 32 | + * Creates a protocol with a given version |
| 33 | + * |
| 34 | + * @param {object} config |
| 35 | + * @param {number} config.version The version of the protocol |
| 36 | + * @param {Connection} config.connection The connection used to talk with the database |
| 37 | + * @param {Chunker} config.chunker The chunker |
| 38 | + * @param {boolean} config.disableLosslessIntegers Disable the lossless integers |
| 39 | + * @param {boolean} config.serversideRouting It's using server side routing |
| 40 | + */ |
| 41 | +export default function create ({ |
| 42 | + version, |
| 43 | + connection, // should be removed |
| 44 | + chunker, |
| 45 | + disableLosslessIntegers, |
| 46 | + serversideRouting |
| 47 | +} = {}) { |
| 48 | + switch (version) { |
| 49 | + case 1: |
| 50 | + return new BoltProtocolV1(connection, chunker, disableLosslessIntegers) |
| 51 | + case 2: |
| 52 | + return new BoltProtocolV2(connection, chunker, disableLosslessIntegers) |
| 53 | + case 3: |
| 54 | + return new BoltProtocolV3(connection, chunker, disableLosslessIntegers) |
| 55 | + case 4.0: |
| 56 | + return new BoltProtocolV4x0(connection, chunker, disableLosslessIntegers) |
| 57 | + case 4.1: |
| 58 | + return new BoltProtocolV4x1( |
| 59 | + connection, |
| 60 | + chunker, |
| 61 | + disableLosslessIntegers, |
| 62 | + serversideRouting |
| 63 | + ) |
| 64 | + case 4.2: |
| 65 | + return new BoltProtocolV4x2( |
| 66 | + connection, |
| 67 | + chunker, |
| 68 | + disableLosslessIntegers, |
| 69 | + serversideRouting |
| 70 | + ) |
| 71 | + case 4.3: |
| 72 | + return new BoltProtocolV4x3( |
| 73 | + connection, |
| 74 | + chunker, |
| 75 | + disableLosslessIntegers, |
| 76 | + serversideRouting |
| 77 | + ) |
| 78 | + default: |
| 79 | + throw newError('Unknown Bolt protocol version: ' + version) |
| 80 | + } |
| 81 | +} |
0 commit comments