All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.db.generic.query.properties Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
#
# The pattern _${PROJECT}_ in table names is replaced by the SqlManager with 
# "_ONLINE_" or "_OFFLINE_" to choose the right database tables for
# SQL queries that are project dependent!
#

#
# Project table attributes
#
C_PROJECTS_PUBLISH_TAG_0=PUBLISH_TAG
C_PROJECTS_PROJECT_ID_0=PROJECT_ID
C_PROJECTS_USER_ID_0=USER_ID
C_PROJECTS_GROUP_ID_0=GROUP_ID
C_PROJECTS_MANAGERGROUP_ID_0=MANAGERGROUP_ID
C_PROJECTS_PROJECT_NAME_0=PROJECT_NAME
C_PROJECTS_PROJECT_DESCRIPTION_0=PROJECT_DESCRIPTION
C_PROJECTS_PROJECT_FLAGS_0=PROJECT_FLAGS
C_PROJECTS_DATE_CREATED_0=DATE_CREATED
C_PROJECTS_PROJECT_TYPE_0=PROJECT_TYPE
C_PROJECTS_PROJECT_OU_0=PROJECT_OU
C_PROJECT_PUBLISHDATE_0=PROJECT_PUBLISHDATE
C_PROJECT_PUBLISHED_BY_0=PROJECT_PUBLISHED_BY
	
#
# Project queries
#
C_PROJECTS_CREATE_10=\
INSERT INTO CMS_PROJECTS \
	(PROJECT_ID,\
	USER_ID,\
	GROUP_ID,\
	MANAGERGROUP_ID,\
	PROJECT_NAME,\
	PROJECT_DESCRIPTION,\
	PROJECT_FLAGS,\
	DATE_CREATED,\
	PROJECT_TYPE,\
	PROJECT_OU)\
VALUES \
	(?,?,?,?,?,?,?,?,?,?)
	
C_PROJECTS_WRITE_6=\
UPDATE \
	CMS_PROJECTS \
SET \
	PROJECT_DESCRIPTION=?,\
	GROUP_ID=?,\
	MANAGERGROUP_ID=?,\
	PROJECT_FLAGS=?,\
	PROJECT_TYPE=? \
WHERE \
	CMS_PROJECTS.PROJECT_ID=?
	
C_PROJECTS_READ_1=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.PROJECT_ID=? \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME

C_PROJECTS_READ_BYUSER_1=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.USER_ID=? \
	AND CMS_PROJECTS.PROJECT_FLAGS=0 \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME
	
	
C_PROJECTS_READ_BYGROUP_2=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	(CMS_PROJECTS.GROUP_ID=? OR CMS_PROJECTS.MANAGERGROUP_ID=?) \
	AND CMS_PROJECTS.PROJECT_FLAGS=0 \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME
	
	
C_PROJECTS_READ_BYOU_1=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.PROJECT_OU LIKE ? \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME
	
C_PROJECTS_READ_BYRESOURCE_1=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS, CMS_PROJECTRESOURCES \
WHERE \
	CMS_PROJECTS.PROJECT_ID = CMS_PROJECTRESOURCES.PROJECT_ID \
	AND CMS_PROJECTRESOURCES.RESOURCE_PATH LIKE ? \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME
	
	
C_PROJECTS_READ_BYMANAGER_1=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.MANAGERGROUP_ID=? \
    AND CMS_PROJECTS.PROJECT_FLAGS=0 \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME
                    
                    
C_PROJECTS_READ_BYNAME_2=\
SELECT \
	CMS_PROJECTS.PROJECT_ID,\
	CMS_PROJECTS.PROJECT_NAME,\
	CMS_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_PROJECTS.USER_ID,\
	CMS_PROJECTS.GROUP_ID,\
	CMS_PROJECTS.MANAGERGROUP_ID,\
	CMS_PROJECTS.PROJECT_FLAGS,\
	CMS_PROJECTS.DATE_CREATED,\
	CMS_PROJECTS.PROJECT_TYPE,\
	CMS_PROJECTS.PROJECT_OU \
FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.PROJECT_NAME=? \
	AND CMS_PROJECTS.PROJECT_OU=? \
ORDER BY \
	CMS_PROJECTS.PROJECT_OU, CMS_PROJECTS.PROJECT_NAME                          
                    
	
C_PROJECTS_DELETE_1=\
DELETE FROM \
	CMS_PROJECTS \
WHERE \
	CMS_PROJECTS.PROJECT_ID=?
                 
                    
#
# Project history queries
#
C_PROJECTS_HISTORY_CREATE=\
INSERT INTO CMS_HISTORY_PROJECTS \
	(PUBLISH_TAG,\
	PROJECT_ID,\
	PROJECT_NAME,\
	PROJECT_PUBLISHDATE,\
	PROJECT_PUBLISHED_BY,\
	USER_ID,\
	GROUP_ID,\
	MANAGERGROUP_ID,\
	PROJECT_DESCRIPTION,\
	DATE_CREATED,\
	PROJECT_TYPE,\
	PROJECT_OU) \
VALUES \
	(?,?,?,?,?,?,?,?,?,?,?,?)
                         
                         
C_PROJECTS_HISTORY_READ=\
SELECT \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG,\
	CMS_HISTORY_PROJECTS.PROJECT_ID,\
	CMS_HISTORY_PROJECTS.PROJECT_NAME,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHDATE,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHED_BY,\
	CMS_HISTORY_PROJECTS.USER_ID,\
	CMS_HISTORY_PROJECTS.GROUP_ID,\
	CMS_HISTORY_PROJECTS.MANAGERGROUP_ID,\
	CMS_HISTORY_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_HISTORY_PROJECTS.DATE_CREATED,\
	CMS_HISTORY_PROJECTS.PROJECT_TYPE,\
	CMS_HISTORY_PROJECTS.PROJECT_OU \
FROM \
	CMS_HISTORY_PROJECTS \
WHERE \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG=?
                         
                                 
C_PROJECTS_HISTORY_READ_BYID=\
SELECT \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG,\
	CMS_HISTORY_PROJECTS.PROJECT_ID,\
	CMS_HISTORY_PROJECTS.PROJECT_NAME,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHDATE,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHED_BY,\
	CMS_HISTORY_PROJECTS.USER_ID,\
	CMS_HISTORY_PROJECTS.GROUP_ID,\
	CMS_HISTORY_PROJECTS.MANAGERGROUP_ID,\
	CMS_HISTORY_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_HISTORY_PROJECTS.DATE_CREATED,\
	CMS_HISTORY_PROJECTS.PROJECT_TYPE,\
	CMS_HISTORY_PROJECTS.PROJECT_OU \
FROM \
	CMS_HISTORY_PROJECTS \
WHERE \
	CMS_HISTORY_PROJECTS.PROJECT_ID=?\
ORDER BY \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG DESC

                                 
C_PROJECTS_HISTORY_READ_ALL=\
SELECT \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG,\
	CMS_HISTORY_PROJECTS.PROJECT_ID,\
	CMS_HISTORY_PROJECTS.PROJECT_NAME,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHDATE,\
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHED_BY,\
	CMS_HISTORY_PROJECTS.PROJECT_DESCRIPTION,\
	CMS_HISTORY_PROJECTS.USER_ID,\
	CMS_HISTORY_PROJECTS.GROUP_ID,\
	CMS_HISTORY_PROJECTS.MANAGERGROUP_ID,\
	CMS_HISTORY_PROJECTS.DATE_CREATED,\
	CMS_HISTORY_PROJECTS.PROJECT_TYPE,\
	CMS_HISTORY_PROJECTS.PROJECT_OU \
FROM \
	CMS_HISTORY_PROJECTS \
ORDER BY \
	CMS_HISTORY_PROJECTS.PUBLISH_TAG DESC
    
                         
C_PROJECTRESOURCES_HISTORY_CREATE=\
INSERT INTO CMS_HISTORY_PROJECTRESOURCES \
	(PUBLISH_TAG,\
	PROJECT_ID,\
	RESOURCE_PATH) \
VALUES \
	(?,?,?)
                           
                                 
C_PROJECTRESOURCES_HISTORY_READ=\
SELECT \
	CMS_HISTORY_PROJECTRESOURCES.RESOURCE_PATH \
FROM \
	CMS_HISTORY_PROJECTRESOURCES \
WHERE \
	CMS_HISTORY_PROJECTRESOURCES.PUBLISH_TAG=?
	
	
#
# Project resource queries
#
C_PROJECTRESOURCES_CREATE_2=\
INSERT INTO CMS_PROJECTRESOURCES \
	(PROJECT_ID,\
	RESOURCE_PATH) \
VALUES \
	(?,?)


C_PROJECTRESOURCES_DELETE_2=\
DELETE FROM \
	CMS_PROJECTRESOURCES \
WHERE \
	CMS_PROJECTRESOURCES.PROJECT_ID=? \
	AND CMS_PROJECTRESOURCES.RESOURCE_PATH=?
                          
                          
C_PROJECTRESOURCES_DELETEALL_1=\
DELETE FROM \
	CMS_PROJECTRESOURCES \
WHERE \
	CMS_PROJECTRESOURCES.PROJECT_ID=?

	
C_PROJECTRESOURCES_READ_2=\
SELECT \
	CMS_PROJECTRESOURCES.RESOURCE_PATH \
FROM \
	CMS_PROJECTRESOURCES \
WHERE \
	CMS_PROJECTRESOURCES.PROJECT_ID=? \
	AND CMS_PROJECTRESOURCES.RESOURCE_PATH=?
	
	
C_PROJECTRESOURCES_READ_BY_ID_1=\
SELECT \
	CMS_PROJECTRESOURCES.RESOURCE_PATH \
FROM \
	CMS_PROJECTRESOURCES \
WHERE \
	CMS_PROJECTRESOURCES.PROJECT_ID=?
	
#
# CMS_RESOURCE_LOCKS queries
#
C_RESOURCE_LOCKS_READALL=\
SELECT \
	CMS_RESOURCE_LOCKS.RESOURCE_PATH,\
	CMS_RESOURCE_LOCKS.USER_ID,\
	CMS_RESOURCE_LOCKS.PROJECT_ID,\
	CMS_RESOURCE_LOCKS.LOCK_TYPE \
