New Features
Enhanced Features

Generate Getter/Setter with different visiblity

DB Visual ARCHITECT(DB-VA) generates properties (Getter/Setter) for each attribute for ORM-Persistable class. By default, the property visibility is generated as public and you can change the property visibility by following the attribute model’s visibility. In this article, you will learn how to change the generation option for property visibility, either Public or Follow attribute.

Configuring Property Visibility

DB-VA generates persistent classes based on the class model defined on class diagram. The property (Getter and Setter) for each attribute will be generated automatically. The attribute visibility must be private in persistable class but you can set the property visibility to Follow attribute or Public visibility.

In class diagram, the following symbols: +, -, #, and ~ are used to represent the public, private, protected, and package visibility of the attribute respectively.

  • public – accessible by any other class anywhere.
  • private – accessible only within the class; even methods in subclasses in the same package do not have right to access the attribute.
  • protected – accessible by the package classes and any subclasses that are in other packages.
  • package – accessible to classes in the same package but not the classes in other packages, even if they are subclasses.

Let’s try the following steps to configure the propety visibility:

  1. Create a Class Diagram
    create_class_diagram.jpg

  2. Create an ORM-Persitable Class called Customer with the following attributes:
    VisibilityNameType
    publicnameString
    protectedageint
    packageaddressString
    privategenderchar

    customer_class.jpg

  3. Click Tools > Object-Relational Mapping (ORM) > Synchronize to Entity Relationship Diagram from the menu to synchronize the class diagram to ERD.
    menu_syn_erd.jpg

    The Entity Relationship Diagram (ERD) is created.
    customer_erd.jpg

  4. Select Tools > Object-Relational Mapping (ORM) > Generate Code... to open Database Code Generation dialog box.
    menu_gen_code.jpg

  5. Click Advance Settings button to open Advance Settings dialog box.
    open_advance_setting_dialog.jpg

  6. You can select Default(Public/Follow attribute), Public or Follow attribute from the drop-down menu of Getter/Setter Visibility.
    select_property_option_in_advan.jpg

    The Default(Public/Follow attribute) option of Getter/Setter Visibility can be changed from the application Options.
    1. Select Tools > Options… to open Options dialog box.
      menu_app_options.jpg

    2. Select ORM and configure the Getter/Setter Visibility to Public or Follow Attribute and click OK to confirm the setting.
      app_options_dialog.jpg

    3. The Default value for Advance Settings dialog box will be updated according to the changes in default options in the application.
      default_option.jpg

  7. After configured the Getter/Setter Visibility option, you can configure the other options for code generation, such as the output path and click OK to start generating the persistent classes and library on Database Code Generation dialog box.

Generated Code

When you select Public or Allow attribute for Getter/Setter Visibility. The visibility of the getter and setter methods will be generated based on your selection. The following are the samples of generated code include Java and C#.

public - Getter/Setter Visibility

Java

package test;
/**
 * ORM-Persistable Class
 */
public class Customer {
...
   private String name;
	
   private int age;
	
   private String address;
	
   private char gender;
	
   private int ID;
	
   public void setName(String value) {
     this.name = value;
   }
	
   public String getName() {
     return name;
   }
	
   public void setAge(int value) {
     this.age = value;
   }
	
   public int getAge() {
     return age;
   }
	
 
   public void setAddress(String value) {
     this.address = value;
   }
   
   public String getAddress() {
     return address;
   }
	
   public void setGender(char value) {
     this.gender = value;
   }
 
   public char getGender() {
     return gender;
   }
...
}
C#
namespace test {
/// <summary>
/// ORM-Persistable Class
/// </summary>
public class Customer {
  public Customer() {
  }
  ...
  private string __name;
		
  private int __age;
		
  private string __address;
		
  private char __gender;
		
  private int __ID;
		
  public string Name {
    set {
	this.__name = value;
    }
			
    get {
        return __name;
    }
  }
		
  public int Age {
    set {
	this.__age = value;
    }
			
    get {
	return __age;
    }
  }
		
  public string Address {
    set {
	this.__address = value;
    }
			
    get {
	return __address;
    }
  }
		
  public char Gender {
    set {
	this.__gender = value;
    }
			
    get {
	return __gender;
    }
  ...
}

Follow attribute - Getter/Setter Visibility

Java
package test;
 
/**
 * ORM-Persistable Class
 */
public class Customer {
  ...
  private String name;
	
  private int age;
	
  private String address;
	
  private char gender;
	
  private int ID;
	
  public void setName(String value) {
    this.name = value;
  }
	
  public String getName() {
    return name;
  }
	
  protected void setAge(int value) {
    this.age = value;
  }
	
  protected int getAge() {
    return age;
  }
	
  void setAddress(String value) {
    this.address = value;
  }
	
  String getAddress() {
    return address;
  }
	
  private void setGender(char value) {
    this.gender = value;
  }
	
  private char getGender() {
    return gender;
  }
...
}
C#
namespace test {
/// <summary>
/// ORM-Persistable Class
/// </summary>
public class Customer {
  public Customer() {
  }
  private string __name;
		
  private int __age;
		
  private string __address;
		
  private char __gender;
		
  private int __ID;
		
  public string Name {
    set {
	this.__name = value;
    }
			
    get {
	return __name;
    }
  }
		
  protected int Age {
    set {
	this.__age = value;
    }
			
    get {
	return __age;
    }
  }
		
  string Address {
   set {
	this.__address = value;
   }
			
   get {
	return __address;
   }
  }
		
  private char Gender {
    set {
	this.__gender = value;
    }
			
    get {
	return __gender;
    }
  }
...
}

Downloads

Related Articles

Resources

 
 
Last modified: 2006/03/30 09:47
 
 
Home | Recent Topics | Highlights | UML Diagrams | Tips and Tricks | Object-Relational Mapping
visual-paradigm.com Home | Training Center | UML Center | VP Gallery | Discussion Forum | UML Open Directory