Dynamic Getters Getters

Forum destinado a Linguagem JAVA! Classes, orientação a objeto, conexão com banco, chamada de procedures, etc
Post Reply
leandro_bonato
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 22
Joined: Mon, 14 Oct 2013 9:24 pm

Good evening, Srs., I'm wanting to develop the getters and setters dynamically, this includes the attributes of being dynamic as well, follows the sample code of attributes and getters and fixed setters, without being dynamic. Is there any way to develop this dynamically? To warn you I need to use them in database. Thanks!

Select all

package beans; 
import java.beans.*; 
import java.sql.Date; 
 
public class ClassesBeans{ 
      
private int codigo; 
private String nome; 
 
public int getCodigo(){ 
return codigo; 
} 
 
public String getNome(){ 
return nome; 
} 
 
public void setCodigo(înt codigo){ 
this.codigo = codigo; 
} 
 
public void setNome(){ 
this.nome = nome; 
} 
}
This is only an example of all classes, the rest is practically the same.

All these lines of code dynamically must be done, which I do not need to do this fixed and then have to fetch these fixed fields, it is only me to point the class and method and it constructs what I need. The idea is basically that. Thanks!
leandro_bonato
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 22
Joined: Mon, 14 Oct 2013 9:24 pm

Nobody ???? : Shock:
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Let me understand better: Do you want to generate automatic get and sets according to the fields of a table?
I believe that if this is what you want, just make a cursor at Oracle All_Tab_Columns.

Thus:

Select all

begin 
  DBMS_OUTPUT.PUT_LINE('package beans;'); 
  DBMS_OUTPUT.PUT_LINE('import java.beans.*;'); 
  DBMS_OUTPUT.PUT_LINE('import java.sql.Date;'); 
  DBMS_OUTPUT.PUT_LINE(''); 
  DBMS_OUTPUT.PUT_LINE('public class ClassesBeans{'); 
  DBMS_OUTPUT.PUT_LINE(''); 
   
  FOR vcur IN (select * from all_tab_columns WHERE table_name='FND_USER') 
  LOOP 
    -- Aqui esta INT pra todos, você vai ter que fazer um DE-PARA, tipo, se for varchar 
    -- converte pra String, se for Number, INT ou float, etc. 
    DBMS_OUTPUT.PUT_LINE('private int '|| LOWER(vcur.column_name)||';'); 
  END LOOP; 
 
  DBMS_OUTPUT.PUT_LINE(''); 
 
  FOR vcur IN (select * from all_tab_columns WHERE table_name='FND_USER') 
  LOOP 
    -- Aqui esta INT pra todos, você vai ter que fazer um DE-PARA, tipo, se for varchar 
    -- converte pra String, se for Number, INT ou float, etc. 
    DBMS_OUTPUT.PUT_LINE('public int get'||INITCAP(vcur.column_name)||'(){'); 
    DBMS_OUTPUT.PUT_LINE('return '||LOWER(vcur.column_name)||';'); 
    DBMS_OUTPUT.PUT_LINE('}'); 
    DBMS_OUTPUT.PUT_LINE(''); 
 
    DBMS_OUTPUT.PUT_LINE('public int set'||INITCAP(vcur.column_name)||'(int '||LOWER(vcur.column_name)||'){'); 
    DBMS_OUTPUT.PUT_LINE('this.'||LOWER(vcur.column_name)||'='||LOWER(vcur.column_name)||';'); 
    DBMS_OUTPUT.PUT_LINE('}'); 
    DBMS_OUTPUT.PUT_LINE('');     
 
    DBMS_OUTPUT.PUT_LINE('public void set'||INITCAP(vcur.column_name)||'()'); 
    DBMS_OUTPUT.PUT_LINE('this.'||LOWER(vcur.column_name)||'='||LOWER(vcur.column_name)||';'); 
    DBMS_OUTPUT.PUT_LINE('}'); 
    DBMS_OUTPUT.PUT_LINE('');     
  END LOOP; 
end;  
In the example above, it generates the following text:

Select all

package beans; 
import java.beans.*; 
import java.sql.Date; 
  