FROM \
	CMS_RESOURCE_LOCKS

C_RESOURCE_LOCKS_DELETEALL=\
DELETE \
FROM \
	CMS_RESOURCE_LOCKS

C_RESOURCE_LOCK_WRITE=\
INSERT INTO CMS_RESOURCE_LOCKS \
	(RESOURCE_PATH,\
	USER_ID,\
	PROJECT_ID,\
	LOCK_TYPE) \
VALUES \
	(?,?,?,?)
	

# CMS_RESOURCE_LOCKS column names: 
C_RESOURCE_LOCKS_RESOURCE_PATH=RESOURCE_PATH
C_RESOURCE_LOCKS_USER_ID=USER_ID
C_RESOURCE_LOCKS_PROJECT_ID=PROJECT_ID
C_RESOURCE_LOCKS_LOCK_TYPE=LOCK_TYPE

						   
#
# Database table attribs required to create a valid resource instance
#
C_RESOURCES_RESOURCE_ID=RESOURCE_ID
C_RESOURCES_STRUCTURE_ID=STRUCTURE_ID
C_RESOURCES_PUBLISH_TAG=PUBLISH_TAG
C_RESOURCES_HISTORY_VERSION=VERSION
C_RESOURCES_HISTORY_PARENTID=PARENT_ID
C_RESOURCES_VERSION=RESOURCE_VERSION
C_RESOURCES_STRUCTURE_VERSION=STRUCTURE_VERSION
C_RESOURCES_RESOURCE_TYPE=RESOURCE_TYPE
C_RESOURCES_RESOURCE_FLAGS=RESOURCE_FLAGS
C_RESOURCES_RESOURCE_PATH=RESOURCE_PATH
C_RESOURCES_GROUP_NAME=GROUP_NAME
C_RESOURCES_PROJECT_LASTMODIFIED=PROJECT_LASTMODIFIED
C_PROJECT_ID_RESOURCES=CMS_OFFLINE_RESOURCES.PROJECT_LASTMODIFIED
C_RESOURCE_FLAGS=RESOURCE_FLAGS
C_RESOURCES_STATE=RESOURCE_STATE
C_RESOURCES_DATE_CREATED=DATE_CREATED
C_RESOURCES_DATE_LASTMODIFIED=DATE_LASTMODIFIED
C_RESOURCES_DATE_RELEASED=DATE_RELEASED
C_RESOURCES_DATE_EXPIRED=DATE_EXPIRED
C_RESOURCES_SIZE=RESOURCE_SIZE
C_RESOURCES_DATE_CONTENT=DATE_CONTENT
C_RESOURCES_USER_CREATED=USER_CREATED
C_RESOURCES_USER_LASTMODIFIED=USER_LASTMODIFIED
C_RESOURCES_FILE_CONTENT=FILE_CONTENT
C_RESOURCES_STRUCTURE_STATE=STRUCTURE_STATE
C_RESOURCES_SIBLING_COUNT=SIBLING_COUNT

#
# these strings are used as replacements for ${XXX} patterns in SQL statements when the properties hash is loaded
#

# patterns for statements to select resources/folders (= selections without content)
# THINGS TO KNOW: don't select the project-ID attrib. of the structure table per default!
# There are cases, where the project-ID attrib. of the project-resources tab. is used
# as the project-ID!
C_RESOURCES_SELECT_ATTRIBS=\
    CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID,\
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID,\
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH,\
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE,\
	CMS_${PROJECT}_STRUCTURE.DATE_RELEASED,\
	CMS_${PROJECT}_STRUCTURE.DATE_EXPIRED,\
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_VERSION,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_TYPE,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_FLAGS,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_STATE,\
	CMS_${PROJECT}_RESOURCES.DATE_CREATED,\
	CMS_${PROJECT}_RESOURCES.DATE_LASTMODIFIED,\
	CMS_${PROJECT}_RESOURCES.USER_CREATED,\
	CMS_${PROJECT}_RESOURCES.USER_LASTMODIFIED,\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED AS LOCKED_IN_PROJECT,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_SIZE,\
	CMS_${PROJECT}_RESOURCES.DATE_CONTENT,\
	CMS_${PROJECT}_RESOURCES.SIBLING_COUNT,\
	CMS_${PROJECT}_RESOURCES.RESOURCE_VERSION
	
C_RESOURCES_SELECT_TABLES=CMS_${PROJECT}_STRUCTURE,CMS_${PROJECT}_RESOURCES

C_RESOURCES_SELECT_ATTRIBS_HISTORY=\
	CMS_HISTORY_STRUCTURE.PUBLISH_TAG, \
	CMS_HISTORY_STRUCTURE.VERSION,\
	CMS_HISTORY_STRUCTURE.STRUCTURE_VERSION,\
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID,\
	CMS_HISTORY_STRUCTURE.RESOURCE_PATH,\
	CMS_HISTORY_STRUCTURE.STRUCTURE_STATE,\
	CMS_HISTORY_STRUCTURE.DATE_RELEASED,\
	CMS_HISTORY_STRUCTURE.DATE_EXPIRED,\
	CMS_HISTORY_STRUCTURE.PARENT_ID,\
	CMS_HISTORY_RESOURCES.RESOURCE_ID,\
	CMS_HISTORY_RESOURCES.RESOURCE_TYPE,\
	CMS_HISTORY_RESOURCES.RESOURCE_FLAGS,\
	CMS_HISTORY_RESOURCES.RESOURCE_STATE,\
	CMS_HISTORY_RESOURCES.DATE_CREATED,\
	CMS_HISTORY_RESOURCES.DATE_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.USER_CREATED,\
	CMS_HISTORY_RESOURCES.USER_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.RESOURCE_SIZE,\
	CMS_HISTORY_RESOURCES.DATE_CONTENT,\
	CMS_HISTORY_RESOURCES.RESOURCE_VERSION,\
	CMS_HISTORY_RESOURCES.SIBLING_COUNT
	
C_HISTORY_SELECT_RESOURCE=\
	CMS_HISTORY_RESOURCES.PUBLISH_TAG,\
	CMS_HISTORY_RESOURCES.RESOURCE_ID,\
	CMS_HISTORY_RESOURCES.RESOURCE_TYPE,\
	CMS_HISTORY_RESOURCES.RESOURCE_FLAGS,\
	CMS_HISTORY_RESOURCES.RESOURCE_STATE,\
	CMS_HISTORY_RESOURCES.DATE_CREATED,\
	CMS_HISTORY_RESOURCES.DATE_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.USER_CREATED,\
	CMS_HISTORY_RESOURCES.USER_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED,\
	CMS_HISTORY_RESOURCES.RESOURCE_SIZE,\
	CMS_HISTORY_RESOURCES.DATE_CONTENT,\
	CMS_HISTORY_RESOURCES.SIBLING_COUNT,\
	CMS_HISTORY_RESOURCES.RESOURCE_VERSION,\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED AS LOCKED_IN_PROJECT
	
C_RESOURCES_SELECT_TABLES_HISTORY=CMS_HISTORY_STRUCTURE,CMS_HISTORY_RESOURCES

C_FILES_SELECT_TABLES_OFFLINE=\
CMS_OFFLINE_STRUCTURE,\
CMS_OFFLINE_RESOURCES,\
CMS_OFFLINE_CONTENTS

C_FILES_SELECT_TABLES_ONLINE=\
CMS_ONLINE_STRUCTURE,\
CMS_ONLINE_RESOURCES,\
CMS_CONTENTS

C_FILES_SELECT_TABLES_HISTORY=\
CMS_HISTORY_RESOURCES,\
CMS_HISTORY_STRUCTURE,\
CMS_CONTENTS

C_JOIN_STRUCTURE_RESOURCE=CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID
C_JOIN_RESOURCE_STRUCTURE=CMS_${PROJECT}_RESOURCES.RESOURCE_ID=CMS_${PROJECT}_STRUCTURE.RESOURCE_ID
C_JOIN_STRUCTURE_RESOURCE_HISTORY=CMS_HISTORY_STRUCTURE.RESOURCE_ID=CMS_HISTORY_RESOURCES.RESOURCE_ID AND CMS_HISTORY_STRUCTURE.PUBLISH_TAG=CMS_HISTORY_RESOURCES.PUBLISH_TAG

C_JOIN_RESOURCE_OFFLINE_FILE=CMS_OFFLINE_CONTENTS.RESOURCE_ID=CMS_OFFLINE_RESOURCES.RESOURCE_ID
C_JOIN_RESOURCE_ONLINE_FILE=CMS_CONTENTS.RESOURCE_ID=CMS_ONLINE_RESOURCES.RESOURCE_ID AND CMS_CONTENTS.ONLINE_FLAG=1


#
# SQL statements
#
C_RESOURCES_UNMARK=\
UPDATE \
	CMS_OFFLINE_RESOURCES \
SET \
	PROJECT_LASTMODIFIED='00000000-0000-0000-0000-000000000000' \
WHERE \
	CMS_OFFLINE_RESOURCES.PROJECT_LASTMODIFIED=?
                    
                    
C_RESOURCES_WRITE=\
INSERT INTO CMS_${PROJECT}_RESOURCES \
	(RESOURCE_ID,\
	RESOURCE_TYPE,\
	RESOURCE_FLAGS,\
	DATE_CREATED,\
	USER_CREATED,\
	DATE_LASTMODIFIED,\
	USER_LASTMODIFIED,\
	RESOURCE_STATE,\
	RESOURCE_SIZE,\
	DATE_CONTENT,\
	PROJECT_LASTMODIFIED,\
	SIBLING_COUNT,\
	RESOURCE_VERSION) \
VALUES \
	(?,?,?,?,?,?,?,?,?,?,?,?,?)


C_RESOURCES_READ_VERSION_RES=\
SELECT \
    CMS_${PROJECT}_RESOURCES.RESOURCE_VERSION \
FROM \
	CMS_${PROJECT}_RESOURCES \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?

C_RESOURCES_READ_VERSION_STR=\
SELECT \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_VERSION \
FROM \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?


