Skip to content

This module provides direct access to Adabas database data in a Golang-based application. This contains all transactional operations on the database.

License

Notifications You must be signed in to change notification settings

SoftwareAG/adabas-go-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exploit your assets in Adabas by using the Adabas API for Go

Introduction

This package is designed for using Adabas databases from Go. It's an data interface to Adabas. You can find a detailed overview about the design and technical implementation here.

For details have a look at the API documentation. It can be referenced here: https://godoc.org/github.com/SoftwareAG/adabas-go-api/adabas

Features

In general, users of the Adabas API for Go do not need to know a basic level of Adabas APIs such as Adabas control blocks or Adabas buffer layouts. The Adabas API for Go provides a more user friendly and optimized use of Adabas files and fields. It is similar to the Adabas Client for Java product delivered by Software AG.

This is a list of features which the Adabas API for Go supports:

  • Read, Insert, Delete and Update of Adabas records
  • Search are limited to the Adabas standard search capabilities (see Search documentation)
  • Work with field descriptors and special descriptors like sub-/super-descriptors
  • Work with the Adabas TCP/IP (ADATCP) layer on Linux, Unix and Windows
  • Work with interface to Adabas Client library (ADALNK)
  • Work with Adabas Mainframe using the Entire Network infrastructure (ADALNK)
  • Support Unicode access of Adabas Unicode fields
  • Work with Adabas Maps, a short name to long name definition
  • Work with Adabas period groups and multiple fields
  • Work with large object reads and writes
  • Work with partial large object reads and writes
  • Is optimized for network access using ADATCP by using Multifetch feature
  • Provide Go structure usage by reflecting structure fields to Adabas Map definitions or plain Adabas shortnames

Usage

Inside the code the Adabas API for Go can be used importing the Go API. Beside the API, some small sample applications are provided in GitHub. These examples of the Adabas API for Go can be downloaded using the go get command:

go get -u github.com/softwareag/adabas-go-api/adabas

You can compile it with the new Adabas TCP/IP interface on Linux, Unix and Windows. In this case no additional native library is needed. This is the default behavior.

Alternatively the Adabas native local access with Adabas client native libraries (ADALNK) can be used. The AdabasClient installation is a prerequisite in this case.

Enable native library access

The default is the Adabas TCP/IP interface enabled in the Go API. It is possible to enable Adabas Client native interface support using the Adabas Client library. You need to provide the Go build tag adalnk and the CGO compile flags defining build flags for the Adabas Client library. If the Adabas environment is sourced, you can define CGO compile flags as follows:

On Unix:

CGO_CFLAGS=-I${ACLDIR}/inc
CGO_LDFLAGS=-L${ACLDIR}/lib -ladalnkx -lsagsmp2 -lsagxts3 -ladazbuf

On Windows:

CGO_CFLAGS=-I%ACLDIR%\..\inc
CGO_LDFLAGS=-L%ACLDIR%\..\bin -L%ACLDIR%\..\lib -ladalnkx

The application is built with Adabas API for Go as follows (please note that the tag adalnk is needed to enable local IPC access):

go build -tags adalnk application.go

First step

A detailed description how to do the first steps using the Adabas Docker community edition is provided here. Independent of the used environment of Docker (like Kubernetes or others), it describes how to call Adabas in a Microservice environment.

Adabas API for Go example

Standard usage

The logical view of the data can be defined using Adabas Maps. The Adabas Maps are introduced in the Adabas Client for Java product delivered by Software AG. A detailed description of Adabas maps is available here.

The creation of Adabas maps is done by the infrastructure of the Adabas Client for Java. The product contains a Adabas Data Designer rich client or Eclipse plugin. The tools provide the management of Adabas map definitions. A programmatical approach to create Adabas maps is part of the Adabas API for Go.

In the first example a logical read on the database file uses Adabas maps:

import (
  "github.com/SoftwareAG/adabas-go-api/adabas"
)
// Create new connection handler using the Adabas Map repository in database 24 file 4
connection, _ := adabas.NewConnection("acj;map;config=[24,4]")
defer connection.Close()
// Create a read request using the Map definition
request, _ := connection.CreateMapReadRequest("EMPLOYEES-NAT-DDM")
// Define the result records content
_ = request.QueryFields("NAME,PERSONNEL-ID")
// Read logical using a range search query
result, _ := request.ReadLogicalWith("PERSONNEL-ID=[11100301:11100303]")
// Result is dumped to stdout
result.DumpValues()

The next example shows a cursor read on the database file:

// Read logical with cursor using a range search query
result,rerr := request.ReadLogicalWithCursoring("PERSONNEL-ID=[11100301:11100303]")
// Result is dumped to stdout
for col.HasNextRecord() {
  record, rerr := col.NextRecord()
    ...
}

See detailed documentation here.

Classic database usage

It is possible to use classical Adabas database parameters to read data. The approach does not contain format enhancements like Natural DDM's or the Adabas Map approach. It is a raw access to the database.

