/** * Get the table name if this is a table-based generator, the sequence name otherwise. * * @return the table or the sequence name */ public String getTable() { return metadata.getName(); }
@Override public Cache<PersistentIdSourceKey, Object> getIdSourceCache(IdSourceKeyMetadata keyMetadata) { return idSourceCaches.get( keyMetadata.getName() ); }
@Override public Cache<PersistentIdSourceKey, Object> getIdSourceCache(IdSourceKeyMetadata keyMetadata) { return idSourceCaches.get( keyMetadata.getName() ); }
@Override public Cache<PerTableSerializableIdSourceKey> getIdSourceCache(IdSourceKeyMetadata keyMetadata) { return idSourceCaches.get( keyMetadata.getName() ); }
private static ConcurrentMap<String, Cache<PersistentIdSourceKey, Object>> initializeIdSourceCaches(EmbeddedCacheManager embeddedCacheManager, Set<IdSourceKeyMetadata> idSourceTypes) { ConcurrentMap<String, Cache<PersistentIdSourceKey, Object>> idSourceCaches = newConcurrentHashMap( idSourceTypes.size() ); for ( IdSourceKeyMetadata idSourceKeyMetadata : idSourceTypes ) { if ( !idSourceCaches.containsKey( idSourceKeyMetadata.getName() ) ) { Cache<PersistentIdSourceKey, Object> idSourceCache = embeddedCacheManager.getCache( idSourceKeyMetadata.getName() ); idSourceCaches.put( idSourceKeyMetadata.getName(), idSourceCache ); } } return idSourceCaches; }
private static ConcurrentMap<String, Cache<PersistentIdSourceKey, Object>> initializeIdSourceCaches(EmbeddedCacheManager embeddedCacheManager, Set<IdSourceKeyMetadata> idSourceTypes) { ConcurrentMap<String, Cache<PersistentIdSourceKey, Object>> idSourceCaches = newConcurrentHashMap( idSourceTypes.size() ); for ( IdSourceKeyMetadata idSourceKeyMetadata : idSourceTypes ) { if ( !idSourceCaches.containsKey( idSourceKeyMetadata.getName() ) ) { Cache<PersistentIdSourceKey, Object> idSourceCache = embeddedCacheManager.getCache( idSourceKeyMetadata.getName() ); idSourceCaches.put( idSourceKeyMetadata.getName(), idSourceCache ); } } return idSourceCaches; }
private static String inferMessageName(IdSourceKeyMetadata idSourceKeyMetadata) { return SanitationUtils.convertNameSafely( idSourceKeyMetadata.getName() ); }
private static Set<String> getCacheNames(Set<EntityKeyMetadata> entityTypes, Set<AssociationKeyMetadata> associationTypes, Set<IdSourceKeyMetadata> idSourceTypes) { Set<String> cacheNames = new HashSet<String>(); for ( EntityKeyMetadata entityKeyMetadata : entityTypes ) { cacheNames.add( entityKeyMetadata.getTable() ); } for ( AssociationKeyMetadata associationKeyMetadata : associationTypes ) { cacheNames.add( getCacheName( associationKeyMetadata ) ); } for ( IdSourceKeyMetadata idSourceKeyMetadata : idSourceTypes ) { cacheNames.add( idSourceKeyMetadata.getName() ); } return cacheNames; }
/** * Adds a unique constraint to make sure that each node of the same "sequence table" is unique. */ private void addUniqueConstraintForTableBasedSequence(List<Statement> statements, IdSourceKeyMetadata generatorKeyMetadata) { Statement statement = createUniqueConstraintStatement( generatorKeyMetadata.getKeyColumnName(), generatorKeyMetadata.getName() ); statements.add( statement ); }
private static Set<String> getCacheNames(Set<EntityKeyMetadata> entityTypes, Set<AssociationKeyMetadata> associationTypes, Set<IdSourceKeyMetadata> idSourceTypes) { Set<String> cacheNames = new HashSet<String>(); for ( EntityKeyMetadata entityKeyMetadata : entityTypes ) { cacheNames.add( entityKeyMetadata.getTable() ); } for ( AssociationKeyMetadata associationKeyMetadata : associationTypes ) { cacheNames.add( getCacheName( associationKeyMetadata ) ); } for ( IdSourceKeyMetadata idSourceKeyMetadata : idSourceTypes ) { cacheNames.add( idSourceKeyMetadata.getName() ); } return cacheNames; }
public void createSequence(IdSourceKeyMetadata metadata, CassandraDatastoreProvider datastoreProvider) { List<String> primaryKeyName = new ArrayList<String>( 1 ); primaryKeyName.add( metadata.getKeyColumnName() ); List<String> columnNames = new ArrayList<String>( 2 ); columnNames.add( metadata.getKeyColumnName() ); columnNames.add( metadata.getValueColumnName() ); List<String> columnTypes = new ArrayList<String>( 2 ); columnTypes.add( "varchar" ); columnTypes.add( "bigint" ); datastoreProvider.createColumnFamilyIfNeeded( metadata.getName(), primaryKeyName, columnNames, columnTypes ); }
private static ConcurrentMap<String, Cache<PerTableSerializableIdSourceKey>> initializeIdSourceCaches(CacheManager embeddedCacheManager, Set<IdSourceKeyMetadata> idSourceTypes) { ConcurrentMap<String, Cache<PerTableSerializableIdSourceKey>> idSourceCaches = newConcurrentHashMap( idSourceTypes.size() ); for ( IdSourceKeyMetadata idSourceKeyMetadata : idSourceTypes ) { String cacheName = idSourceKeyMetadata.getName(); if ( !idSourceCaches.containsKey( cacheName ) ) { idSourceCaches.put( cacheName, new Cache<PerTableSerializableIdSourceKey>( getCache( embeddedCacheManager, cacheName, CacheNames.IDENTIFIER_CACHE ) ) ); } } return idSourceCaches; }
public IgniteCache<String, Long> getIdSourceCache(IdSourceKeyMetadata keyMetadata) { String idSourceCacheName = getEntityCacheName( keyMetadata.getName() ); return getCache( idSourceCacheName, false ); }
private CacheConfiguration createCacheConfiguration(IdSourceKeyMetadata idSourceKeyMetadata) { CacheConfiguration result = new CacheConfiguration(); result.setName( StringHelper.stringBeforePoint( idSourceKeyMetadata.getName() ) ); return result; }
/** * Adds a unique constraint to make sure that each node of the same "sequence table" is unique. */ private void addUniqueConstraintForTableBasedSequence(Statements statements, IdSourceKeyMetadata generatorKeyMetadata) { Statement statement = createUniqueConstraintStatement( generatorKeyMetadata.getKeyColumnName(), generatorKeyMetadata.getName() ); statements.addStatement( statement ); }
protected String sequenceName(IdSourceKey key) { return key.getMetadata().getType() == IdSourceType.SEQUENCE ? key.getMetadata().getName() : key.getColumnValue(); }
public Number getSequenceValue(NextValueRequest request) { final String cacheName = request.getKey().getMetadata().getName(); final SequencesPerCache sequencesSet = sequencesPerCache.computeIfAbsent( cacheName, ( k ) -> { SequenceTableDefinition sequenceTableDefinition = idSchemaPerName.get( cacheName ); if ( sequenceTableDefinition == null ) { throw log.valueRequestedForUnknownSequence( request.getKey().getTable(), request.getKey().getColumnValue() ); } return new SequencesPerCache( provider.getCache( cacheName ) ); } ); return sequencesSet.getSequenceValue( request ); } }
/** * Adds a unique constraint to make sure that each node of the same "sequence table" is unique. */ private void addUniqueConstraintForTableBasedSequence(IdSourceKeyMetadata generatorKeyMetadata) { Label generatorKeyLabel = Label.label( generatorKeyMetadata.getName() ); if ( isMissingUniqueConstraint( generatorKeyLabel ) ) { neo4jDb.schema().constraintFor( generatorKeyLabel ).assertPropertyIsUnique( generatorKeyMetadata.getKeyColumnName() ).create(); } }
/** * Ex.: * <pre> * MERGE (n:hibernate_sequences:TABLE_BASED_SEQUENCE {sequence_name: {sequenceName}}) ON CREATE SET n.current_value = {initialValue} RETURN n * </pre> */ private void addTableSequence(NextValueRequest request) { IdSourceKeyMetadata idSourceKeyMetadata = request.getKey().getMetadata(); String query = "MERGE (n" + labels( idSourceKeyMetadata.getName(), NodeLabel.TABLE_BASED_SEQUENCE.name() ) + " { " + idSourceKeyMetadata.getKeyColumnName() + ": {" + SEQUENCE_NAME_QUERY_PARAM + "}} ) ON CREATE SET n." + idSourceKeyMetadata.getValueColumnName() + " = {" + INITIAL_VALUE_QUERY_PARAM + "} RETURN n"; neo4jDb.execute( query, params( request ) ); }
private Long nextValueInsert(IdSourceKeyMetadata metadata, String sequenceName, Long value) { Insert insert = QueryBuilder.insertInto( quote( metadata.getName() ) ) .value( quote( metadata.getKeyColumnName() ), QueryBuilder.bindMarker( "sequence_name" ) ) .value( quote( metadata.getValueColumnName() ), QueryBuilder.bindMarker( "sequence_value" ) ) .ifNotExists(); PreparedStatement preparedStatement = provider.getSession().prepare( insert.toString() ); BoundStatement boundStatement = preparedStatement.bind(); boundStatement.setString( "sequence_name", sequenceName ); boundStatement.setLong( "sequence_value", value ); try { provider.getSession().execute( boundStatement ); } catch (DriverException e) { throw e; } return nextValueSelect( metadata, sequenceName ); }