C_RESOURCES_UPDATE_RESOURCE_VERSION=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_VERSION = ? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID = ?
	 
C_RESOURCES_UPDATE_STRUCTURE_VERSION=\
UPDATE \
	CMS_${PROJECT}_STRUCTURE \
SET \
	STRUCTURE_VERSION = ? \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID = ?
	 
C_STRUCTURE_WRITE=\
INSERT INTO CMS_${PROJECT}_STRUCTURE \
	(STRUCTURE_ID,\
	RESOURCE_ID,\
	RESOURCE_PATH,\
	STRUCTURE_STATE,\
	DATE_RELEASED,\
	DATE_EXPIRED,\
	PARENT_ID,\
	STRUCTURE_VERSION) \
VALUES \
	(?,?,?,?,?,?,?,?)

	
C_RESOURCES_HISTORY_WRITE=\
INSERT INTO CMS_HISTORY_RESOURCES \
    (RESOURCE_ID,\
	RESOURCE_TYPE,\
	RESOURCE_FLAGS,\
	DATE_CREATED,\
	USER_CREATED,\
	DATE_LASTMODIFIED,\
	USER_LASTMODIFIED,\
	RESOURCE_STATE,\
	RESOURCE_SIZE,\
	DATE_CONTENT,\
	PROJECT_LASTMODIFIED,\
	SIBLING_COUNT,\
	RESOURCE_VERSION,\
	PUBLISH_TAG) \
VALUES \
	(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
	
	
C_STRUCTURE_HISTORY_WRITE=\
INSERT INTO CMS_HISTORY_STRUCTURE \
	(STRUCTURE_ID,\
	RESOURCE_ID,\
	RESOURCE_PATH,\
	STRUCTURE_STATE,\
	DATE_RELEASED,\
	DATE_EXPIRED,\
	STRUCTURE_VERSION,\
	PARENT_ID,\
	PUBLISH_TAG,\
	VERSION) \
VALUES \
	(?,?,?,?,?,?,?,?,?,?)


C_RESOURCES_WRITE_PUBLISH_HISTORY=\
INSERT INTO CMS_PUBLISH_HISTORY \
	(PUBLISH_TAG,\
	STRUCTURE_ID,\
	RESOURCE_ID,\
	RESOURCE_PATH,\
	RESOURCE_STATE,\
	RESOURCE_TYPE,\
	HISTORY_ID,\
	SIBLING_COUNT) \
VALUES \
	(?,?,?,?,?,?,?,?)
	
	
C_RESOURCES_UPDATE_RESOURCES=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_TYPE=?,\
	RESOURCE_FLAGS=?,\
	DATE_LASTMODIFIED=?,\
	USER_LASTMODIFIED=?,\
	RESOURCE_STATE=?,\
	RESOURCE_SIZE=?,\
	DATE_CONTENT=?,\
	PROJECT_LASTMODIFIED=?,\
	SIBLING_COUNT=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
C_RESOURCES_UPDATE_RESOURCES_WITHOUT_STATE=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_TYPE=?,\
	RESOURCE_FLAGS=?,\
	DATE_LASTMODIFIED=?,\
	USER_LASTMODIFIED=?,\
	RESOURCE_SIZE=?,\
	DATE_CONTENT=?,\
	PROJECT_LASTMODIFIED=?,\
	SIBLING_COUNT=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
C_RESOURCES_TRANSFER_RESOURCE=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	USER_CREATED=?,\
	USER_LASTMODIFIED=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?	
	
C_RESOURCES_UPDATE_STRUCTURE=\
UPDATE \
	CMS_${PROJECT}_STRUCTURE \
SET \
	RESOURCE_ID=?,\
	RESOURCE_PATH=?,\
	STRUCTURE_STATE=?, \
	DATE_RELEASED=?, \
	DATE_EXPIRED=?, \
	PARENT_ID=? \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?
	
	
C_RESOURCES_HISTORY_READ_ALL_VERSIONS=\
SELECT \
	${C_RESOURCES_SELECT_ATTRIBS_HISTORY},\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED AS LOCKED_IN_PROJECT \
FROM \
	${C_RESOURCES_SELECT_TABLES_HISTORY} \
WHERE \
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE_HISTORY} \
ORDER BY \
	CMS_HISTORY_STRUCTURE.PUBLISH_TAG DESC


C_RESOURCES_HISTORY_READ_NEW_VERSIONS=\
SELECT \
    ${C_HISTORY_SELECT_RESOURCE} \
FROM \
	CMS_HISTORY_RESOURCES \
WHERE \
	CMS_HISTORY_RESOURCES.RESOURCE_ID=? \
	AND CMS_HISTORY_RESOURCES.PUBLISH_TAG>? \
ORDER BY \
	CMS_HISTORY_RESOURCES.PUBLISH_TAG ASC


C_RESOURCES_HISTORY_READ_BTW_VERSIONS=\
SELECT \
    ${C_HISTORY_SELECT_RESOURCE} \
FROM \
	CMS_HISTORY_RESOURCES \
WHERE \
	CMS_HISTORY_RESOURCES.RESOURCE_ID=? \
	AND CMS_HISTORY_RESOURCES.PUBLISH_TAG>? \
	AND CMS_HISTORY_RESOURCES.PUBLISH_TAG= 0

C_RESOURCES_READ_PARENT_STRUCTURE_ID=\
SELECT \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID \
FROM \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH=?	
		
		
C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF=\
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	CMS_${PROJECT}_PROPERTIES, \
	CMS_${PROJECT}_RESOURCES, \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID = ? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH LIKE ?) \
UNION \
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	CMS_${PROJECT}_PROPERTIES, \
	CMS_${PROJECT}_STRUCTURE, \
	CMS_${PROJECT}_RESOURCES \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID = ? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID = CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH LIKE ?) \
ORDER BY RESOURCE_PATH DESC

C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF_VALUE=\
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	CMS_${PROJECT}_PROPERTIES, \
	CMS_${PROJECT}_RESOURCES, \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH LIKE ? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_VALUE LIKE ?) \
UNION \
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	CMS_${PROJECT}_PROPERTIES, \
	CMS_${PROJECT}_STRUCTURE, \
	CMS_${PROJECT}_RESOURCES \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID = ? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID = CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_ID = CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH LIKE ? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_VALUE LIKE ?) \
ORDER BY RESOURCE_PATH DESC

C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITH_STATE=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE (\
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID) \
	AND CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED = ? \
	AND \
	(\
		(\
			CMS_${PROJECT}_RESOURCES.RESOURCE_STATE=? \
			AND CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE<=?\
		)\
		OR \
		(\
			CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE=? \
			AND CMS_${PROJECT}_RESOURCES.RESOURCE_STATE<=?\
		)\
	) \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC


C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITHOUT_STATE=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED = ? \
	AND \
	(\
		CMS_${PROJECT}_RESOURCES.RESOURCE_STATE<>? \
		OR CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE<>? \
	)\
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC	
	
	
C_RESOURCES_READ_WITH_ACE_1=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	CMS_${PROJECT}_ACCESSCONTROL, ${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH LIKE ? \
	AND CMS_${PROJECT}_STRUCTURE.RESOURCE_ID = CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC	


C_RESOURCES_GET_RESOURCE_IN_PROJECT_IGNORE_STATE=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED = ? \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC	
		
		
C_RESOURCE_REPLACE=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_TYPE=?,\
	RESOURCE_SIZE=?, \
	DATE_CONTENT=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?


C_RESOURCES_UPDATE_SIBLING_COUNT=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	SIBLING_COUNT=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
	
C_RESOURCES_MOVE=\
UPDATE \
	CMS_${PROJECT}_STRUCTURE \
SET \
	RESOURCE_PATH=?, \
	PARENT_ID=? \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?
	
	
C_RESOURCES_UPDATE_FLAGS=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_FLAGS=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
	
C_RESOURCES_UPDATE_RESOURCE_STATE=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_STATE=?, \
    PROJECT_LASTMODIFIED=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
	
C_RESOURCES_UPDATE_RESOURCE_PROJECT=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_FLAGS=?, \
    PROJECT_LASTMODIFIED=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?

 	
C_RESOURCES_UPDATE_RESOURCE_STATELASTMODIFIED=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	RESOURCE_STATE=?, \
    DATE_LASTMODIFIED=?, \
    USER_LASTMODIFIED=?, \
    PROJECT_LASTMODIFIED=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?	


C_RESOURCES_UPDATE_STRUCTURE_STATE=\
UPDATE \
	CMS_${PROJECT}_STRUCTURE \
SET \
	STRUCTURE_STATE=? \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?
	
	
C_RESOURCES_UPDATE_RELEASE_EXPIRED=\
UPDATE \
	CMS_${PROJECT}_STRUCTURE \
SET \
	DATE_RELEASED=?, \
    DATE_EXPIRED=? \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?	
	

C_RESOURCES_READ_RESOURCE_STATE=\
SELECT \
	CMS_${PROJECT}_RESOURCES.RESOURCE_STATE \
FROM \
	CMS_${PROJECT}_RESOURCES \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
		
	
C_RESOURCES_COUNT_SIBLINGS=\
SELECT \
	COUNT(CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID) \
FROM \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_ID=?

	
C_RESOURCES_DELETE_BY_RESOURCEID=\
DELETE FROM \
	CMS_${PROJECT}_RESOURCES \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?
	
		
C_STRUCTURE_DELETE_BY_STRUCTUREID=\
DELETE FROM \
	CMS_${PROJECT}_STRUCTURE \
WHERE \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=?


C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED=\
UPDATE \
	CMS_${PROJECT}_RESOURCES \
SET \
	PROJECT_LASTMODIFIED=? \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=?	


C_CONTENT_PUBLISH_MAXTAG=\
SELECT MAX(CMS_CONTENTS.PUBLISH_TAG_TO) FROM CMS_CONTENTS

C_PROJECTS_HISTORY_MAXTAG=\
SELECT \
	MAX(CMS_HISTORY_PROJECTS.PUBLISH_TAG) \
FROM \
	CMS_HISTORY_PROJECTS


C_RESOURCES_HISTORY_MAXTAG=\
SELECT \
	MAX(CMS_HISTORY_STRUCTURE.PUBLISH_TAG) \
FROM \
	CMS_HISTORY_STRUCTURE


C_STRUCTURE_HISTORY_MAXVER=\
SELECT \
	MAX(CMS_HISTORY_STRUCTURE.VERSION) \
FROM \
	CMS_HISTORY_STRUCTURE \
WHERE \
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID=?


C_STRUCTURE_HISTORY_MAXVER_BYTIME=\
SELECT \
	MAX(CMS_HISTORY_STRUCTURE.VERSION) \
FROM \
	CMS_HISTORY_STRUCTURE, \
	CMS_HISTORY_PROJECTS \
WHERE \
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID=? \
	AND CMS_HISTORY_STRUCTURE.PUBLISH_TAG=CMS_HISTORY_PROJECTS.PUBLISH_TAG \
	AND CMS_HISTORY_PROJECTS.PROJECT_PUBLISHDATE= CMS_${PROJECT}_RESOURCES.RESOURCE_STATE) OR \
	(CMS_${PROJECT}_RESOURCES.RESOURCE_STATE=? AND CMS_${PROJECT}_RESOURCES.RESOURCE_STATE >= CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE))
