Créer une routine et déclarer une variable statique - 8.0

Guide d'utilisation de Talend Big Data Platform Studio

Version
8.0
Language
Français (France)
EnrichDitaval
Big Data Platform
Product
Talend Big Data Platform
Module
Studio Talend
Content
Création et développement

Procédure

  1. Dans l'arborescence Repository, créez une routine MyRoutine.
  2. Déclarez une variable dans la routine et configurez sa valeur comme nulle, par exemple :
    private static String name = null;                      
  3. Ajouter les méthodes setter/getter pour cette variable et appuyez sur Ctrl+S pour sauvegarder les modifications.
    public static synchronized void setValue(String message) {
        name=message;
    }
    
    public static synchronized String getValue() {
        return name;
    }                      
    Remarque : Le code compet Java pour cette routine est le suivant :
    package routines;
    /*
    * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
    * it must be before the "{talendTypes}" key.
    *
    * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
    * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
    * Short
    *
    * 3. {Category} define a category for the Function. it is required. its value is user-defined .
    *
    * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
    *
    * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
    * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
    * added. you can have many parameters for the Function.
    *
    * 5. {example} gives a example for the Function. it is optional.
    */
    public class MyRoutine {
        private static String name = null;
    
    	/**
    	 * helloExample: not return value, only print "hello" + message.
    	 *
    	 *
    	 * {talendTypes} String
    	 *
    	 * {Category} User Defined
    	 *
    	 * {param} string("world") input: The string need to be printed.
    	 *
    	 * {example} helloExemple("world") # hello world !.
    	 */
    	public static void helloExample(String message) {
    		if (message == null) {
    			message = "World"; //$NON-NLS-1$
    		}
    		System.out.println("Hello " + message + " !"); //$NON-NLS-1$ //$NON-NLS-2$
    	}
    
    	public static synchronized void setValue(String message) {
    		name = message;
    	}
    
    	public static synchronized String getValue() {
    		return name;
    	}
    }