private static Set<String> buildColumnNames(AssociationKey associationKey, Set<String> columnsFromRow) { Set<String> columnNames = new HashSet<String>( columnsFromRow.size() + associationKey.getColumnNames().length ); columnNames.addAll( columnsFromRow ); Collections.addAll( columnNames, associationKey.getColumnNames() ); return columnNames; }
PerTableSerializableAssociationKey(AssociationKey key) { columnNames = key.getColumnNames(); columnValues = 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 void writeObject(ObjectOutput output, AssociationKey key) throws IOException { output.writeInt( VERSION ); output.writeUTF( key.getTable() ); output.writeObject( key.getColumnNames() ); output.writeObject( key.getColumnValues() ); }
/** * Returns the value of the given column if part of this key. Use {@link AssociationKeyMetadata#isKeyColumn(String)} * to check whether a given column is part of this key prior to invoking this method. * * @param columnName the name of interest * @return the value of the given column. */ public Object getColumnValue(String columnName) { for ( int i = 0; i < getColumnNames().length; i++ ) { String name = getColumnNames()[i]; if ( name.equals( columnName ) ) { return getColumnValues()[i]; } } throw new AssertionFailure( String.format( "Given column %s is not part of this key: %s", columnName, this.toString() ) ); } }
private String createAssociationQuery(AssociationKey key, boolean selectObjects) { StringBuilder sb = new StringBuilder(); if ( selectObjects ) { sb.append( "SELECT _KEY, _VAL FROM " ); } else { sb.append( "SELECT _KEY FROM " ); } sb.append( key.getMetadata().getTable() ).append( " WHERE " ); boolean first = true; for ( String columnName : key.getColumnNames() ) { if ( !first ) { sb.append( " AND " ); } else { first = false; } sb.append( StringHelper.realColumnName( columnName ) ).append( "=?" ); } return sb.toString(); }
SerializableAssociationKey(AssociationKey key) { columnNames = key.getColumnNames(); columnValues = key.getColumnValues(); table = key.getTable(); }
public static PersistentAssociationKey fromAssociationKey(AssociationKey key) { return new PersistentAssociationKey( key.getColumnNames(), key.getColumnValues() ); }
public static PersistentAssociationKey fromAssociationKey(AssociationKey key) { return new PersistentAssociationKey( key.getColumnNames(), 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 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; }
/** * 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() ); }
for ( int i = 0; i < associationKey.getColumnNames().length; i++ ) { String key = associationKey.getEntityKey().getColumnNames()[i]; if ( ownerNode.containsKey( key ) ) { properties.put( associationKey.getColumnNames()[i], ownerNode.get( key ) );
Select.Where selectWhere = select.where( eq( quote( key.getColumnNames()[0] ), QueryBuilder.bindMarker() ) ); for ( int i = 1; i < key.getColumnNames().length; i++ ) { selectWhere = selectWhere.and( eq( quote( key.getColumnNames()[i] ), QueryBuilder.bindMarker() ) ); String name = column.getName(); boolean foundColumn = false; for ( int i = 0; i < key.getColumnNames().length; i++ ) { if ( name.equals( key.getColumnNames()[i] ) ) { foundColumn = true; break; combinedKeys.addAll( Arrays.asList( key.getColumnNames() ) ); for ( Object column : tableMetadata.getPrimaryKey().getColumns() ) { String name = ( (Column) column ).getName();
for ( String columnName : key.getColumnNames() ) { if ( !keyColumnNames.contains( columnName ) ) { deleteSelection.column( quote( columnName ) ); for ( String columnName : key.getColumnNames() ) { if ( keyColumnNames.contains( columnName ) ) { delete.where( eq( quote( columnName ), QueryBuilder.bindMarker( columnName ) ) );
for ( int i = 0; i < associationKey.getColumnNames().length; i++ ) { if ( ownerNode.hasProperty( associationKey.getEntityKey().getColumnNames()[i] ) ) { properties.put( associationKey.getColumnNames()[i], ownerNode.getProperty( associationKey.getEntityKey().getColumnNames()[i] ) );
QueryBuilder qb = Search.getQueryFactory( c ).from( provider.getEntityType( c ) ); final String[] columnNames = key.getColumnNames(); FilterConditionContext bqEnd = null; boolean firstIteration = true;
if ( clearBo != null ) { BinaryObjectBuilder clearBoBuilder = provider.createBinaryObjectBuilder( clearBo ); for ( String columnName : key.getColumnNames() ) { clearBoBuilder.removeField( columnName );
for ( String columnName : associationKey.getColumnNames() ) { entityTuple.put( columnName, associationRow.get( columnName ) );