C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_AFTER=\
	CMS_${PROJECT}_RESOURCES.DATE_LASTMODIFIED >= ?
C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_BEFORE=\
	CMS_${PROJECT}_RESOURCES.DATE_LASTMODIFIED <= ?
C_STRUCTURE_SELECT_BY_DATE_EXPIRED_AFTER=\
	(CMS_${PROJECT}_STRUCTURE.DATE_EXPIRED != 0) AND (CMS_${PROJECT}_STRUCTURE.DATE_EXPIRED >= ?)
C_STRUCTURE_SELECT_BY_DATE_EXPIRED_BEFORE=\
	(CMS_${PROJECT}_STRUCTURE.DATE_EXPIRED != 0) AND (CMS_${PROJECT}_STRUCTURE.DATE_EXPIRED <= ?)
C_STRUCTURE_SELECT_BY_DATE_RELEASED_AFTER=\
	(CMS_${PROJECT}_STRUCTURE.DATE_RELEASED != 0) AND (CMS_${PROJECT}_STRUCTURE.DATE_RELEASED >= ?)
C_STRUCTURE_SELECT_BY_DATE_RELEASED_BEFORE=\
	(CMS_${PROJECT}_STRUCTURE.DATE_RELEASED != 0) AND (CMS_${PROJECT}_STRUCTURE.DATE_RELEASED <= ?)
C_RESOURCES_SELECT_ONLY_FOLDERS=\
	CMS_${PROJECT}_RESOURCES.RESOURCE_SIZE = -1
C_RESOURCES_SELECT_ONLY_FILES=\
	CMS_${PROJECT}_RESOURCES.RESOURCE_SIZE > -1
#
# Resources order
#
C_RESOURCES_ORDER_BY_PATH=\
	ORDER BY CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH

#
# Files
#

C_FILE_CONTENT=FILE_CONTENT


C_OFFLINE_CONTENTS_WRITE=\
INSERT INTO CMS_OFFLINE_CONTENTS (\
	RESOURCE_ID,\
	FILE_CONTENT) \
VALUES \
	(?,?)


C_ONLINE_CONTENTS_WRITE=\
INSERT INTO CMS_CONTENTS (\
	RESOURCE_ID,\
	FILE_CONTENT,\
	PUBLISH_TAG_FROM,\
	PUBLISH_TAG_TO,\
	ONLINE_FLAG) \
VALUES \
	(?,?,?,?,?)
	
C_ONLINE_CONTENTS_HISTORY=\
UPDATE \
	CMS_CONTENTS \
SET \
	ONLINE_FLAG = 0 \
WHERE \
	CMS_CONTENTS.RESOURCE_ID = ? \
	AND CMS_CONTENTS.ONLINE_FLAG = 1
	
C_ONLINE_CONTENTS_DELETE=\
DELETE FROM \
	CMS_CONTENTS \
WHERE \
	CMS_CONTENTS.RESOURCE_ID = ? \
	AND CMS_CONTENTS.ONLINE_FLAG = 1
	
C_HISTORY_CONTENTS_UPDATE=\
UPDATE \
	CMS_CONTENTS \
SET \
	PUBLISH_TAG_TO = ? \
WHERE \
	CMS_CONTENTS.RESOURCE_ID = ? \
	AND CMS_CONTENTS.ONLINE_FLAG = 1


C_OFFLINE_CONTENTS_UPDATE=\
UPDATE \
	CMS_OFFLINE_CONTENTS \
SET \
	FILE_CONTENT=? \
WHERE \
	CMS_OFFLINE_CONTENTS.RESOURCE_ID=?


C_OFFLINE_FILES_CONTENT=\
SELECT \
	CMS_OFFLINE_CONTENTS.FILE_CONTENT \
FROM \
	CMS_OFFLINE_CONTENTS \
WHERE \
	CMS_OFFLINE_CONTENTS.RESOURCE_ID=?
	
	
C_ONLINE_FILES_CONTENT=\
SELECT \
	CMS_CONTENTS.FILE_CONTENT \
FROM \
	CMS_CONTENTS,\
	CMS_ONLINE_RESOURCES \
WHERE \
	CMS_ONLINE_RESOURCES.RESOURCE_ID=? \
	AND ${C_JOIN_RESOURCE_ONLINE_FILE}
	
	
C_RESOURCES_HISTORY_READ_VERSION=\
SELECT \
	${C_RESOURCES_SELECT_ATTRIBS_HISTORY},\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED AS LOCKED_IN_PROJECT \
FROM \
	${C_RESOURCES_SELECT_TABLES_HISTORY} \
WHERE \
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID=? \
	AND CMS_HISTORY_STRUCTURE.VERSION=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE_HISTORY}
	
C_HISTORY_READ_CONTENT=\
SELECT \
	CMS_CONTENTS.FILE_CONTENT \
FROM \
	CMS_CONTENTS \
WHERE \
	CMS_CONTENTS.RESOURCE_ID=? \
	AND CMS_CONTENTS.PUBLISH_TAG_TO>=? \
	AND CMS_CONTENTS.PUBLISH_TAG_FROM<=?
	
############
# This query is just used by deprecated methods
# remove it as soon as possible
# see org.opencms.db.I_CmsHistoryDriver#readFile(CmsDbContext, CmsUUID, int)
############	
C_FILES_READ_HISTORY_BYID=\
SELECT \
	${C_RESOURCES_SELECT_ATTRIBS_HISTORY},\
	CMS_HISTORY_RESOURCES.PROJECT_LASTMODIFIED AS LOCKED_IN_PROJECT \
FROM \
	${C_RESOURCES_SELECT_TABLES_HISTORY}\
WHERE \
	CMS_HISTORY_STRUCTURE.STRUCTURE_ID=? \
	AND CMS_HISTORY_STRUCTURE.PUBLISH_TAG=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE_HISTORY} 


C_OFFLINE_FILE_CONTENT_DELETE=\
DELETE FROM \
	CMS_OFFLINE_CONTENTS \
WHERE \
	CMS_OFFLINE_CONTENTS.RESOURCE_ID=?


#
# Property definitions
#
C_PROPERTYDEF_ID=PROPERTYDEF_ID
C_PROPERTYDEF_NAME=PROPERTYDEF_NAME
C_PROPERTYDEF_TYPE=PROPERTYDEF_TYPE


C_PROPERTYDEF_READ=\
SELECT \
	* \
FROM \
	CMS_${PROJECT}_PROPERTYDEF \
WHERE \
	CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_NAME=?	
	
C_PROPERTYDEF_READ_HISTORY=\
SELECT \
	* \
FROM \
	CMS_HISTORY_PROPERTYDEF \
WHERE \
	CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_NAME=?
	
C_PROPERTYDEF_READALL=\
SELECT \
	* \
FROM \
	CMS_${PROJECT}_PROPERTYDEF	
	
C_PROPERTYDEF_CREATE=\
INSERT INTO CMS_${PROJECT}_PROPERTYDEF (\
	PROPERTYDEF_ID,\
	PROPERTYDEF_NAME,\
	PROPERTYDEF_TYPE) \
VALUES \
	(?,?,?)
	
	
C_PROPERTYDEF_CREATE_HISTORY=\
INSERT INTO CMS_HISTORY_PROPERTYDEF (\
	PROPERTYDEF_ID,\
	PROPERTYDEF_NAME,\
	PROPERTYDEF_TYPE) \
VALUES \
	(?,?,?)
	
	
C_PROPERTYDEF_DELETE=\
DELETE FROM \
	CMS_${PROJECT}_PROPERTYDEF \
WHERE \
	CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_ID=?
	
	
C_PROPERTYDEF_DELETE_HISTORY=\
DELETE FROM \
	CMS_HISTORY_PROPERTYDEF \
WHERE \
	CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_ID=?


#
# Properties
#
C_PROPERTY_VALUE=PROPERTY_VALUE
C_PROPERTY_RESOURCE_ID=RESOURCE_ID


C_PROPERTIES_READALL_COUNT=\
SELECT \
	COUNT(*) \
FROM \
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=?

	
C_PROPERTIES_UPDATE=\
UPDATE \
	CMS_${PROJECT}_PROPERTIES \
SET \
	PROPERTY_VALUE=? \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_TYPE=? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=?

	
C_PROPERTIES_CREATE=\
INSERT INTO CMS_${PROJECT}_PROPERTIES \
	(PROPERTY_ID,\
	PROPERTYDEF_ID,\
	PROPERTY_MAPPING_ID,\
	PROPERTY_MAPPING_TYPE,\
	PROPERTY_VALUE) \
VALUES \
	(?,?,?,?,?)
	
	
C_PROPERTIES_HISTORY_CREATE=\
INSERT INTO CMS_HISTORY_PROPERTIES \
	(STRUCTURE_ID,\
	PROPERTYDEF_ID,\
	PROPERTY_MAPPING_ID,\
	PROPERTY_MAPPING_TYPE,\
	PROPERTY_VALUE,\
	PUBLISH_TAG) \
VALUES \
	(?,?,?,?,?,?)


