Class CreateSqlTableComponent
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.contentio.export.sql.CreateSqlTableComponent
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
Create SQl Table Component
-
Field Summary
Modifier and TypeFieldDescriptionprotected ContentTypeExtensionPoint
Content type extension point.protected I18nUtils
The i18n translator.protected LanguagesManager
The language managerprotected NormalizeNameComponent
The normalise name component.static final String
Prefix for parent table columnstatic final String
Code of default language for commentsstatic final String
The encodingstatic final String
The enginestatic final String
The component role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
_executeQueries
(List<String> listQuery) Execute query listprotected void
addAdditionalData
(ContentType contentType, StringBuilder currentCreateTableSQLQuery, String tableName) Add additionnal data for content (title, type, language, creator, creationDate, ....)protected String
addColumn
(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName, String comment, String type) Add a columnprotected void
addColumnForContainer
(ModelItemContainer modelItemContainer, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix) Add all the column for each attribute in theModelItemContainer
.protected void
addColumnForSingleAttribute
(ElementDefinition definition, StringBuilder currentCreateTableSQLQuery, String tableName, String columnName) Add column for single attributeprotected void
addColumnParentId
(StringBuilder currentCreateTableSQLQuery, String tableParentName, String tableName) Add an id column which refer to another tableprotected void
addSortColumn
(StringBuilder currentCreateTableSQLQuery, String tableName) Add a column to sortprotected String
convertTypeToSql
(String type) Return the sql type corresponding to the attribute and the database typeprotected String
createCommentQuery
(String table, String column, String comments) Create the query to add comment to a table or a columnprotected void
Create table for contentprotected String
Create the query to add engineprotected String
createForeignKeyQuery
(String fkName, String tableName, String columnName) Create the query to add foreign keyprotected void
Create the two table mapping (for table name and column name)protected String
Create the query to add primary keyprotected void
createQueriesForTableCreation
(ModelItemContainer modelItemContainer, String tableName, String tableParentName, String comment, boolean isSortTable) Create SQL queries to create necessary SQL tables for content type exportprotected void
createQueryForMultipleAttribute
(ElementDefinition definition, String tableParentName, String tableName) Create table for multiple attributeprotected void
Create table for images in rich textprotected void
createTableForEnumerator
(ElementDefinition definition, String tableParentName, String tableName, String columnName, StringBuilder currentCreateTableSQLQuery) Create the table for the enumerator (key, value)createTables
(ExportConfiguration exportConfiguration) Create sql tables for contentsprotected void
createTablesInfos
(Map<String, String> contents) Created all tables informationsprotected void
Execute SQL queriesprotected void
fillMappingTables
(String mappingTableName, String mappingColumnName) Fill the two mapping table (for table name and column name)protected void
fillTableForEnumerator
(ElementDefinition definition, String tableName) Fill values for the enumerator tableprotected PreparedStatement
getInsertPreparedStatementFromTableName
(String tableName) Prepare INSERT statementprotected void
initialize
(String productVersion) Initializationvoid
service
(ServiceManager manager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The component role -
DEFAULT_LANGUAGE_CODE_FOR_COMMENTS
Code of default language for comments- See Also:
-
MYSQL_CONTENT_EXPORT_ENGINE
The engine- See Also:
-
MYSQL_CONTENT_EXPORT_CHARSET
The encoding- See Also:
-
COLUMN_PARENT_TABLE_PREFIX
Prefix for parent table column- See Also:
-
_contentTypeExtensionPoint
Content type extension point. -
_i18nTranslator
The i18n translator. -
_normalizeNameComponent
The normalise name component. -
_languageManager
The language manager
-
-
Constructor Details
-
CreateSqlTableComponent
public CreateSqlTableComponent()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
createTables
public Map<String,ExportTableInfo> createTables(ExportConfiguration exportConfiguration) throws SQLException, IOException Create sql tables for contents- Parameters:
exportConfiguration
- the content export configuration- Returns:
- tablesInfos
- Throws:
SQLException
- if a sql error occurredIOException
- if an IO error occurred
-
initialize
Initialization- Parameters:
productVersion
- The database product version
-
createTablesInfos
Created all tables informations- Parameters:
contents
- to export- Throws:
SQLException
- if a sql error occurred
-
createQueriesForTableCreation
protected void createQueriesForTableCreation(ModelItemContainer modelItemContainer, String tableName, String tableParentName, String comment, boolean isSortTable) Create SQL queries to create necessary SQL tables for content type export- Parameters:
modelItemContainer
- the currentModelItemContainer
tableName
- the table name The SQL table nametableParentName
- The SQL parent table namecomment
- the commentisSortTable
- true if table's rows have to be ordered
-
createRichTextDataTable
Create table for images in rich text -
createContentTable
Create table for content -
createTableForEnumerator
protected void createTableForEnumerator(ElementDefinition definition, String tableParentName, String tableName, String columnName, StringBuilder currentCreateTableSQLQuery) Create the table for the enumerator (key, value)- Parameters:
definition
- the attribute definitiontableParentName
- the table parent nametableName
- the table namecolumnName
- the column namecurrentCreateTableSQLQuery
- the current SQL create table query
-
fillTableForEnumerator
Fill values for the enumerator table- Parameters:
definition
- the attribute definitiontableName
- the table name
-
createMappingTables
Create the two table mapping (for table name and column name) -
fillMappingTables
Fill the two mapping table (for table name and column name)- Parameters:
mappingTableName
- the table mapping table namemappingColumnName
- the column mapping table name
-
addColumnForContainer
protected void addColumnForContainer(ModelItemContainer modelItemContainer, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix) Add all the column for each attribute in theModelItemContainer
.- Parameters:
modelItemContainer
- the attribute definitionscurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnNamePrefix
- the column namePrefix
-
addColumnForSingleAttribute
protected void addColumnForSingleAttribute(ElementDefinition definition, StringBuilder currentCreateTableSQLQuery, String tableName, String columnName) Add column for single attribute- Parameters:
definition
- the attribute definitioncurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnName
- the column name
-
addColumn
protected String addColumn(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName, String comment, String type) Add a column- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnName
- the desired column namecomment
- the column commenttype
- the column type- Returns:
- the actual column name, after normalization of the desired one
-
createQueryForMultipleAttribute
protected void createQueryForMultipleAttribute(ElementDefinition definition, String tableParentName, String tableName) Create table for multiple attribute- Parameters:
definition
- the attribute definitiontableParentName
- the name of the table for the attribute's containertableName
- the table name
-
addAdditionalData
protected void addAdditionalData(ContentType contentType, StringBuilder currentCreateTableSQLQuery, String tableName) Add additionnal data for content (title, type, language, creator, creationDate, ....)- Parameters:
contentType
- the modelcurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table name
-
addSortColumn
Add a column to sort- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querytableName
- the table name
-
addColumnParentId
protected void addColumnParentId(StringBuilder currentCreateTableSQLQuery, String tableParentName, String tableName) Add an id column which refer to another table- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querytableParentName
- the table parent nametableName
- the table name
-
createCommentQuery
Create the query to add comment to a table or a column- Parameters:
table
- the table namecolumn
- the column namecomments
- the comments- Returns:
- the query to add comment to a table or a column
-
createForeignKeyQuery
Create the query to add foreign key- Parameters:
fkName
- the foreign key nametableName
- the table namecolumnName
- the column name- Returns:
- the query to add comment to a table or a column
-
createEngineQuery
Create the query to add engine- Returns:
- the query to add engine
-
createPrimaryKeyQuery
Create the query to add primary key- Returns:
- the query to add primary key
-
convertTypeToSql
Return the sql type corresponding to the attribute and the database type- Parameters:
type
- the attribute's type- Returns:
- the sql type
-
executeQueries
Execute SQL queries- Throws:
SQLException
- if a sql error occurredIOException
- if an IO error occurred
-
_executeQueries
Execute query list- Parameters:
listQuery
- the list of query to execute- Throws:
SQLException
- if a sql error occurredIOException
- if an IO error occurred
-
getInsertPreparedStatementFromTableName
protected PreparedStatement getInsertPreparedStatementFromTableName(String tableName) throws SQLException Prepare INSERT statement- Parameters:
tableName
- the table name- Returns:
- the INSERT preparedStatement
- Throws:
SQLException
- if a sql error occurred
-