Browse code

Add db_oracle module and toolses for it

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3997 689a6050-402a-0410-94f2-e92a70836424

Iouri Kharon authored on 09/04/2008 15:46:09
Showing 40 changed files
... ...
@@ -81,6 +81,12 @@ case $DBENGINE in
81 81
 			DBENGINELOADED=1
82 82
 		fi
83 83
 		;;
84
+	ORACLE|oracle|Oracle)
85
+		if [ -f "$MYLIBDIR/openserctl.oracle" ]; then
86
+			. "$MYLIBDIR/openserctl.oracle"
87
+			DBENGINELOADED=1
88
+		fi
89
+		;;
84 90
 
85 91
 	DBTEXT|dbtext)
86 92
 		if [ -f "$MYLIBDIR/openserctl.dbtext" ]; then
87 93
new file mode 100644
... ...
@@ -0,0 +1,105 @@
1
+#!/bin/sh
2
+#
3
+# $Id$
4
+#
5
+# sc: openser control; tool for maintaining openser
6
+#
7
+#===================================================================
8
+
9
+##### ----------------------------------------------- #####
10
+### ORACLE specific variables and functions
11
+#
12
+SESSOPT="set term off feed 0 lin 8000 pages 50000 ver off colsep '|'
13
+col count(*) jus l format 'tm'
14
+alter session set nls_date_format='DD-MM-RR HH24:MI:SS';
15
+"
16
+
17
+##### ----------------------------------------------- #####
18
+### load SQL base
19
+#
20
+if [ -f "$MYLIBDIR/openserctl.sqlbase" ]; then
21
+	. "$MYLIBDIR/openserctl.sqlbase"
22
+else
23
+	echo "Cannot load SQL core functions '$MYLIBDIR/openserctl.sqlbase' - exiting ..."
24
+	exit -1
25
+fi
26
+
27
+if [ -f "$MYLIBDIR/openserdbfunc.oracle" ]; then
28
+	. "$MYLIBDIR/openserdbfunc.oracle"
29
+else
30
+	echo "Cannot load ORACLE core functions '$MYLIBDIR/openserdbfunc.oracle' - exiting ..."
31
+	exit -1
32
+fi
33
+
34
+##### ----------------------------------------------- #####
35
+### binaries
36
+if [ -z "$SQLPLUS" ] ; then
37
+	locate_tool sqlplus
38
+	if [ -z "$TOOLPATH" ] ; then
39
+		echo "error: 'sqlplus' tool not found: set SQLPLUS variable to correct tool path"
40
+		exit
41
+	fi
42
+	SQLPLUS="$TOOLPATH"
43
+	export SQLPLUS
44
+fi
45
+
46
+if [ -z "$OPENSER_ORASEL" ] ; then
47
+	locate_tool openser_orasel
48
+	if [ -n "$TOOLPATH" ] ; then
49
+		OPENSER_ORASEL="$TOOLPATH"
50
+		export OPENSER_ORASEL
51
+	fi
52
+fi
53
+
54
+##### ----------------------------------------------- #####
55
+
56
+# input: sql query, optional sqlplus command-line params
57
+oracle_query() {
58
+	# if password not yet queried, query it now
59
+	prompt_oracle_pw rw
60
+	mdbg "oracle_query: $SQLPLUS $2 -S -L -R 3 $DBRWUSER@$DBNAME '$1'"
61
+	RC=`echo "$SESSOPT $1" | $SQLPLUS $2 -S -L -R 3 ${DBRWUSER}/${DBRWPW}@${DBNAME}`
62
+	RE=$?
63
+	echo "$RC"
64
+	if [ $RE -eq 0 ]; then
65
+		echo "$RC" | $EGREP -qi "error"
66
+		if [ $? -eq 0 ]; then RE=1; fi
67
+	fi
68
+	if [ $RE -eq 0 ]; then
69
+		echo "$RC" | $EGREP -q "ORA-[0-9]"
70
+		if [ $? -eq 0 ]; then RE=1; fi
71
+	fi
72
+	return $RE
73
+}
74
+
75
+# input: sql query, optional sqlplus command-line params
76
+oracle_ro_query() {
77
+	# if password not yet queried, query it now
78
+	prompt_oracle_pw ro
79
+	if [ -z "$OPENSER_ORASEL" ]; then
80
+		mdbg "oracle_ro_query: $SQLPLUS $2 -S -L -R 3 $DBROUSER@$DBNAME '$1'"
81
+		RC=`echo "$SESSOPT $1" | $SQLPLUS $2 -S -L -R 3 ${DBROUSER}/${DBROPW}@${DBNAME}`
82
+		RE=$?
83
+		echo "$RC"
84
+		if [ $RE -eq 0 ]; then
85
+			echo "$RC" | $EGREP -qi "error"
86
+			if [ $? -eq 0 ]; then RE=1; fi
87
+		fi
88
+		if [ $RE -eq 0 ]; then
89
+			echo "$RC" | $EGREP -q "ORA-[0-9]"
90
+			if [ $? -eq 0 ]; then RE=1; fi
91
+		fi
92
+		return $RE
93
+	else
94
+		mdbg "oracle_ro_query: $OPENSER_ORASEL $DBROUSER@$DBNAME $2 -N -e '$1'"
95
+		$OPENSER_ORASEL ${DBROUSER}/${DBROPW}@${DBNAME} $2 -Ne "$1"
96
+		return $?
97
+	fi
98
+}
99
+
100
+DBCMD=oracle_query
101
+DBROCMD=oracle_ro_query
102
+DBRAWPARAMS=""
103
+if [ -n "$OPENSER_ORASEL" ]; then
104
+DBRAWPARAMS="-B"
105
+fi
... ...
@@ -12,7 +12,7 @@
12 12
 ## chrooted directory
13 13
 # $CHROOT_DIR="/path/to/chrooted/directory"
14 14
 
15
-## database type: MYSQL, PGSQL, DB_BERKELEY, or DBTEXT, by default none is loaded
15
+## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT, by default none is loaded
16 16
 # If you want to setup a database with openserdbctl, you must at least specify
17 17
 # this parameter.
18 18
 # DBENGINE=MYSQL
... ...
@@ -20,7 +20,7 @@
20 20
 ## database host
21 21
 # DBHOST=localhost
22 22
 
23
-## database name
23
+## database name (for ORACLE this is TNS name)
24 24
 # DBNAME=openser
25 25
 
26 26
 # database path used by dbtext or db_berkeley
... ...
@@ -38,7 +38,7 @@
38 38
 ## password for database read only user
39 39
 # DBROPW=openserro
40 40
 
41
-## database super user
41
+## database super user (for ORACLE this is 'scheme-creator' user)
42 42
 # DBROOTUSER="root"
43 43
 
44 44
 # user name column
... ...
@@ -82,6 +82,14 @@ case $DBENGINE in
82 82
 			merr "could not load the script in $MYLIBDIR/openserdbctl.pgsql for database engine $DBENGINE"
83 83
 		fi
84 84
 		;;
85
+	ORACLE|oracle|Oracle)
86
+		if [ -f "$MYLIBDIR/openserdbctl.oracle" ]; then
87
+			. "$MYLIBDIR/openserdbctl.oracle"
88
+			USED_DBENGINE="oracle"
89
+		else
90
+			merr "could not load the script in $MYLIBDIR/openserdbctl.oracle for database engine $DBENGINE"
91
+		fi
92
+		;;
85 93
 	DBTEXT|dbtext|textdb)
86 94
 		if [ -f "$MYLIBDIR/openserdbctl.dbtext" ]; then
87 95
 			. "$MYLIBDIR/openserdbctl.dbtext"
... ...
@@ -117,7 +125,9 @@ openser_dump()  # pars: <database name>
117 125
 		merr "openser_dump function takes two param"
118 126
 		exit 1
119 127
 	fi