C_PROPERTIES_READ=\
SELECT \
	CMS_${PROJECT}_PROPERTIES.PROPERTY_VALUE,\
	CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_TYPE \
FROM \
	CMS_${PROJECT}_PROPERTYDEF,\
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_NAME=? \
    AND CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_ID \
	AND \
	(\
		CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=? \
			OR \
		CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=?\
	)
                     
                     
C_PROPERTIES_READALL=\
SELECT \
	CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_NAME,\
	CMS_${PROJECT}_PROPERTIES.PROPERTY_VALUE,\
	CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_TYPE \
FROM \
	CMS_${PROJECT}_PROPERTYDEF,\
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	(\
		CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=? \
			OR \
		CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=?\
	) \
	AND \
	(\
		CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=CMS_${PROJECT}_PROPERTYDEF.PROPERTYDEF_ID\
	)                     
                     

C_PROPERTIES_HISTORY_READ_PUBTAG=\
SELECT \
	MAX(CMS_HISTORY_PROPERTIES.PUBLISH_TAG) \
FROM \
	CMS_HISTORY_PROPERTIES \
WHERE \
	CMS_HISTORY_PROPERTIES.STRUCTURE_ID=? \
	AND CMS_HISTORY_PROPERTIES.PUBLISH_TAG<=?


C_PROPERTIES_HISTORY_READALL_RES=\
SELECT \
	CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_NAME, \
	CMS_HISTORY_PROPERTIES.PROPERTY_VALUE,\
	CMS_HISTORY_PROPERTIES.PROPERTY_MAPPING_TYPE \
FROM \
	CMS_HISTORY_PROPERTIES,\
	CMS_HISTORY_PROPERTYDEF \
WHERE \
	CMS_HISTORY_PROPERTIES.PROPERTYDEF_ID=CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_ID \
	AND CMS_HISTORY_PROPERTIES.PROPERTY_MAPPING_ID=? \
	AND CMS_HISTORY_PROPERTIES.PUBLISH_TAG=?
                            
	
C_PROPERTIES_HISTORY_READALL_STR=\
SELECT \
	CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_NAME, \
	CMS_HISTORY_PROPERTIES.PROPERTY_VALUE,\
	CMS_HISTORY_PROPERTIES.PROPERTY_MAPPING_TYPE \
FROM \
	CMS_HISTORY_PROPERTIES,\
	CMS_HISTORY_PROPERTYDEF \
WHERE \
	CMS_HISTORY_PROPERTIES.PROPERTYDEF_ID=CMS_HISTORY_PROPERTYDEF.PROPERTYDEF_ID \
	AND CMS_HISTORY_PROPERTIES.STRUCTURE_ID=? \
	AND CMS_HISTORY_PROPERTIES.PUBLISH_TAG=?
                            
	
C_PROPERTIES_DELETE_ALL_STRUCTURE_AND_RESOURCE_VALUES=\
DELETE FROM \
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	(\
		PROPERTY_MAPPING_ID=? \
		AND PROPERTY_MAPPING_TYPE=?\
	) \
	OR \
	(\
		PROPERTY_MAPPING_ID=? \
		AND PROPERTY_MAPPING_TYPE=?\
	)
	
	
C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE=\
DELETE FROM \
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_TYPE=?
	
	
C_PROPERTIES_DELETE=\
DELETE FROM \
	CMS_${PROJECT}_PROPERTIES \
WHERE \
	CMS_${PROJECT}_PROPERTIES.PROPERTYDEF_ID=?  \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_ID=? \
	AND CMS_${PROJECT}_PROPERTIES.PROPERTY_MAPPING_TYPE=?
	

#
# Groups
#
C_GROUPS_GROUP_ID_0=GROUP_ID
C_GROUPS_PARENT_GROUP_ID_0=PARENT_GROUP_ID
C_GROUPS_GROUP_NAME_0=GROUP_NAME
C_GROUPS_GROUP_DESCRIPTION_0=GROUP_DESCRIPTION
C_GROUPS_GROUP_FLAGS_0=GROUP_FLAGS
C_GROUPS_GROUP_OU_0=GROUP_OU

C_GROUPS_READ_BY_NAME_2=\
SELECT \
	* \
FROM \
	CMS_GROUPS \
WHERE \
	CMS_GROUPS.GROUP_NAME=? AND \
	CMS_GROUPS.GROUP_OU=?
	
	
C_GROUPS_READ_BY_ID_1=\
SELECT \
	* \
FROM \
	CMS_GROUPS \
WHERE \
	CMS_GROUPS.GROUP_ID=?
	
	
C_GROUPS_CREATE_GROUP_6=\
INSERT INTO CMS_GROUPS (\
	GROUP_ID,\
	PARENT_GROUP_ID,\
	GROUP_NAME,\
	GROUP_DESCRIPTION,\
	GROUP_FLAGS,\
	GROUP_OU) \
VALUES \
	(?,?,?,?,?,?)
	
	
C_GROUPS_WRITE_GROUP_4=\
UPDATE \
	CMS_GROUPS \
SET \
	GROUP_DESCRIPTION=?,\
	GROUP_FLAGS=?,\
	PARENT_GROUP_ID=? \
WHERE \
	CMS_GROUPS.GROUP_ID=?
	
	
C_GROUPS_DELETE_GROUP_2=\
DELETE FROM \
	CMS_GROUPS \
WHERE \
	CMS_GROUPS.GROUP_NAME=? AND \
	CMS_GROUPS.GROUP_OU=?
	
	
C_GROUPS_GROUP_OU_EQUALS_1	=GROUP_OU = ?
C_GROUPS_GROUP_OU_LIKE_1	=GROUP_OU LIKE ?
C_GROUPS_SELECT_GROUPS_1	=GROUP_FLAGS < ?
C_GROUPS_SELECT_ROLES_1		=GROUP_FLAGS >= ?
C_GROUPS_ORDER_0			=ORDER BY GROUP_OU, GROUP_NAME

C_GROUPS_GET_GROUPS_0=\
SELECT \
	* \
FROM \
	CMS_GROUPS \
WHERE 
	
	
C_GROUPS_GET_CHILD_1=\
SELECT \
	* \
FROM \
	CMS_GROUPS \
WHERE \
	CMS_GROUPS.PARENT_GROUP_ID=?
	
	
# Query is built within the CmsUserDriver class
C_GROUPS_GET_GROUPS_OF_USER_1=\
SELECT \
	* \
FROM \
	CMS_GROUPS G,\
	CMS_GROUPUSERS GU \
WHERE \
	GU.USER_ID=? \
    AND G.GROUP_ID=GU.GROUP_ID \
    AND
	

	
C_GROUPS_ADD_USER_TO_GROUP_3=\
INSERT INTO CMS_GROUPUSERS \
	(GROUP_ID,\
	USER_ID,\
	GROUPUSER_FLAGS) \
VALUES \
	(?,?,?)
	
	
C_GROUPS_USER_IN_GROUP_2=\
SELECT \
	* \
FROM \
	CMS_GROUPUSERS \
WHERE \
	CMS_GROUPUSERS.GROUP_ID=? \
	AND CMS_GROUPUSERS.USER_ID=?
	
	
C_GROUPS_GET_USERS_OF_GROUP_2=\
SELECT \
	U.USER_ID,\
	U.USER_NAME,\
	U.USER_PASSWORD,\
	U.USER_FIRSTNAME,\
	U.USER_LASTNAME,\
	U.USER_EMAIL,\
	U.USER_LASTLOGIN,\
	U.USER_FLAGS,\
	U.USER_OU,\
	U.USER_DATECREATED \
FROM \
	CMS_GROUPS G, \
	CMS_USERS U, \
	CMS_GROUPUSERS GU \
WHERE \
	G.GROUP_NAME=? \
	AND G.GROUP_OU=? \
	AND G.GROUP_OU=U.USER_OU \
    AND U.USER_ID=GU.USER_ID \
    AND GU.GROUP_ID=G.GROUP_ID \
ORDER BY \
	U.USER_OU,U.USER_NAME

	
C_GROUPS_GET_ALL_USERS_OF_GROUP_2=\
SELECT \
	U.USER_ID,\
	U.USER_NAME,\
	U.USER_PASSWORD,\
	U.USER_FIRSTNAME,\
	U.USER_LASTNAME,\
	U.USER_EMAIL,\
	U.USER_LASTLOGIN,\
	U.USER_FLAGS,\
	U.USER_OU,\
	U.USER_DATECREATED \
FROM \
	CMS_GROUPS G, \
	CMS_USERS U, \
	CMS_GROUPUSERS GU \
WHERE \
	G.GROUP_NAME=? \
	AND G.GROUP_OU=? \
    AND U.USER_ID=GU.USER_ID \
    AND GU.GROUP_ID=G.GROUP_ID \
ORDER BY \
	U.USER_OU,U.USER_NAME

	
C_GROUPS_REMOVE_USER_FROM_GROUP_2=\
DELETE FROM \
	CMS_GROUPUSERS \
WHERE \
	CMS_GROUPUSERS.GROUP_ID=? \
	AND CMS_GROUPUSERS.USER_ID=?


#
# Users
#
C_USERS_USER_ID_0=USER_ID
C_USERS_USER_NAME_0=USER_NAME
C_USERS_USER_PASSWORD_0=USER_PASSWORD
C_USERS_USER_FIRSTNAME_0=USER_FIRSTNAME
C_USERS_USER_LASTNAME_0=USER_LASTNAME
C_USERS_USER_LASTLOGIN_0=USER_LASTLOGIN
C_USERS_USER_FLAGS_0=USER_FLAGS
C_USERS_USER_EMAIL_0=USER_EMAIL
C_USERS_USER_OU_0=USER_OU
C_USERS_USER_DATECREATED_0=USER_DATECREATED

C_USER_ATTRIBS=\
	CMS_USERS.USER_ID,\
	CMS_USERS.USER_NAME,\
	CMS_USERS.USER_PASSWORD,\
	CMS_USERS.USER_FIRSTNAME,\
	CMS_USERS.USER_LASTNAME,\
	CMS_USERS.USER_EMAIL,\
	CMS_USERS.USER_LASTLOGIN,\
	CMS_USERS.USER_FLAGS,\
	CMS_USERS.USER_OU,\
	CMS_USERS.USER_DATECREATED

