Class CreateSqlTableComponent
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.contentio.export.sql.CreateSqlTableComponent
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class CreateSqlTableComponent extends AbstractLogEnabled implements Component, Serviceable
Create SQl Table Component
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentTypeExtensionPoint
_contentTypeExtensionPoint
Content type extension point.protected I18nUtils
_i18nTranslator
The i18n translator.protected LanguagesManager
_languageManager
The language managerprotected NormalizeNameComponent
_normalizeNameComponent
The normalise name component.static String
COLUMN_PARENT_TABLE_PREFIX
Prefix for parent table columnstatic String
DEFAULT_LANGUAGE_CODE_FOR_COMMENTS
Code of default language for commentsstatic String
MYSQL_CONTENT_EXPORT_CHARSET
The encodingstatic String
MYSQL_CONTENT_EXPORT_ENGINE
The enginestatic String
ROLE
The component role
-
Constructor Summary
Constructors Constructor Description CreateSqlTableComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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
createContentTable()
Create table for contentprotected String
createEngineQuery()
Create the query to add engineprotected String
createForeignKeyQuery(String fkName, String tableName, String columnName)
Create the query to add foreign keyprotected void
createMappingTables()
Create the two table mapping (for table name and column name)protected String
createPrimaryKeyQuery()
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
createRichTextDataTable()
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)Map<String,ExportTableInfo>
createTables(ExportConfiguration exportConfiguration)
Create sql tables for contentsprotected void
createTablesInfos(Map<String,String> contents)
Created all tables informationsprotected void
executeQueries()
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 Detail
-
DEFAULT_LANGUAGE_CODE_FOR_COMMENTS
public static final String DEFAULT_LANGUAGE_CODE_FOR_COMMENTS
Code of default language for comments- See Also:
- Constant Field Values
-
MYSQL_CONTENT_EXPORT_ENGINE
public static final String MYSQL_CONTENT_EXPORT_ENGINE
The engine- See Also:
- Constant Field Values
-
MYSQL_CONTENT_EXPORT_CHARSET
public static final String MYSQL_CONTENT_EXPORT_CHARSET
The encoding- See Also:
- Constant Field Values
-
COLUMN_PARENT_TABLE_PREFIX
public static final String COLUMN_PARENT_TABLE_PREFIX
Prefix for parent table column- See Also:
- Constant Field Values
-
_contentTypeExtensionPoint
protected ContentTypeExtensionPoint _contentTypeExtensionPoint
Content type extension point.
-
_i18nTranslator
protected I18nUtils _i18nTranslator
The i18n translator.
-
_normalizeNameComponent
protected NormalizeNameComponent _normalizeNameComponent
The normalise name component.
-
_languageManager
protected LanguagesManager _languageManager
The language manager
-
-
Constructor Detail
-
CreateSqlTableComponent
public CreateSqlTableComponent()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- 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
protected void initialize(String productVersion)
Initialization- Parameters:
productVersion
- The database product version
-
createTablesInfos
protected void createTablesInfos(Map<String,String> contents) throws SQLException
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
protected void createRichTextDataTable()
Create table for images in rich text
-
createContentTable
protected void 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
protected void fillTableForEnumerator(ElementDefinition definition, String tableName)
Fill values for the enumerator table- Parameters:
definition
- the attribute definitiontableName
- the table name
-
createMappingTables
protected void createMappingTables()
Create the two table mapping (for table name and column name)
-
fillMappingTables
protected void fillMappingTables(String mappingTableName, String mappingColumnName)
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
protected void addSortColumn(StringBuilder currentCreateTableSQLQuery, String tableName)
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
protected String createCommentQuery(String table, String column, String comments)
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
protected String createForeignKeyQuery(String fkName, String tableName, String columnName)
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
protected String createEngineQuery()
Create the query to add engine- Returns:
- the query to add engine
-
createPrimaryKeyQuery
protected String createPrimaryKeyQuery()
Create the query to add primary key- Returns:
- the query to add primary key
-
convertTypeToSql
protected String convertTypeToSql(String type)
Return the sql type corresponding to the attribute and the database type- Parameters:
type
- the attribute's type- Returns:
- the sql type
-
executeQueries
protected void executeQueries() throws SQLException, IOException
Execute SQL queries- Throws:
SQLException
- if a sql error occurredIOException
- if an IO error occurred
-
_executeQueries
protected void _executeQueries(List<String> listQuery) throws SQLException, IOException
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
-
-