Class CreateSqlTableComponent
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.contentio.export.component.CreateSqlTableComponent
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class CreateSqlTableComponent extends AbstractLogEnabled implements Component, Serviceable
Create SQl Table Component
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CreateSqlTableComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_executeQueryFromlistQuery(List<String> listQuery)
Execute query listprivate int
_getNbTable()
protected void
addAdditionnalContentMetadata(MetadataDefinitionHolder metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName)
Add additionnal metadata for content (title, type, language, creator, creationDate, ....)protected void
addColumnForBooleanMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for Boolean metadataprotected void
addColumnForCompositeMetadata(MetadataDefinitionHolder metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix)
Add all the column for each metadata in the compositeprivate void
addColumnForContentMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for content metadataprotected void
addColumnForDateMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for Date metadataprotected void
addColumnForDateTimeMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for DateTime metadataprotected void
addColumnForDoubleMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for Double metadataprotected void
addColumnForEnumStringMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for enumerator metadataprotected void
addColumnForLongMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for Long metadataprotected void
addColumnForMetadata(MetadataDefinition metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix)
Add column for the metadata (multiple or single)protected void
addColumnForRichTextMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for rich Textprotected void
addColumnForSingleMetadata(MetadataDefinition metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnName)
Add column for single metadataprotected void
addColumnForStringMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for String metadataprotected void
addColumnForUserMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName)
Add column for User metadataprotected void
addColumnParentId(StringBuilder currentCreateTableSQLQuery, String tableParentName, String tableName)
Add an id column which refer to another tableprotected void
addColumnsForBinaryMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment)
Add columns for binary metadataprotected void
addColumnsForFileMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment)
Add columns for file metadataprotected void
addColumnsForGeocodeMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment)
Add columns for geocode metadataprotected void
addColumnsForMultilingualStringMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment)
Add columns for multilangual string metadata (one for each language)protected void
addSortColumn(StringBuilder currentCreateTableSQLQuery, String tableName)
Add a column to sortprotected String
convertMetadataTypeToSql(String metadataType)
Return the sql type depends on the metadata 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 metadata 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
createMappingNameTableSql()
Create the two table mapping (for table name and column name)protected String
createPrimaryKeyQuery()
Create the query to add primary keyprotected void
createRichTextDataTable()
Create table for images in rich textprotected void
createSqlQueriesForTableCreation(MetadataDefinitionHolder metadataDef, String tableName, String tableParentName, String comment, boolean isSortTable)
Create SQL queries to create necessary SQL tables for content type exportprotected void
createSqlQueryForMultipleMetadata(MetadataDefinition metadataDef, String tableParentName, String tableName)
Create table for a multiple metadataMap<String,ExportTableInfo>
createSqlTables(ExportConfiguration exportConfiguration)
Create sql tables for contentsprotected void
createTableForEnumerator(MetadataDefinition metadataDef, String tableParentName, String tableName, String columnName, StringBuilder currentCreateTableSQLQuery)
Create the table for the enumerator (key, value)protected void
createTablesInfos(Map<String,String> contents)
Created all tables informationsprotected void
executeSqlQueries()
Execute SQL queriesprotected void
fillMappingTableSql(String mappingTableName, String mappingColumnName)
Fill the two mapping table (for table name and column name)protected void
fillTableForEnumerator(MetadataDefinition metadataDef, 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
-
_MYSQL_VERSION_NUMBER_EXTRACT
private static final Pattern _MYSQL_VERSION_NUMBER_EXTRACT
-
_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
-
_connection
private Connection _connection
-
_databaseType
private String _databaseType
-
_tablesInfos
private LinkedHashMap<String,ExportTableInfo> _tablesInfos
-
_commentTableMaxLength
private int _commentTableMaxLength
-
_commentColumnMaxLength
private int _commentColumnMaxLength
-
_sqlTablePrefix
private String _sqlTablePrefix
-
_sqlPrefixConf
private String _sqlPrefixConf
-
_mappingPolicy
private String _mappingPolicy
-
_mappingTablesQueries
private ArrayList<String> _mappingTablesQueries
-
_exportNoMultiValuedTable
private boolean _exportNoMultiValuedTable
-
_fkIndice
private int _fkIndice
-
_pkIndice
private int _pkIndice
-
-
Constructor Detail
-
CreateSqlTableComponent
public CreateSqlTableComponent()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
createSqlTables
public Map<String,ExportTableInfo> createSqlTables(ExportConfiguration exportConfiguration) throws SQLException, ContextException, IOException
Create sql tables for contents- Parameters:
exportConfiguration
- the content export configuration- Returns:
- tablesInfos
- Throws:
SQLException
- if a sql error occurredContextException
- if a context 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, ContextException
Created all tables informations- Parameters:
contents
- to export- Throws:
SQLException
- if a sql error occurredContextException
- if a context error occurred
-
createSqlQueriesForTableCreation
protected void createSqlQueriesForTableCreation(MetadataDefinitionHolder metadataDef, String tableName, String tableParentName, String comment, boolean isSortTable) throws ContextException
Create SQL queries to create necessary SQL tables for content type export- Parameters:
metadataDef
- the metadata definition model The component holding metadata definitionstableName
- the table name The SQL table nametableParentName
- The SQL parent table namecomment
- the commentisSortTable
- true if table's rows have to be ordered- Throws:
ContextException
- if a context error occurred
-
createSqlQueryForMultipleMetadata
protected void createSqlQueryForMultipleMetadata(MetadataDefinition metadataDef, String tableParentName, String tableName) throws ContextException
Create table for a multiple metadata- Parameters:
metadataDef
- the metadata definition modeltableParentName
- the table parent nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
createRichTextDataTable
protected void createRichTextDataTable() throws ContextException
Create table for images in rich text- Throws:
ContextException
- if a context error occurred
-
createContentTable
protected void createContentTable() throws ContextException
Create table for metadata content- Throws:
ContextException
- if a context error occurred
-
createTableForEnumerator
protected void createTableForEnumerator(MetadataDefinition metadataDef, String tableParentName, String tableName, String columnName, StringBuilder currentCreateTableSQLQuery) throws ContextException
Create the table for the enumerator (key, value)- Parameters:
metadataDef
- the metadata definition modeltableParentName
- the table parent nametableName
- the table namecolumnName
- the column namecurrentCreateTableSQLQuery
- the current SQL create table query- Throws:
ContextException
- if a context error occurred
-
fillTableForEnumerator
protected void fillTableForEnumerator(MetadataDefinition metadataDef, String tableName)
Fill values for the enumerator table- Parameters:
metadataDef
- the metadata definition modeltableName
- the table name
-
createMappingNameTableSql
protected void createMappingNameTableSql() throws ContextException
Create the two table mapping (for table name and column name)- Throws:
ContextException
- if a context error occurred
-
fillMappingTableSql
protected void fillMappingTableSql(String mappingTableName, String mappingColumnName) throws ContextException
Fill the two mapping table (for table name and column name)- Parameters:
mappingTableName
- the table mapping table namemappingColumnName
- the column mapping table name- Throws:
ContextException
- if a context error occurred
-
addColumnForCompositeMetadata
protected void addColumnForCompositeMetadata(MetadataDefinitionHolder metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix) throws ContextException
Add all the column for each metadata in the composite- Parameters:
metadataDef
- the metadata definition modelcurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnNamePrefix
- the column namePrefix- Throws:
ContextException
- if a context error occurred
-
addColumnForMetadata
protected void addColumnForMetadata(MetadataDefinition metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnNamePrefix) throws ContextException
Add column for the metadata (multiple or single)- Parameters:
metadataDef
- the metadata definition modelcurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnNamePrefix
- the column namePrefix- Throws:
ContextException
- if a context error occurred
-
addColumnForSingleMetadata
protected void addColumnForSingleMetadata(MetadataDefinition metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName, String columnName) throws ContextException
Add column for single metadata- Parameters:
metadataDef
- the metadata definition modelcurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table namecolumnName
- the column name- Throws:
ContextException
- if a context error occurred
-
addSortColumn
protected void addSortColumn(StringBuilder currentCreateTableSQLQuery, String tableName) throws ContextException
Add a column to sort- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querytableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnParentId
protected void addColumnParentId(StringBuilder currentCreateTableSQLQuery, String tableParentName, String tableName) throws ContextException
Add an id column which refer to another table- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querytableParentName
- the table parent nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnsForGeocodeMetadata
protected void addColumnsForGeocodeMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment) throws ContextException
Add columns for geocode metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table queryinitialColumnName
- the initial column nametableName
- the table namecomment
- the comment- Throws:
ContextException
- if a context error occurred
-
addColumnsForBinaryMetadata
protected void addColumnsForBinaryMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment) throws ContextException
Add columns for binary metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table queryinitialColumnName
- the initial column nametableName
- the table namecomment
- the comment- Throws:
ContextException
- if a context error occurred
-
addColumnsForFileMetadata
protected void addColumnsForFileMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment) throws ContextException
Add columns for file metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table queryinitialColumnName
- the initial column nametableName
- the table namecomment
- the comment- Throws:
ContextException
- if a context error occurred
-
addColumnsForMultilingualStringMetadata
protected void addColumnsForMultilingualStringMetadata(StringBuilder currentCreateTableSQLQuery, String initialColumnName, String tableName, String comment) throws ContextException
Add columns for multilangual string metadata (one for each language)- Parameters:
currentCreateTableSQLQuery
- the current SQL create table queryinitialColumnName
- the initial column nametableName
- the table namecomment
- the comment- Throws:
ContextException
- if a context error occurred
-
addColumnForRichTextMetadata
protected void addColumnForRichTextMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for rich Text- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForContentMetadata
private void addColumnForContentMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for content metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForDoubleMetadata
protected void addColumnForDoubleMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for Double metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForDateTimeMetadata
protected void addColumnForDateTimeMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for DateTime metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForDateMetadata
protected void addColumnForDateMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for Date metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForStringMetadata
protected void addColumnForStringMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for String metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForUserMetadata
protected void addColumnForUserMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for User metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForEnumStringMetadata
protected void addColumnForEnumStringMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for enumerator metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForBooleanMetadata
protected void addColumnForBooleanMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for Boolean metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addColumnForLongMetadata
protected void addColumnForLongMetadata(StringBuilder currentCreateTableSQLQuery, String columnName, String tableName) throws ContextException
Add column for Long metadata- Parameters:
currentCreateTableSQLQuery
- the current SQL create table querycolumnName
- the column nametableName
- the table name- Throws:
ContextException
- if a context error occurred
-
addAdditionnalContentMetadata
protected void addAdditionnalContentMetadata(MetadataDefinitionHolder metadataDef, StringBuilder currentCreateTableSQLQuery, String tableName) throws ContextException
Add additionnal metadata for content (title, type, language, creator, creationDate, ....)- Parameters:
metadataDef
- the metadata definition modelcurrentCreateTableSQLQuery
- the current SQL create table querytableName
- the table name- Throws:
ContextException
- if a context error occurred
-
createCommentQuery
protected String createCommentQuery(String table, String column, String comments) throws ContextException
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
- Throws:
ContextException
- if a context error occurred
-
createForeignKeyQuery
protected String createForeignKeyQuery(String fkName, String tableName, String columnName) throws ContextException
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
- Throws:
ContextException
- if a context error occurred
-
createEngineQuery
protected String createEngineQuery() throws ContextException
Create the query to add engine- Returns:
- the query to add engine
- Throws:
ContextException
- if a context error occurred
-
createPrimaryKeyQuery
protected String createPrimaryKeyQuery() throws ContextException
Create the query to add primary key- Returns:
- the query to add primary key
- Throws:
ContextException
- if a context error occurred
-
convertMetadataTypeToSql
protected String convertMetadataTypeToSql(String metadataType)
Return the sql type depends on the metadata and the database type- Parameters:
metadataType
- the metadata type- Returns:
- the sql type depends on the metadata and the database type
-
executeSqlQueries
protected void executeSqlQueries() throws SQLException, IOException
Execute SQL queries- Throws:
SQLException
- if a sql error occurredIOException
- if an IO error occurred
-
_getNbTable
private int _getNbTable()
-
_executeQueryFromlistQuery
protected void _executeQueryFromlistQuery(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, ContextException
Prepare INSERT statement- Parameters:
tableName
- the table name- Returns:
- the INSERT preparedStatement
- Throws:
SQLException
- if a sql error occurredContextException
- if a context error occurred
-
-