CREATE TABLE resources (
	resource_id int NOT NULL ,
	parent_resource_id int,
	zone_id int,
	acl_id int NOT NULL ,
	left_index int DEFAULT (-1),
	right_index int DEFAULT (-1),
	http_facility_no int NOT NULL,
	http_ui_style int,
	name varchar (64) NOT NULL ,
	title_big_string_id int NOT NULL,
	introduction_big_string_id int NOT NULL,
	description_big_string_id int NOT NULL,
	flags int NOT NULL,
	CONSTRAINT PK_resources PRIMARY KEY
	(
		resource_id
	),
	CONSTRAINT FK_resources_to_zones FOREIGN KEY
	(
		zone_id
	) REFERENCES zones (
		zone_id
	),
	CONSTRAINT FK_resources_to_acls FOREIGN KEY
	(
		acl_id
	) REFERENCES acls (
		acl_id
	),
	CONSTRAINT FK_resources_to_big_strings_a FOREIGN KEY
	(
		title_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_resources_to_big_strings_b FOREIGN KEY
	(
		introduction_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_resources_to_big_strings_c FOREIGN KEY
	(
		description_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_resources_to_objects FOREIGN KEY
	(
		resource_id
	) REFERENCES objects (
		id
	)
)
GO

/* Required for timed release. */
alter table resources add column open_timestamp timestamp null
GO

/* Required for timed release. */
alter table resources add column close_timestamp timestamp null
GO

INSERT INTO classes (type, db_name, table_name, java_class)
	VALUES(10,	'building2', 'resources', 'org.bodington.server.resources.Resource')
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 1, 'resource_id', 'setResourceId', 'getResourceId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 1, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 2, 'parent_resource_id', 'setParentResourceId', 'getParentResourceId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 3, 'zone_id', 'setZoneId', 'getZoneId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 4, 'acl_id', 'setAclId', 'getAclId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 6, 'http_facility_no', 'setHttpFacilityNo', 'getHttpFacilityNo', 'int', 'int', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 7, 'http_ui_style', 'setHttpUIStyle', 'getHttpUIStyle', 'java.lang.Integer', 'java.lang.Integer', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 8, 'name', 'setName', 'getName', 'java.lang.String', 'java.lang.String', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 9, 'title_big_string_id', 'setTitleBigStringId', 'getTitleBigStringId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 10, 'description_big_string_id', 'setDescriptionBigStringId', 'getDescriptionBigStringId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 11, 'introduction_big_string_id', 'setIntroductionBigStringId', 'getIntroductionBigStringId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 12, 'flags', 'setFlags', 'getFlags', 'int', 'int', 0, null, null, null )
GO

/* Required for timed release. */
INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 13, 'open_timestamp', 'setOpenTimestamp', 'getOpenTimestamp', 'java.sql.Timestamp', 'java.sql.Timestamp', 0, null, null, null)
GO

/* Required for timed release. */
INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(10, 14, 'close_timestamp', 'setCloseTimestamp', 'getCloseTimestamp', 'java.sql.Timestamp', 'java.sql.Timestamp', 0, null, null, null)
GO
