Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] Passing parameters from one method to another
[JET] Passing parameters from one method to another [message #659786] Tue, 15 March 2011 11:38 Go to next message
Leslie Aguilera is currently offline Leslie Aguilera
Messages: 11
Registered: November 2010
Junior Member
Hello everybody,

I want to know if there is a way for my jet template to pass the value of a variable before I execute my project. I'm creating a dynamical mysql database, and I have a main method that creates indexes for every table through a for loop.

<%for (Table table: db.getTables()) {%>
createTable(con,"<%=table.getName()%>","<%=getCreateTableCommand(db,table)%>");	


As you can see, this method calls another one:

public static void createTable (Connection con,  String tableName, String createTableStatement) throws SQLException {
		Statement st = null;
		st = con.createStatement();
		System.out.println(String.format("Creating table %s.",tableName));		
		try {
				st.executeUpdate(createTableStatement);
		} catch (SQLException e) {
			 if ( e.getErrorCode() == 1050) {
			   	System.out.println(String.format("\tTable %s already exists. Dropped.",tableName));			  	
			   	st.executeUpdate(String.format("DROP TABLE %s",tableName));
				System.out.println(String.format("\tCreating table %s.", tableName));
				st.executeUpdate("createTableStatement");
			}
			else {
			 		ServiceMessage.Exception.handle(e);
			 }
		}
		st.close();
	}



Here, I'm trying to execute the "Create Table" query beforehand and if this table exists, I delete it and create it again. But before dropping the table, I need to delete its constraints/foreign keys, and for that I need the table name so I can use a rutine under jsp tags that would construct me the sentences I need for. My *real* problem is, that I don't know how to send the table name from the first method to createTable method because those methods weren't written under jsp tags java since I'm going to use them after I translate my template, and even if createTable receives the String tableName (which contains the name of the table that I'm currently creating) I can't use it like this:

<% 	List <String> fk  = public List <String> getTablesWithFK (tableName); %>


Because when the template is translating, it doesn't recognize the variable.

Since I can't merge both methods in only one (that would simplify my existence, because I can directly use <%=table.getName()%> as parameter in getTableswithFK()), is there any way I can receive that value from one method to another?

Thanks in advance.
Re: [JET] Passing parameters from one method to another [message #659803 is a reply to message #659786] Tue, 15 March 2011 12:24 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Are you trying to execute the 'createTable' method during template execution? If so, try this:

<%for (Table table: db.getTables()) {
    createTable(con, table.getName(), getCreateTableCommand(db,table));	
} %>


Paul
Re: [JET] Passing parameters from one method to another [message #659822 is a reply to message #659803] Tue, 15 March 2011 14:05 Go to previous messageGo to next message
Leslie Aguilera is currently offline Leslie Aguilera
Messages: 11
Registered: November 2010
Junior Member
Nou, that method is executed after the template is translated and generate a java class with the results of that template. Crying or Very Sad
Re: [JET] Passing parameters from one method to another [message #659836 is a reply to message #659822] Tue, 15 March 2011 14:32 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
So you want to generate some Java code, then compile and execute it, after it has been generated?

If so, why not create a simple Ant build that does that, and run it after the template has executed. (If needed, you could create a template the produces the Ant build.xml file, too).

Paul
Re: [JET] Passing parameters from one method to another [message #659839 is a reply to message #659836] Tue, 15 March 2011 14:39 Go to previous message
Leslie Aguilera is currently offline Leslie Aguilera
Messages: 11
Registered: November 2010
Junior Member
I'll try doing that. Thank you x)
Previous Topic:[Xpand]define of the return type
Next Topic:[JET] Weird behaviour with Jet Builder when it's translating the templates
Goto Forum:
  


Current Time: Wed Apr 23 20:50:32 EDT 2014

Powered by FUDForum. Page generated in 0.01572 seconds