C_USERS_ADD_10=\
INSERT INTO CMS_USERS \
	(USER_ID,\
	USER_NAME,\
	USER_PASSWORD,\
	USER_FIRSTNAME,\
	USER_LASTNAME,\
	USER_EMAIL,\
	USER_LASTLOGIN,\
	USER_FLAGS,\
	USER_OU,\
	USER_DATECREATED\
) \
VALUES \
	(?,?,?,?,?,?,?,?,?,?)
	
	
C_USERS_READ_BY_NAME_2=\
SELECT \
	${C_USER_ATTRIBS} \
FROM \
	CMS_USERS \
WHERE \
	CMS_USERS.USER_NAME=? \
    AND CMS_USERS.USER_OU=?
	
	
C_USERS_READ_BY_ID_1=\
SELECT \
	${C_USER_ATTRIBS} \
FROM \
	CMS_USERS \
WHERE \
	CMS_USERS.USER_ID=?
	
	
C_USERS_READ_WITH_PWD_3=\
SELECT \
	${C_USER_ATTRIBS} \
FROM \
	CMS_USERS \
WHERE \
	CMS_USERS.USER_NAME=? \
	AND CMS_USERS.USER_OU=? \
    AND CMS_USERS.USER_PASSWORD=?
	
C_USERS_WRITE_6=\
UPDATE \
	CMS_USERS \
SET \
	USER_FIRSTNAME=?,\
	USER_LASTNAME=?,\
	USER_EMAIL=?,\
	USER_LASTLOGIN=?,\
	USER_FLAGS=? \
WHERE \
	CMS_USERS.USER_ID=?
	
C_USERS_WRITE_2=\
UPDATE \
	CMS_USERS \
SET \
	USER_LASTLOGIN=? \
WHERE \
	CMS_USERS.USER_ID=?	
	
C_USERS_DELETE_2=\
DELETE FROM \
	CMS_USERS \
WHERE \
	CMS_USERS.USER_NAME = ? AND \
	CMS_USERS.USER_OU = ?
	

C_USERS_GET_USERS_FOR_ORGUNIT_1=\
SELECT \
	${C_USER_ATTRIBS} \
FROM \
	CMS_USERS \
WHERE \
    (CMS_USERS.USER_FLAGS < 32768 \
    OR CMS_USERS.USER_FLAGS >= 65536) \
    AND CMS_USERS.USER_OU LIKE ? \
ORDER BY \
	CMS_USERS.USER_NAME
	
C_USERS_GET_WEBUSERS_FOR_ORGUNIT_1=\
SELECT \
	${C_USER_ATTRIBS} \
FROM \
	CMS_USERS \
WHERE \
    CMS_USERS.USER_FLAGS >= 32768 \
    AND CMS_USERS.USER_FLAGS < 65536 \
    AND CMS_USERS.USER_OU LIKE ? \
ORDER BY \
	CMS_USERS.USER_NAME
	

C_USERS_SET_PWD_3=\
UPDATE \
	CMS_USERS \
SET \
	USER_PASSWORD=? \
WHERE \
	CMS_USERS.USER_NAME=? AND \
	CMS_USERS.USER_OU=?
	

C_USERS_SET_ORGUNIT_2=\
UPDATE \
  CMS_USERS \
SET \
  USER_OU = ? \
WHERE \
  CMS_USERS.USER_ID = ?


#
# Userdata
#
C_USERDATA_USERID_0=USER_ID
C_USERDATA_KEY_0=DATA_KEY
C_USERDATA_VALUE_0=DATA_VALUE
C_USERDATA_TYPE_0=DATA_TYPE

C_USERDATA_ATTRIBS=\
	CMS_USERDATA.USER_ID,\
	CMS_USERDATA.DATA_KEY,\
	CMS_USERDATA.DATA_VALUE,\
	CMS_USERDATA.DATA_TYPE

C_USERDATA_WRITE_4=\
INSERT INTO	CMS_USERDATA \
	(USER_ID,\
	DATA_KEY,\
	DATA_VALUE,\
	DATA_TYPE) \
VALUES \
    (?, ?, ?, ?)
    
    C_USERDATA_UPDATE_4=\
UPDATE \
	CMS_USERDATA \
SET \
	DATA_VALUE =?, \
	DATA_TYPE=? \
WHERE \
	USER_ID =? \
	AND DATA_KEY =?
	
	

C_USERDATA_DELETE_1=\
DELETE FROM CMS_USERDATA \
WHERE \
    CMS_USERDATA.USER_ID = ?
    
C_USERDATA_DELETE_2=\
DELETE FROM CMS_USERDATA \
WHERE \
    CMS_USERDATA.USER_ID = ? \
    AND CMS_USERDATA.DATA_KEY = ?    
    
C_USERDATA_READ_1=\
SELECT \
	${C_USERDATA_ATTRIBS} \
FROM \
    CMS_USERDATA \
WHERE \
	CMS_USERDATA.USER_ID = ?

#
# User history
#
C_PRINCIPALS_HISTORY_ID=PRINCIPAL_ID
C_PRINCIPALS_HISTORY_NAME=PRINCIPAL_NAME
C_PRINCIPALS_HISTORY_DESCRIPTION=PRINCIPAL_DESCRIPTION
C_PRINCIPALS_HISTORY_EMAIL=PRINCIPAL_EMAIL
C_PRINCIPALS_HISTORY_OU=PRINCIPAL_OU
C_PRINCIPALS_HISTORY_TYPE=PRINCIPAL_TYPE
C_PRINCIPALS_HISTORY_USERDELETED=PRINCIPAL_USERDELETED
C_PRINCIPALS_HISTORY_DATEDELETED=PRINCIPAL_DATEDELETED

C_PRINCIPAL_HISTORY_ATTRIBS=\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_ID,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_NAME,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_DESCRIPTION,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_OU,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_EMAIL,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_TYPE,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_USERDELETED,\
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_DATEDELETED

C_HISTORY_PRINCIPAL_CREATE=\
INSERT INTO CMS_HISTORY_PRINCIPALS \
	(PRINCIPAL_ID,\
	PRINCIPAL_NAME,\
	PRINCIPAL_DESCRIPTION,\
	PRINCIPAL_OU,\
	PRINCIPAL_EMAIL,\
	PRINCIPAL_TYPE,\
	PRINCIPAL_USERDELETED,\
	PRINCIPAL_DATEDELETED) \
VALUES \
	(?,?,?,?,?,?,?,?)
	
C_HISTORY_PRINCIPAL_READ=\
SELECT \
	${C_PRINCIPAL_HISTORY_ATTRIBS} \
FROM \
	CMS_HISTORY_PRINCIPALS \
WHERE \
	CMS_HISTORY_PRINCIPALS.PRINCIPAL_ID=?

C_PROJECTS_HISTORY_READ_TAG_FOR_DATE=\
SELECT \
	MAX(CMS_HISTORY_PROJECTS.PUBLISH_TAG) \
FROM \
	CMS_HISTORY_PROJECTS \
WHERE \
	CMS_HISTORY_PROJECTS.PROJECT_PUBLISHDATE= 0 / <= 3
#
C_SELECT_NONDELETED_VFS_SIBLINGS=\
SELECT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=? \
	AND CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE IN(0,1,2) \
	AND ${C_JOIN_STRUCTURE_RESOURCE} \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC

	
C_SELECT_VFS_SIBLINGS=\
SELECT \
	${C_RESOURCES_SELECT_ATTRIBS},\
	CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_RESOURCES.RESOURCE_ID=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE} \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC	
			
#
#	Access Control Entries
#
C_ACCESS_RESOURCE_ID_0=RESOURCE_ID
C_ACCESS_PRINCIPAL_ID_0=PRINCIPAL_ID
C_ACCESS_ACCESS_ALLOWED_0=ACCESS_ALLOWED
C_ACCESS_ACCESS_DENIED_0=ACCESS_DENIED
C_ACCESS_ACCESS_FLAGS_0=ACCESS_FLAGS

C_ACCESS_CREATE_5=\
INSERT INTO CMS_${PROJECT}_ACCESSCONTROL \
	(RESOURCE_ID,\
	PRINCIPAL_ID,\
	ACCESS_ALLOWED,\
	ACCESS_DENIED,\
	ACCESS_FLAGS) \
VALUES \
	(?,?,?,?,?)
	
	
C_ACCESS_UPDATE_5=\
UPDATE \
	CMS_${PROJECT}_ACCESSCONTROL \
SET \
	ACCESS_ALLOWED=?,\
	ACCESS_DENIED=?,\
	ACCESS_FLAGS=? \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=? \
	AND CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID = ?
	
	
C_ACCESS_REMOVE_2=\
DELETE FROM \
	CMS_${PROJECT}_ACCESSCONTROL \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=? \
	AND CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID = ?
	
	
C_ACCESS_REMOVE_ALL_1=\
DELETE FROM \
	CMS_${PROJECT}_ACCESSCONTROL \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=?
	
C_ACCESS_REMOVE_ALL_FOR_PRINCIPAL_1=\
DELETE FROM \
	CMS_${PROJECT}_ACCESSCONTROL \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID=?

	
C_ACCESS_READ_ENTRY_2=\
SELECT \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_ALLOWED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_DENIED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_FLAGS \
FROM \
	CMS_${PROJECT}_ACCESSCONTROL \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=? \
	AND CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID = ?
	
		
C_ACCESS_READ_ENTRIES_1=\
SELECT \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_ALLOWED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_DENIED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_FLAGS \
FROM \
	CMS_${PROJECT}_ACCESSCONTROL \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=?
	
C_ACCESS_READ_ENTRIES_0=\
SELECT \
	CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_ALLOWED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_DENIED,\
	CMS_${PROJECT}_ACCESSCONTROL.ACCESS_FLAGS \
FROM \
	CMS_${PROJECT}_ACCESSCONTROL
	


