vendredi 5 juillet 2019

Create a database model from SQLite DB

If you want to create a DBModel from an existing SQLite database here is how to proceed...

1) Download the ".jar" file containing the SQLite JDBC driver
from https://bitbucket.org/xerial/sqlite-jdbc/downloads/


2) Put the ".jar" file in "TelosysTools/lib"


3) Configure the JDBC connection in the "databases.dbcfg" file
  • With Telosys-CLI use the "edb" command or edit the file with any text editor
  • With Telosys Eclipse Plugin open it with the specialized editor
 Here's a configuration example :

 <db id = "1"
    name     = "SQLiteDB"
    driver   = "org.sqlite.JDBC"
    url      = "jdbc:sqlite:D:/mypath/database.sqlite"
    typeName = "SQLLITE"
    dialect  = "org.hibernate.dialect.SQLiteDialect"
    isolationLevel = ""
    poolSize       = "10" >
       <property name="user"      value="" />
       <property name="password"  value="" />
       <metadata catalog="" schema=""
            table-name-pattern="%" table-types="TABLE  VIEW  "
            table-name-exclude=""  table-name-include=""  />
  </db>


In "url" parameter replace "D:/mypath/database.sqlite" by your database file path

4) Test the connection
With Telosys-CLI you can use the following "Check DataBase" commands :
  > cdb     ( check the connection )
  > cdb -i  ( check the connection and get database information )
  > cdb -t  ( check the connection and get database tables )
  > cdb -c  ( check the connection and get database colomns )
 ( enter "? cdb" for all options )
With Telosys Eclipse Plugin use the GUI (tabs "Information", "Meta-data", buttons "Get tables", "Get columns", etc)

5) If the connection is OK you can create the database model
With Telosys-CLI  run the "New Db Model" command
  > ndbm
With Telosys Eclipse Plugin use the GUI

Info : with SQLite DB only the tables and columns are retrieved (the model created doesn't contain Primary Keys and Foreign Keys)

lundi 15 avril 2019

How to use Telosys code generation without entities


In some cases you may need to use templates to generate only a few files unrelated to the notion of model and entities.

This can be useful for generating configuration files or isolated files for which the variables defined in the project are sufficient.

In its current version Telosys can launch a generation only if there is a "model". But there is a simple way to use code generation without entities : just create a void model.

To do that create a "DSL model" (you can name it "void-model" for example )
Once the "void model" is created select this model as the current model (in Eclipse just open it).



Then select a bundle containing your templates and execute them...



NB: all the templates present in the bundle must respect the following rules:
  • in the "templates.cfg" file they must have a  cardinality of "1" so that each template is executed just once regardless of the number of entities
  • in the ".vm" file they must not refer to entity ( ${entity}, ${attribute}, etc )

Example of template definition in "templates.cfg" :



So you can generate files from templates that only use project variables and no entity.

vendredi 12 avril 2019

How to manipulate strings in a Telosys template


All Java objects methods can be used in a template (".vm" file),
hence it’s possible to use all the methods defined in the Java class “String”.



For all information about 'String' methods see the Java doc :
 https://docs.oracle.com/javase/7/docs/api/java/lang/String.html



Examples :


length is $STR.length()

#set($STR = $STR.replaceFirst("def", "xy" )

#if ( $STR.endsWith("ef") )
YES, it ends with "ef"
#else
NO
#end

charAt(2) : $STR.charAt(2)

#if ( $STR.equalsIgnoreCase($STR2) )
YES
#else
NO
#end


$STR.toUpperCase()
$STR.toLowerCase()


lundi 27 août 2018

How to generate files outside the current location


With the default configuration the telosys tooling is located in the project folder where the files are generated.



It's possible to change the configuration in order to specify a specific destination for the generated files.

With this configuration, it is possible to generate files anywhere.
You just have to indicate the destination directory.

If you are using Telosys-CLI


  Use the command "ecfg" (Edit Configuration) to edit the "telosys-tools.cfg" file.

  Define the "SpecificDestinationFolder" property
  Examples :
  SpecificDestinationFolder=C\:\\dir1\\dir2
  SpecificDestinationFolder=/dir1/dir2


If you are using Telosys Eclipse Plugin 

  In the project workspace open the "Telosys Tools properties editor"
  from the menu : "File" - "Properties" - "Telosys Tools"
  or with a Right-Click on the project "Properties" - "Telosys Tools"

  Select the "Advanced" tab and set the specific location for code generation


Hence it's possible to create a "General project" just for Telosys tooling and use it to generate outside the workspace.