Class MysqlSchemaCodegen

    • Field Detail

      • ENUM_MAX_ELEMENTS

        public static final Integer ENUM_MAX_ELEMENTS
      • IDENTIFIER_MAX_LENGTH

        public static final Integer IDENTIFIER_MAX_LENGTH
      • mysqlNumericTypes

        protected Vector<String> mysqlNumericTypes
      • mysqlDateAndTimeTypes

        protected Vector<String> mysqlDateAndTimeTypes
      • mysqlStringTypes

        protected Vector<String> mysqlStringTypes
      • mysqlSpatialTypes

        protected Vector<String> mysqlSpatialTypes
      • defaultDatabaseName

        protected String defaultDatabaseName
      • databaseNamePrefix

        protected String databaseNamePrefix
      • databaseNameSuffix

        protected String databaseNameSuffix
      • tableNamePrefix

        protected String tableNamePrefix
      • tableNameSuffix

        protected String tableNameSuffix
      • columnNamePrefix

        protected String columnNamePrefix
      • columnNameSuffix

        protected String columnNameSuffix
      • jsonDataTypeEnabled

        protected Boolean jsonDataTypeEnabled
      • namedParametersEnabled

        protected Boolean namedParametersEnabled
      • identifierNamingConvention

        protected String identifierNamingConvention
    • Constructor Detail

      • MysqlSchemaCodegen

        public MysqlSchemaCodegen()
    • Method Detail

      • processIntegerTypeProperty

        public void processIntegerTypeProperty​(CodegenModel model,
                                               CodegenProperty property)
        Processes each model's property mapped to integer type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processDecimalTypeProperty

        public void processDecimalTypeProperty​(CodegenModel model,
                                               CodegenProperty property)
        Processes each model's property mapped to decimal type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processBooleanTypeProperty

        public void processBooleanTypeProperty​(CodegenModel model,
                                               CodegenProperty property)
        Processes each model's property mapped to boolean type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processStringTypeProperty

        public void processStringTypeProperty​(CodegenModel model,
                                              CodegenProperty property)
        Processes each model's property mapped to string type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processDateTypeProperty

        public void processDateTypeProperty​(CodegenModel model,
                                            CodegenProperty property)
        Processes each model's property mapped to date type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processJsonTypeProperty

        public void processJsonTypeProperty​(CodegenModel model,
                                            CodegenProperty property)
        Processes each model's property mapped to JSON type and adds related vendor extensions
        Parameters:
        model - model
        property - model's property
      • processUnknownTypeProperty

        public void processUnknownTypeProperty​(CodegenModel model,
                                               CodegenProperty property)
        Processes each model's property not mapped to any type and adds related vendor extensions Most of time it's related to referenced properties eg. \Model\User
        Parameters:
        model - model
        property - model's property
      • toCodegenMysqlDataTypeArgument

        public HashMap<String,​Object> toCodegenMysqlDataTypeArgument​(Object value)
        Generates codegen property for MySQL data type argument
        Parameters:
        value - argument value
        Returns:
        generated codegen property
      • toCodegenMysqlDataTypeDefault

        public HashMap<String,​Object> toCodegenMysqlDataTypeDefault​(String defaultValue,
                                                                          String mysqlDataType)
        Generates default codegen property for MySQL column definition Ref: https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html
        Parameters:
        defaultValue - value
        mysqlDataType - MySQL data type
        Returns:
        generated codegen property
      • getMysqlMatchedIntegerDataType

        public String getMysqlMatchedIntegerDataType​(Long minimum,
                                                     Long maximum,
                                                     Boolean unsigned)
        Finds best fitted MySQL data type for integer variable based on minimum and maximum properties
        Parameters:
        minimum - (optional) codegen property
        maximum - (optional) codegen property
        unsigned - (optional) whether variable is unsigned or not
        Returns:
        MySQL integer data type
      • getMysqlMatchedStringDataType

        public String getMysqlMatchedStringDataType​(Integer minLength,
                                                    Integer maxLength)
        Finds best fitted MySQL data type for string variable based on minLength and maxLength properties
        Parameters:
        minLength - (optional) codegen property
        maxLength - (optional) codegen property
        Returns:
        MySQL string data type
      • isMysqlDataType

        public Boolean isMysqlDataType​(String dataType)
        Checks whether string is one of MySQL Data Types Ref: https://dev.mysql.com/doc/refman/8.0/en/data-type-overview.html
        Parameters:
        dataType - which needs to check
        Returns:
        true if value is correct MySQL data type, otherwise false
      • toDatabaseName

        public String toDatabaseName​(String name)
        Converts name to valid MySQL database name Produced name must be used with backticks only, eg. `database_name`
        Parameters:
        name - source name
        Returns:
        database name
      • toTableName

        public String toTableName​(String name)
        Converts name to valid MySQL column name Produced name must be used with backticks only, eg. `table_name`
        Parameters:
        name - source name
        Returns:
        table name
      • toColumnName

        public String toColumnName​(String name)
        Converts name to valid MySQL column name Produced name must be used with backticks only, eg. `column_name`
        Parameters:
        name - source name
        Returns:
        column name
      • toMysqlIdentifier

        public String toMysqlIdentifier​(String name,
                                        String prefix,
                                        String suffix)
        Converts name to valid MySQL identifier which can be used as database, table, column name Produced name must be used with backticks only, eg. `column_name`
        Parameters:
        name - source name
        prefix - when escaped name is digits only, prefix will be prepended
        suffix - when escaped name is digits only, suffix will be appended
        Returns:
        identifier name
      • escapeMysqlUnquotedIdentifier

        public String escapeMysqlUnquotedIdentifier​(String identifier)
        Escapes MySQL identifier to use it in SQL statements without backticks, eg. SELECT identifier FROM Ref: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
        Parameters:
        identifier - source identifier
        Returns:
        escaped identifier
      • escapeMysqlQuotedIdentifier

        public String escapeMysqlQuotedIdentifier​(String identifier)
        Escapes MySQL identifier to use it in SQL statements with backticks, eg. SELECT `identifier` FROM Ref: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
        Parameters:
        identifier - source identifier
        Returns:
        escaped identifier
      • setDefaultDatabaseName

        public void setDefaultDatabaseName​(String databaseName)
        Sets default database name for all MySQL queries Provided value will be escaped when necessary
        Parameters:
        databaseName - source name
      • getDefaultDatabaseName

        public String getDefaultDatabaseName()
        Returns default database name for all MySQL queries This value must be used with backticks only, eg. `database_name`
        Returns:
        default database name
      • setJsonDataTypeEnabled

        public void setJsonDataTypeEnabled​(Boolean enabled)
        Enables special JSON data type in all MySQL queries JSON data type requires MySQL version 5.7.8
        Parameters:
        enabled - true to enable, otherwise false
      • getJsonDataTypeEnabled

        public Boolean getJsonDataTypeEnabled()
        Whether JSON data type enabled or disabled in all MySQL queries
        Returns:
        true if enabled otherwise false
      • setNamedParametersEnabled

        public void setNamedParametersEnabled​(Boolean enabled)
        Enables named parameters in prepared SQLs
        Parameters:
        enabled - true to enable, otherwise false
      • getNamedParametersEnabled

        public Boolean getNamedParametersEnabled()
        Whether named parameters enabled or disabled in prepared SQLs
        Returns:
        true if enabled otherwise false
      • setIdentifierNamingConvention

        public void setIdentifierNamingConvention​(String naming)
        Sets identifier naming convention for table names and column names. This is not related to database name which is defined by defaultDatabaseName option.
        Parameters:
        naming - identifier naming convention (original|snake_case)
      • getIdentifierNamingConvention

        public String getIdentifierNamingConvention()
        Returns identifier naming convention for table names and column names.
        Returns:
        identifier naming convention
      • toSrcPath

        public String toSrcPath​(String packageName)
        Slightly modified version of AbstractPhpCodegen.toSrcPath method.
        Parameters:
        packageName - package name
        Returns:
        path