xref: /onnv-gate/usr/src/lib/libnisdb/db_scheme_c.x (revision 702:9495c7c1ed3a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  *	db_scheme_c.x
240Sstevel@tonic-gate  *
25*702Sth160488  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*702Sth160488  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate %#pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #if RPC_HDR
320Sstevel@tonic-gate %#ifndef _DB_SCHEMA_H
330Sstevel@tonic-gate %#define _DB_SCHEMA_H
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef USINGC
360Sstevel@tonic-gate %#include "db_item_c.h"
370Sstevel@tonic-gate %#include "db_entry_c.h"
380Sstevel@tonic-gate #else
390Sstevel@tonic-gate %#include "db_item.h"
400Sstevel@tonic-gate %#include "db_entry.h"
41*702Sth160488 #endif /* USINGC */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate const DB_KEY_CASE = TA_CASE;
440Sstevel@tonic-gate 
45*702Sth160488 #endif /* RPC_HDR */
460Sstevel@tonic-gate %
470Sstevel@tonic-gate %#include "nisdb_rw.h"
480Sstevel@tonic-gate %
490Sstevel@tonic-gate %/* Positional information of where field starts within record
500Sstevel@tonic-gate %   and its maximum length in terms of bytes. */
510Sstevel@tonic-gate struct db_posn_info {
520Sstevel@tonic-gate   short int start_column;
530Sstevel@tonic-gate   short int max_len;
540Sstevel@tonic-gate };
550Sstevel@tonic-gate 
560Sstevel@tonic-gate %/* Description of a key */
570Sstevel@tonic-gate struct db_key_desc {
580Sstevel@tonic-gate   item *key_name;
590Sstevel@tonic-gate   unsigned long key_flags;  /* corresponds to tc_flags in table_col defn */
600Sstevel@tonic-gate   int column_number;        /* column within data structure */
610Sstevel@tonic-gate   db_posn_info where;       /* where within record entry is 'key' located */
620Sstevel@tonic-gate   short int store_type;     /* ISAM or SS ?  maybe useless */
630Sstevel@tonic-gate };
640Sstevel@tonic-gate 
650Sstevel@tonic-gate %/* Description of the data field. */
660Sstevel@tonic-gate struct db_data_desc {
670Sstevel@tonic-gate   db_posn_info where;       /* where within record entry is 'data' located */
680Sstevel@tonic-gate   short int store_type;     /* ISAM or SS ? maybe useless */
690Sstevel@tonic-gate };
700Sstevel@tonic-gate 
710Sstevel@tonic-gate %/* A scheme is a description of the fields of a table. */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
740Sstevel@tonic-gate #ifdef USINGC
750Sstevel@tonic-gate 
760Sstevel@tonic-gate struct db_scheme {
770Sstevel@tonic-gate   db_key_desc keys<>;
780Sstevel@tonic-gate   short int max_columns;  /* applies to data only ? */
790Sstevel@tonic-gate   db_data_desc data;
800Sstevel@tonic-gate   __nisdb_rwlock_t scheme_rwlock;
810Sstevel@tonic-gate };
820Sstevel@tonic-gate 
830Sstevel@tonic-gate typedef struct db_scheme  * db_scheme_p;
84*702Sth160488 #endif /* USINGC */
85*702Sth160488 #endif /* RPC_HDR */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #ifndef USINGC
880Sstevel@tonic-gate #ifdef RPC_HDR
890Sstevel@tonic-gate %
900Sstevel@tonic-gate %class db_scheme {
910Sstevel@tonic-gate % protected:
920Sstevel@tonic-gate %  struct {
930Sstevel@tonic-gate %	int keys_len;
940Sstevel@tonic-gate %	db_key_desc *keys_val;
950Sstevel@tonic-gate %  } keys;
960Sstevel@tonic-gate %  short int max_columns;  /* applies to data only ? */
970Sstevel@tonic-gate %  db_data_desc data;
980Sstevel@tonic-gate %  STRUCTRWLOCK(scheme);
990Sstevel@tonic-gate %
1000Sstevel@tonic-gate % public:
1010Sstevel@tonic-gate %/* Accessor: return number of keys in scheme. */
1020Sstevel@tonic-gate %  int numkeys() { return keys.keys_len; }
1030Sstevel@tonic-gate %
1040Sstevel@tonic-gate %/* Accessor:  return location of array of key_desc's. */
1050Sstevel@tonic-gate %  db_key_desc* keyloc () { return keys.keys_val; }
1060Sstevel@tonic-gate %
1070Sstevel@tonic-gate %/* Constructor:  create empty scheme */
1080Sstevel@tonic-gate %  db_scheme() {
1090Sstevel@tonic-gate %	keys.keys_len = 0;
1100Sstevel@tonic-gate %	keys.keys_val = NULL;
1110Sstevel@tonic-gate %	(void) __nisdb_rwinit(&scheme_rwlock);
1120Sstevel@tonic-gate %  }
1130Sstevel@tonic-gate %
1140Sstevel@tonic-gate %/* Constructor:  create new scheme by making copy of 'orig'.
1150Sstevel@tonic-gate %   All items within old scheme are also copied (i.e. no shared pointers). */
1160Sstevel@tonic-gate %  db_scheme( db_scheme* orig );
1170Sstevel@tonic-gate %
1180Sstevel@tonic-gate %/* Constructor:  create new sheme by using information in 'zdesc'. */
1190Sstevel@tonic-gate %  db_scheme( table_obj * );
1200Sstevel@tonic-gate %
1210Sstevel@tonic-gate %/* Destructor:  delete all keys associated with scheme and scheme itself. */
1220Sstevel@tonic-gate %  ~db_scheme();
1230Sstevel@tonic-gate %
1240Sstevel@tonic-gate %/* Free space occupied by columns. */
1250Sstevel@tonic-gate %  void clear_columns( int );
1260Sstevel@tonic-gate %
1270Sstevel@tonic-gate %/* Predicate:  return whether given string is one of the index names
1280Sstevel@tonic-gate %   of this scheme.  If so, return in 'result' the index's number. */
1290Sstevel@tonic-gate %  bool_t find_index( char*, int* );
1300Sstevel@tonic-gate %
1310Sstevel@tonic-gate %/* Print out description of table. */
1320Sstevel@tonic-gate %  void print();
1330Sstevel@tonic-gate %
1340Sstevel@tonic-gate %/* Size of the non-MT/LDAP portion of the db_scheme structure */
1350Sstevel@tonic-gate %  ulong_t oldstructsize(void) {
1360Sstevel@tonic-gate %	return ((ulong_t)&(this->scheme_rwlock) - (ulong_t)this);
1370Sstevel@tonic-gate %  }
1380Sstevel@tonic-gate %
1390Sstevel@tonic-gate %/* Locking methods */
1400Sstevel@tonic-gate %
1410Sstevel@tonic-gate %  int acqexcl(void) {
1420Sstevel@tonic-gate %	return (WLOCK(scheme));
1430Sstevel@tonic-gate %  }
1440Sstevel@tonic-gate %
1450Sstevel@tonic-gate %  int relexcl(void) {
1460Sstevel@tonic-gate %	return (WULOCK(scheme));
1470Sstevel@tonic-gate %  }
1480Sstevel@tonic-gate %
1490Sstevel@tonic-gate %  int acqnonexcl(void) {
1500Sstevel@tonic-gate %	return (RLOCK(scheme));
1510Sstevel@tonic-gate %  }
1520Sstevel@tonic-gate %
1530Sstevel@tonic-gate %  int relnonexcl(void) {
1540Sstevel@tonic-gate %	return (RULOCK(scheme));
1550Sstevel@tonic-gate %  }
1560Sstevel@tonic-gate %};
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate %typedef class db_scheme * db_scheme_p;
159*702Sth160488 #endif /* RPC_HDR */
160*702Sth160488 #endif /* USINGC */
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate #if RPC_HDR
163*702Sth160488 %#endif /* _DB_SCHEMA_H */
1640Sstevel@tonic-gate 
165*702Sth160488 #endif /* RPC_HDR */
166