Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git
build.gradle
java {
- srcDir "source/java"
+ srcDir "."
}
}
}
dependencies {
+ compile fileTree(
+ dir: 'lib',
+ includes: ['*.jar']
+ )
}
com/whitemagicsoftware/rxm/RelationMap.java
+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.
+ */
+ public void map( String map ) {
+ getExpressions().add( map );
+ }
+
+ /**
+ * Walks through the given <b>rxm</b> and creates the equivalent
+ * SQL statement.
+ *
+ * @return A SQL statement based on the current set of expressions.
+ */
+ private String parse() {
+ }
+
+ /**
+ * 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 String setQuery( String query ) {
+ this.query = query;
+ }
+}
+

First implementation of Java rxm API.

Author Dave Jarvis <email>
Date 2015-02-10 18:36:51 GMT-0800
Commit 7d78dfdf7bd5ff600e06773572fd0ebcd4ce0e28
Parent f193a53
Delta 113 lines added, 1 line removed, 112-line increase