public class ClassesBeans{ 
  
private int password_accesses_left; 
private int gcn_code_combination_id; 
private int person_party_id; 
private int user_guid; 
private int user_id; 
private int user_name; 
private int last_update_date; 
private int last_updated_by; 
private int creation_date; 
private int created_by; 
private int last_update_login; 
private int encrypted_foundation_password; 
private int encrypted_user_password; 
private int session_number; 
private int start_date; 
private int end_date; 
private int description; 
private int last_logon_date; 
private int password_date; 
private int password_lifespan_accesses; 
private int password_lifespan_days; 
private int employee_id; 
private int email_address; 
private int fax; 
private int customer_id; 
private int supplier_id; 
private int web_password; 
  
public int getPassword_Accesses_Left(){ 
return password_accesses_left; 
} 
  
public int setPassword_Accesses_Left(int password_accesses_left){ 
this.password_accesses_left=password_accesses_left; 
} 
  
public void setPassword_Accesses_Left() 
this.password_accesses_left=password_accesses_left; 
} 
  
public int getGcn_Code_Combination_Id(){ 
return gcn_code_combination_id; 
} 
  
public int setGcn_Code_Combination_Id(int gcn_code_combination_id){ 
this.gcn_code_combination_id=gcn_code_combination_id; 
} 
  
public void setGcn_Code_Combination_Id() 
this.gcn_code_combination_id=gcn_code_combination_id; 
} 
  
public int getPerson_Party_Id(){ 
return person_party_id; 
} 
  
public int setPerson_Party_Id(int person_party_id){ 
this.person_party_id=person_party_id; 
} 
  
public void setPerson_Party_Id() 
this.person_party_id=person_party_id; 
} 
  
public int getUser_Guid(){ 
return user_guid; 
} 
  
public int setUser_Guid(int user_guid){ 
this.user_guid=user_guid; 
} 
  
public void setUser_Guid() 
this.user_guid=user_guid; 
} 
  
public int getUser_Id(){ 
return user_id; 
} 
  
public int setUser_Id(int user_id){ 
this.user_id=user_id; 
} 
  
public void setUser_Id() 
this.user_id=user_id; 
} 
  
public int getUser_Name(){ 
return user_name; 
} 
  
public int setUser_Name(int user_name){ 
this.user_name=user_name; 
} 
  
public void setUser_Name() 
this.user_name=user_name; 
} 
  
public int getLast_Update_Date(){ 
return last_update_date; 
} 
  
public int setLast_Update_Date(int last_update_date){ 
this.last_update_date=last_update_date; 
} 
  
public void setLast_Update_Date() 
this.last_update_date=last_update_date; 
} 
  
public int getLast_Updated_By(){ 
return last_updated_by; 
} 
  
public int setLast_Updated_By(int last_updated_by){ 
this.last_updated_by=last_updated_by; 
} 
  
public void setLast_Updated_By() 
this.last_updated_by=last_updated_by; 
} 
  
public int getCreation_Date(){ 
return creation_date; 
} 
  
public int setCreation_Date(int creation_date){ 
this.creation_date=creation_date; 
} 
  
public void setCreation_Date() 
this.creation_date=creation_date; 
} 
  
public int getCreated_By(){ 
return created_by; 
} 
  
public int setCreated_By(int created_by){ 
this.created_by=created_by; 
} 
  
public void setCreated_By() 
this.created_by=created_by; 
} 
  
public int getLast_Update_Login(){ 
return last_update_login; 
} 
  
public int setLast_Update_Login(int last_update_login){ 
this.last_update_login=last_update_login; 
} 
  
public void setLast_Update_Login() 
this.last_update_login=last_update_login; 
} 
  
public int getEncrypted_Foundation_Password(){ 
return encrypted_foundation_password; 
} 
  
public int setEncrypted_Foundation_Password(int encrypted_foundation_password){ 
this.encrypted_foundation_password=encrypted_foundation_password; 
} 
  
public void setEncrypted_Foundation_Password() 
this.encrypted_foundation_password=encrypted_foundation_password; 
} 
  
public int getEncrypted_User_Password(){ 
return encrypted_user_password; 
} 
  
public int setEncrypted_User_Password(int encrypted_user_password){ 
this.encrypted_user_password=encrypted_user_password; 
} 
  
public void setEncrypted_User_Password() 
this.encrypted_user_password=encrypted_user_password; 
} 
  
public int getSession_Number(){ 
return session_number; 
} 
  
