This is not an attempt to embed TCL in java - we have no plans to implement any superfluous TCL language features. It's only the familiar syntax that we're borrowing - the generated code is perfectly normal java/jdbc, and some of the problems that can arise in TCL, such as accidentally clobbering variables, show up as errors when the java code is compiled. For further motivation, see the competitive analysis in the requirements document. Along with Bill's implementation of the Arsdigita Templating System, this allows us to eliminate our use of custom JSP tags.
ACS Java 3.4 ACS Java 4.0 <ad:db_query id="insert_new_alert"> insert into bboard_email_alerts ( user_id, topic_id, frequency, keywords ) values ( :user_id, :topic_id, :frequency, :keywords) <ad:db_bind><%= user.getUserId() %></ad:db_bind> <ad:db_bind><%= topic_id %></ad:db_bind> <ad:db_bind><%= frequency %></ad:db_bind> <ad:db_bind><%= db.bindObj(keywords) %></ad:db_bind> </ad:db_query> <% db.dml(insert_new_alert); %><% db_dml insert_new_alert { insert into bboard_email_alerts ( user_id, topic_id, frequency, keywords ) values ( :user_id, :topic_id, :frequency, :keywords) } %>
If an argument is specified as being a code block (in the db-api.grm file), the parser recursively searches it for additional macros.
Appearing on its own, in statement context, the db_string macro generates a String declaration, along with a semicolon to end the complete java statement. Appearing within a java statement, in expression context, it generates an expression whose value is the query result. You may choose either usage according to your needs. Macros that work this way are:
Valid macro usage Generated code db_string next_seq { select my_sequence.nextval from dual }String next_seq = new SqlFragment("select my_sequence.nextval from dual", new Object[] {}).oneValue().toString();String next_seq = [db_string next_seq { select my_sequence.nextval from dual }];String next_seq = new SqlFragment("select my_sequence.nextval from dual", new Object[] {}).oneValue().toString();
db_sql user_clause {
user_id=:user_id
}
db_1row user_email {
select email from users where $user_clause
}
|
.ajp -> .jsp -> .java -> .class
.acsj -> .java -> .class
Whenever you do an update of the acs-java-4 project from CVS, you should rebuild all of your java library sources using the following procedure:
#!/usr/bin/perl $args2 = $args1 = join(@ARGV); $args2 =~ s/\.acsj/\.java/; `java com.arsdigita.db.MacroTranslator \$ACS_JAVA/WEB-INF/db-api.grm $args1` `javac $args2`