/** * Converting association key to cache key * * @param key - association key * @return string key */ public Object createParentKeyObject(AssociationKey key) { Object result = null; if ( key.getColumnValues().length == 1 ) { result = key.getColumnValues()[0]; } else { throw new UnsupportedOperationException( "Not implemented yet" ); } return result; }
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() ); }
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() ); }
/** * 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 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() ); }
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; }
String fieldName = mapper.convertColumnNameToFieldName( columnNames[i] ); if ( firstIteration ) { bqEnd = qb.having( fieldName ).eq( key.getColumnValues()[i] ); firstIteration = false; bqEnd = bqEnd.and().having( fieldName ).eq( key.getColumnValues()[i] );
SqlFieldsQuery sqlQuery = provider.createSqlFieldsQueryWithLog( createAssociationQuery( key, true ), hints, key.getColumnValues() ); Iterable<List<?>> list = executeWithHints( associationCache, sqlQuery, hints );
Object[] columnValues = key.getColumnValues(); ResultSet resultSet = bindAndExecute( columnValues, select );
SqlFieldsQuery sqlQuery = provider.createSqlFieldsQueryWithLog( createAssociationQuery( key, true ), hints, key.getColumnValues() ); Iterable<List<?>> list = executeWithHints( associationCache, sqlQuery, hints ); for ( List<?> item : list ) { SqlFieldsQuery sqlQuery = provider.createSqlFieldsQueryWithLog( createAssociationQuery( key, false ), hints, key.getColumnValues() ); Iterable<List<?>> list = executeWithHints( associationCache, sqlQuery, hints ); for ( List<?> item : list ) {