Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorial:sakila_customization [2020/04/16 10:56]
tutorial:sakila_customization [2020/04/16 10:56] (current)
Line 1: Line 1:
 +<WRAP adihi>​After having changed a value in the Film Editor, if you try to save your change into the database, an error occurs:
 +  * <wrap adicode><​color red>​Caused by: java.sql.SQLException:​ Data truncated for column '​release_year'​ at row 1</​color></​wrap>​
 +</​WRAP>​
 +\\
 +This error is caused by a inaccurate mapping of the special type year of the column "​release_year"​ in the table Film of the **mysql** database.
 +<sxh sql>
 +release_year year(4)
 +</​sxh>​
 +is mapped in: 
 +<sxh java>
 +private Date releaseYear;​
 +</​sxh>​
 +<WRAP adihi>
 +In order to fix the problem, you must apply these 4 changes:
 +</​WRAP>​
 +== Changes on Film.java file == 
 +<​sub>​Update</​sub>​
 +<sxh java; title: Film.java>​
 + private Date releaseYear;​
 +
 + ...
 +
 +    @Temporal(TemporalType.DATE)
 +    @Column(name="​release_year",​ length=0)
 +    public Date getReleaseYear() {
 +        return this.releaseYear;​
 +    }
 +    ​
 +    public void setReleaseYear(Date releaseYear) {
 +        this.releaseYear = releaseYear;​
 +    }
 +</​sxh>​
 +<​sub>​by</​sub>​
 +<sxh java; title: Film.java>​
 + private Date releaseYear;​
 +
 + ...
 +
 +    @Temporal(TemporalType.DATE)
 +    @Column(name="​release_year",​ length=0)
 +    public Date getReleaseYear() {
 +        return this.releaseYear;​
 +    }
 +    ​
 +    public void setReleaseYear(Date releaseYear) {
 +        this.releaseYear = releaseYear;​
 +    }
 +</​sxh>​
 +<WRAP indic>
 +Regenerate EJB is you use a application server.
 +</​WRAP> ​
 +\\
 +== Changes on FilmDI.axml file ==
 +<​sub>​Update</​sub>​
 +<sxh java; title: Film.java>​
 +      <​dateText property="​releaseYear"​ style="​SWT.BORDER | AdiSWT.DELETE_BUTTON"​ id="​releaseYear"/>​
 +</​sxh>​
 +<​sub>​by</​sub>​
 +<sxh java; title: Film.java>​
 +        <​formattedText editPattern="####"​ format="​Integer"​ property="​releaseYear"​ id="​releaseYear">​
 +            <​validators>​
 +                <​validator key="​invalidYear"​ errorMessage="#​MSG(film,​ invalid.year.value,​ #​FV())">​
 +                    <​errorWhen>​return #FV() &lt; 1900 ||  #FV() &gt; 2155;</​errorWhen>​
 +                </​validator>​
 +            </​validators>​
 +        </​formattedText>​
 +</​sxh>​
 +\\
 +== Changes on FilmTI.axml file ==
 +<​sub>​Update</​sub>​
 +<sxh java; title: Film.java>​
 +        <​tableColumn property="​releaseYear"​ sorted="​true"​ id="​releaseYearTC"/>​
 +</​sxh>​
 +<​sub>​by</​sub>​
 +<sxh java; title: Film.java>​
 +        <​tableColumn property="​releaseYear"​ pattern="#####"​ sorted="​true"​ id="​releaseYearTC"/>​
 +</​sxh>​
 +\\
 +== Changes on film.properties file ==
 +add line:
 +<sxh text; title: film.properties>​
 +invalid.year.value = Invalid year '​{0}'​! Value must be between 1900 and 2155
 +</​sxh>​
 +\\
 +----
 +\\
 +==== Update Scenario.xml to inject changes inside automatic generation process ====
 +<WRAP adihi>
 +By modifying the **Scenario.xml** file as follows, you force the automatic generation process to include changes described above.
 +</​WRAP>​
 +\\
 +<wrap adicode>​Update</​wrap>​
 +<sxh xml; title: Scenario.xml;​ first-line: 151>
 +        <​pluginEntity entityURI="​adi://​myproject/​model.film/​FilmMM">​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmMM"​ type="​ENTITY"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmQUERY"​ type="​QUERY"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmDI"​ type="​DETAIL"/>​
 +            <​generationUnit adiResourceURI="​adi://​./​film"​ type="​MESSAGE_BUNDLE"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmEDITOR"​ type="​EDITOR"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmTI"​ type="​TABLE"/>​
 +        </​pluginEntity>​
 +</​sxh>​
 +<wrap adicode>​by</​wrap>​
 +<sxh xml; title: Scenario.xml;​ first-line: 151>
 +<​pluginEntity entityURI="​adi://​./​./​FilmMM">​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmMM"​ type="​ENTITY"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmQUERY"​ type="​QUERY"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmDI"​ type="​DETAIL"/>​
 +            <​generationUnit adiResourceURI="​adi://​./​film"​ type="​MESSAGE_BUNDLE"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmEDITOR"​ type="​EDITOR"/>​
 +            <​generationUnit adiResourceURI="​adi://​model.film/​FilmTI"​ type="​TABLE"/>​
 +            <​messages>​
 +                <message key="​invalid.year.value"​ value="​Invalid year '​{0}'​! Value must be between 1900 and 2155"/>​
 +            </​messages>​
 +            <​propertyField id="​releaseYear"​ pojoType="​int">​
 +                <​controlField xsi:​type="​formattedTextType"​ editPattern="####"​ format="​Integer">​
 +                    <​validators>​
 +                        <​validator key="​invalidYear"​ errorMessage="#​MSG(film,​ invalid.year.value,​ #​FV())">​
 +                            <​errorWhen>​return #FV() &lt; 1900 ||  #FV() &gt; 2155;</​errorWhen>​
 +                        </​validator>​
 +                    </​validators>​
 +                </​controlField>​
 +            </​propertyField>​
 +        </​pluginEntity>​
 +</​sxh>​
 +<WRAP indic>
 +Each time, you decide to relaunch a generation process, these modifications will be made in appropriate files.
 +|< 100% 10em - >|
 +^  <​html><​small></​html>​Line 159<​html></​small></​html>:​|@#​eff5fb:​add an item in **FilmGENERATED.properties** file.|
 +^  <​html><​small></​html>​Line 161<​html></​small></​html>:​|@#​eff5fb:​Type for **release_year** is **int**. Change will automatically be made in the accurate pojo (**fFilm.java**).|
 +^  <​html><​small></​html>​Line 162<​html></​small></​html>:​|@#​eff5fb:​The controller linked to **release_year** will be a **FormattedText** controller.|
 +^  <​html><​small></​html>​Lines 164-166<​html></​small></​html>:​|@#​eff5fb:​Add a validator: value of the property must be between <wrap adicode>​1900</​wrap>​ and <wrap adicode>​2155</​wrap>​.|
 +</​WRAP>​
 +\\
 +\\
 +<WRAP indic>
 +These intended modifications can be stored in a customized <wrap adicode>​Scenario Tree</​wrap>​ which will be merged to the standard <wrap adicode>​Scenario Tree</​wrap>​ as shown in this [[customize_scenario|page]].
 +</​WRAP>​
 +