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
FieldsModifier and TypeFieldDescriptionprotected ContentTypeExtensionPointContent type extension point.protected I18nUtilsThe i18n translator.protected LanguagesManagerThe language managerprotected NormalizeNameComponentThe normalise name component.static final StringPrefix for parent table columnstatic final StringCode of default language for commentsstatic final StringThe encodingstatic final StringThe enginestatic final StringThe component role -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_executeQueries(List<String> listQuery) Execute query listprotected voidaddAdditionalData(ContentType contentType, StringBuilder currentCreateTableSQLQuery, String tableName) Add additionnal data for content (title, type, language, creator, creationDate, ....)protected StringaddColumn(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName, String comment, String type) Add a columnprotected voidaddColumnForContainer(ModelItemContainer modelItemContainer, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix) Add all the column for each attribute in theModelItemContainer.protected voidaddColumnForSingleAttribute(ElementDefinition definition, StringBuilder currentCreateTableSQLQuery, String tableName, String columnName) Add column for single attributeprotected voidaddColumnParentId(StringBuilder currentCreateTableSQLQuery, String tableParentName, String tableName) Add an id column which refer to another tableprotected voidaddSortColumn(StringBuilder currentCreateTableSQLQuery, String tableName) Add a column to sortprotected StringconvertTypeToSql(String type) Return the sql type corresponding to the attribute and the database type.
Default to the sql type corresponding to "string" in case of unknown type.protected StringcreateCommentQuery(String table, String column, String comments) Create the query to add comment to a table or a columnprotected voidCreate table for contentprotected StringCreate the query to add engineprotected StringcreateForeignKeyQuery(String fkName, String tableName, String columnName) Create the query to add foreign keyprotected voidCreate the two table mapping (for table name and column name)protected StringCreate the query to add primary keyprotected voidcreateQueriesForTableCreation(ModelItemContainer modelItemContainer, String tableName, String tableParentName, String comment, boolean isSortTable) Create SQL queries to create necessary SQL tables for content type exportprotected voidcreateQueryForMultipleAttribute(ElementDefinition definition, String tableParentName, String tableName) Create table for multiple attributeprotected voidCreate table for images in rich textprotected voidcreateTableForEnumerator(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 voidcreateTablesInfos(Map<String, String> contents) Created all tables informationsprotected voidExecute SQL queriesprotected voidfillMappingTables(String mappingTableName, String mappingColumnName) Fill the two mapping table (for table name and column name)protected voidfillTableForEnumerator(ElementDefinition definition, String tableName) Fill values for the enumerator tableprotected PreparedStatementgetInsertPreparedStatementFromTableName(String tableName) Prepare INSERT statementprotected voidinitialize(String productVersion) Initializationvoidservice(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:
servicein 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 currentModelItemContainertableName- 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.
Default to the sql type corresponding to "string" in case of unknown 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
-