A quick example to read data from a database file 11 of the Adabas database with database ID 23 is here:

// Create new connection handler to database
connection, _ := adabas.NewConnection("acj;target=23")
defer connection.Close()
// To work on file 11 create corresponding read request
request, _ := connection.CreateFileReadRequest(11)
// Define the result records content
request.QueryFields("AA,AB")
// Requst unlimited number of records
request.Limit = 0
// Read in the database using search query
result,_ := request.ReadLogicalWith("AA=60010001")
var aa,ac,ad,ae string
// Read given AA(alpha) and all entries of group AB to string variables
result.Values[0].Scan(&aa,&ac,&ad,&ae)

The example code is referenced here. See detailed documentation here.

Adabas reflected to Go-struct

Go-struct with Adabas Map definition

The Adabas API for Go can handle simple Go struct-definitions to map them to an Adabas Map definition.

For example if the structure is defined like this:

type Employees struct {
ID        string
Birth     int64
Name      string `adabas:"Name"`
First     string `adabas:"FirstName"`
}

The struct can be used to read or store data of the Adabas Map field Birth, Name and FirstName directly using the corresponding struct-fields Birth, Name and First. To store the struct record, do this:

// Create new connection handler to database
connection, _ := adabas.NewConnection("acj;map=EMPLOYEES")
defer connection.Close()

storeRequest, err := connection.NewMapStoreRequest(Employees{})
e:=  &Employees{ID: "ID3", Birth: 456, Name: "Name3", FirstName: "First name3"}
err = storeRequest.StoreData(e)
err = storeRequest.EndTransaction()

The read of the struct data will be done similar with:

// Create new connection handler to database
connection, _ := adabas.NewConnection("acj;map=EMPLOYEE")
defer connection.Close()
request, _ := connection.CreateMapReadRequest(&Employees{})
defer request.Close()
result, err := request.ReadLogicalWith("ID>'ID'")
e := result.Data[0].(*Employees)

All fields of the struct are mapped to an Adabas Map field name. The adabas tag of the struct definition changes the mapped name.

Define Go-struct to Adabas shortname field definition

The Adabas API for Go can handle simple Go struct-definitions to map them to an Adabas field shortname. This is an direct connection into the database. It might be used to work on RAW data or Large objects directly.

For example if the structure is defined like this:

type NewEmployeesInMap struct {
	Index  uint64                `adabas:":isn"`
	ID     string                `adabas:":key:AA"`
	Income []*NewEmployeesIncome `adabas:"::L0"`
}

type NewEmployeesIncome struct {
	CurCode string `adabas:"::LA"`
	Salary  int    `adabas:"::LB"`
	Bonus   []int  `adabas:"::LC"`
}

The Go-struct can be used to read or store data of the Adabas new employee example file (File 9) directly. In this example the slice of an sub structure is generated in the call. The third value in the :-separated field defines the Adabas shortname. In the example above, the period group L0 is read into the NewEmployeesIncome Go-struct-slice.

To read the record using the NewEmployeesInMap-struct out of Adabas database file 9 of database id 24:

connection, _ := NewConnection("acj;inmap=24")
defer connection.Close()
request, _ := connection.CreateMapReadRequest(&NewEmployeesInMap{},9)
_ = request.QueryFields("*")
response, rerr := request.SearchAndOrder("AA=11100108", "AA")

To read the record using the NewEmployeesInMap-struct out of Adabas database file 9 of database on ADATCP host desthost port 64100, do this:

connection, _ := NewConnection("acj;inmap=adatcp://desthost:64100")
defer connection.Close()
request, _ := connection.CreateMapReadRequest(&NewEmployeesInMap{},9)
_ = request.QueryFields("*")
response, rerr := request.SearchAndOrder("AA=11100108", "AA")

All fields of the struct are mapped to an Adabas classic field shortname. The adabas tag of the struct definition defines the Adabas shortname.

Log output

To enable log output in sample executables, please set the ENABLE_DEBUG environment variable to 1 for debug level output and 2 for info level output. This will enable the logging.

To use logging in your code with the Adabas API, you can enable logging by setting the log instance with your logger instances with:

adatypes.Central.Log = logger

Summary

The Adabas API for Go offers easy access to store or read data in or out of Adabas. The Go API should help developers to work with data in Adabas without needing to be an expert on special Adabas database features. Go functions enable developers to use Go as a programming language to access Adabas in the same way as other data sources are embedded in a Go project. By using the native AdabasClient library, you can access all platforms Adabas runs on like Linux, Unix, Windows and Mainframe (z/OS with Entire Network).

Step by step all relevant Adabas features are or will be supported.


These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.


For more information you can Ask a Question in the TECHcommunity Forums.

You can find additional information in the Software AG TECHcommunity.


Contact us at TECHcommunity if you have any questions.

About

This module provides direct access to Adabas database data in a Golang-based application. This contains all transactional operations on the database.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages