Skip to content

Commit

Permalink
detach INDEX_TABLE from CITYDB_PKG
Browse files Browse the repository at this point in the history
  • Loading branch information
yaozhihang committed May 18, 2018
1 parent 37848e7 commit 5911550
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 94 deletions.
3 changes: 3 additions & 0 deletions Oracle/SQLScripts/CREATE_DB2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ FROM dual;
-- create objectclass instances and functions
@@SCHEMA/OBJECTCLASS/OBJECTCLASS_INSTANCES.sql
@@SCHEMA/OBJECTCLASS/AGGREGATION_INFO_INSTANCES.sql
@@SCHEMA/INDEX_TABLE/INDEX_TABLE.sql

--// create and fill INDEX_TABLE
@@SCHEMA/OBJECTCLASS/OBJCLASS.sql

-- create spatial metadata
Expand Down
27 changes: 0 additions & 27 deletions Oracle/SQLScripts/PL_SQL/CITYDB_PKG/INDEX/IDX.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,6 @@ CREATE OR REPLACE TYPE BODY INDEX_OBJ IS
END;
/

/******************************************************************
* INDEX_TABLE that holds INDEX_OBJ instances
*
******************************************************************/
CREATE TABLE INDEX_TABLE (
ID NUMBER PRIMARY KEY,
obj INDEX_OBJ
);

CREATE SEQUENCE INDEX_TABLE_SEQ INCREMENT BY 1 START WITH 1 MINVALUE 1;

/******************************************************************
* Populate INDEX_TABLE with INDEX_OBJ instances
*
******************************************************************/
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('CITYOBJECT_ENVELOPE_SPX', 'CITYOBJECT', 'ENVELOPE', 'PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('SURFACE_GEOM_SPX', 'SURFACE_GEOMETRY', 'GEOMETRY', 'PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('SURFACE_GEOM_SOLID_SPX', 'SURFACE_GEOMETRY', 'SOLID_GEOMETRY', 'PARAMETERS (''sdo_indx_dims=3'') PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('CITYOBJECT_INX', 'CITYOBJECT', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('CITYOBJECT_LINEAGE_INX', 'CITYOBJECT', 'LINEAGE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('SURFACE_GEOM_INX', 'SURFACE_GEOMETRY', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('APPEARANCE_INX', 'APPEARANCE', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('APPEARANCE_THEME_INX', 'APPEARANCE', 'THEME'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('SURFACE_DATA_INX', 'SURFACE_DATA', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('ADDRESS_INX', 'ADDRESS', 'GMLID, GMLID_CODESPACE'));
COMMIT;

/*****************************************************************
* PACKAGE citydb_idx
*
Expand Down
55 changes: 55 additions & 0 deletions Oracle/SQLScripts/SCHEMA/INDEX_TABLE/INDEX_TABLE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- 3D City Database - The Open Source CityGML Database
-- http://www.3dcitydb.org/
--
-- Copyright 2013 - 2018
-- Chair of Geoinformatics
-- Technical University of Munich, Germany
-- https://www.gis.bgu.tum.de/
--
-- The 3D City Database is jointly developed with the following
-- cooperation partners:
--
-- virtualcitySYSTEMS GmbH, Berlin <http://www.virtualcitysystems.de/>
-- M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

/******************************************************************
* INDEX_TABLE that holds INDEX_OBJ instances
*
******************************************************************/
CREATE TABLE INDEX_TABLE (
ID NUMBER PRIMARY KEY,
obj INDEX_OBJ
);

CREATE SEQUENCE INDEX_TABLE_SEQ INCREMENT BY 1 START WITH 1 MINVALUE 1;

/******************************************************************
* Populate INDEX_TABLE with INDEX_OBJ instances
*
******************************************************************/
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('CITYOBJECT_ENVELOPE_SPX', 'CITYOBJECT', 'ENVELOPE', 'PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('SURFACE_GEOM_SPX', 'SURFACE_GEOMETRY', 'GEOMETRY', 'PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_spatial_3d('SURFACE_GEOM_SOLID_SPX', 'SURFACE_GEOMETRY', 'SOLID_GEOMETRY', 'PARAMETERS (''sdo_indx_dims=3'') PARALLEL'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('CITYOBJECT_INX', 'CITYOBJECT', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('CITYOBJECT_LINEAGE_INX', 'CITYOBJECT', 'LINEAGE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('SURFACE_GEOM_INX', 'SURFACE_GEOMETRY', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('APPEARANCE_INX', 'APPEARANCE', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('APPEARANCE_THEME_INX', 'APPEARANCE', 'THEME'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('SURFACE_DATA_INX', 'SURFACE_DATA', 'GMLID, GMLID_CODESPACE'));
INSERT INTO index_table (id, obj) VALUES (INDEX_TABLE_SEQ.nextval, INDEX_OBJ.construct_normal('ADDRESS_INX', 'ADDRESS', 'GMLID, GMLID_CODESPACE'));

COMMIT;

3 changes: 3 additions & 0 deletions PostgreSQL/SQLScripts/CREATE_DB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ SET search_path TO citydb, :current_path;
\echo 'Creating additional schema ''citydb_pkg'' ...'
\i CREATE_CITYDB_PKG.sql

--// create and fill INDEX_TABLE
\i SCHEMA/INDEX_TABLE/INDEX_TABLE.sql

--// update search_path on database level
ALTER DATABASE :"DBNAME" SET search_path TO citydb, citydb_pkg, :current_path;

Expand Down
140 changes: 73 additions & 67 deletions PostgreSQL/SQLScripts/PL_pgSQL/CITYDB_PKG/INDEX/IDX.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* drop_indexes(type INTEGER, schema_name TEXT DEFAULT 'citydb') RETURNS text[]
* drop_normal_indexes(schema_name TEXT DEFAULT 'citydb') RETURNS text[]
* drop_spatial_indexes(schema_name TEXT DEFAULT 'citydb') RETURNS text[]
* get_index(idx_table_name TEXT, idx_column_name TEXT) RETURNS citydb_pkg.INDEX_OBJ
* get_index(idx_table_name TEXT, idx_column_name TEXT, schema_name TEXT DEFAULT 'citydb') RETURNS citydb_pkg.INDEX_OBJ
* index_status(idx citydb_pkg.INDEX_OBJ, schema_name TEXT DEFAULT 'citydb') RETURNS TEXT
* index_status(idx_table_name TEXT, idx_column_name TEXT, schema_name TEXT) RETURNS TEXT
* status_normal_indexes(schema_name TEXT DEFAULT 'citydb') RETURNS text[]
Expand Down Expand Up @@ -106,33 +106,6 @@ $$
LANGUAGE 'sql' IMMUTABLE STRICT;


/******************************************************************
* INDEX_TABLE that holds INDEX_OBJ instances
*
******************************************************************/
DROP TABLE IF EXISTS citydb_pkg.INDEX_TABLE;
CREATE TABLE citydb_pkg.INDEX_TABLE (
ID SERIAL PRIMARY KEY,
obj citydb_pkg.INDEX_OBJ
);


/******************************************************************
* Populate INDEX_TABLE with INDEX_OBJ instances
*
******************************************************************/
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('cityobject_envelope_spx', 'cityobject', 'envelope'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('surface_geom_spx', 'surface_geometry', 'geometry'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('surface_geom_solid_spx', 'surface_geometry', 'solid_geometry'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('cityobject_inx', 'cityobject', 'gmlid, gmlid_codespace'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('cityobject_lineage_inx', 'cityobject', 'lineage'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('surface_geom_inx', 'surface_geometry', 'gmlid, gmlid_codespace'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('appearance_inx', 'appearance', 'gmlid, gmlid_codespace'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('appearance_theme_inx', 'appearance', 'theme'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('surface_data_inx', 'surface_data', 'gmlid, gmlid_codespace'));
INSERT INTO citydb_pkg.index_table (obj) VALUES (citydb_pkg.construct_normal('address_inx', 'address', 'gmlid, gmlid_codespace'));


/*****************************************************************
* index_status
*
Expand Down Expand Up @@ -330,8 +303,8 @@ DECLARE
sql_error_msg TEXT;
rec RECORD;
BEGIN
FOR rec IN
SELECT * FROM citydb_pkg.index_table WHERE (obj).type = $1
FOR rec IN EXECUTE format('
SELECT * FROM %I.index_table WHERE (obj).type = %L', $2, $1)
LOOP
sql_error_msg := citydb_pkg.create_index(rec.obj, $2);
idx_log := array_append(
Expand Down Expand Up @@ -370,8 +343,8 @@ DECLARE
sql_error_msg TEXT;
rec RECORD;
BEGIN
FOR rec IN
SELECT * FROM citydb_pkg.index_table WHERE (obj).type = $1
FOR rec IN EXECUTE format('
SELECT * FROM %I.index_table WHERE (obj).type = %L', $2, $1)
LOOP
sql_error_msg := citydb_pkg.drop_index(rec.obj, $2);
idx_log := array_append(
Expand Down Expand Up @@ -399,20 +372,27 @@ LANGUAGE plpgsql STRICT;
******************************************************************/
CREATE OR REPLACE FUNCTION citydb_pkg.status_spatial_indexes(schema_name TEXT DEFAULT 'citydb') RETURNS text[] AS
$$
SELECT
array_agg(
citydb_pkg.index_status(obj, $1)
|| ':' || (obj).index_name
|| ':' || $1
|| ':' || (obj).table_name
|| ':' || (obj).attribute_name
) AS log
FROM
citydb_pkg.index_table
WHERE
(obj).type = 1;
DECLARE
idx_log text[] := '{}';
BEGIN
EXECUTE format('
SELECT
array_agg(
concat(citydb_pkg.index_status(obj,' || '''%I''' || '),' || ''':''' || ',' ||
'(obj).index_name,' || ''':''' || ',' ||
'''%I'',' || ''':''' || ',' ||
'(obj).table_name,' || ''':''' || ',' ||
'(obj).attribute_name
)) AS log
FROM
%I.index_table
WHERE
(obj).type = 1',$1, $1, $1) INTO idx_log;

RETURN idx_log;
END;
$$
LANGUAGE sql STRICT;
LANGUAGE plpgsql STRICT;


/******************************************************************
Expand All @@ -423,20 +403,27 @@ LANGUAGE sql STRICT;
******************************************************************/
CREATE OR REPLACE FUNCTION citydb_pkg.status_normal_indexes(schema_name TEXT DEFAULT 'citydb') RETURNS text[] AS
$$
SELECT
array_agg(
citydb_pkg.index_status(obj, $1)
|| ':' || (obj).index_name
|| ':' || $1
|| ':' || (obj).table_name
|| ':' || (obj).attribute_name
) AS log
FROM
citydb_pkg.index_table
WHERE
(obj).type = 0;
DECLARE
idx_log text[] := '{}';
BEGIN
EXECUTE format('
SELECT
array_agg(
concat(citydb_pkg.index_status(obj,' || '''%I''' || '),' || ''':''' || ',' ||
'(obj).index_name,' || ''':''' || ',' ||
'''%I'',' || ''':''' || ',' ||
'(obj).table_name,' || ''':''' || ',' ||
'(obj).attribute_name
)) AS log
FROM
%I.index_table
WHERE
(obj).type = 0',$1, $1, $1) INTO idx_log;

RETURN idx_log;
END;
$$
LANGUAGE sql STRICT;
LANGUAGE plpgsql STRICT;


/******************************************************************
Expand Down Expand Up @@ -506,15 +493,34 @@ LANGUAGE sql STRICT;
******************************************************************/
CREATE OR REPLACE FUNCTION citydb_pkg.get_index(
idx_table_name TEXT,
idx_column_name TEXT
idx_column_name TEXT,
schema_name TEXT DEFAULT 'citydb'
) RETURNS citydb_pkg.INDEX_OBJ AS
$$
SELECT
obj
FROM
citydb_pkg.index_table
WHERE
(obj).table_name = lower($1)
AND (obj).attribute_name = lower($2);
DECLARE
idx_obj citydb_pkg.INDEX_OBJ;
index_name TEXT;
table_name TEXT;
attribute_name TEXT;
type NUMERIC(1);
srid INTEGER;
is_3d NUMERIC(1, 0);
BEGIN
EXECUTE format('
SELECT
(obj).index_name,
(obj).table_name,
(obj).attribute_name,
(obj).type,
(obj).srid,
(obj).is_3d
FROM
%I.index_table
WHERE
(obj).table_name = lower('||'''%I'''||')
AND (obj).attribute_name = lower('||'''%I'''||')', $3, $1, $2) INTO index_name, table_name, attribute_name, type, srid, is_3d;

RETURN (index_name, table_name, attribute_name, type, srid, is_3d)::citydb_pkg.INDEX_OBJ;
END;
$$
LANGUAGE sql STRICT;
LANGUAGE plpgsql STRICT;
3 changes: 3 additions & 0 deletions PostgreSQL/SQLScripts/SCHEMA/CREATE_SCHEMA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ SELECT version as citydb_version from citydb_pkg.citydb_version();
\i OBJECTCLASS/OBJECTCLASS_INSTANCES.sql
\i OBJECTCLASS/AGGREGATION_INFO_INSTANCES.sql

--// create and fill INDEX_TABLE
\i INDEX_TABLE/INDEX_TABLE.sql

--// create schema FUNCTIONS
\i OBJECTCLASS/OBJCLASS.sql
\i ENVELOPE/ENVELOPE.sql
Expand Down
51 changes: 51 additions & 0 deletions PostgreSQL/SQLScripts/SCHEMA/INDEX_TABLE/INDEX_TABLE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- 3D City Database - The Open Source CityGML Database
-- http://www.3dcitydb.org/
--
-- Copyright 2013 - 2018
-- Chair of Geoinformatics
-- Technical University of Munich, Germany
-- https://www.gis.bgu.tum.de/
--
-- The 3D City Database is jointly developed with the following
-- cooperation partners:
--
-- virtualcitySYSTEMS GmbH, Berlin <http://www.virtualcitysystems.de/>
-- M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

/******************************************************************
* INDEX_TABLE that holds INDEX_OBJ instances
*
******************************************************************/
CREATE TABLE INDEX_TABLE (
ID SERIAL PRIMARY KEY,
obj citydb_pkg.INDEX_OBJ
);


/******************************************************************
* Populate INDEX_TABLE with INDEX_OBJ instances
*
******************************************************************/
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('cityobject_envelope_spx', 'cityobject', 'envelope'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('surface_geom_spx', 'surface_geometry', 'geometry'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_spatial_2d('surface_geom_solid_spx', 'surface_geometry', 'solid_geometry'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('cityobject_inx', 'cityobject', 'gmlid, gmlid_codespace'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('cityobject_lineage_inx', 'cityobject', 'lineage'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('surface_geom_inx', 'surface_geometry', 'gmlid, gmlid_codespace'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('appearance_inx', 'appearance', 'gmlid, gmlid_codespace'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('appearance_theme_inx', 'appearance', 'theme'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('surface_data_inx', 'surface_data', 'gmlid, gmlid_codespace'));
INSERT INTO index_table (obj) VALUES (citydb_pkg.construct_normal('address_inx', 'address', 'gmlid, gmlid_codespace'));

0 comments on commit 5911550

Please sign in to comment.