protected void addKeyValuesFromKeyName( EntityKeyMetadata entityKeyMetadata, String prefix, String key, Entity document) { if ( key.startsWith( prefix ) ) { String keyWithoutPrefix = getKeyWithoutTablePrefix( prefix, key ); Map<String, Object> keys = keyStringToMap( entityKeyMetadata, keyWithoutPrefix ); for ( Map.Entry<String, Object> entry : keys.entrySet() ) { document.set( entry.getKey(), entry.getValue() ); } } }
protected void addKeyValuesFromKeyName( EntityKeyMetadata entityKeyMetadata, String prefix, String key, Map<String, String> document) { if ( key.startsWith( prefix ) ) { String keyWithoutPrefix = key.substring( prefix.length() ); Map<String, String> keys = keyToMap( entityKeyMetadata, keyWithoutPrefix ); for ( Map.Entry<String, String> entry : keys.entrySet() ) { document.put( entry.getKey(), entry.getValue() ); } } }
public IgniteTupleSnapshot(Object id, BinaryObject binaryObject, EntityKeyMetadata keyMetadata) { this.id = id; this.binaryObject = binaryObject; this.keyMetadata = keyMetadata; Set<String> idColumnNames = new HashSet<>(); for ( String columnName : keyMetadata.getColumnNames() ) { if ( keyMetadata.isKeyColumn( columnName ) ) { idColumnNames.add( columnName ); } } if ( idColumnNames.isEmpty() ) { throw new UnsupportedOperationException( "There is no id column in entity " + keyMetadata.getTable() + ". Hmm..." ); } this.isSimpleId = idColumnNames.size() == 1; this.columnNames = CollectionHelper.asSet( keyMetadata.getColumnNames() ); }
private CacheConfiguration<?,?> createEntityCacheConfiguration(EntityKeyMetadata entityKeyMetadata, SchemaDefinitionContext context) { CacheConfiguration<?,?> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setStoreKeepBinary( true ); cacheConfiguration.setSqlSchema( QueryUtils.DFLT_SCHEMA ); cacheConfiguration.setBackups( 1 ); cacheConfiguration.setName( StringHelper.stringBeforePoint( entityKeyMetadata.getTable() ) ); cacheConfiguration.setAtomicityMode( CacheAtomicityMode.TRANSACTIONAL ); QueryEntity queryEntity = new QueryEntity(); queryEntity.setTableName( entityKeyMetadata.getTable() ); queryEntity.setKeyType( getEntityIdClassName( entityKeyMetadata.getTable(), context ).getSimpleName() ); queryEntity.setValueType( StringHelper.stringAfterPoint( entityKeyMetadata.getTable() ) ); addTableInfo( queryEntity, context, entityKeyMetadata.getTable() ); for ( AssociationKeyMetadata associationKeyMetadata : context.getAllAssociationKeyMetadata() ) { if ( associationKeyMetadata.getAssociationKind() != AssociationKind.EMBEDDED_COLLECTION && associationKeyMetadata.getTable().equals( entityKeyMetadata.getTable() ) && !IgniteAssociationSnapshot.isThirdTableAssociation( associationKeyMetadata ) ) { appendIndex( queryEntity, associationKeyMetadata, context ); } } log.debugf( "queryEntity: %s", queryEntity ); cacheConfiguration.setQueryEntities( Arrays.asList( queryEntity ) ); return cacheConfiguration; }
/** * Deconstruct the key name into its components: * Single key: Use the value from the key * Multiple keys: De-serialize the JSON map. */ protected Map<String, Object> keyStringToMap(EntityKeyMetadata entityKeyMetadata, String key) { if ( entityKeyMetadata.getColumnNames().length == 1 ) { return Collections.singletonMap( entityKeyMetadata.getColumnNames()[0], (Object) key ); } return strategy.deserialize( key, Map.class ); }
/** * Deconstruct the key name into its components: * Single key: Use the value from the key * Multiple keys: De-serialize the JSON map. */ @SuppressWarnings("unchecked") protected Map<String, String> keyToMap(EntityKeyMetadata entityKeyMetadata, String key) { if ( entityKeyMetadata.getColumnNames().length == 1 ) { return Collections.singletonMap( entityKeyMetadata.getColumnNames()[0], key ); } return strategy.deserialize( key, Map.class ); }
@Override public void forEachTuple(final ModelConsumer consumer, TupleTypeContext tupleTypeContext, EntityKeyMetadata entityKeyMetadata) { KeyScanCursor<String> cursor = null; String prefix = entityKeyMetadata.getTable() + ":"; ScanArgs scanArgs = ScanArgs.Builder.matches( prefix + "*" ); do { cursor = scan( cursor, scanArgs ); consumer.consume( new RedisJsonDialectTuplesSupplier( cursor, entityStorageStrategy, prefix, entityKeyMetadata ) ); } while ( !cursor.isFinished() ); }
@Override public void forEachTuple(ModelConsumer consumer, TupleTypeContext tupleTypeContext, EntityKeyMetadata entityKeyMetadata) { KeyScanCursor<String> cursor = null; String prefix = entityKeyMetadata.getTable() + ":"; ScanArgs scanArgs = ScanArgs.Builder.matches( prefix + "*" ); do { cursor = scan( cursor, scanArgs ); consumer.consume( new RedisHashDialectTuplesSupplier( cursor, connection, prefix, entityKeyMetadata ) ); } while ( !cursor.isFinished() ); }
public IgniteAssociationRowSnapshot(Object id, BinaryObject binaryObject, AssociationKeyMetadata associationMetadata) { this.id = id; this.binaryObject = binaryObject; this.associationMetadata = associationMetadata; this.thirdTableLink = IgniteAssociationSnapshot.isThirdTableAssociation( associationMetadata ); if ( this.thirdTableLink ) { Set<String> cn = new HashSet<>(); Collections.addAll( cn, associationMetadata.getRowKeyColumnNames() ); Collections.addAll( cn, associationMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns() ); this.columnNames = Collections.unmodifiableSet( cn ); this.isSimpleId = true; //vk: not used in this case } else { Set<String> idColumnNames = new HashSet<>(); EntityKeyMetadata entityKeyMetadata = associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); for ( String columnName : entityKeyMetadata.getColumnNames() ) { if ( entityKeyMetadata.isKeyColumn( columnName ) ) { idColumnNames.add( columnName ); } } if ( idColumnNames.isEmpty() ) { throw new UnsupportedOperationException( "There is no id column in entity " + entityKeyMetadata.getTable() + ". Hmm..." ); } this.columnNames = CollectionHelper.asSet( entityKeyMetadata.getColumnNames() ); this.isSimpleId = idColumnNames.size() == 1; } }
/** * Finds key type name for cache for entities with composite id * @param keyMetadata * @return */ private String findKeyType(EntityKeyMetadata keyMetadata) { String result = compositeIdTypes.get( keyMetadata.getTable() ); if ( result == null ) { String cacheType = getEntityTypeName( keyMetadata.getTable() ); IgniteCache<Object, BinaryObject> cache = getEntityCache( keyMetadata ); CacheConfiguration cacheConfig = cache.getConfiguration( CacheConfiguration.class ); if ( cacheConfig.getQueryEntities() != null ) { for ( QueryEntity qe : (Collection<QueryEntity>) cacheConfig.getQueryEntities() ) { if ( qe.getValueType() != null && cacheType.equalsIgnoreCase( qe.getValueType() ) ) { result = qe.getKeyType(); break; } } } if ( result == null ) { if ( cacheConfig.getKeyType() != null ) { result = cacheConfig.getKeyType().getSimpleName(); } if ( result == null ) { // if nothing found we use id field name result = StringHelper.stringBeforePoint( keyMetadata.getColumnNames()[0] ); result = StringUtils.capitalize( result ); } } compositeIdTypes.put( keyMetadata.getTable(), result ); } return result; }
static LightblueEntityMetadataId extractEntityInfo(EntityKeyMetadata keyMetadata) { Matcher entityVersionMatcher = LIGHTBLUE_TABLE_PATTERN.matcher(keyMetadata.getTable()); if (!entityVersionMatcher.matches()) { throw new IllegalArgumentException("table does not match lightblue table format: {entityName}/{version}"); } String entityVersion = entityVersionMatcher.group(3); if (entityVersion == null || entityVersion.length() > 0) { entityVersion = null; } return new LightblueEntityMetadataId(entityVersionMatcher.group(1), entityVersion); }
public LightblueTupleSnapshot(ObjectNode node, EntityKeyMetadata keyMetadata, OperationType operationType) { this.node = node; this.operationType = operationType; LightblueEntityMetadataId metadataId = LightblueEntityMetadataId.extractEntityInfo(keyMetadata); this.entityName = metadataId.entityName; this.entityVersion = metadataId.entityVersion; columnNames = findLeafNodeFieldNames("", node); }
public RedisJsonDialectTuplesSupplier(KeyScanCursor<String> cursor, JsonEntityStorageStrategy storageStrategy, String prefix, EntityKeyMetadata entityKeyMetadata) { this.cursor = cursor; this.storageStrategy = storageStrategy; this.prefix = prefix; this.entityKeyMetadata = entityKeyMetadata; }
public RedisJsonTupleIterator(KeyScanCursor<String> cursor, JsonEntityStorageStrategy storageStrategy, String prefix, EntityKeyMetadata entityKeyMetadata) { this.storageStrategy = storageStrategy; this.prefix = prefix; this.entityKeyMetadata = entityKeyMetadata; this.iterator = cursor.getKeys().iterator(); }
public RedisHashDialectTuplesSupplier(KeyScanCursor<String> cursor, RedisClusterCommands<String, String> connection, String prefix, EntityKeyMetadata entityKeyMetadata) { this.cursor = cursor; this.connection = connection; this.prefix = prefix; this.entityKeyMetadata = entityKeyMetadata; }
public RedisHashTupleIterator(KeyScanCursor<String> cursor, RedisClusterCommands<String, String> connection, String prefix, EntityKeyMetadata entityKeyMetadata) { this.connection = connection; this.prefix = prefix; this.entityKeyMetadata = entityKeyMetadata; this.iterator = cursor.getKeys().iterator(); }
public EntityKeyMetadata getKeyMetaData(String entityType) { OgmEntityPersister persister = (OgmEntityPersister) getSessionFactory().getEntityPersister( entityType ); return persister.getEntityKeyMetadata(); }
public <K> IgniteCache<K, BinaryObject> getEntityCache(EntityKeyMetadata keyMetadata) { String entityCacheName = getEntityCacheName( keyMetadata.getTable() ); return getCache( entityCacheName, true ); }
@Override public void forEachTuple(ModelConsumer consumer, TupleTypeContext tupleTypeContext, EntityKeyMetadata entityKeyMetadata) { throw new UnsupportedOperationException( "forEachTuple() is not implemented" ); }
public IgnitePortableFromProjectionResultCursor(Iterable<List<?>> resultCursor, RowSelection rowSelection, EntityKeyMetadata keyMetadata) { super( resultCursor, rowSelection ); this.keyMetadata = keyMetadata; }
public static <K> IgniteCache<K, BinaryObject> getEntityCache(SessionFactory sessionFactory, EntityKeyMetadata entityKeyMetadata) { IgniteDatastoreProvider castProvider = getProvider( sessionFactory ); return castProvider.getEntityCache( entityKeyMetadata ); }
@Override public void forEachTuple(ModelConsumer consumer, EntityKeyMetadata... entityKeyMetadatas) { throw new UnsupportedOperationException("not yet supported"); }