Summary

restSQL 0.8.7 adds auto-increment/sequence-based column support and extends function-based column support to PostgreSQL.
  1. Insert responses now embed the inserted object(s), including the value of an auto-generated numeric column value (usually a primary key).
  2. Function-based columns in select operations will now work in PostgreSQL, as well as MySQL.
  3. The release includes two changes to the Java API that will require minor client updates. Some implementation packages were created necessitating changes to restsql.properties files.
  4. The release also fixes Deployment errors on JBoss 6/7 and 404 Not Found on configuration browsing.

Auto-increment/Sequence support

Following shows an insert that excludes the primary key, actor_id, relying on the default value's auto-increment in MySQL or sequence in PostgreSQL:

POST /restsql/res/Actor HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/xml

first_name=JULIANNE&last_name=DENCH

The write response now includes the inserted object, along with the auto-generated primary key value:

HTTP/1.1 200 OK
Content-Type: application/xml

<writeResponse rowsAffected="1">
   <actor actor_id="202" first_name="JULIANNE" last_name="DENCH" />
<writeResponse/>

The response for a delete and update request will continue to only include the rowsAffected attribute (no child elements).

Auto-generated columns in child tables in hierarchical resources will also work. Following shows an insert for children in a hierarchical resource:

POST /restsql/res/LanguageFilms HTTP/1.1
Content-Type: application/json
Accept: application/json

{ "langs": [
      { "langId": 100
         "movies": [
            { "year": 2011, "title": "BLESSED SUN" },
            { "year": 2012, "title": "WICKED SUN" }
         ]
      },
      { "langId": 101,
         "movies": [
            { "year": 2011, "title": "BLESSED MOON" },
            { "year": 2013, "title": "WICKED MOON" }
          ]
      }
   ]
}

and the response:

HTTP/1.1 200 OK
Content-Type: application/json

{ "rowsAffected": 4,
	"langs": [
      { "langId": 100
         "movies": [
            { film_id: 5003, "year": 2011, "title": "BLESSED SUN" },
            { fiml_id: 5004, "year": 2012, "title": "WICKED SUN" }
         ]
      },
      { "langId": 101,
         "movies": [
            { film_id: 5005, "year": 2011, "title": "BLESSED MOON" },
            { film_id: 5006, "year": 2013, "title": "WICKED MOON" }
          ]
      }
   ]
}

Java clients can use the new WriteResponse object to examine the auto-generated column value.

Function-based columns in PostgreSQL

Columns may contain functions however these may only be returned passively in a read request. They may not be queried as a parameter to any operation, nor may they be contained in any rows in the body in a write operation. This support was previously only available forMySQL.

This extension was contributed by rhuitl.

See SqlResource Rules for guidelines on SQL Resources.

Java API Changes

The org.restsql.core.NameValuePair was renamed to RequestValue, but its usage and functionality remain unchanged. It models a request parameter name-value-operator trinity and a resource identifier name-value pair (a PK as a request parameter). RequestValue s are passed in collections to Factory.getRequest(..) methods when creating a Request.

The org.restsql.core.SqlResource.write() signature has changed. It now returns a WriteResponse object instead of an integer. The write response includes the rows affected integer and it contains a collection of ResponseValues, which models the inserted row values, including any auto-generated column values (based on auto-increment or sequence). The collection is a list of sets ( List<Set<ResponseValue>> ) since it is also used by the framework for HTTP POSTs with XML/JSON bodies containing multiple requests. For a single insert request, get the first row (index 0). Children are embedded in a ResponseValue named after the child table name (or alias). The value is list of sets ( List<Set<ResponseValue>> ). ResponseValue is ordered by its column number in the set.

Note: API stability is planned for 1.0 release.

restsql.properties changes

A new sequence manager interface and db-specific implementations were added.

New db-specific packages were created and the metadata implementations were moved and renamed.

All serialization classes were moved to a new package.

# DB-specific implementation classes - match the implementation to your database
# For MySQL:
#	org.restsql.core.SequenceManager=org.restsql.core.impl.mysql.MySqlSequenceManager
#	org.restsql.core.SqlResourceMetaData=org.restsql.core.impl.mysql.MySqlSqlResourceMetaData
# For PostgreSQL:
#	org.restsql.core.SequenceManager=org.restsql.core.impl.postgresql.PostgreSqlSequenceManager
#	org.restsql.core.SqlResourceMetaData=org.restsql.core.impl.postgresql.PostgreSqlSqlResourceMetaData
org.restsql.core.SequenceManager=org.restsql.core.impl.mysql.MySqlSequenceManager
org.restsql.core.SqlResourceMetaData=org.restsql.core.impl.mysql.MySqlSqlResourceMetaData

# Implementation classes - use these to customize the framework
...
org.restsql.core.Factory.RequestDeserializerFactory=org.restsql.core.impl.serial.RequestDeserializerFactoryImpl
org.restsql.core.Factory.ResponseSerializerFactory=org.restsql.core.impl.serial.ResponseSerializerFactoryImpl

If you are using MySQL with the built-in implementation classes, none of the preceeding properties are required. Please refer to the following examples:

Migration

HTTP API requests have not changed. HTTP Responses for Insert (POST) requests now embed the inserted objects. Client code will need to change to take consume the returned child elements (XML) or child attributes (JSON).

Java API clients must be changed to use the renamed RequestValue object and to accept the new WriteResponse object on write operations.

Possibly change restsql.properties per above.