public int setSession_Number(int session_number){ 
this.session_number=session_number; 
} 
  
public void setSession_Number() 
this.session_number=session_number; 
} 
  
public int getStart_Date(){ 
return start_date; 
} 
  
public int setStart_Date(int start_date){ 
this.start_date=start_date; 
} 
  
public void setStart_Date() 
this.start_date=start_date; 
} 
  
public int getEnd_Date(){ 
return end_date; 
} 
  
public int setEnd_Date(int end_date){ 
this.end_date=end_date; 
} 
  
public void setEnd_Date() 
this.end_date=end_date; 
} 
  
public int getDescription(){ 
return description; 
} 
  
public int setDescription(int description){ 
this.description=description; 
} 
  
public void setDescription() 
this.description=description; 
} 
  
public int getLast_Logon_Date(){ 
return last_logon_date; 
} 
  
public int setLast_Logon_Date(int last_logon_date){ 
this.last_logon_date=last_logon_date; 
} 
  
public void setLast_Logon_Date() 
this.last_logon_date=last_logon_date; 
} 
  
public int getPassword_Date(){ 
return password_date; 
} 
  
public int setPassword_Date(int password_date){ 
this.password_date=password_date; 
} 
  
public void setPassword_Date() 
this.password_date=password_date; 
} 
  
public int getPassword_Lifespan_Accesses(){ 
return password_lifespan_accesses; 
} 
  
public int setPassword_Lifespan_Accesses(int password_lifespan_accesses){ 
this.password_lifespan_accesses=password_lifespan_accesses; 
} 
  
public void setPassword_Lifespan_Accesses() 
this.password_lifespan_accesses=password_lifespan_accesses; 
} 
  
public int getPassword_Lifespan_Days(){ 
return password_lifespan_days; 
} 
  
public int setPassword_Lifespan_Days(int password_lifespan_days){ 
this.password_lifespan_days=password_lifespan_days; 
} 
  
public void setPassword_Lifespan_Days() 
this.password_lifespan_days=password_lifespan_days; 
} 
  
public int getEmployee_Id(){ 
return employee_id; 
} 
  
public int setEmployee_Id(int employee_id){ 
this.employee_id=employee_id; 
} 
  
public void setEmployee_Id() 
this.employee_id=employee_id; 
} 
  
public int getEmail_Address(){ 
return email_address; 
} 
  
public int setEmail_Address(int email_address){ 
this.email_address=email_address; 
} 
  
public void setEmail_Address() 
this.email_address=email_address; 
} 
  
public int getFax(){ 
return fax; 
} 
  
public int setFax(int fax){ 
this.fax=fax; 
} 
  
public void setFax() 
this.fax=fax; 
} 
  
public int getCustomer_Id(){ 
return customer_id; 
} 
  
public int setCustomer_Id(int customer_id){ 
this.customer_id=customer_id; 
} 
  
public void setCustomer_Id() 
this.customer_id=customer_id; 
} 
  
public int getSupplier_Id(){ 
return supplier_id; 
} 
  
public int setSupplier_Id(int supplier_id){ 
this.supplier_id=supplier_id; 
} 
  
public void setSupplier_Id() 
this.supplier_id=supplier_id; 
} 
  
public int getWeb_Password(){ 
return web_password; 
} 
  
public int setWeb_Password(int web_password){ 
this.web_password=web_password; 
} 
  
public void setWeb_Password() 
this.web_password=web_password; 
} 
leandro_bonato
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 22
Joined: Mon, 14 Oct 2013 9:24 pm

Thanks for the answer. What would I do to apply this at run time in Java? Why is he in an anonymous block. Why this will be used for Selects, Inserts, Updates and Deletes with Dynamic SQL in Oracle.

Thanks!
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

I do not know if I'm understanding right what you want to do.
In case, these codes were generated in Oracle.

Do you want to create a Java stored procedure on the bank with these codes?
or want to use this in an external Java program?
leandro_bonato
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 22
Joined: Mon, 14 Oct 2013 9:24 pm

Good afternoon, thank you for the answer. I would like to use them in the external Java, but since you touched the subject, if you can show me in the two ways so I can see which fits better than I want I would appreciate. If it's a bit too inconvenient it can be just the external Java model only. Thanks!
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest