use of org.neo4j.token.TokenCreator in project neo4j by neo4j.
the class RecordStorageEngineFactory method createMigrationTargetSchemaRuleAccess.
public static SchemaRuleMigrationAccess createMigrationTargetSchemaRuleAccess(NeoStores stores, CursorContext cursorContext, MemoryTracker memoryTracker) {
SchemaStore dstSchema = stores.getSchemaStore();
TokenCreator propertyKeyTokenCreator = (name, internal) -> {
PropertyKeyTokenStore keyTokenStore = stores.getPropertyKeyTokenStore();
DynamicStringStore nameStore = keyTokenStore.getNameStore();
byte[] bytes = PropertyStore.encodeString(name);
List<DynamicRecord> nameRecords = new ArrayList<>();
AbstractDynamicStore.allocateRecordsFromBytes(nameRecords, bytes, nameStore, cursorContext, memoryTracker);
nameRecords.forEach(record -> nameStore.prepareForCommit(record, cursorContext));
nameRecords.forEach(record -> nameStore.updateRecord(record, cursorContext));
nameRecords.forEach(record -> nameStore.setHighestPossibleIdInUse(record.getId()));
int nameId = Iterables.first(nameRecords).getIntId();
PropertyKeyTokenRecord keyTokenRecord = keyTokenStore.newRecord();
long tokenId = keyTokenStore.nextId(cursorContext);
keyTokenRecord.setId(tokenId);
keyTokenRecord.initialize(true, nameId);
keyTokenRecord.setInternal(internal);
keyTokenRecord.setCreated();
keyTokenStore.prepareForCommit(keyTokenRecord, cursorContext);
keyTokenStore.updateRecord(keyTokenRecord, cursorContext);
keyTokenStore.setHighestPossibleIdInUse(keyTokenRecord.getId());
return Math.toIntExact(tokenId);
};
TokenHolders dstTokenHolders = tokenHoldersForSchemaStore(stores, propertyKeyTokenCreator, cursorContext);
return new SchemaRuleMigrationAccessImpl(stores, new SchemaStorage(dstSchema, dstTokenHolders, () -> KernelVersion.LATEST), cursorContext, memoryTracker);
}
use of org.neo4j.token.TokenCreator in project neo4j by neo4j.
the class SchemaStorageReadAndWriteTest method before.
@BeforeAll
void before() throws Exception {
testDirectory.prepareDirectory(getClass(), "test");
var storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
neoStores = storeFactory.openNeoStores(true, StoreType.SCHEMA, StoreType.PROPERTY_KEY_TOKEN, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN);
AtomicInteger tokenIdCounter = new AtomicInteger();
TokenCreator tokenCreator = (name, internal) -> tokenIdCounter.incrementAndGet();
TokenHolders tokens = new TokenHolders(new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
tokens.setInitialTokens(StoreTokens.allTokens(neoStores), NULL);
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.propertyKeyTokens().size()));
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.labelTokens().size()));
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.relationshipTypeTokens().size()));
storage = new SchemaStorage(neoStores.getSchemaStore(), tokens, () -> KernelVersion.LATEST);
}
Aggregations