C_SELECT_PUBLISHED_RESOURCES=\
SELECT \
	CMS_PUBLISH_HISTORY.STRUCTURE_ID,\
	CMS_PUBLISH_HISTORY.RESOURCE_ID,\
	CMS_PUBLISH_HISTORY.RESOURCE_PATH,\
	CMS_PUBLISH_HISTORY.RESOURCE_STATE,\
	CMS_PUBLISH_HISTORY.RESOURCE_TYPE,\
	CMS_PUBLISH_HISTORY.SIBLING_COUNT,\
	CMS_PUBLISH_HISTORY.PUBLISH_TAG \
FROM \
	CMS_PUBLISH_HISTORY \
WHERE \
	CMS_PUBLISH_HISTORY.HISTORY_ID=? \
ORDER BY \
	CMS_PUBLISH_HISTORY.RESOURCE_TYPE ASC,\
	CMS_PUBLISH_HISTORY.RESOURCE_STATE ASC,\
	CMS_PUBLISH_HISTORY.RESOURCE_PATH ASC

C_DELETE_PUBLISH_HISTORY=\
DELETE FROM \
	CMS_PUBLISH_HISTORY \
WHERE \
	CMS_PUBLISH_HISTORY.PUBLISH_TAG>=0 \
	AND CMS_PUBLISH_HISTORY.PUBLISH_TAG=? \
	AND CMS_PUBLISH_JOBS.FINISH_TIME<=? \
ORDER BY \
	CMS_PUBLISH_JOBS.ENQUEUE_TIME ASC	

C_PUBLISHJOB_READ_JOB=\
SELECT \
	CMS_PUBLISH_JOBS.HISTORY_ID,\
	CMS_PUBLISH_JOBS.PROJECT_ID,\
	CMS_PUBLISH_JOBS.PROJECT_NAME,\
	CMS_PUBLISH_JOBS.USER_ID,\
	CMS_PUBLISH_JOBS.PUBLISH_LOCALE,\
	CMS_PUBLISH_JOBS.PUBLISH_FLAGS,\
	CMS_PUBLISH_JOBS.RESOURCE_COUNT,\
	CMS_PUBLISH_JOBS.ENQUEUE_TIME,\
	CMS_PUBLISH_JOBS.START_TIME,\
	CMS_PUBLISH_JOBS.FINISH_TIME \
FROM \
	CMS_PUBLISH_JOBS \
WHERE \
	CMS_PUBLISH_JOBS.HISTORY_ID=?
	
C_PUBLISHJOB_READ_PUBLISHLIST=\
SELECT \
	CMS_PUBLISH_JOBS.HISTORY_ID, \
	CMS_PUBLISH_JOBS.PROJECT_ID, \
	CMS_PUBLISH_JOBS.PUBLISH_LIST \
FROM \
	CMS_PUBLISH_JOBS \
WHERE \
	CMS_PUBLISH_JOBS.HISTORY_ID=?	
	
C_PUBLISHJOB_READ_REPORT=\
SELECT \
	CMS_PUBLISH_JOBS.PUBLISH_REPORT \
FROM \
	CMS_PUBLISH_JOBS \
WHERE \
	CMS_PUBLISH_JOBS.HISTORY_ID=?
	
C_PUBLISHJOB_WRITE=\
UPDATE \
	CMS_PUBLISH_JOBS \
SET \
	PROJECT_ID=?,\
	PROJECT_NAME=?,\
	USER_ID=?,\
	PUBLISH_LOCALE=?,\
	PUBLISH_FLAGS=?,\
	RESOURCE_COUNT=?,\
	ENQUEUE_TIME=?,\
	START_TIME=?,\
	FINISH_TIME=? \
WHERE \
	CMS_PUBLISH_JOBS.HISTORY_ID=?
	
C_PUBLISHJOB_WRITE_REPORT=\
UPDATE \
	CMS_PUBLISH_JOBS \
SET \
	PUBLISH_REPORT=? \
WHERE \
	CMS_PUBLISH_JOBS.HISTORY_ID=?
	
#	
# Static export
#
C_STATICEXPORT_WRITE_PUBLISHED_LINKS=\
INSERT INTO CMS_STATICEXPORT_LINKS \
	(LINK_ID,\
	LINK_RFS_PATH,\
	LINK_TYPE,\
	LINK_PARAMETER,\
	LINK_TIMESTAMP) \
VALUES \
	(?,?,?,?,?)

   
C_STATICEXPORT_READ_PUBLISHED_RESOURCES=\
SELECT \
	COUNT(*) \
FROM \
	CMS_STATICEXPORT_LINKS \
WHERE \
	CMS_STATICEXPORT_LINKS.LINK_RFS_PATH=?    
	

C_STATICEXPORT_DELETE_PUBLISHED_LINKS=\
DELETE FROM \
	CMS_STATICEXPORT_LINKS \
WHERE \
	CMS_STATICEXPORT_LINKS.LINK_RFS_PATH=? \
	AND CMS_STATICEXPORT_LINKS.LINK_TYPE=? \
	AND CMS_STATICEXPORT_LINKS.LINK_PARAMETER=?	

 
C_STATICEXPORT_DELETE_ALL_PUBLISHED_LINKS=\
DELETE FROM \
	CMS_STATICEXPORT_LINKS \
WHERE \
	CMS_STATICEXPORT_LINKS.LINK_TYPE=? 	
  
C_STATICEXPORT_READ_ALL_PUBLISHED_LINKS=\
SELECT \
	CMS_STATICEXPORT_LINKS.LINK_RFS_PATH \
FROM \
	CMS_STATICEXPORT_LINKS \
WHERE \
	CMS_STATICEXPORT_LINKS.LINK_TYPE=? \
	AND CMS_STATICEXPORT_LINKS.LINK_TIMESTAMP>=? 
 
 
C_STATICEXPORT_READ_PUBLISHED_LINK_PARAMETERS=\
SELECT \
	CMS_STATICEXPORT_LINKS.LINK_PARAMETER \
FROM \
	CMS_STATICEXPORT_LINKS \
WHERE \
	CMS_STATICEXPORT_LINKS.LINK_RFS_PATH=?

C_SELECT_RESOURCES_FOR_PRINCIPAL_ATTR=\
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS} \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_RESOURCES.USER_CREATED=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE}) \
UNION \
(SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS} \
FROM \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_RESOURCES.USER_LASTMODIFIED=? \
	AND ${C_JOIN_STRUCTURE_RESOURCE}) 
	
C_SELECT_RESOURCES_FOR_PRINCIPAL_ACE=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS} \
FROM \
	CMS_${PROJECT}_ACCESSCONTROL, \
	${C_RESOURCES_SELECT_TABLES} \
WHERE \
	CMS_${PROJECT}_ACCESSCONTROL.PRINCIPAL_ID=? \
	AND CMS_${PROJECT}_ACCESSCONTROL.RESOURCE_ID=CMS_${PROJECT}_RESOURCES.RESOURCE_ID \
	AND ${C_JOIN_STRUCTURE_RESOURCE} \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.RESOURCE_PATH ASC

C_RESOURCES_DELETE_PUBLISH_HISTORY_ENTRY=\
DELETE FROM \
    CMS_PUBLISH_HISTORY \
WHERE \
    CMS_PUBLISH_HISTORY.HISTORY_ID = ? \
    AND CMS_PUBLISH_HISTORY.PUBLISH_TAG = ? \
    AND CMS_PUBLISH_HISTORY.STRUCTURE_ID = ? \
    AND CMS_PUBLISH_HISTORY.RESOURCE_PATH = ?

#
# Content Relation Engine table columns
#
C_RELATION_SOURCE_ID=RELATION_SOURCE_ID
C_RELATION_SOURCE_PATH=RELATION_SOURCE_PATH
C_RELATION_TARGET_ID=RELATION_TARGET_ID
C_RELATION_TARGET_PATH=RELATION_TARGET_PATH
C_RELATION_TYPE=RELATION_TYPE
# All attributes to select
C_RELATIONS_SELECT_ATTRIBS=\
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_SOURCE_ID,\
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_SOURCE_PATH,\
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_ID,\
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_PATH,\
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TYPE


#
# Content Relation Engine filter conditions
#
C_RELATION_FILTER_SOURCE_ID=CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_SOURCE_ID = ?
C_RELATION_FILTER_SOURCE_PATH=CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_SOURCE_PATH LIKE ?
C_RELATION_FILTER_TARGET_ID=CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_ID = ?
C_RELATION_FILTER_TARGET_PATH=CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_PATH LIKE ?
C_RELATION_FILTER_TYPE=CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TYPE IN 


#
# Relation creation query
#
C_CREATE_RELATION=\
INSERT INTO CMS_${PROJECT}_RESOURCE_RELATIONS \
	(RELATION_SOURCE_ID,\
	RELATION_SOURCE_PATH,\
	RELATION_TARGET_ID,\
	RELATION_TARGET_PATH,\
	RELATION_TYPE) \
VALUES \
	(?,?,?,?,?)


C_READ_RELATIONS=\
SELECT DISTINCT \
	${C_RELATIONS_SELECT_ATTRIBS} \
FROM \
	CMS_${PROJECT}_RESOURCE_RELATIONS \
WHERE
# the conditions are build in the vfs driver

C_READ_RESOURCE_OUS=\
SELECT DISTINCT \
	${C_RELATIONS_SELECT_ATTRIBS} \
FROM \
	CMS_${PROJECT}_RESOURCE_RELATIONS \
WHERE \
    CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TYPE = ? \
    AND ? LIKE CONCAT(CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_PATH, '%')


C_MOVE_RELATIONS_SOURCE=\
UPDATE \
	CMS_${PROJECT}_RESOURCE_RELATIONS \
SET \
	RELATION_SOURCE_PATH=? \
WHERE \
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_SOURCE_ID=?


C_MOVE_RELATIONS_TARGET=\
UPDATE \
	CMS_${PROJECT}_RESOURCE_RELATIONS \
SET \
	RELATION_TARGET_PATH=? \
WHERE \
	CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_ID=?


C_DELETE_RELATIONS=\
DELETE FROM \
    CMS_${PROJECT}_RESOURCE_RELATIONS \
WHERE
# the conditions are build in the vfs driver

C_RELATIONS_REPAIR_BROKEN=\
UPDATE \
    CMS_${PROJECT}_RESOURCE_RELATIONS \
