@Test public void destroy() throws Exception { StateRecord r1 = ledger.findOrCreate(HashId.createRandom()); r1.destroy(); assertNull(ledger.getRecord(r1.getId())); }
@Override public void destroy(StateRecord record) { long recordId = record.getRecordId(); if (recordId == 0) { throw new IllegalStateException("can't destroy record without recordId"); } protect(() -> { inPool(d -> { d.update("DELETE FROM ledger WHERE id = ?", recordId); return null; }); synchronized (cachedRecords) { cachedRecords.remove(record.getId()); } synchronized (cachedRecordsById) { cachedRecordsById.remove(record.getRecordId()); } return null; }); }
PostgresLedger implements Ledger { @Override public void destroy(StateRecord record) { long recordId = record.getRecordId(); if (recordId == 0) { throw new IllegalStateException("can't destroy record without recordId"); } protect(() -> { inPool(d -> { d.update("DELETE FROM ledger WHERE id = ?", recordId); return null; }); synchronized (cachedRecords) { cachedRecords.remove(record.getId()); } synchronized (cachedRecordsById) { cachedRecordsById.remove(record.getRecordId()); } return null; }); } }
PostgresLedger implements Ledger { @Override public void destroy(StateRecord record) { long recordId = record.getRecordId(); if (recordId == 0) { throw new IllegalStateException("can't destroy record without recordId"); } protect(() -> { inPool(d -> { d.update("DELETE FROM ledger WHERE id = ?", recordId); return null; }); synchronized (cachedRecords) { cachedRecords.remove(record.getId()); } synchronized (cachedRecordsById) { cachedRecordsById.remove(record.getRecordId()); } return null; }); } PostgresLedger(String connectionString, Properties properties);  PostgresLedger(String connectionString); }
PostgresLedger implements Ledger { @Override public void destroy(StateRecord record) { long recordId = record.getRecordId(); if (recordId == 0) { throw new IllegalStateException("can't destroy record without recordId"); } protect(() -> { inPool(d -> { d.update("DELETE FROM ledger WHERE id = ?", recordId); return null; }); synchronized (cachedRecords) { cachedRecords.remove(record.getId()); } synchronized (cachedRecordsById) { cachedRecordsById.remove(record.getRecordId()); } return null; }); } PostgresLedger(String connectionString, Properties properties);  PostgresLedger(String connectionString); final T inPool(DbPool.DbConsumer<T> consumer); @Override StateRecord getRecord(HashId itemId); @Override StateRecord createOutputLockRecord(long creatorRecordId, HashId newItemHashId); @Override StateRecord getLockOwnerOf(StateRecord rc); @Override StateRecord findOrCreate(HashId itemId); @Override Map<HashId,StateRecord> findUnfinished(); @Override Approvable getItem(final StateRecord record); @Override void putItem(StateRecord record, Approvable item, Instant keepTill); @Override byte[] getKeepingItem(HashId itemId); @Override @Deprecated Object getKeepingByOrigin(HashId origin, int limit); @Override Binder getKeepingBy(String field, HashId id, Binder tags, int limit, int offset, String sortBy, String sortOrder); @Override void putKeepingItem(StateRecord record, Approvable item); @Override void close(); @Override long countRecords(); @Override Map<ItemState, Integer> getLedgerSize(ZonedDateTime createdAfter); @Override T transaction(Callable<T> callable); void testClearLedger(); @Override void destroy(StateRecord record); @Override void markTestRecord(HashId hash); @Override boolean isTestnet(HashId itemId); @Override void save(StateRecord stateRecord); @Override void reload(StateRecord stateRecord); void enableCache(boolean enable); Db getDb(); @Override void saveConfig(NodeInfo myInfo, NetConfig netConfig, PrivateKey nodeKey); @Override Object[] loadConfig(); @Override void addNode(NodeInfo nodeInfo); @Override void removeNode(NodeInfo nodeInfo); void cleanup(boolean isPermanetMode); void savePayment(int amount, ZonedDateTime date); Map<Integer,Integer> getPayments(ZonedDateTime fromDate); @Override NImmutableEnvironment getEnvironment(long environmentId); @Override NImmutableEnvironment getEnvironment(HashId contractId); @Override NImmutableEnvironment getEnvironment(NSmartContract smartContract); @Override void updateSubscriptionInStorage(long subscriptionId, ZonedDateTime expiresAt); @Override void updateStorageExpiresAt(long storageId, ZonedDateTime expiresAt); @Override void saveFollowerEnvironment(long environmentId, ZonedDateTime expiresAt, ZonedDateTime mutedAt, double spent, int startedCallbacks); @Override void updateNameRecord(long nameRecordId, ZonedDateTime expiresAt); @Override Set<HashId> saveEnvironment(NImmutableEnvironment environment); @Override Set<HashId> findBadReferencesOf(Set<HashId> ids); @Override long saveSubscriptionInStorage(HashId hashId, boolean subscriptionOnChain, ZonedDateTime expiresAt, long environmentId); @Override void clearExpiredSubscriptions(); @Override void clearExpiredStorages(); @Override void clearExpiredStorageContractBinaries(); @Override void updateEnvironment(long id, String ncontractType, HashId ncontractHashId, byte[] kvStorage, byte[] transactionPack); @Override Set<Long> getSubscriptionEnviromentIds(HashId id); @Override NCallbackService.FollowerCallbackState getFollowerCallbackStateById(HashId id); @Override Collection<CallbackRecord> getFollowerCallbacksToResyncByEnvId(long environmentId); @Override Collection<CallbackRecord> getFollowerCallbacksToResync(); @Override void addFollowerCallback(HashId id, long environmentId, ZonedDateTime expiresAt, ZonedDateTime storedUntil); @Override void updateFollowerCallbackState(HashId id, NCallbackService.FollowerCallbackState state); @Override void removeFollowerCallback(HashId id); @Override byte[] getSmartContractById(HashId smartContractId); @Override byte[] getContractInStorage(HashId contractId); @Override byte[] getContractInStorage(HashId slotId, HashId contractId); @Override List<byte[]> getContractsInStorageByOrigin(HashId slotId, HashId originId); @Override void removeEnvironmentSubscription(long subscriptionId); @Override void removeEnvironmentStorage(long storageId); @Override long removeEnvironment(HashId ncontractHashId); long getEnvironmentId(HashId ncontractHashId); void removeSubscriptionsByEnvId(long environmentId); void removeStorageContractsByEnvId(long environmentId); @Override void removeExpiredStoragesAndSubscriptionsCascade(); @Override void addNameRecord(final NNameRecord nameRecord); @Override long saveContractInStorage(HashId contractId, byte[] binData, ZonedDateTime expiresAt, HashId origin, long environmentId); @Override void removeNameRecord(NNameRecord nameRecord); @Override void addNameRecordEntry(final NNameRecordEntry nameRecordEntryModel); @Override void removeNameRecordEntry(NNameRecordEntry nameRecordEntry); @Override List<String> isAllNameRecordsAvailable(final Collection<String> reducedNames); @Override List<String> isAllOriginsAvailable(final Collection<HashId> origins); @Override List<String> isAllAddressesAvailable(final Collection<String> addresses); void clearExpiredNameRecords(Duration holdDuration); @Override @Deprecated NNameRecord getNameRecord(final String name); @Override Set<NNameRecord> getNameRecords(final String name); @Override List<NNameRecordEntry> getNameEntries(final long environmentId); @Override @Deprecated List<NNameRecordEntry> getNameEntries(final String nameReduced); @Override List<NNameRecord> getNamesByAddress(String address); @Override List<NNameRecord> getNamesByOrigin(byte[] origin); @Override VoteInfo initiateVoting(Contract contract, ZonedDateTime expiresAt, String roleName, Set<HashId> candidates); @Override VoteInfo getVotingInfo(HashId votingItem); @Override void addVotes(long votingId, long candidateId, List<KeyAddress> votes); @Override List<VoteResult> getVotes(HashId itemId, boolean queryAddresses); @Override void closeVote(HashId itemId); @Override void saveUbotSession(UbotSessionCompact sessionCompact); void saveUbotStorages(HashId executableContractId, ZonedDateTime expiresAt, Map<String, HashId> storages); @Override void saveUbotStorageValue(HashId executableContractId, ZonedDateTime expiresAt, String storageName, HashId value); @Override HashId getUbotStorageValue(HashId executableContractId, String storageName); @Override void getUbotStorages(HashId executableContractId, Map<String, HashId> dest); @Override UbotSessionCompact loadUbotSession(HashId executableContractId); @Override UbotSessionCompact loadUbotSessionByRequestId(HashId requestId); @Override UbotSessionCompact loadUbotSessionById(HashId sessionId); @Override boolean hasUbotSession(HashId executableContractId); @Override void deleteUbotSession(HashId executableContractId); @Override void deleteExpiredUbotSessions(); @Override void deleteExpiredUbotStorages(); @Override void saveUbotTransaction(HashId executableContractId, String transactionName, Binder state); @Override Binder loadUbotTransaction(HashId executableContractId, String transactionName); }
PostgresLedger implements Ledger { @Override public void destroy(StateRecord record) { long recordId = record.getRecordId(); if (recordId == 0) { throw new IllegalStateException("can't destroy record without recordId"); } protect(() -> { inPool(d -> { d.update("DELETE FROM ledger WHERE id = ?", recordId); return null; }); synchronized (cachedRecords) { cachedRecords.remove(record.getId()); } synchronized (cachedRecordsById) { cachedRecordsById.remove(record.getRecordId()); } return null; }); } PostgresLedger(String connectionString, Properties properties);  PostgresLedger(String connectionString); final T inPool(DbPool.DbConsumer<T> consumer); @Override StateRecord getRecord(HashId itemId); @Override StateRecord createOutputLockRecord(long creatorRecordId, HashId newItemHashId); @Override StateRecord getLockOwnerOf(StateRecord rc); @Override StateRecord findOrCreate(HashId itemId); @Override Map<HashId,StateRecord> findUnfinished(); @Override Approvable getItem(final StateRecord record); @Override void putItem(StateRecord record, Approvable item, Instant keepTill); @Override byte[] getKeepingItem(HashId itemId); @Override @Deprecated Object getKeepingByOrigin(HashId origin, int limit); @Override Binder getKeepingBy(String field, HashId id, Binder tags, int limit, int offset, String sortBy, String sortOrder); @Override void putKeepingItem(StateRecord record, Approvable item); @Override void close(); @Override long countRecords(); @Override Map<ItemState, Integer> getLedgerSize(ZonedDateTime createdAfter); @Override T transaction(Callable<T> callable); void testClearLedger(); @Override void destroy(StateRecord record); @Override void markTestRecord(HashId hash); @Override boolean isTestnet(HashId itemId); @Override void save(StateRecord stateRecord); @Override void reload(StateRecord stateRecord); void enableCache(boolean enable); Db getDb(); @Override void saveConfig(NodeInfo myInfo, NetConfig netConfig, PrivateKey nodeKey); @Override Object[] loadConfig(); @Override void addNode(NodeInfo nodeInfo); @Override void removeNode(NodeInfo nodeInfo); void cleanup(boolean isPermanetMode); void savePayment(int amount, ZonedDateTime date); Map<Integer,Integer> getPayments(ZonedDateTime fromDate); @Override NImmutableEnvironment getEnvironment(long environmentId); @Override NImmutableEnvironment getEnvironment(HashId contractId); @Override NImmutableEnvironment getEnvironment(NSmartContract smartContract); @Override void updateSubscriptionInStorage(long subscriptionId, ZonedDateTime expiresAt); @Override void updateStorageExpiresAt(long storageId, ZonedDateTime expiresAt); @Override void saveFollowerEnvironment(long environmentId, ZonedDateTime expiresAt, ZonedDateTime mutedAt, double spent, int startedCallbacks); @Override void updateNameRecord(long nameRecordId, ZonedDateTime expiresAt); @Override Set<HashId> saveEnvironment(NImmutableEnvironment environment); @Override Set<HashId> findBadReferencesOf(Set<HashId> ids); @Override long saveSubscriptionInStorage(HashId hashId, boolean subscriptionOnChain, ZonedDateTime expiresAt, long environmentId); @Override void clearExpiredSubscriptions(); @Override void clearExpiredStorages(); @Override void clearExpiredStorageContractBinaries(); @Override void updateEnvironment(long id, String ncontractType, HashId ncontractHashId, byte[] kvStorage, byte[] transactionPack); @Override Set<Long> getSubscriptionEnviromentIds(HashId id); @Override NCallbackService.FollowerCallbackState getFollowerCallbackStateById(HashId id); @Override Collection<CallbackRecord> getFollowerCallbacksToResyncByEnvId(long environmentId); @Override Collection<CallbackRecord> getFollowerCallbacksToResync(); @Override void addFollowerCallback(HashId id, long environmentId, ZonedDateTime expiresAt, ZonedDateTime storedUntil); @Override void updateFollowerCallbackState(HashId id, NCallbackService.FollowerCallbackState state); @Override void removeFollowerCallback(HashId id); @Override byte[] getSmartContractById(HashId smartContractId); @Override byte[] getContractInStorage(HashId contractId); @Override byte[] getContractInStorage(HashId slotId, HashId contractId); @Override List<byte[]> getContractsInStorageByOrigin(HashId slotId, HashId originId); @Override void removeEnvironmentSubscription(long subscriptionId); @Override void removeEnvironmentStorage(long storageId); @Override long removeEnvironment(HashId ncontractHashId); long getEnvironmentId(HashId ncontractHashId); void removeSubscriptionsByEnvId(long environmentId); void removeStorageContractsByEnvId(long environmentId); @Override void removeExpiredStoragesAndSubscriptionsCascade(); @Override void addNameRecord(final NNameRecord nameRecord); @Override long saveContractInStorage(HashId contractId, byte[] binData, ZonedDateTime expiresAt, HashId origin, long environmentId); @Override void removeNameRecord(NNameRecord nameRecord); @Override void addNameRecordEntry(final NNameRecordEntry nameRecordEntryModel); @Override void removeNameRecordEntry(NNameRecordEntry nameRecordEntry); @Override List<String> isAllNameRecordsAvailable(final Collection<String> reducedNames); @Override List<String> isAllOriginsAvailable(final Collection<HashId> origins); @Override List<String> isAllAddressesAvailable(final Collection<String> addresses); void clearExpiredNameRecords(Duration holdDuration); @Override @Deprecated NNameRecord getNameRecord(final String name); @Override Set<NNameRecord> getNameRecords(final String name); @Override List<NNameRecordEntry> getNameEntries(final long environmentId); @Override @Deprecated List<NNameRecordEntry> getNameEntries(final String nameReduced); @Override List<NNameRecord> getNamesByAddress(String address); @Override List<NNameRecord> getNamesByOrigin(byte[] origin); @Override VoteInfo initiateVoting(Contract contract, ZonedDateTime expiresAt, String roleName, Set<HashId> candidates); @Override VoteInfo getVotingInfo(HashId votingItem); @Override void addVotes(long votingId, long candidateId, List<KeyAddress> votes); @Override List<VoteResult> getVotes(HashId itemId, boolean queryAddresses); @Override void closeVote(HashId itemId); @Override void saveUbotSession(UbotSessionCompact sessionCompact); void saveUbotStorages(HashId executableContractId, ZonedDateTime expiresAt, Map<String, HashId> storages); @Override void saveUbotStorageValue(HashId executableContractId, ZonedDateTime expiresAt, String storageName, HashId value); @Override HashId getUbotStorageValue(HashId executableContractId, String storageName); @Override void getUbotStorages(HashId executableContractId, Map<String, HashId> dest); @Override UbotSessionCompact loadUbotSession(HashId executableContractId); @Override UbotSessionCompact loadUbotSessionByRequestId(HashId requestId); @Override UbotSessionCompact loadUbotSessionById(HashId sessionId); @Override boolean hasUbotSession(HashId executableContractId); @Override void deleteUbotSession(HashId executableContractId); @Override void deleteExpiredUbotSessions(); @Override void deleteExpiredUbotStorages(); @Override void saveUbotTransaction(HashId executableContractId, String transactionName, Binder state); @Override Binder loadUbotTransaction(HashId executableContractId, String transactionName); final static String SEARCH_TAGS; }