Remove Integer/Enum conversion, it wasn't necessary.

This commit is contained in:
Greg Burd 2017-08-09 11:49:38 -04:00
parent 512cb0f608
commit fa39908f4c
3 changed files with 47 additions and 51 deletions

View file

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.helenus</groupId>
<artifactId>helenus-core</artifactId>
<version>2.0.11-SNAPSHOT</version>
<version>2.0.12-SNAPSHOT</version>
<packaging>jar</packaging>
<name>helenus</name>

View file

@ -10,56 +10,58 @@ import java.util.function.Function;
*/
public class UnitOfWork {
private final HelenusSession session;
private ArrayList<UnitOfWork> nested;
private final HelenusSession session;
private ArrayList<UnitOfWork> nested;
UnitOfWork(HelenusSession session) {
this.session = session;
// log.record(txn::start)
}
UnitOfWork(HelenusSession session) {
this.session = session;
// log.record(txn::start)
}
/**
* Marks the beginning of a transactional section of work. Will write a record
* to the shared write-ahead log.
*
* @return the handle used to commit or abort the work.
*/
public UnitOfWork begin() {
if (nested == null) {
nested = new ArrayList<UnitOfWork>();
}
UnitOfWork unitOfWork = new UnitOfWork(session);
nested.add(unitOfWork);
return unitOfWork;
}
/**
* Marks the beginning of a transactional section of work. Will write a record
* to the shared write-ahead log.
*
* @return the handle used to commit or abort the work.
*/
public UnitOfWork begin() {
if (nested == null) {
nested = new ArrayList<UnitOfWork>();
}
UnitOfWork unitOfWork = new UnitOfWork(session);
nested.add(unitOfWork);
return unitOfWork;
}
/**
* Checks to see if the work performed between calling begin and now can be
* committed or not.
*
/**
* Checks to see if the work performed between calling begin and now can be
* committed or not.
*
* @return a function from which to chain work that only happens when commit is successful
* @throws ConflictingUnitOfWorkException
* when the work overlaps with other concurrent writers.
*/
public Function<Void, Void> commit() throws ConflictingUnitOfWorkException {
nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit));
// log.record(txn::provisionalCommit)
// examine log for conflicts in read-set and write-set between begin and provisional commit
// if (conflict) { throw new ConflictingUnitOfWorkException(this) }
* @throws ConflictingUnitOfWorkException when the work overlaps with other concurrent writers.
*/
public Function<Void, Void> commit() throws ConflictingUnitOfWorkException {
if (nested != null) {
nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit));
}
// log.record(txn::provisionalCommit)
// examine log for conflicts in read-set and write-set between begin and provisional commit
// if (conflict) { throw new ConflictingUnitOfWorkException(this) }
// else return function so as to enable commit.andThen(() -> { do something iff commit was successful; })
return Function.<Void>identity();
}
return Function.<Void>identity();
}
/**
* Explicitly discard the work and mark it as as such in the log.
*/
public void abort() {
// log.record(txn::abort)
// cache.invalidateSince(txn::start time)
}
/**
* Explicitly discard the work and mark it as as such in the log.
*/
public void abort() {
// log.record(txn::abort)
// cache.invalidateSince(txn::start time)
}
public String describeConflicts() {
return "it's complex...";
}
public String describeConflicts() {
return "it's complex...";
}
}
:q

View file

@ -105,12 +105,6 @@ public class MapperInvocationHandler<E> implements InvocationHandler {
throw new HelenusException("missing default type for enum user type " + returnType);
}
} else if (returnType.isEnum() && (value.getClass() == Integer.class || value.getClass() == int.class)) {
try {
value = Class.forName(returnType.getName()).getEnumConstants()[(Integer) value];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid ordinal " + value + " for enum type " + returnType.getSimpleName());
}
}
return value;