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 fd99b60913
3 changed files with 46 additions and 51 deletions

View file

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

View file

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

View file

@ -105,12 +105,6 @@ public class MapperInvocationHandler<E> implements InvocationHandler {
throw new HelenusException("missing default type for enum user type " + returnType); 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; return value;