Skip to content

How to add new functions to GreenCity project

Vasyl edited this page Sep 3, 2020 · 2 revisions

Follow this guideline if you want to add new functions that will run on the project startup. Also you can use this approach to make run any SQL files (e.g. SQL-script for populating tables with data).


  1. Open DataSourceMatadata class (package greencity.config).
  2. Find createFunctions() method.
  3. On databasePopulator call addScript() method and specify the path to the SQL file, like in the example below.


Features when adding functions.

  1. If in your function you have syntax like $$ or $BODY$ it should be replaced with a single quote sign '.
    Why? Hibernate can not recognize syntax with dollar signs, so you have to replace it with single quote signs. Later, when Hibernate runs this function, it will replace this ' signs back to $$ or $BODY$ respectively, so that the function looks as it should in your database.

  2. If in your function you have syntax like $$ or $BODY$, you already replaced it with singe quote signs ', and in the body of your function you also have these single quote signs ', you should replace every single ' in your body with two the same '' like in the example below. Not to be confused with double-quotes.
    Why? After you replaced $$ or $BODY$ with ', this single quote will conflict with the other ones that in the function's body, so Hibernate will not know where the end of the quote that you put instead of $$ or $BODY$, and the first one that it will meet, will be considered as the needed one (wrongly). Therefore, to prevent this behavior, we do such actions. And again, later, during the project startup process, all these '' in your function will be replaced back to ' and the function will be created in the database correctly.

Wrong function's body Right function's body

P.S Instead of word BODY you can have any other word (e.g. $text$, $my_word$, $MARS$ etc.).