Skip to content

Commit

Permalink
refactor: remove old implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream committed Aug 27, 2023
1 parent b79c241 commit 8cdde67
Show file tree
Hide file tree
Showing 38 changed files with 524 additions and 1,179 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ let package = Package(
.product(name: "CryptoSwift", package: "CryptoSwift"),
]
),
.executableTarget(name: "OracleNIOExample", dependencies: ["OracleNIO"]),
.testTarget(
name: "OracleNIOTests",
dependencies: ["OracleNIO"]
Expand Down
18 changes: 6 additions & 12 deletions Sources/OracleNIO/Connection/OracleConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ public class OracleConnection {
var serviceName: String
var username: String
var password: String
var autocommit: Bool

// "(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=XEPDB1)(CID=(PROGRAM=\(ProcessInfo.processInfo.processName))(HOST=\(ProcessInfo.processInfo.hostName))(USER=\(ProcessInfo.processInfo.userName))))(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.22)(PORT=1521)))"

public init(address: SocketAddress, serviceName: String, username: String, password: String, autocommit: Bool = false) {
public init(
address: SocketAddress,
serviceName: String,
username: String,
password: String
) {
self.address = address
self.serviceName = serviceName
self.username = username
self.password = password
self.autocommit = autocommit
}
}

var autocommit: Bool { configuration.autocommit }

var capabilities = Capabilities()
let configuration: Configuration
let channel: Channel
Expand Down Expand Up @@ -216,11 +215,6 @@ public class OracleConnection {

return promise.futureResult
}

@available(*, deprecated)
func createRequest<T: TNSRequest>() -> T {
T.initialize(from: self)
}
}

extension OracleConnection: CapabilitiesProvider {
Expand Down
24 changes: 13 additions & 11 deletions Sources/OracleNIO/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ enum Constants {
static let TNS_SESSGET_SESSION_CHANGED: UInt32 = 4

// MARK: LOB operations
static let TNS_LOB_OP_GET_LENGTH = 0x0001
static let TNS_LOB_OP_READ = 0x0002
static let TNS_LOB_OP_TRIM = 0x0020
static let TNS_LOB_OP_WRITE: UInt32 = 0x0040
static let TNS_LOB_OP_GET_CHUNK_SIZE = 0x4000
static let TNS_LOB_OP_CREATE_TEMP: UInt32 = 0x0110
static let TNS_LOB_OP_FREE_TEMP: UInt32 = 0x0111
static let TNS_LOB_OP_OPEN = 0x8000
static let TNS_LOB_OP_CLOSE = 0x10000
static let TNS_LOB_OP_IS_OPEN = 0x11000
static let TNS_LOB_OP_ARRAY: UInt32 = 0x80000
enum LOBOperation: UInt32 {
case getLength = 0x0001
case read = 0x0002
case trim = 0x0020
case write = 0x0040
case getChunkSize = 0x4000
case createTemp = 0x0110
case freeTemp = 0x0111
case open = 0x8000
case close = 0x10000
case isOpen = 0x11000
case array = 0x80000
}

// MARK: LOB locator constants
static let TNS_LOB_LOCATOR_OFFSET_FLAG_1 = 4
Expand Down
76 changes: 0 additions & 76 deletions Sources/OracleNIO/Cursor.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/OracleNIO/Data/ByteBuffer+OracleCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension ByteBuffer: OracleEncodable {
var slice = self.slice()
if length <= Constants.TNS_MAX_SHORT_LENGTH {
buffer.writeInteger(UInt8(length))
buffer.writeBuffer(&slice)
} else {
buffer.writeInteger(Constants.TNS_LONG_LENGTH_INDICATOR)
while buffer.readableBytes > 0 {
Expand All @@ -30,6 +31,8 @@ extension ByteBuffer: OracleEncodable {
}

extension ByteBuffer: OracleDecodable {
public var size: UInt32 { UInt32(self.readableBytes) }

public init<JSONDecoder: OracleJSONDecoder>(
from buffer: inout ByteBuffer,
type: OracleDataType,
Expand Down
95 changes: 87 additions & 8 deletions Sources/OracleNIO/Data/LOB+OracleCodable.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,88 @@
import NIOCore

public struct LOB {
let size: UInt64
let chunkSize: UInt32
let locator: ByteBuffer
let hasMetadata: Bool
public final class LOB {
var size: UInt64
var chunkSize: UInt32
internal var locator: ByteBuffer
var hasMetadata: Bool
public let dbType: DBType

weak var cleanupContext: CleanupContext?

init(
size: UInt64,
chunkSize: UInt32,
locator: ByteBuffer,
hasMetadata: Bool,
dbType: DBType
) {
self.size = size
self.chunkSize = chunkSize
self.locator = locator
self.hasMetadata = hasMetadata
self.dbType = dbType
}
deinit { self.free() }

static func create(dbType: DBType, locator: ByteBuffer?) -> Self {
if let locator {
return self.init(
size: 0,
chunkSize: 0,
locator: locator,
hasMetadata: false,
dbType: dbType
)
} else {
let locator = ByteBuffer(repeating: 0, count: 40)
let lob = self.init(
size: 0,
chunkSize: 0,
locator: locator,
hasMetadata: false,
dbType: dbType
)
fatalError("TODO: create temp lob on db")
return lob
}
}

func encoding() -> String {
locator.moveReaderIndex(to: 0)
if dbType.csfrm == Constants.TNS_CS_NCHAR ||
(locator.readableBytes >= Constants.TNS_LOB_LOCATOR_OFFSET_FLAG_3 &&
((locator.getInteger(
at: Constants.TNS_LOB_LOCATOR_OFFSET_FLAG_3, as: UInt8.self
)! & Constants.TNS_LOB_LOCATOR_VAR_LENGTH_CHARSET) != 0))
{
return Constants.TNS_ENCODING_UTF16
}
return Constants.TNS_ENCODING_UTF8
}

func write(
_ buffer: ByteBuffer, offset: UInt64, on connection: OracleConnection
) {
fatalError("TODO: write lob")
}

func free() {
let flags1 = self.locator.getInteger(
at: Constants.TNS_LOB_LOCATOR_OFFSET_FLAG_1, as: UInt8.self
)!
let flags4 = self.locator.getInteger(
at: Constants.TNS_LOB_LOCATOR_OFFSET_FLAG_4, as: UInt8.self
)!
if flags1 & Constants.TNS_LOB_LOCATOR_FLAGS_ABSTRACT != 0 ||
flags4 & Constants.TNS_LOB_LOCATOR_FLAGS_TEMP != 0 {
if self.cleanupContext?.tempLOBsToClose == nil {
self.cleanupContext?.tempLOBsToClose = []
}
self.cleanupContext?.tempLOBsToClose?.append(self.locator)
self.cleanupContext?.tempLOBsTotalSize += self.locator.readableBytes
}
}

}

extension LOB: OracleEncodable {
Expand All @@ -21,7 +99,7 @@ extension LOB: OracleEncodable {
}

extension LOB: OracleDecodable {
public init<JSONDecoder: OracleJSONDecoder>(
public convenience init<JSONDecoder: OracleJSONDecoder>(
from buffer: inout ByteBuffer,
type: OracleDataType,
context: OracleDecodingContext<JSONDecoder>
Expand All @@ -31,11 +109,12 @@ extension LOB: OracleDecodable {
let size = try buffer.throwingReadUB8()
let chunkSize = try buffer.throwingReadUB4()
let locator = try buffer.readOracleSpecificLengthPrefixedSlice()
self = LOB(
self.init(
size: size,
chunkSize: chunkSize,
locator: locator,
hasMetadata: true
hasMetadata: true,
dbType: type
)
default:
throw OracleDecodingError.Code.typeMismatch
Expand Down
2 changes: 1 addition & 1 deletion Sources/OracleNIO/Data/RowID+OracleCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension RowID: OracleDecodable {
case .rowID:
let rba = buffer.readUB4()
let partitionID = buffer.readUB2()
buffer.skipUB1()
buffer.moveReaderIndex(forwardBy: 1)
let blockNumber = buffer.readUB4()
let slotNumber = buffer.readUB2()
self = RowID(
Expand Down
3 changes: 2 additions & 1 deletion Sources/OracleNIO/Data/String+OracleCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ extension String: OracleEncodable {
into buffer: inout ByteBuffer,
context: OracleEncodingContext<JSONEncoder>
) where JSONEncoder: OracleJSONEncoder {
buffer.writeBytesAndLength(self.bytes)
ByteBuffer(string: self)
.encode(into: &buffer, context: context)
}

public static var oracleType: DBType {
Expand Down

This file was deleted.

25 changes: 0 additions & 25 deletions Sources/OracleNIO/Extensions/ByteBuffer/ByteBuffer+LOB.swift

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8cdde67

Please sign in to comment.