120
-	if [ "$PW" = "" ] ; then
128
+	if [ "$USED_DBENGINE" == "oracle" ]; then
129
+		oracle_dump $1 $2
130
+	elif [ "$PW" = "" ] ; then
121 131
 		$DUMP_CMD $1 > $2
122 132
 	else
123 133
 		$DUMP_CMD "-p$PW" $1 > $2
... ...
@@ -136,7 +146,11 @@ openser_restore() #pars: <database name> <filename>
136 146
 		merr "openser_restore function takes two params"
137 147
 		exit 1
138 148
 	fi
139
-	sql_query $1 < $2
149
+	if [ "$USED_DBENGINE" == "oracle" ]; then
150
+		oracle_restore $1 $2
151
+	else
152
+		sql_query $1 < $2
153
+	fi
140 154
 	if [ "$?" -ne 0 ]; then
141 155
 			merr "db restore failed"
142 156
 			exit 1
143 157
new file mode 100644
... ...
@@ -0,0 +1,312 @@
1
+#!/bin/sh
2
+# $Id$
3
+#
4
+# Script for adding and dropping OpenSER Oracle tables
5
+#
6
+# History:
7
+
8
+##In you not have 'AS SYSDBA' access to database connect, comment next string
9
+##and Oracle administrator must create DBROOTUSER
10
+##(see scripts/oracle/admin/_create_as_sys.tmpl)
11
+DBSYSUSER="sys"
12
+
13
+
14
+# path to the database schemas
15
+DATA_DIR="/usr/local/share/openser"
16
+if [ -d "$DATA_DIR/oracle" ] ; then
17
+	DB_SCHEMA="$DATA_DIR/oracle"
18
+else
19
+	DB_SCHEMA="./oracle"
20
+fi
21
+
22
+
23
+##### ----------------------------------------------- #####
24
+### load ORACLE SQL base
25
+#
26
+if [ -f "$MYLIBDIR/openserdbfunc.oracle" ]; then
27
+	. "$MYLIBDIR/openserdbfunc.oracle"
28
+else
29
+	echo "Cannot load ORACLE core functions '$MYLIBDIR/openserdbfunc.oracle' - exiting ..."
30
+	exit -1
31
+fi
32
+
33
+if [ -z "$SQLPLUS" ] ; then
34
+	SQLPLUS=`which sqlplus 2>/dev/null`
35
+	if [ -z "$SQLPLUS" ]; then
36
+		merr "'sqlplus' tool not found: set SQLPLUS variable to correct tool path"
37
+		exit 1
38
+	fi
39
+	export SQLPLUS
40
+fi
41
+if [ -z "$OPENSER_ORASEL" ] ; then
42
+	OPENSER_ORASEL=`which openser_orasel 2>/dev/null`
43
+	if [ -n "$SQLPLUS" ]; then
44
+		export OPENSER_ORASEL
45
+	fi
46
+fi
47
+
48
+#################################################################
49
+ORALOG=/tmp/opensrdbctl.log
50
+
51
+if [ -z "$SED" ]; then
52
+	SED="sed"
53
+fi
54
+
55
+SED_ROOTUSER="$SED -e s/%DBROOTUSER%/$DBROOTUSER/g"
56
+SED_USERS="$SED_ROOTUSER;s/%DBROUSER%/$DBROUSER/g;s/%DBRWUSER%/$DBRWUSER/g"
57
+
58
+#################################################################
59
+# config vars
60
+#################################################################
61
+
62
+# 'db'-privileges (scheme) Oracle user
63
+if [ -z "$DBROOTUSER" ]; then
64
+	merr "scheme owner (pivileged user) 'DBROOTUSER' must be defined."
65
+	exit 1
66
+fi
67
+
68
+#################################################################
69
+oracle_root_cmd()
70
+{
71
+	prompt_oracle_pw root
72
+	SUFF=""
73
+	if [ -n "$1" ]; then
74
+		SUFF="@$1"
75
+	fi
76
+	ORACLE_ROOT_CMD="$SQLPLUS -S -L -R 3 $DBROOTUSER/${DBROOTPW}$SUFF"
77
+	export ORACLE_ROOT_CMD
78
+}
79
+
80
+
81
+openser_drop()  # pars: <database name>
82
+{
83
+if [ $# -ne 1 ] ; then
84
+	merr "openser_drop function takes one params"
85
+	exit 1
86
+fi
87
+
88
+oracle_root_cmd $1
89
+
90
+echo "DROP USER $DBROUSER CASCADE;
91
+      DROP USER $DBRWUSER CASCADE;" | $ORACLE_ROOT_CMD >$ORALOG
92
+if [ $? -ne 0 ] || check_oracle_log ; then
93
+	mwarn "Could not drop $DBRWUSER or $DBROUSER users, try to continue.."
94
+else
95
+	minfo "Database user deleted"
96
+fi
97
+
98
+$SED_ROOTUSER $DB_SCHEMA/inc/_dropsch.tmpl | $ORACLE_ROOT_CMD >$ORALOG
99
+if [ $? -ne 0 ] || check_oracle_log ; then
100
+	merr "Dropping scheme for '$DBROOTUSER' in database '$1' failed!"
101
+	exit 1
102
+fi
103
+
104
+if [ -n "$DBSYSUSER" ]; then
105
+	get_answer "ask" "Remove user '$DBROOTUSER' (complete remove scheme)? (y/n): "
106
+	if [ "$ANSWER" = "y" ]; then
107
+		prompt_oracle_pw sys
108
+		SUFF=""
109
+		if [ -n "$1" ]; then
110
+			SUFF="@$1"
111
+		fi
112
+		SYSCMD="$SQLPLUS -S -L -R 3 $DBSYSUSER/${DBSYSPW}$SUFF AS SYSDBA"
113
+		echo "DROP USER $DBROOTUSER CASCADE;" | $SYSCMD	>$ORALOG
114
+		if [ $? -ne 0 ] || check_oracle_log ; then
115
+			merr "Dropping scheme in database '$1' failed!"
116
+			exit 1
117
+		fi
118
+	fi
119
+fi
120
+
121
+minfo "Scheme '$DBROOTUSER' in database '$1' dropped"
122
+} #openser_drop
123
+
124
+
125
+openser_create() # pars: <database name>
126
+{
127
+if [ $# -ne 1 ] ; then
128
+	merr "openser_create function takes one param"
129
+	exit 1
130
+fi
131
+
132
+minfo "creating scheme for '$DBROOTUSER' in database '$1' ..."
133
+
134
+if [ -n "$DBSYSUSER" ]; then
135
+	get_answer "ask" "Create user '$DBROOTUSER' (is new scheme)? (y/n): "
136
+	if [ "$ANSWER" = "y" ]; then
137
+		prompt_oracle_pw sys
138
+		prompt_oracle_pw root
139
+		SUFF=""
140
+		if [ -n "$1" ]; then
141
+			SUFF="@$1"
142
+		fi
143
+		SYSCMD="$SQLPLUS -S -L -R 3 $DBSYSUSER/${DBSYSPW}$SUFF AS SYSDBA"
144
+
145
+		echo "create user $DBROOTUSER identified by $DBROOTPW
146
+		    default tablespace DATA temporary tablespace TEMP
147
+		    profile DEFAULT;" | $SYSCMD >$ORALOG
148
+		if [ $? -ne 0 ] || check_oracle_log ; then
149
+			mwarn "Create privileged user in database failed, perhaps they allready exist? Try to continue.."
150
+		fi
151
+
152
+		$SED_ROOTUSER $DB_SCHEMA/inc/_grantroot.tmpl | $SYSCMD >$ORALOG
153
+		if [ $? -ne 0 ] || check_oracle_log ; then
154
+			merr "Creating scheme in database '$1' failed!"
155
+			exit 1
156
+		fi
157
+	fi
158
+fi
159
+
160
+
161
+oracle_root_cmd $1
162
+
163
+$SED_ROOTUSER $DB_SCHEMA/inc/_createsch.tmpl | $ORACLE_ROOT_CMD >$ORALOG
164
+if [ $? -ne 0 ] || check_oracle_log ; then
165
+	merr "Creating scheme for '$DBROOTUSER' in database '$1' failed!"
166
+	exit 1
167
+fi
168
+
169
+cat $DB_SCHEMA/inc/_create_compat.sql | $ORACLE_ROOT_CMD >$ORALOG
170
+if [ $? -ne 0 ] || check_oracle_log ; then
171
+	merr "Creating compatibility functions for '$DBROOTUSER' in database '$1' failed!"
172
+	exit 1
173
+fi
174
+
175
+prompt_oracle_pw rw
176
+prompt_oracle_pw ro
177
+echo "create user $DBROUSER identified by $DBROPW
178
+    default tablespace DATA temporary tablespace TEMP profile DEFAULT;
179
+ grant connect to $DBROUSER;
180
+ create user $DBRWUSER identified by $DBRWPW
181
+    default tablespace DATA temporary tablespace TEMP profile DEFAULT;
182
+ grant connect to $DBRWUSER;" | $ORACLE_ROOT_CMD >$ORALOG
183
+if [ $? -ne 0 ] || check_oracle_log ; then
184
+	mwarn "Create user in database scheme failed, perhaps they allready exist? Try to continue.."
185
+fi
186
+
187
+$SED_USERS $DB_SCHEMA/inc/_grantfunc.tmpl | $ORACLE_ROOT_CMD >$ORALOG
188
+if [ $? -ne 0 ] || check_oracle_log ; then
189
+	merr "Make compatibility functions for users failed!"
190
+	exit 1
191
+fi
192
+
193
+
194
+for TABLE in $STANDARD_MODULES; do
195
+	mdbg "Creating core table: $TABLE"
196
+	cat $DB_SCHEMA/$TABLE-create.sql | $ORACLE_ROOT_CMD >$ORALOG
197
+	if [ $? -ne 0 ] || check_oracle_log ; then
198
+		merr "Creating core tables failed!"
199
+		exit 1
200
+	fi
201
+done
202
+
203
+if [ -e $DB_SCHEMA/extensions-create.sql ]; then
204
+	minfo "Creating custom extensions tables"
205
+	cat $DB_SCHEMA/extensions-create.sql | $ORACLE_ROOT_CMD >$ORALOG
206
+	if [ $? -ne 0 ] || check_oracle_log ; then
207
+		merr "Creating custom extensions tables failed!"
208
+		exit 1
209
+	fi
210
+fi
211
+
212
+minfo "Core OpenSER tables succesfully created."
213
+
214
+get_answer $INSTALL_PRESENCE_TABLES "Install presence related tables? (y/n): "
215
+if [ "$ANSWER" = "y" ]; then
216
+	presence_create $1
217
+fi
218
+
219
+get_answer $INSTALL_EXTRA_TABLES "Install tables for $EXTRA_MODULES? (y/n): "
220
+if [ "$ANSWER" = "y" ]; then
221
+	extra_create $1
222
+fi
223
+} # openser_create
224
+
225
+
226
+presence_create() # pars: <database name>
227
+{
228
+if [ $# -ne 1 ] ; then
229
+	merr "presence_create function takes one param"
230
+	exit 1
231
+fi
232
+
233
+minfo "creating presence tables..."
234
+oracle_root_cmd $1
235
+
236
+cat $DB_SCHEMA/presence-create.sql | $ORACLE_ROOT_CMD >$ORALOG
237
+if [ $? -ne 0 ] || check_oracle_log ; then
238
+	merr "Failed to create presence tables!"
239
+	exit 1
240
+fi
241
+
242
+cat $DB_SCHEMA/rls-create.sql | $ORACLE_ROOT_CMD >$ORALOG
243
+if [ $? -ne 0 ] || check_oracle_log ; then
244
+	merr "Failed to create rls-presence tables!"
245
+	exit 1
246
+fi
247
+
248
+minfo "Presence tables succesfully created."
249
+}
250
+
251
+extra_create() # pars: <database name>
252
+{
253
+if [ $# -ne 1 ] ; then
254
+	merr "extra_create function takes one param"
255
+	exit 1
256
+fi
257
+
258
+minfo "creating extra tables..."
259
+oracle_root_cmd $1
260
+
261
+for TABLE in $EXTRA_MODULES; do
262
+	mdbg "Creating extra table: $TABLE"
263
+	cat $DB_SCHEMA/$TABLE-create.sql | $ORACLE_ROOT_CMD >$ORALOG
264
+	if [ $? -ne 0 ] || check_oracle_log ; then
265
+		merr "Creating extra tables failed!"
266
+		exit 1
267
+	fi
268
+done
269
+
270
+minfo "Extra tables succesfully created."
271
+}
272
+
273
+
274
+oracle_dump()
275
+{
276
+	if [ $# -ne 2 ] ; then
277
+		merr "oracle_dump function takes two params"
278
+		exit 1
279
+	fi
280
+	prompt_oracle_pw rw
281
+	if [ -n "$1" ]; then
282
+		SUFF="@$1"
283
+	fi
284
+	if [ -n "$OPENSER_ORASEL" ]; then
285
+		$OPENSER_ORASEL ${DBROUSER}/${DBROPW}$SUFF -BLNe \
286
+		    "select * from table(dump_tables('$DBROOTUSER'));" >$2
287
+	else
288
+		echo "set feed 0 lin 8000 pages 0
289
+		    select * from table(dump_tables('$DBROOTUSER'));" | \
290
+			$SQLPLUS -S -L -R 3 ${DBROUSER}/${DBROPW}$SUFF >$2
291
+	fi
292
+	return $?
293
+}
294
+
295
+oracle_restore()
296
+{
297
+	if [ $# -ne 2 ] ; then
298
+		merr "oracle_restore function takes two params"
299
+		exit 1
300
+	fi
301
+	prompt_oracle_pw rw
302
+	SUFF=""
303
+	if [ -n "$1" ]; then
304
+		SUFF="@$1"
305
+	fi
306
+	cat "$2" | $SQLPLUS -S -L -R 3 ${DBRWUSER}/${DBRWPW}$SUFF >$ORALOG
307
+	if [ $? -ne 0 ] || check_oracle_log ; then
308
+		return 1
309
+	fi
310
+	return 0
311
+}
312
+
0 313
new file mode 100644
... ...
@@ -0,0 +1,89 @@
1
+#!/bin/sh
2
+# $Id$
3
+#
4
+# Script for common functions for Oracle engine in openser
5
+#
6
+# History:
7
+
8
+if [ -z "$EGREP" ]; then
9
+	EGREP="egrep"
10
+fi
11
+
12
+# read any password
13
+prompt_oracle_pw()
14
+{
15
+	case $1 in
16
+	    rw)
17
+		if [ -n "$DBRWPW" ]; then
18
+			return
19
+		fi
20
+		CURDBUSER="$DBRWUSER"
21
+		;;
22
+	    ro)
23
+		if [ -n "$DBROPW" ]; then
24
+			return
25
+		fi
26
+		CURDBUSER="$DBROUSER"
27
+		;;
28
+	    root)
29
+		if [ -n "$DBROOTPW" ]; then
30
+			return
31
+		fi
32
+		CURDBUSER="$DBROOTUSER"
33
+		;;
34
+	    sys)
35
+		if [ -n "$DBSYSPW" ]; then
36
+			return
37
+		fi
38
+		CURDBUSER="$DBSYSUSER"
39
+		;;
40
+	    *)
41
+		merr "prompt_oracle_pw: argument error"
42
+		exit 1
43
+		;;
44
+	esac
45
+	savetty=`stty -g`
46
+	echo -n "Oracle password for $CURDBUSER: "
47
+	stty -echo
48
+	case $1 in
49
+	    rw)
50
+		read DBRWPW
51
+		export DBRWPW
52
+		CURPW=$DBRWPW
53
+		;;
54
+	    ro)
55
+		read DBROPW
56
+		export DBROPW
57
+		CURPW=$DBROPW
58
+		;;
59
+	    root)
60
+		read DBROOTPW
61
+		export DBROOTPW
62
+		CURPW=$DBROOTPW
63
+		;;
64
+	    sys)
65
+		read DBSYSPW
66
+		export DBSYSPW
67
+		CURPW=$DBSYSPW
68
+		;;
69
+	esac
70
+	stty $savetty
71
+	echo
72
+	if [ -z "$CURPW" ]; then
73
+		merr "empty password is illegal"
74
+		exit 1
75
+	fi
76
+}
77
+
78
+check_oracle_log()
79
+{
80
+	if [ -f $ORALOG ]; then
81
+		$EGREP -qi "error" $ORALOG
82
+		if [ $? -eq 0 ]; then
83
+			echo "NOTE: last errors stored in $ORALOG"
84
+			return 0
85
+		fi
86
+		rm $ORALOG
87
+	fi
88
+	return 1
89
+}
0 90
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+BITMASK => NUMBER(11)
2
+INTEGER => NUMBER(<=10)
3
+BLOB    => VARCHAR2(4000)
0 4
new file mode 100644
... ...
@@ -0,0 +1,45 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('acc',4);
2
+create table ACC
3
+(
4
+  ID         NUMBER(10) not null,
5
+  METHOD     VARCHAR2(16) DEFAULT '',
6
+  FROM_TAG   VARCHAR2(64) DEFAULT '',
7
+  TO_TAG     VARCHAR2(64) DEFAULT '',
8
+  CALLID     VARCHAR2(64) DEFAULT '',
9
+  SIP_CODE   VARCHAR2(3) DEFAULT '',
10
+  SIP_REASON VARCHAR2(32) DEFAULT '',
11
+  TIME       DATE not null
12
+);
13
+alter table ACC add constraint PK_ACC primary key (ID);
14
+create index ACC_CALLID_IDX on ACC (CALLID);
15
+create or replace trigger acc_tr
16
+before insert on acc FOR EACH ROW
17
+BEGIN
18
+  auto_id(:NEW.id);
19
+END acc_tr;
20
+/
21
+BEGIN map2users('ACC'); END;
22
+/
23
+
24
+INSERT INTO VERSION (table_name,table_version) values ('missed_calls',3);
25
+create table MISSED_CALLS
26
+(
27
+  ID         NUMBER(10) not null,
28
+  METHOD     VARCHAR2(16) DEFAULT '',
29
+  FROM_TAG   VARCHAR2(64) DEFAULT '',
30
+  TO_TAG     VARCHAR2(64) DEFAULT '',
31
+  CALLID     VARCHAR2(64) DEFAULT '',
32
+  SIP_CODE   VARCHAR2(3) DEFAULT '',
33
+  SIP_REASON VARCHAR2(32) DEFAULT '',
34
+  TIME       DATE not null
35
+);
36
+alter table MISSED_CALLS add constraint PK_MISSED_CALLS primary key (ID);
37
+create index MISSED_CALLS_CALLID_IDX on MISSED_CALLS (CALLID);
38
+create or replace trigger missed_calls_tr
39
+before insert on missed_calls FOR EACH ROW
40
+BEGIN
41
+  auto_id(:NEW.id);
42
+END missed_calls_tr;
43
+/
44
+BEGIN map2users('MISSED_CALLS'); END;
45
+/
0 46
new file mode 100644
... ...
@@ -0,0 +1,2 @@
1
+replace '%DBROOTUSER%' to user (scheme) name and '%DBROOTPW%' to password in
2
+_create_as_sys_tmpl, and tell Oracle administrator to execute it :)
0 3
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+create user %DBROOTUSER%
2
+  identified by %DBROOTPW%
3
+  default tablespace DATA
4
+  temporary tablespace TEMP
5
+  profile DEFAULT;
6
+-- Grant/Revoke role privileges
7
+grant connect to %DBROOTUSER% with admin option;
8
+grant resource to %DBROOTUSER%;
9
+-- Grant/Revoke system privileges
10
+grant create any synonym to %DBROOTUSER%;
11
+grant create role to %DBROOTUSER%;
12
+grant create user to %DBROOTUSER%;
13
+grant drop user to %DBROOTUSER%;
14
+grant unlimited tablespace to %DBROOTUSER%;
15
+grant select on sys.dba_role_privs to %DBROOTUSER%;
0 16
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+DROP USER %DBROOTUSER% CASCADE;
0 2
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('dbaliases',1);
2
+create table DBALIASES
3
+(
4
+  ID             NUMBER(10) not null,
5
+  ALIAS_USERNAME VARCHAR2(64) DEFAULT '',
6
+  ALIAS_DOMAIN   VARCHAR2(64) DEFAULT '',
7
+  USERNAME       VARCHAR2(64) DEFAULT '',
8
+  DOMAIN         VARCHAR2(64) DEFAULT ''
9
+);
10
+alter table DBALIASES add constraint PK_DBALIASES primary key (ID);
11
+alter table DBALIASES add constraint DBALIASES_ALIAS_IDX unique (ALIAS_USERNAME,ALIAS_DOMAIN);
12
+create index DBALIASES_TARGET_IDX on DBALIASES (USERNAME,DOMAIN);
13
+create or replace trigger dbaliases_tr
14
+before insert on dbaliases FOR EACH ROW
15
+BEGIN
16
+  auto_id(:NEW.id);
17
+END dbaliases_tr;
18
+/
19
+BEGIN map2users('DBALIASES'); END;
20
+/
0 21
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('subscriber',6);
2
+create table SUBSCRIBER
3
+(
4
+  ID               NUMBER(10) not null,
5
+  USERNAME         VARCHAR2(64) default '',
6
+  DOMAIN           VARCHAR2(64) default '',
7
+  PASSWORD         VARCHAR2(25) default '',
8
+  EMAIL_ADDRESS    VARCHAR2(64) default '',
9
+  HA1              VARCHAR2(64) default '',
10
+  HA1B             VARCHAR2(64) default '',
11
+  RPID             VARCHAR2(64) default null
12
+);
13
+alter table SUBSCRIBER add constraint PK_SUBSCRIBER primary key (ID);
14
+alter table SUBSCRIBER add constraint SUBSCRIBER_ACCOUNT_IDX unique (USERNAME,DOMAIN);
15
+create index SUBSCRIBER_USERNAME_IDX on SUBSCRIBER (USERNAME);
16
+create or replace trigger subscriber_tr
17
+before insert on subscriber FOR EACH ROW
18
+BEGIN
19
+  auto_id(:NEW.id);
20
+END subscriber_tr;
21
+/
22
+BEGIN map2users('SUBSCRIBER'); END;
23
+/
0 24
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('usr_preferences',2);
2
+create table USR_PREFERENCES
3
+(
4
+  ID            NUMBER(10) not null,
5
+  UUID          VARCHAR2(64) default '',
6
+  USERNAME      VARCHAR2(128) default 0,
7
+  DOMAIN        VARCHAR2(64) default '',
8
+  ATTRIBUTE     VARCHAR2(32) default '',
9
+  TYPE          NUMBER(10) default 0,
10
+  VALUE         VARCHAR2(128) default '',
11
+  LAST_MODIFIED DATE default to_date('01-JAN-1900 00:00:01','dd-mm-yyyy hh24:mi:ss')
12
+);
13
+alter table USR_PREFERENCES add constraint PK_USR_PREFERENCES primary key (ID);
14
+create index USR_PREFERENCES_UA_IDX on USR_PREFERENCES (UUID,ATTRIBUTE);
15
+create index USR_PREFERENCES_UDA_IDX on USR_PREFERENCES (USERNAME,DOMAIN, ATTRIBUTE);
16
+create or replace trigger usr_preferences_tr
17
+before insert on usr_preferences FOR EACH ROW
18
+BEGIN
19
+  auto_id(:NEW.id);
20
+END usr_preferences_tr;
21
+/
22
+BEGIN map2users('USR_PREFERENCES'); END;
23
+/
0 24
new file mode 100644
... ...
@@ -0,0 +1,65 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('carrierroute',2);
2
+create table CARRIERROUTE
3
+(
4
+  ID             NUMBER(10) not null,
5
+  CARRIER        NUMBER(10) default 0,
6
+  DOMAIN         VARCHAR2(64) default '',
7
+  SCAN_PREFIX    VARCHAR2(64) default '',
8
+  FLAGS		 NUMBER(11) default 0,
9
+  MASKS		 NUMBER(11) default 0,
10
+  PROB           NUMBER default 0,
11
+  STRIP          NUMBER(10) default 0,
12
+  REWRITE_HOST   VARCHAR2(128) default '',
13
+  REWRITE_PREFIX VARCHAR2(64) default '',
14
+  REWRITE_SUFFIX VARCHAR2(64) default '',
15
+  DESCRIPTION    VARCHAR2(255) default null
16
+);
17
+alter table CARRIERROUTE add constraint PK_CARRIERROUTE primary key (ID);
18
+create or replace trigger carrierroute_tr
19
+before insert on carrierroute FOR EACH ROW
20
+BEGIN
21
+  auto_id(:NEW.id);
22
+END carrierroute_tr;
23
+/
24
+BEGIN map2users('CARRIERROUTE'); END;
25
+/
26
+
27
+INSERT INTO VERSION (table_name,table_version) values ('carrierfailueroute',1);
28
+create table CARRIERFAILUREROUTE
29
+(
30
+  ID             NUMBER(10) not null,
31
+  CARRIER        NUMBER(10) default 0,
32
+  DOMAIN         VARCHAR2(64) default '',
33
+  SCAN_PREFIX    VARCHAR2(64) default '',
34
+  HOST_NAME      VARCHAR2(128) default '',
35
+  REPLY_CODE     VARCHAR2(3) default '',
36
+  FLAGS          NUMBER(11) default 0,
37
+  MASK           NUMBER(11) default 0,
38
+  NEXT_DOMAIN    VARCHAR2(64) default '',
39
+  DESCRIPTION    VARCHAR2(255) default null
40
+);
41
+alter table CARRIERFAILUREROUTE add constraint PK_CARRIERFAILUREROUTE primary key (ID);
42
+create or replace trigger carrierfailureroute_tr
43
+before insert on carrierfailureroute FOR EACH ROW
44
+BEGIN
45
+  auto_id(:NEW.id);
46
+END carrierfailureroute_tr;
47
+/
48
+BEGIN map2users('CARRIERFAILUREROUTE'); END;
49
+/
50
+
51
+INSERT INTO VERSION (table_name,table_version) values ('route_tree',1);
52
+create table ROUTE_TREE
53
+(
54
+  ID      NUMBER(10) not null,
55
+  CARRIER VARCHAR2(64) default null
56
+);
57
+alter table ROUTE_TREE add constraint PK_ROUTE_TREE primary key (ID);
58
+create or replace trigger route_tree_tr
59
+before insert on route_tree FOR EACH ROW
60
+BEGIN
61
+  auto_id(:NEW.id);
62
+END route_tree_tr;
63
+/
64
+BEGIN map2users('ROUTE_TREE'); END;
65
+/
0 66
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('cpl',2);
2
+create table CPL
3
+(
4
+  ID       NUMBER(10) not null,
5
+  USERNAME VARCHAR2(64) not null,
6
+  DOMAIN   VARCHAR2(64) default '',
7
+  CPL_XML  VARCHAR2(1000),
8
+  CPL_BIN  VARCHAR2(1000)
9
+);
10
+alter table CPL add constraint PK_CPL primary key (ID);
11
+alter table CPL add constraint CPL_ACCOUNT_IDX unique (USERNAME,DOMAIN);
12
+create or replace trigger cpl_tr
13
+before insert on cpl FOR EACH ROW
14
+BEGIN
15
+  auto_id(:NEW.id);
16
+end cpl_tr;
17
+/
18
+BEGIN map2users('CPL'); END;
19
+/
0 20
new file mode 100644
... ...
@@ -0,0 +1,33 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('dialog',2);
2
+create table DIALOG
3
+(
4
+  ID               NUMBER(10) not null,
5
+  HASH_ENTRY       NUMBER(10) not null,
6
+  HASH_ID          NUMBER(10) not null,
7
+  CALLID           VARCHAR2(255) not null,
8
+  FROM_URI         VARCHAR2(128) not null,
9
+  FROM_TAG         VARCHAR2(64) not null,
10
+  TO_URI           VARCHAR2(128) not null,
11
+  TO_TAG           VARCHAR2(64) not null,
12
+  CALLER_CSEQ      VARCHAR2(7) not null,
13
+  CALLEE_CSEQ      VARCHAR2(7) not null,
14
+  CALLER_ROUTE_SET VARCHAR2(512),
15
+  CALLEE_ROUTE_SET VARCHAR2(512),
16
+  CALLER_CONTACT   VARCHAR2(128) not null,
17
+  CALLEE_CONTACT   VARCHAR2(128) not null,
18
+  CALLER_SOCK      VARCHAR2(64) not null,
19
+  CALLEE_SOCK      VARCHAR2(64) not null,
20
+  STATE            NUMBER(10) not null,
21
+  START_TIME       NUMBER(10) not null,
22
+  TIMEOUT          NUMBER(10) not null
23
+);
24
+alter table DIALOG add constraint PK_DIALOG primary key (ID);
25
+create index DIALOG_HASH_IDX on DIALOG (HASH_ENTRY,HASH_ID);
26
+create or replace trigger dialog_tr
27
+before insert on dialog FOR EACH ROW
28
+BEGIN
29
+  auto_id(:NEW.id);
30
+END dialog_tr;
31
+/
32
+BEGIN map2users('DIALOG'); END;
33
+/
0 34
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('dispatcher',2);
2
+create table DISPATCHER
3
+(
4
+  ID          NUMBER(10) not null,
5
+  SETID       NUMBER(10) default 0,
6
+  DESTINATION VARCHAR2(192) default '',
7
+  FLAGS       NUMBER(11) default 0,
8
+  DESCRIPTION VARCHAR2(64) default ''
9
+);
10
+alter table DISPATCHER add constraint PK_DISPATCHER primary key (ID);
11
+create or replace trigger dispatcher_tr
12
+before insert on dispatcher FOR EACH ROW
13
+BEGIN
14
+  auto_id(:NEW.id);
15
+END dispatcher_tr;
16
+/
17
+BEGIN map2users('DISPATCHER'); END;
18
+/
0 19
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('domain',1);
2
+create table DOMAIN
3
+(
4
+  ID            NUMBER(10) not null,
5
+  DOMAIN        VARCHAR2(64) default '',
6
+  LAST_MODIFIED DATE default to_date('01-JAN-1900 00:00:01','dd-mm-yyyy hh24:mi:ss')
7
+);
8
+alter table DOMAIN add constraint PK_DOMAIN primary key (ID);
9
+alter table DOMAIN add constraint DOMAIN_DOMAIN_IDX unique (DOMAIN);
10
+create or replace trigger domain_tr
11
+before insert on domain FOR EACH ROW
12
+BEGIN
13
+  auto_id(:NEW.id);
14
+END domain_tr;
15
+/
16
+BEGIN map2users('DOMAIN'); END;
17
+/
0 18
new file mode 100644
... ...
@@ -0,0 +1,21 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('domainpolicy',2);
2
+create table DOMAINPOLICY
3
+(
4
+  ID          NUMBER(10) not null,
5
+  RULE        VARCHAR2(255) not null,
6
+  TYPE        VARCHAR2(255) not null,
7
+  ATT         VARCHAR2(255),
8
+  VAL         VARCHAR2(128),
9
+  DESCRIPTION VARCHAR2(255) not null
10
+);
11
+alter table DOMAINPOLICY add constraint PK_DOMAINPOLICY primary key (ID);
12
+alter table DOMAINPOLICY add constraint DOMAINPOLICY_RAV_IDX unique (RULE,ATT,VAL);
13
+create index DOMAINPOLICY_RULE_IDX on DOMAINPOLICY (RULE);
14
+create or replace trigger domainpolicy_tr
15
+before insert on domainpolicy FOR EACH ROW
16
+BEGIN
17
+  auto_id(:NEW.id);
18
+END domainpolicy_tr;
19
+/
20
+BEGIN map2users('DOMAINPOLICY'); END;
21
+/
0 22
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('grp',2);
2
+create table GRP
3
+(
4
+  ID            NUMBER(10) not null,
5
+  USERNAME      VARCHAR2(64) default '',
6
+  DOMAIN        VARCHAR2(64) default '',
7
+  GRP           VARCHAR2(64) default '',
8
+  LAST_MODIFIED DATE default to_date('01-JAN-1900 00:00:01','dd-mm-yyyy hh24:mi:ss')
9
+);
10
+alter table GRP add constraint PK_GRP primary key (ID);
11
+alter table GRP add constraint GRP_ACCOUNT_GROUP_IDX unique (USERNAME,DOMAIN,GRP);
12
+create or replace trigger grp_tr
13
+before insert on grp FOR EACH ROW
14
+BEGIN
15
+  auto_id(:NEW.id);
16
+END grp_tr;
17
+/
18
+BEGIN map2users('GRP'); END;
19
+/
20
+
21
+INSERT INTO VERSION (table_name,table_version) values ('re_grp',1);
22
+create table RE_GRP
23
+(
24
+  ID       NUMBER(10) not null,
25
+  REG_EXP  VARCHAR2(128) default '',
26
+  GROUP_ID NUMBER(10) default 0
27
+);
28
+alter table RE_GRP add constraint PK_RE_GRP primary key (ID);
29
+create index RE_GRP_GROUP_IDX on RE_GRP (GROUP_ID);
30
+create or replace trigger re_grp_tr
31
+before insert on re_grp FOR EACH ROW
32
+BEGIN
33
+  auto_id(:NEW.id);
34
+END re_grp_tr;
35
+/
36
+BEGIN map2users('RE_GRP'); END;
37
+/
0 38
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('imc_rooms',1);
2
+create table IMC_ROOMS
3
+(
4
+  ID     NUMBER(10) not null,
5
+  NAME   VARCHAR2(64) not null,
6
+  DOMAIN VARCHAR2(64) not null,
7
+  FLAG   NUMBER(10) not null
8
+);
9
+alter table IMC_ROOMS add constraint PK_IMC_ROOMS primary key (ID);
10
+alter table IMC_ROOMS add constraint IMC_ROOMS_NAME_DOMAIN_IDX unique (NAME,DOMAIN);
11
+create or replace trigger imc_rooms_tr
12
+before insert on imc_rooms FOR EACH ROW
13
+BEGIN
14
+  auto_id(:NEW.id);
15
+END imc_rooms_tr;
16
+/
17
+BEGIN map2users('IMC_ROOMS'); END;
18
+/
19
+
20
+INSERT INTO VERSION (table_name,table_version) values ('imc_members',1);
21
+create table IMC_MEMBERS
22
+(
23
+  ID       NUMBER(10) not null,
24
+  USERNAME VARCHAR2(64) not null,
25
+  DOMAIN   VARCHAR2(64) not null,
26
+  ROOM     VARCHAR2(64) not null,
27
+  FLAG     NUMBER(10) not null
28
+);
29
+alter table IMC_MEMBERS add constraint PK_IMC_MEMBERS primary key (ID);
30
+alter table IMC_MEMBERS add constraint IMC_MEMBERS_ACCOUNT_ROOM_IDX unique (USERNAME,DOMAIN,ROOM);
31
+create or replace trigger imc_members_tr
32
+before insert on imc_members FOR EACH ROW
33
+BEGIN
34
+  auto_id(:NEW.id);
35
+END imc_members_tr;
36
+/
37
+BEGIN map2users('IMC_MEMBERS'); END;
38
+/
0 39
new file mode 100644
... ...
@@ -0,0 +1,107 @@
1
+create or replace function now(v1 in number := 0) return date is
2
+Result date;
3
+begin
4
+ SELECT sysdate INTO Result FROM dual;
5
+ return Result;
6
+end now;
7
+/
8
+
9
+create or replace function rand(v1 in number := 0) return number is
10
+Result number;
11
+begin
12
+ SELECT dbms_random.value INTO Result FROM dual;
13
+ return Result;
14
+end rand;
15
+/
16
+
17
+create or replace function concat(v1 in varchar2, v2 in varchar2, v3 in varchar2) return varchar2 IS
18
+Result varchar2(4000);
19
+begin
20
+ SELECT v1||v2||v3 INTO Result from dual;
21
+ return Result;
22
+end concat;
23
+/
24
+
25
+create or replace TYPE TABLE_STRING IS TABLE OF VARCHAR2(4000);
26
+/
27
+create or replace function DUMP_TABLES(P_OWNER in VARCHAR2) RETURN TABLE_STRING
28
+    PIPELINED
29
+IS
30
+  CURSOR COLUMNS_CUR (P_OWNER in VARCHAR2, P_TABLE in VARCHAR2) IS
31
+    SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
32
+    FROM ALL_TAB_COLUMNS
33
+    WHERE OWNER = UPPER(P_OWNER) AND TABLE_NAME = UPPER(P_TABLE)
34
+    ORDER BY COLUMN_ID;
35
+
36
+  COLUMN_REC COLUMNS_CUR%ROWTYPE;
37
+
38
+  TABLE_REC_CUR SYS_REFCURSOR;
39
+  L_QUERY VARCHAR2(8000);
40
+  L_QUERY1 VARCHAR2(8000);
41
+  L_QUERY2 VARCHAR2(8000);
42
+  L_LINE VARCHAR2(8000);
43
+
44
+  L_COMA CHAR(2) := '  ';
45
+
46
+  FIRST_ROW BOOLEAN := TRUE;
47
+BEGIN
48
+FOR cur IN (SELECT TABLE_NAME FROM all_tables WHERE owner=UPPER(P_OWNER)) LOOP
49
+  L_QUERY1 := 'SELECT ''INSERT INTO ' || cur.table_name;
50
+  L_QUERY2 :='(';
51
+  OPEN COLUMNS_CUR(P_OWNER, cur.table_name);
52
+  FIRST_ROW := TRUE;
53
+  LOOP
54
+    FETCH COLUMNS_CUR INTO COLUMN_REC;
55
+
56
+    IF FIRST_ROW AND COLUMNS_CUR%NOTFOUND THEN
57
+      PIPE ROW('Table ''' || P_OWNER || '.' || cur.table_name || ''' not found');
58
+    END IF;
59
+
60
+    EXIT WHEN COLUMNS_CUR%NOTFOUND;
61
+
62
+    IF FIRST_ROW THEN
63
+      L_QUERY2 := L_QUERY2 || COLUMN_REC.COLUMN_NAME;
64
+      L_QUERY := ' VALUES ('' || ';
65
+    ELSE
66
+      L_QUERY2 := L_QUERY2||','||COLUMN_REC.COLUMN_NAME;
67
+      L_COMA := ', ';
68
+      L_QUERY := L_QUERY || ' || '', '' || ';
69
+    END IF;
70
+
71
+    IF COLUMN_REC.DATA_TYPE = 'VARCHAR2' OR COLUMN_REC.DATA_TYPE = 'CHAR' THEN
72
+      L_QUERY := L_QUERY || 'NVL2(' || COLUMN_REC.COLUMN_NAME || ', '''''''' ||
73
+      REPLACE(' || COLUMN_REC.COLUMN_NAME || ', '''''''', '''''''''''') || '''''''', ''NULL'')';
74
+    ELSIF COLUMN_REC.DATA_TYPE = 'DATE' THEN
75
+      L_QUERY := L_QUERY || 'NVL2(' || COLUMN_REC.COLUMN_NAME || ', ''TO_DATE('''''' ||
76
+      TO_CHAR(' || COLUMN_REC.COLUMN_NAME || ', ''yyyy-mm-dd hh24:mi:ss'') ||
77
+      '''''', ''''yyyy-mm-dd hh24:mi:ss'''')'', ''NULL'')';
78
+    ELSE
79
+      L_QUERY := L_QUERY || 'NVL(TO_CHAR(' || COLUMN_REC.COLUMN_NAME || '), ''NULL'')';
80
+    END IF;
81
+
82
+    FIRST_ROW := FALSE;
83
+
84
+  END LOOP;
85
+
86
+  IF NOT FIRST_ROW THEN
87
+    L_QUERY :=L_QUERY1||L_QUERY2||')'|| L_QUERY || ' || '');'' AS LINE FROM ' || COLUMN_REC.TABLE_NAME;
88
+  END IF;
89
+
90
+  CLOSE COLUMNS_CUR;
91
+
92
+ /* IF FIRST_ROW THEN
93
+    RETURN;
94
+  END IF;*/
95
+
96
+  OPEN TABLE_REC_CUR FOR L_QUERY;
97
+
98
+  LOOP
99
+    FETCH TABLE_REC_CUR INTO L_LINE;
100
+    EXIT WHEN TABLE_REC_CUR%NOTFOUND;
101
+    PIPE ROW(L_LINE);
102
+  END LOOP;
103
+  CLOSE TABLE_REC_CUR;
104
+END LOOP;
105
+  RETURN;
106
+END;
107
+/
0 108
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+create sequence seq_%DBROOTUSER%
2
+minvalue 1
3
+maxvalue 9999999999999999999999999999
4
+start with 1
5
+increment by 1
6
+cache 20;
7
+
8
+create or replace procedure auto_id(fld out number) is
9
+begin
10
+  SELECT seq_%DBROOTUSER%.NEXTVAL INTO fld FROM dual;
11
+end auto_id;
12
+/
0 13
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+--DROP USER %DBROUSER% CASCADE;
2
+--DROP USER %DBRWUSER% CASCADE;
3
+
4
+BEGIN
5
+  FOR cur IN (SELECT 'DROP TABLE '||table_name||' CASCADE CONSTRAINTS PURGE'
6
+      stmt from all_tables where owner=UPPER('%DBROOTUSER%')) LOOP
7
+    EXECUTE IMMEDIATE cur.stmt;
8
+  END LOOP;
9
+
10
+  FOR cur IN (SELECT 'DROP '||object_type||' '||object_name
11
+      stmt from all_objects where owner=UPPER('%DBROOTUSER%')) LOOP
12
+    EXECUTE IMMEDIATE cur.stmt;
13
+  END LOOP;
14
+END;
15
+/
0 16
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+BEGIN
2
+  FOR cur IN (SELECT OBJECT_NAME FROM All_Procedures
3
+	WHERE owner=UPPER('%DBROOTUSER%') and object_name <> 'MAP2USERS') LOOP
4
+    EXECUTE IMMEDIATE('GRANT EXECUTE ON %DBROOTUSER%.'||cur.OBJECT_NAME
5
+	||' to %DBRWUSER%');
6
+    EXECUTE IMMEDIATE('GRANT EXECUTE ON %DBROOTUSER%.'||cur.OBJECT_NAME
7
+	||' to %DBROUSER%');
8
+    EXECUTE IMMEDIATE('CREATE OR REPLACE SYNONYM %DBRWUSER%.'||cur.OBJECT_NAME
9
+	||' for %DBROOTUSER%.'||cur.OBJECT_NAME);
10
+    EXECUTE IMMEDIATE('CREATE OR REPLACE SYNONYM %DBROUSER%.'||cur.OBJECT_NAME
11
+	||' for %DBROOTUSER%.'||cur.OBJECT_NAME);
12
+  END LOOP;
13
+END;
14
+/
15
+
16
+CREATE OR REPLACE PROCEDURE map2users(tbl varchar2) is
17
+BEGIN
18
+  EXECUTE IMMEDIATE('GRANT SELECT ON '||tbl||' to %DBROUSER%');
19
+  EXECUTE IMMEDIATE('GRANT SELECT,INSERT,UPDATE,DELETE ON '||tbl
20
+    ||' to %DBRWUSER%');
21
+  EXECUTE IMMEDIATE('CREATE OR REPLACE SYNONYM %DBROUSER%.'||tbl
22
+    ||' for %DBROOTUSER%.'||tbl);
23
+  EXECUTE IMMEDIATE('CREATE OR REPLACE SYNONYM %DBRWUSER%.'||tbl
24
+    ||' for %DBROOTUSER%.'||tbl);
25
+END map2users;
26
+/
0 27
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+--create user %DBROOTUSER% identified by %DBROOTPW%
2
+-- default tablespace DATA temporary tablespace TEMP profile DEFAULT;
3
+
4
+grant connect to %DBROOTUSER% with admin option;
5
+
6
+grant resource, create any synonym, create role,
7
+      create user, drop user, unlimited tablespace to %DBROOTUSER%;
8
+
9
+grant select on sys.dba_role_privs to %DBROOTUSER%;
0 10
new file mode 100644
... ...
@@ -0,0 +1,47 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('gw',7);
2
+create table GW
3
+(
4
+  ID         NUMBER(10) not null,
5
+  GW_NAME    VARCHAR2(128) not null,
6
+  GRP_ID     NUMBER(10) not null,
7
+  IP_ADDR    VARCHAR2(15) not null,
8
+  PORT       NUMBER(5),
9
+  URI_SCHEME NUMBER(5),
10
+  TRANSPORT  NUMBER(5),
11
+  STRIP      NUMBER(5),
12
+  TAG        VARCHAR2(16) default null,
13
+  FLAGS      NUMBER(11) default 0
14
+);
15
+alter table GW add constraint PK_GW primary key (ID);
16
+alter table GW add constraint GW_NAME_IDX unique (GW_NAME);
17
+create index GW_GRP_ID_IDX on GW (GRP_ID);
18
+create or replace trigger gw_tr
19
+before insert on gw FOR EACH ROW
20
+BEGIN
21
+  auto_id(:NEW.id);
22
+END gw_tr;
23
+/
24
+BEGIN map2users('GW'); END;
25
+/
26
+
27
+INSERT INTO VERSION (table_name,table_version) values ('lcr',2);
28
+create table LCR
29
+(
30
+  ID       NUMBER(10) not null,
31
+  PREFIX   VARCHAR2(16) default null,
32
+  FROM_URI VARCHAR2(64) default null,
33
+  GRP_ID   NUMBER(10) not null,
34
+  PRIORITY NUMBER(5) not null
35
+);
36
+alter table LCR add constraint PK_LCR primary key (ID);
37
+create index LCR_FROM_URI_IDX on LCR (FROM_URI);
38
+create index LCR_GRP_ID_IDX on LCR (GRP_ID);
39
+create index LCR_PREFIX_IDX on LCR (PREFIX);
40
+create or replace trigger lcr_tr
41
+before insert on lcr FOR EACH ROW
42
+BEGIN
43
+  auto_id(:NEW.id);
44
+END lcr_tr;
45
+/
46
+BEGIN map2users('LCR'); END;
47
+/
0 48
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('silo',5);
2
+create table SILO
3
+(
4
+  ID       NUMBER(10) not null,
5
+  SRC_ADDR VARCHAR2(128) default '',
6
+  DST_ADDR VARCHAR2(128) default '',
7
+  USERNAME VARCHAR2(64) default '',
8
+  DOMAIN   VARCHAR2(64) default '',
9
+  INC_TIME NUMBER(10) default 0,
10
+  EXP_TIME NUMBER(10) default 0,
11
+  SND_TIME NUMBER(10) default 0,
12
+  CTYPE    VARCHAR2(32) default 'text/plain',
13
+  BODY     VARCHAR2(4000) default ''
14
+);
15
+alter table SILO add constraint PK_SILO primary key (ID);
16
+create index SILO_ACCOUNT_IDX on SILO (USERNAME, DOMAIN);
17
+create or replace trigger silo_tr
18
+before insert on silo FOR EACH ROW
19
+BEGIN
20
+  auto_id(:NEW.id);
21
+END silo_tr;
22
+/
23
+BEGIN map2users('SILO'); END;
24
+/
0 25
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('pdt',1);
2
+create table PDT
3
+(
4
+  ID      NUMBER(10) not null,
5
+  SDOMAIN VARCHAR2(128) not null,
6
+  PREFIX  VARCHAR2(32) not null,
7
+  DOMAIN  VARCHAR2(128) default ''
8
+);
9
+alter table PDT add constraint PK_PDT primary key (ID);
10
+alter table PDT add constraint PDT_SDOMAIN_PREFIX_IDX unique (SDOMAIN,PREFIX);
11
+create or replace trigger pdt_tr
12
+before insert on pdt FOR EACH ROW
13
+BEGIN
14
+  auto_id(:NEW.id);
15
+END pdt_tr;
16
+/
17
+BEGIN map2users('PDT'); END;
18
+/
0 19
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+INSERT INTO VERSION (table_name,table_version) values ('trusted',4);
2
+create table TRUSTED
3
+(
4
+  ID           NUMBER(10) not null,
5
+  SRC_IP       VARCHAR2(50) not null,
6
+  PROTO        VARCHAR2(4) not null,
7
+  FROM_PATTERN VARCHAR2(64) default null,
8
+  TAG          VARCHAR2(32)
9
+);
10
+alter table TRUSTED add constraint PK_TRUSTED primary key (ID);
11
+create index TRUSTED_PEER_IDX on TRUSTED (SRC_IP);
12
+create or replace trigger TRUSTED_tr
13
+before insert on TRUSTED FOR EACH ROW
14
+BEGIN
15
+  auto_id(:NEW.id);
16
+END TRUSTED_tr;
17
+/
18
+BEGIN map2users('TRUSTED'); END;
19
+/
20
+
21
+INSERT INTO VERSION (table_name,table_version) values ('address',3);
22
+create table ADDRESS
23
+(
24
+  ID      NUMBER(10) not null,
25
+  GRP     NUMBER(5) default 0,
26
+  IP_ADDR VARCHAR2(15) not null,
27
+  MASK    NUMBER(5) default 32,
28
+  PORT    NUMBER(5) default 0
29
+);
30
+alter table ADDRESS add constraint PK_ADDRESS primary key (ID);
31
+create or replace trigger address_tr
32
+before insert on address FOR EACH ROW
33
+BEGIN
34
+  auto_id(:NEW.id);
35
+END address_tr;
36
+/
37
+BEGIN map2users('ADDRESS'); END;
38
+/
0 39
new file mode 100644
... ...
@@ -0,0 +1,138 @@
1
+INSERT INTO VERSION (table_name,table_version) VALUES ('presentity',2);
2
+create table PRESENTITY
3
+(
4
+  ID            NUMBER(10) not null,
5
+  USERNAME      VARCHAR2(64) not null,
6
+  DOMAIN        VARCHAR2(64) not null,
7
+  EVENT         VARCHAR2(64) not null,
8
+  ETAG          VARCHAR2(64) not null,
9
+  EXPIRES       NUMBER(10) not null,
10
+  RECEIVED_TIME NUMBER(10) not null,
11
+  BODY          VARCHAR2(4000) not null
12
+);
13
+alter table PRESENTITY add constraint PK_PRESENTITY primary key (ID);
14
+alter table PRESENTITY add constraint PRESENTITY_PRESENTITY_IDX unique (USERNAME, DOMAIN, EVENT, ETAG);
15
+create or replace trigger presentity_tr
16
+before insert on presentity FOR EACH ROW
17
+BEGIN
18
+  auto_id(:NEW.id);
19
+END presentity_tr;
20
+/
21
+BEGIN map2users('PRESENTITY'); END;
22
+/
23
+
24
+INSERT INTO VERSION (table_name,table_version) VALUES ('active_watchers',9);
25
+create table ACTIVE_WATCHERS
26
+(
27
+  ID               NUMBER(10) not null,
28
+  PRESENTITY_URI   VARCHAR2(128) not null,
29
+  WATCHER_USERNAME VARCHAR2(64) not null,
30
+  WATCHER_DOMAIN   VARCHAR2(64) not null,
31
+  TO_USER          VARCHAR2(64) not null,
32
+  TO_DOMAIN        VARCHAR2(64) not null,
33
+  EVENT            VARCHAR2(64) default 'presence',
34
+  EVENT_ID         VARCHAR2(64),
35
+  TO_TAG           VARCHAR2(64) not null,
36
+  FROM_TAG         VARCHAR2(64) not null,
37
+  CALLID           VARCHAR2(64) not null,
38
+  LOCAL_CSEQ       NUMBER(10) not null,
39
+  REMOTE_CSEQ      NUMBER(10) not null,
40
+  CONTACT          VARCHAR2(64) not null,
41
+  RECORD_ROUTE     VARCHAR2(1000),
42
+  EXPIRES          NUMBER(10) not null,
43
+  STATUS           NUMBER(10) default 2,
44
+  REASON           VARCHAR2(64) not null,
45
+  VERSION          NUMBER(10) default 0,
46
+  SOCKET_INFO      VARCHAR2(64) not null,
47
+  LOCAL_CONTACT    VARCHAR2(128) not null
48
+);
49
+alter table ACTIVE_WATCHERS add constraint PK_ACTIVE_WATCHERS primary key (ID);
50
+alter table ACTIVE_WATCHERS add constraint ACTIVE_WATCHERS_IDX unique (PRESENTITY_URI,CALLID,TO_TAG,FROM_TAG);
51
+create or replace trigger active_watchers_tr
52
+before insert on active_watchers FOR EACH ROW
53
+BEGIN
54
+  auto_id(:NEW.id);
55
+END active_watchers_tr;
56
+/
57
+BEGIN map2users('ACTIVE_WATCHERS'); END;
58
+/
59
+
60
+INSERT INTO VERSION (table_name,table_version) VALUES ('watchers',3);
61
+create table WATCHERS
62
+(
63
+  ID               NUMBER(10) not null,
64
+  PRESENTITY_URI   VARCHAR2(128) not null,
65
+  WATCHER_USERNAME VARCHAR2(64) not null,
66
+  WATCHER_DOMAIN   VARCHAR2(64) not null,
67
+  EVENT            VARCHAR2(64) default 'presence',
68
+  STATUS           NUMBER(10) not null,
69
+  REASON           VARCHAR2(64),
70
+  INSERTED_TIME    NUMBER(10) not null
71
+);
72
+alter table WATCHERS add constraint PK_WATCHERS primary key (ID);
73
+alter table WATCHERS add constraint WATCHER_IDX unique (PRESENTITY_URI,WATCHER_USERNAME,WATCHER_DOMAIN,EVENT);
74
+create or replace trigger watchers_tr
75
+before insert on watchers FOR EACH ROW
76
+BEGIN
77
+  auto_id(:NEW.id);
78
+END watchers_tr;
79
+/
80
+BEGIN map2users('WATCHERS'); END;
81
+/