SET \
    RELATION_TARGET_ID = ? \
WHERE \
    CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_PATH = ? \
    AND CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_ID NOT IN (SELECT CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID FROM CMS_${PROJECT}_STRUCTURE)

C_RELATIONS_UPDATE_BROKEN=\
UPDATE \
    CMS_${PROJECT}_RESOURCE_RELATIONS \
SET \
    RELATION_TARGET_ID = '00000000-0000-0000-0000-000000000000' \
WHERE \
    CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_PATH = ? \
    AND CMS_${PROJECT}_RESOURCE_RELATIONS.RELATION_TARGET_ID NOT IN (SELECT CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID FROM CMS_${PROJECT}_STRUCTURE)
    
    
C_RELATIONS_DELETE_BROKEN_LOCALE_RELATIONS=\
DELETE FROM CMS_${PROJECT}_RESOURCE_RELATIONS \
WHERE RELATION_TARGET_PATH = ? AND RELATION_TARGET_ID = '00000000-0000-0000-0000-000000000000' AND RELATION_TYPE = 11

# Normalizes locale relations after creating a relation.
# After creating a locale variant relation from A to B, this statment 
# removes all locale variant relations which are either 
#        - from A to somewhere else than B,
#        - from B to some other resource 
#        - to A from some other resources   
C_RELATIONS_NORMALIZE_LOCALE_RELATIONS=\
DELETE FROM CMS_${PROJECT}_RESOURCE_RELATIONS \
WHERE RELATION_TYPE = 11 AND ((RELATION_SOURCE_ID = ? AND NOT RELATION_TARGET_ID = ?) \
OR RELATION_TARGET_ID = ? \
OR RELATION_SOURCE_ID = ? )

C_READ_STRUCTURE_STATE=\
SELECT \
    CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE \
FROM \
    CMS_${PROJECT}_STRUCTURE \
WHERE \
    CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID = ?

C_READ_RESOURCE_STATE=\
SELECT \
    CMS_${PROJECT}_RESOURCES.RESOURCE_STATE \
FROM \
    CMS_${PROJECT}_RESOURCES \
WHERE \
    CMS_${PROJECT}_RESOURCES.RESOURCE_ID = ?

#
# Log
#
C_LOG_USER_ID=USER_ID
C_LOG_DATE=LOG_DATE
C_LOG_STRUCTURE_ID=STRUCTURE_ID
C_LOG_TYPE=LOG_TYPE
C_LOG_DATA=LOG_DATA
# Log Filter
C_LOG_FILTER_USER_ID=CMS_LOG.USER_ID = ?
C_LOG_FILTER_DATE_FROM=CMS_LOG.LOG_DATE >= ?
C_LOG_FILTER_DATE_TO=CMS_LOG.LOG_DATE <= ?
C_LOG_FILTER_RESOURCE_ID=CMS_LOG.STRUCTURE_ID = ?
C_LOG_FILTER_INCLUDE_TYPE=CMS_LOG.LOG_TYPE IN  
C_LOG_FILTER_EXCLUDE_TYPE=CMS_LOG.LOG_TYPE NOT IN 

C_LOG_SELECT_ATTRIBS=\
	CMS_LOG.USER_ID,\
	CMS_LOG.LOG_DATE,\
	CMS_LOG.STRUCTURE_ID,\
	CMS_LOG.LOG_TYPE,\
	CMS_LOG.LOG_DATA

C_LOG_CREATE_5=\
INSERT INTO CMS_LOG \
	(USER_ID,\
	 LOG_DATE,\
	 STRUCTURE_ID,\
	 LOG_TYPE,\
	 LOG_DATA)\
VALUES \
	(?,?,?,?,?)

C_LOG_READ_PUBLISH_LIST_2=\
SELECT \
    ${C_RESOURCES_SELECT_ATTRIBS}, \
    CMS_${PROJECT}_RESOURCES.PROJECT_LASTMODIFIED, \
    LOG1.LOG_DATE \
FROM (\
    SELECT \
        MAX(CMS_LOG.LOG_DATE) LOG_DATE,\
	    CMS_LOG.STRUCTURE_ID \
    FROM \
        CMS_LOG \
    WHERE \
	    CMS_LOG.USER_ID = ? \
	    AND CMS_LOG.STRUCTURE_ID IS NOT NULL \
    GROUP BY \
        CMS_LOG.STRUCTURE_ID \
    ) LOG1, \
    ${C_RESOURCES_SELECT_TABLES} \
WHERE \
	20 < (\
	    SELECT \
	        LOG2.LOG_TYPE \
	    FROM \
	        CMS_LOG LOG2 \
	    WHERE \
	        LOG2.USER_ID = ? \
	        AND LOG2.STRUCTURE_ID = LOG1.STRUCTURE_ID \
	        AND LOG2.LOG_DATE = LOG1.LOG_DATE \
	    ) \
    AND LOG1.STRUCTURE_ID=CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID \
    AND ${C_JOIN_STRUCTURE_RESOURCE}
    
C_LOG_READ_ENTRIES=\
SELECT DISTINCT \
	${C_LOG_SELECT_ATTRIBS} \
FROM \
	CMS_LOG \
WHERE
# the conditions are build in the project driver

C_LOG_DELETE_ENTRIES=\
DELETE FROM \
    CMS_LOG \
WHERE
# the conditions are build in the project driver

#
# Visit
#
C_VISIT_USER_ID=USER_ID
C_VISIT_DATE=VISIT_DATE
C_VISIT_STRUCTURE_ID=STRUCTURE_ID

C_VISIT_FILTER_USER_ID=CMS_SUBSCRIPTION_VISIT.USER_ID = ?
C_VISIT_FILTER_DATE_FROM=CMS_SUBSCRIPTION_VISIT.VISIT_DATE >= ?
C_VISIT_FILTER_DATE_TO=CMS_SUBSCRIPTION_VISIT.VISIT_DATE <= ?
C_VISIT_FILTER_STRUCTURE_ID=CMS_SUBSCRIPTION_VISIT.STRUCTURE_ID = ?

C_VISIT_SELECT_ATTRIBS=\
	CMS_SUBSCRIPTION_VISIT.USER_ID,\
	CMS_SUBSCRIPTION_VISIT.VISIT_DATE,\
	CMS_SUBSCRIPTION_VISIT.STRUCTURE_ID

C_VISIT_CREATE_3=\
INSERT INTO CMS_SUBSCRIPTION_VISIT \
	(USER_ID,\
	 VISIT_DATE,\
	 STRUCTURE_ID)\
VALUES \
	(?,?,?)

    
C_VISIT_READ_ENTRIES=\
SELECT DISTINCT \
	${C_VISIT_SELECT_ATTRIBS} \
FROM \
	CMS_SUBSCRIPTION_VISIT \
WHERE
# the conditions are build in the subscription driver

C_VISIT_DELETE_ENTRIES=\
DELETE FROM \
    CMS_SUBSCRIPTION_VISIT \
WHERE
# the conditions are build in the subscription driver





#
# Subscription
#
C_SUBSCRIPTION_CHECK_2=\
SELECT \
	* \
FROM \
	CMS_SUBSCRIPTION \
WHERE \
	CMS_SUBSCRIPTION.PRINCIPAL_ID=? AND \
	CMS_SUBSCRIPTION.STRUCTURE_ID=?

C_SUBSCRIPTION_CREATE_2=\
INSERT INTO CMS_SUBSCRIPTION \
	(PRINCIPAL_ID, \
	STRUCTURE_ID, \
	DATE_DELETED) \
VALUES \
	(?,?,0)

C_SUBSCRIPTION_DELETE=\
DELETE FROM \
	CMS_SUBSCRIPTION \
WHERE
# the conditions are build in the user driver

C_SUBSCRIPTION_DELETE_FILTER_PRINCIPAL=CMS_SUBSCRIPTION.PRINCIPAL_ID=?
C_SUBSCRIPTION_DELETE_FILTER_STRUCTURE=CMS_SUBSCRIPTION.STRUCTURE_ID=?
C_SUBSCRIPTION_DELETE_FILTER_DATE=CMS_SUBSCRIPTION.DATE_DELETED>0 AND CMS_SUBSCRIPTION.DATE_DELETED? \
	AND CMS_SUBSCRIPTION_VISIT.VISIT_DATE? 
	
C_SUBSCRIPTION_DELETED_FILTER_PRINCIPAL_SINGLE=CMS_SUBSCRIPTION.PRINCIPAL_ID=?
C_SUBSCRIPTION_DELETED_FILTER_PRINCIPALS=CMS_SUBSCRIPTION.PRINCIPAL_ID IN
	
C_SUBSCRIPTION_FILTER_READ=\
SELECT DISTINCT \
	${C_RESOURCES_SELECT_ATTRIBS} \
FROM \
	${C_RESOURCES_SELECT_TABLES}, \
	CMS_SUBSCRIPTION \
WHERE \
	%(CONDITIONS) \
	AND ${C_JOIN_STRUCTURE_RESOURCE} \
ORDER BY \
	CMS_${PROJECT}_STRUCTURE.STRUCTURE_STATE ASC
	
C_SUBSCRIPTION_FILTER_PRINCIPAL_SINGLE=CMS_SUBSCRIPTION.PRINCIPAL_ID=? AND CMS_SUBSCRIPTION.DATE_DELETED=0 AND CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=CMS_SUBSCRIPTION.STRUCTURE_ID
C_SUBSCRIPTION_FILTER_PRINCIPALS=CMS_SUBSCRIPTION.PRINCIPAL_ID IN
C_SUBSCRIPTION_FILTER_PRINCIPALS_END=AND CMS_SUBSCRIPTION.DATE_DELETED=0 AND CMS_${PROJECT}_STRUCTURE.STRUCTURE_ID=CMS_SUBSCRIPTION.STRUCTURE_ID
C_SUBSCRIPTION_FILTER_RESOURCES_DATE_MODIFIED=CMS_${PROJECT}_RESOURCES.DATE_LASTMODIFIED>? AND CMS_${PROJECT}_RESOURCES.DATE_LASTMODIFIED




© 2015 - 2024 Weber Informatics LLC | Privacy Policy