Repository navigation
Closed
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Milestone
Description
When writing things like object mappers, the builder pattern tends to get in the way unless it has some generic input methods. Here is for example the Mutation usage I had to do
Mutation.WriteBuilder writeBuilder = Mutation.newInsertOrUpdateBuilder( key.getTable() );
tuplePointer.getTuple().getOperations().forEach( op -> {
switch ( op.getType() ) {
case PUT:
ValueBinder<Mutation.WriteBuilder> set = writeBuilder.set( op.getColumn() );
Object object = op.getValue();
//TODO should we convert to Google Spanner native types here or before?
// e.g. they have their own Date and Timestamp
if ( object instanceof Timestamp ) {
set.to( (Timestamp) object );
}
else if ( object instanceof Date ) {
set.to( (Date) object );
}
else if ( object instanceof String ) {
set.to( (String) object );
}
else if ( object instanceof Long ) {
set.to( (Long) object );
}
else if ( object instanceof Boolean ) {
set.to( (Boolean) object );
}
else if ( object instanceof Double ) {
set.to( (Double) object );
}
break;
case PUT_NULL:
case REMOVE:
// TODO add metadata related to the type of the column we nullify
writeBuilder.set( op.getColumn() ).to( (String) null);
break;
}
} );
databaseClient.write( Arrays.asList( writeBuilder.build() ) );
One improvement could be to offer a generic to(Object) method that does the instanceof check for me.
Another possible improvement (that would not help for my case) is to offer
// ideally if types is optional that's even better
setAll(String[] columnNames, Object[] columnValues, Class[] types);
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Activity
saturnism commentedon Apr 8, 2017
/cc @vkedia
vkedia commentedon Apr 20, 2017
@emmanuelbernard @saturnism I think this is a reasonable request. We can add a
.to(Object)to the ValueBinder class. One hitch here is how to make this method work for arrays sinceinstanceofwill not tell us the type of the iterable.emmanuelbernard commentedon May 3, 2017
@vkedia right. In that case, you could make a pair of explicitly named methods like
toObject(Object)toIterable(Iterable value, Class<?> type).yihanzhen commentedon Jan 11, 2018
The feature request is added to the backlog. The issue will be closed but is linked in the backlog and can continue to be used for comment and discussion.
chore(main): release 3.22.4-SNAPSHOT (#1805)
chore: Update generation configuration at Thu Mar 27 02:26:48 UTC 2025 (
chore(main): release 3.22.4-SNAPSHOT (googleapis#1805)
chore: Update generation configuration at Thu Mar 27 02:26:48 UTC 2025 (
chore(main): release 2.24.1-SNAPSHOT (googleapis#1805)
chore: Set blunderbuss config to auto-assign issues and PRs (#1805)
chore: Set blunderbuss config to auto-assign issues and PRs (#1805)