private static String cacheName(AssociationKey key) { return key.getTable(); }
@Override public void writeObject(ObjectOutput output, AssociationKey key) throws IOException { output.writeInt( VERSION ); output.writeUTF( key.getTable() ); output.writeObject( key.getColumnNames() ); output.writeObject( key.getColumnValues() ); }
@Override public void writeObject(ObjectOutput output, AssociationKey key) throws IOException { output.writeInt( VERSION ); output.writeUTF( key.getTable() ); output.writeObject( key.getColumnNames() ); output.writeObject( key.getColumnValues() ); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append( "AssociationKey(" ); sb.append( getTable() ); sb.append( ") [" ); int i = 0; for ( String column : metadata.getColumnNames() ) { sb.append( column ).append( "=" ).append( columnValues[i] ); i++; if ( i < metadata.getColumnNames().length ) { sb.append( ", " ); } } sb.append( "]" ); return sb.toString(); }
SerializableAssociationKey(AssociationKey key) { columnNames = key.getColumnNames(); columnValues = key.getColumnValues(); table = key.getTable(); }
private void createRelationshipForCollectionOfPrimitivesOrMap(AssociationKey associationKey, String collectionRole, String[] columnNames, StringBuilder queryBuilder) { String relationshipType = collectionRole; if ( isPartOfEmbedded( collectionRole ) ) { queryBuilder.append( " MERGE (owner) " ); String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); relationshipType = pathToEmbedded[pathToEmbedded.length - 1]; queryBuilder.append( " CREATE (e) -[r:" ); } else { queryBuilder.append( " CREATE (owner) -[r:" ); } escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( "]->(new:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getTable() ); queryBuilder.append( " {" ); // THe name of the property is the same as the relationship type escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( ": {" ); queryBuilder.append( columnNames.length ); queryBuilder.append( "}" ); queryBuilder.append( "}" ); queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); }
private static Document associationKeyToObject(AssociationKey key, AssociationStorageStrategy storageStrategy) { if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { throw new AssertionFailure( MongoHelpers.class.getName() + ".associationKeyToObject should not be called for associations embedded in entity documents" ); } Object[] columnValues = key.getColumnValues(); Document columns = new Document(); // if the columns are only made of the embedded id columns, remove the embedded id property prefix // _id: [ { id: { id1: "foo", id2: "bar" } } ] becomes _id: [ { id1: "foo", id2: "bar" } ] String prefix = DocumentHelpers.getColumnSharedPrefix( key.getColumnNames() ); prefix = prefix == null ? "" : prefix + "."; int i = 0; for ( String name : key.getColumnNames() ) { MongoHelpers.setValue( columns, name.substring( prefix.length() ), columnValues[i++] ); } Document idObject = new Document(); if ( storageStrategy == AssociationStorageStrategy.GLOBAL_COLLECTION ) { columns.put( MongoDBDialect.TABLE_FIELDNAME, key.getTable() ); } idObject.put( MongoDBDialect.ID_FIELDNAME, columns ); return idObject; }
private void createRelationshipForCollectionOfPrimitivesOrMap(AssociationKey associationKey, String collectionRole, String[] columnNames, StringBuilder queryBuilder) { String relationshipType = collectionRole; if ( isPartOfEmbedded( collectionRole ) ) { queryBuilder.append( " MERGE (owner) " ); String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); relationshipType = pathToEmbedded[pathToEmbedded.length - 1]; queryBuilder.append( " CREATE (e) -[r:" ); } else { queryBuilder.append( " CREATE (owner) -[r:" ); } escapeIdentifier( queryBuilder, relationshipType ); int offset = ownerEntityKeyMetadata.getColumnNames().length; appendProperties( queryBuilder, associationKey.getMetadata().getRowKeyIndexColumnNames(), offset ); queryBuilder.append( "]-> (new:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getTable() ); queryBuilder.append( " {" ); // THe name of the property is the same as the relationship type escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( ": {" ); offset += associationKey.getMetadata().getRowKeyIndexColumnNames().length; queryBuilder.append( offset ); queryBuilder.append( "}" ); queryBuilder.append( "}" ); queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); }
/** * Create the id used to store an {@link org.hibernate.ogm.datastore.couchdb.dialect.backend.json.impl.AssociationDocument} * * @param key the{@link AssociationKey} used to generate the id * @return the value of the generate id */ public static String createAssociationId(AssociationKey key) { return key.getTable() + ":" + fromColumnValues( key.getColumnNames() ) + ":" + fromColumnValues( key.getColumnValues() ); }
private static Document associationKeyToObject(AssociationKey key, AssociationStorageStrategy storageStrategy) { if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { throw new AssertionFailure( MongoHelpers.class.getName() + ".associationKeyToObject should not be called for associations embedded in entity documents" ); } Object[] columnValues = key.getColumnValues(); Document columns = new Document(); // if the columns are only made of the embedded id columns, remove the embedded id property prefix // _id: [ { id: { id1: "foo", id2: "bar" } } ] becomes _id: [ { id1: "foo", id2: "bar" } ] String prefix = DocumentHelpers.getColumnSharedPrefix( key.getColumnNames() ); prefix = prefix == null ? "" : prefix + "."; int i = 0; for ( String name : key.getColumnNames() ) { MongoHelpers.setValue( columns, name.substring( prefix.length() ), columnValues[i++] ); } Document idObject = new Document(); if ( storageStrategy == AssociationStorageStrategy.GLOBAL_COLLECTION ) { columns.put( MongoDBDialect.TABLE_FIELDNAME, key.getTable() ); } idObject.put( MongoDBDialect.ID_FIELDNAME, columns ); return idObject; }
private MongoCollection<Document> getAssociationCollection(AssociationKey key, AssociationStorageStrategy storageStrategy, AssociationContext associationContext) { if ( storageStrategy == AssociationStorageStrategy.GLOBAL_COLLECTION ) { return getCollection( MongoDBConfiguration.DEFAULT_ASSOCIATION_STORE, associationContext.getAssociationTypeContext().getOptionsContext() ); } else { return getCollection( ASSOCIATIONS_COLLECTION_PREFIX + key.getTable(), associationContext.getAssociationTypeContext().getOptionsContext() ); } }
private MongoCollection<Document> getAssociationCollection(AssociationKey key, AssociationStorageStrategy storageStrategy, AssociationContext associationContext) { if ( storageStrategy == AssociationStorageStrategy.GLOBAL_COLLECTION ) { return getCollection( MongoDBConfiguration.DEFAULT_ASSOCIATION_STORE, associationContext.getAssociationTypeContext().getOptionsContext() ); } else { return getCollection( ASSOCIATIONS_COLLECTION_PREFIX + key.getTable(), associationContext.getAssociationTypeContext().getOptionsContext() ); } }
Table tableMetadata = provider.getMetaDataCache().get( key.getTable() ); Set<String> keyColumnNames = new HashSet<String>(); for ( Object columnObject : tableMetadata.getPrimaryKey().getColumns() ) { Delete delete = deleteSelection.from( quote( key.getTable() ) ); List<Object> columnValues = new LinkedList<>();
Table tableMetadata = provider.getMetaDataCache().get( key.getTable() ); Set<String> keyColumnNames = new HashSet<String>(); for ( Object columnObject : tableMetadata.getPrimaryKey().getColumns() ) { Tuple value = op.getValue(); List<Object> columnValues = new ArrayList<>(); Insert insert = QueryBuilder.insertInto( quote( key.getTable() ) ); for ( String columnName : value.getColumnNames() ) { insert.value( quote( columnName ), QueryBuilder.bindMarker( columnName ) ); Delete delete = deleteSelection.from( quote( key.getTable() ) ); List<Object> columnValues = new LinkedList<>(); for ( String columnName : value.getColumnNames() ) {
@Override public Association getAssociation(AssociationKey key, AssociationContext associationContext) { Table tableMetadata = provider.getMetaDataCache().get( key.getTable() ); List<Column> tablePKCols = tableMetadata.getPrimaryKey().getColumns(); Select select = QueryBuilder.select().all().from( quote( key.getTable() ) ); Select.Where selectWhere = select.where( eq( quote( key.getColumnNames()[0] ), QueryBuilder.bindMarker() ) ); for ( int i = 1; i < key.getColumnNames().length; i++ ) {