| | -package com.whitemagicsoftware.rxm; |
| | - |
| | -import java.sql.Connection; |
| | -import java.sql.PreparedStatement; |
| | -import java.sql.SQLException; |
| | - |
| | -import java.util.HashSet; |
| | -import java.util.Set; |
| | - |
| | -/** |
| | - * Abstracts SQL statement code into a terse mapping format. |
| | - */ |
| | -public class RelationMap { |
| | - /** The SQL statement to execute. */ |
| | - private String query; |
| | - |
| | - /** The RXM expressions, which can include module names and mappings. */ |
| | - private Set<String> expressions; |
| | - |
| | - /** |
| | - * Creates a new Relation eXpression Map (<b>rxm</b>). This will parse |
| | - * content and update both the query and the modules as necessary. |
| | - * |
| | - * @param map The <b>rxm</b> to parse. |
| | - */ |
| | - public RelationMap( String map ) { |
| | - map( map ); |
| | - } |
| | - |
| | - public String toXML( Connection connection ) throws SQLException { |
| | - return ""; |
| | - } |
| | - |
| | - public String toJSON( Connection connection ) throws SQLException { |
| | - return ""; |
| | - } |
| | - |
| | - /** |
| | - * Adds an <b>rxm</b> to the set of mappings. |
| | - * |
| | - * @param map The <b>rxm</b> to map. |
| | - */ |
| | - public void map( String map ) { |
| | - getExpressions().add( map ); |
| | - } |
| | - |
| | - /** |
| | - * Walks through the <b>rxm</b> list and creates the equivalent |
| | - * SQL statement. |
| | - * |
| | - * @return A SQL statement based on the current set of expressions. |
| | - */ |
| | - private String parse() { |
| | - return ""; |
| | - } |
| | - |
| | - /** |
| | - * Returns a set of Relational eXpression Maps. |
| | - * |
| | - * @return An non-null set, possibly empty. |
| | - */ |
| | - private Set<String> getExpressions() { |
| | - Set<String> result = this.expressions; |
| | - |
| | - if( result == null ) { |
| | - result = createExpressions(); |
| | - setExpressions( result ); |
| | - } |
| | - |
| | - return this.expressions; |
| | - } |
| | - |
| | - /** |
| | - * Sets the container to hold the expressions. Subclasses should override |
| | - * createExpressions to introduce new behaviour. |
| | - */ |
| | - private void setExpressions( Set<String> expressions ) { |
| | - if( expressions == null ) { |
| | - expressions = createExpressions(); |
| | - } |
| | - |
| | - this.expressions = expressions; |
| | - } |
| | - |
| | - /** |
| | - * Returns the container to hold all expressions. |
| | - * |
| | - * @return A non-null HashSet by default. |
| | - */ |
| | - protected Set<String> createExpressions() { |
| | - return new HashSet<String>(); |
| | - } |
| | - |
| | - /** |
| | - * Sets the SQL statement to execute when calling one of the toX() |
| | - * methods. |
| | - */ |
| | - private String getQuery() { |
| | - return this.query; |
| | - } |
| | - |
| | - /** |
| | - * Stores the SQL statement after parsing the expression mappings. |
| | - * |
| | - * @param query The SQL statement to store |
| | - */ |
| | - private void setQuery( String query ) { |
| | - this.query = query; |
| | - } |
| | -} |
| | - |
| | |