| | |
| | This implementation provides a Java API for building SQL statements |
| | -that produce XML documents based on **rxm**. |
| | +that produce XML documents based on **rxm**. The examples below do not |
| | +show how to obtain a database connection, which the [JDBC documentation](http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html) describes. |
| | |
| | -## Example |
| | +## Basic |
| | |
| | -The following example shows how to use the **rxm** Java API to query the |
| | -database and generate an XML document: |
| | +Use the **rxm** Java API to generate an XML document as follows: |
| | |
| | ``` |
| | import com.whitemagicsoftware.rxm.RelationMap; |
| | |
| | -import java.sql.PreparedStatement; |
| | -import java.sql.ResultSet; |
| | +public class QueryTest { |
| | + public static void main( String args[] ) throws Exception { |
| | + RelationMap rxm = new RelationMap( |
| | + "root > people," + |
| | + "person > person," + |
| | + ".*," |
| | + ); |
| | + |
| | + System.out.println( rxm.toXML( getConnection() ) ); |
| | + } |
| | +} |
| | +``` |
| | + |
| | +## Modules |
| | + |
| | +The **rxm** API allows the definition of modules, such as: |
| | + |
| | +``` |
| | +import com.whitemagicsoftware.rxm.RelationMap; |
| | |
| | public class QueryTest { |
| | public static void main( String args[] ) throws Exception { |
| | - String sql = RelationMap.toSQL( |
| | + RelationMap rxm = new RelationMap(); |
| | + rxm.module( "people", |
| | "root > people," + |
| | "person > person," + |
| | ".*," |
| | ); |
| | |
| | - PreparedStatement statement = getConnection().prepareStatement( sql ); |
| | - ResultSet results = statement.executeQuery(); |
| | + rxm.setQuery( "import 'people'," ); |
| | |
| | - if( results.first() ) { |
| | - System.out.println( results.getString( 0 ) ); |
| | - } |
| | + System.out.println( rxm.toXML( getConnection() ) ); |
| | } |
| | } |
| | ``` |
| | - |
| | -See the [JDBC documentation](http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html) for details to obtain a database connection. |
| | |
| | # Requirements |