use of com.helger.commons.mutable.MutableLong in project phoss-smp by phax.
the class SMPIDFactoryJDBC method readAndUpdateIDCounter.
@Override
protected long readAndUpdateIDCounter(@Nonnegative final int nReserveCount) {
final MutableLong aReadValue = new MutableLong(0);
final DBExecutor aExecutor = new SMPDBExecutor();
aExecutor.performInTransaction(() -> {
// Read existing value
final String sExistingValue = SMPSettingsManagerJDBC.getSettingsValue(aExecutor, SETTINGS_KEY_LATEST_ID);
final long nRead = StringParser.parseLong(sExistingValue, m_nInitialCount);
aReadValue.set(nRead);
// Write new value
final long nNewValue = nRead + nReserveCount;
SMPSettingsManagerJDBC.setSettingsValue(aExecutor, SETTINGS_KEY_LATEST_ID, Long.toString(nNewValue));
if (LOGGER.isDebugEnabled())
LOGGER.debug("Updated SQL ID from " + sExistingValue + " to " + nNewValue);
});
return aReadValue.longValue();
}
use of com.helger.commons.mutable.MutableLong in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method updateSMPTransportProfile.
@Nonnull
public EChange updateSMPTransportProfile(@Nullable final String sSMPTransportProfileID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final MutableLong aUpdated = new MutableLong(-1);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_tprofile SET name=?, deprecated=? WHERE id=?", new ConstantPreparedStatementDataProvider(sName, Boolean.valueOf(bIsDeprecated), sSMPTransportProfileID));
aUpdated.set(nUpdated);
});
if (eSuccess.isFailure()) {
// DB error
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "database-error");
return EChange.UNCHANGED;
}
if (aUpdated.is0()) {
// No such transport profile ID
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditModifySuccess(SMPTransportProfile.OT, "update", sSMPTransportProfileID, sName, Boolean.valueOf(bIsDeprecated));
return EChange.CHANGED;
}
use of com.helger.commons.mutable.MutableLong in project ph-commons by phax.
the class MutableTypeConverterRegistrar method registerTypeConverter.
public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) {
// MutableBigDecimal
aRegistry.registerTypeConverter(MutableBigDecimal.class, BigDecimal.class, MutableBigDecimal::getAsBigDecimal);
aRegistry.registerTypeConverter(BigDecimal.class, MutableBigDecimal.class, MutableBigDecimal::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBigDecimal.class, MutableBigDecimal::getAsBigDecimal);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBigDecimal.class, aSource -> new MutableBigDecimal(TypeConverter.convert(aSource, BigDecimal.class)));
// MutableBigInteger
aRegistry.registerTypeConverter(MutableBigInteger.class, BigInteger.class, MutableBigInteger::getAsBigInteger);
aRegistry.registerTypeConverter(BigInteger.class, MutableBigInteger.class, MutableBigInteger::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBigInteger.class, MutableBigInteger::getAsBigInteger);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBigInteger.class, aSource -> new MutableBigInteger(TypeConverter.convert(aSource, BigInteger.class)));
// MutableBoolean
aRegistry.registerTypeConverter(MutableBoolean.class, Boolean.class, MutableBoolean::getAsBoolean);
aRegistry.registerTypeConverter(Boolean.class, MutableBoolean.class, MutableBoolean::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBoolean.class, MutableBoolean::getAsBoolean);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBoolean.class, aSource -> new MutableBoolean(TypeConverter.convert(aSource, Boolean.class)));
// MutableByte
aRegistry.registerTypeConverter(MutableByte.class, Byte.class, MutableByte::getAsByte);
aRegistry.registerTypeConverter(Byte.class, MutableByte.class, MutableByte::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableByte.class, MutableByte::getAsByte);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableByte.class, aSource -> new MutableByte(TypeConverter.convert(aSource, Byte.class)));
// MutableChar
aRegistry.registerTypeConverter(MutableChar.class, Character.class, MutableChar::getAsCharacter);
aRegistry.registerTypeConverter(Character.class, MutableChar.class, MutableChar::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableChar.class, MutableChar::getAsCharacter);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableChar.class, aSource -> new MutableChar(TypeConverter.convert(aSource, Character.class)));
// MutableDouble
aRegistry.registerTypeConverter(MutableDouble.class, Double.class, MutableDouble::getAsDouble);
aRegistry.registerTypeConverter(Double.class, MutableDouble.class, MutableDouble::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableDouble.class, MutableDouble::getAsDouble);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableDouble.class, aSource -> new MutableDouble(TypeConverter.convert(aSource, Double.class)));
// MutableFloat
aRegistry.registerTypeConverter(MutableFloat.class, Float.class, MutableFloat::getAsFloat);
aRegistry.registerTypeConverter(Float.class, MutableFloat.class, MutableFloat::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableFloat.class, MutableFloat::getAsFloat);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableFloat.class, aSource -> new MutableFloat(TypeConverter.convert(aSource, Float.class)));
// MutableInt
aRegistry.registerTypeConverter(MutableInt.class, Integer.class, MutableInt::getAsInteger);
aRegistry.registerTypeConverter(Integer.class, MutableInt.class, MutableInt::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableInt.class, MutableInt::getAsInteger);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableInt.class, aSource -> new MutableInt(TypeConverter.convert(aSource, Integer.class)));
// MutableLong
aRegistry.registerTypeConverter(MutableLong.class, Long.class, MutableLong::getAsLong);
aRegistry.registerTypeConverter(Long.class, MutableLong.class, MutableLong::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableLong.class, MutableLong::getAsLong);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableLong.class, aSource -> new MutableLong(TypeConverter.convert(aSource, Long.class)));
// MutableShort
aRegistry.registerTypeConverter(MutableShort.class, Short.class, MutableShort::getAsShort);
aRegistry.registerTypeConverter(Short.class, MutableShort.class, MutableShort::new);
aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableShort.class, MutableShort::getAsShort);
aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableShort.class, aSource -> new MutableShort(TypeConverter.convert(aSource, Short.class)));
}
use of com.helger.commons.mutable.MutableLong in project ph-commons by phax.
the class StreamHelperTest method testCopyReaderToWriter.
@Test
@SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION")
public void testCopyReaderToWriter() {
final String sInput = "Hallo";
NonBlockingStringReader aBAIS = new NonBlockingStringReader(sInput);
final NonBlockingStringWriter aBAOS = new NonBlockingStringWriter();
assertTrue(StreamHelper.copyReaderToWriter(aBAIS, aBAOS).isSuccess());
assertEquals(sInput, aBAOS.getAsString());
// try with null streams
aBAIS = new NonBlockingStringReader(sInput);
assertTrue(StreamHelper.copyReaderToWriter(aBAIS, null).isFailure());
assertTrue(StreamHelper.copyReaderToWriter(null, aBAOS).isFailure());
aBAIS = new NonBlockingStringReader(sInput);
assertTrue(StreamHelper.copyReaderToWriter(aBAIS, aBAOS, new char[10]).isSuccess());
final MutableLong aML = new MutableLong(0);
aBAIS = new NonBlockingStringReader(sInput);
assertTrue(StreamHelper.copyReaderToWriter(aBAIS, false, aBAOS, false, new char[10], null, null, aML).isSuccess());
assertEquals(aML.longValue(), sInput.length());
// Must be a ByteArrayReader so that an IOException can be thrown!
assertTrue(StreamHelper.copyReaderToWriter(new WrappedReader(aBAIS) {
@Override
public int read(final char[] aBuf, final int nOfs, final int nLen) throws IOException {
throw new MockIOException();
}
}, aBAOS).isFailure());
// null buffer
StreamHelper.copyReaderToWriter(aBAIS, aBAOS, (char[]) null);
// empty buffer
StreamHelper.copyReaderToWriter(aBAIS, aBAOS, new char[0]);
}
Aggregations