Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Hibernate OGM, Domain model persistence for NoSQL datastores
   *
   * License: GNU Lesser General Public License (LGPL), version 2.1 or later
   * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
   */
  package org.hibernate.ogm.model.impl;
  
 import java.util.List;
 
Stores metadata information common to all keys related to a given association

Author(s):
Emmanuel Bernard <emmanuel@hibernate.org>
 
 
 	private final String table;
 	private final String[] columnNames;
 	private final int hashCode;
 
 	// not part of the object identity
 	private final String[] rowKeyColumnNames;
 	private final String[] rowKeyIndexColumnNames;
 	private final boolean isInverse;
 	private final String collectionRole;
 	private final AssociationKind associationKind;
 	private final boolean isOneToOne;
 
 	private DefaultAssociationKeyMetadata(Builder builder) {
 		this. = builder.table;
 		this. = builder.columnNames;
 
 		this. = builder.rowKeyColumnNames;
 		this. = builder.rowKeyIndexColumnNames;
 		this. = builder.isInverse;
 		this. = builder.associatedEntityKeyMetadata;
 		this. = builder.collectionRole;
 		this. = builder.associationKind;
 		this. = builder.isOneToOne;
 
 		// table hashing should be specific enough
 		this. = .hashCode();
 	}
 
 	public static class Builder {
 
 		private String table;
 		private String[] columnNames;
 		private String[] rowKeyColumnNames;
 		private boolean isInverse;
 		private String collectionRole;
 		private boolean isOneToOne;
 
 		public Builder table(String table) {
 			this. = table;
 			return this;
 		}
 
 		public Builder columnNames(String[] columnNames) {
 			this. = columnNames;
 			return this;
 		}
 
 		public Builder rowKeyColumnNames(String[] rowKeyColumnNames) {
 			this. = rowKeyColumnNames;
 			return this;
 		}
 
 		public Builder rowKeyIndexColumnNames(String[] rowKeyIndexColumnNames) {
 			this. = rowKeyIndexColumnNames;
 			return this;
 		}
 
 		public Builder inverse(boolean isInverse) {
 			this. = isInverse;
 			return this;
 		}
 
 		public Builder associatedEntityKeyMetadata(AssociatedEntityKeyMetadata associatedEntityKeyMetadata) {
 			this. = associatedEntityKeyMetadata;
 			return this;
 		}
 
 		public Builder collectionRole(String collectionRole) {
 			this. = collectionRole;
 			return this;
		}
		public Builder associationKind(AssociationKind associationKind) {
			this. = associationKind;
			return this;
		}
		public Builder oneToOne(boolean isOneToOne) {
			this. = isOneToOne;
			return this;
		}
			return new DefaultAssociationKeyMetadatathis );
		}
	}
	public String getTable() {
		return ;
	}
	public String[] getColumnNames() {
		return ;
	}

The columns identifying an element of the association
	}

The columns representing the index of the element of the association.

For example, the key columns of a map-type property or the column with the order if the property is annotated with javax.persistence.OrderColumn

	}

Returns meta-data about the entity key referenced by associations of this key family.

Returns:
meta-data about the entity key referenced by associations of this key family.
	}

Returns all those columns from the given candidate list which are not part of this key family.

Stores can opt to persist only the returned columns when writing a row of this key family. All other columns can be retrieved from the key meta-data itself when reading an association row.

The column order is not preserved.

		List<StringnonKeyColumns = new ArrayList<String>();
		for ( String column : candidates ) {
			// exclude columns from the associationKey as they can be guessed via metadata
			if ( !isKeyColumncolumn ) ) {
				nonKeyColumns.addcolumn );
			}
		}
		return nonKeyColumns.toArraynew String[nonKeyColumns.size()] );
	}

Returns the name of the single row key column which is not a column of this key itself, in case such a column exists.

If e.g. an association key contains the column "bankAccounts_id" and the row key columns are "bankAccounts_id" and "owners_id", this method will return "owners_id". But if the row columns were "bankAccounts_id", "owners_id" and "order", null would be returned as there were more than one column which are not part of the association key.

Returns:
the name of the single row key column which is not a column of this key itself or null if there is either no or more than one such column.
		String nonKeyColumn = null;
		for ( String column : getRowKeyColumnNames() ) {
			if ( !isKeyColumncolumn ) ) {
				if ( nonKeyColumn != null ) {
					// more than one column which is not contained in the association key; thus rows of this
					// association will be represented by DBObjects rather than single String, int etc. objects
					return null;
				}
				else {
					nonKeyColumn = column;
				}
			}
		}
		return nonKeyColumn;
	}

Whether the given column is part of this key family or not.

Returns:
true if the given column is part of this key, false otherwise.
	public boolean isKeyColumn(String columnName) {
		for ( String keyColumName : getColumnNames() ) {
			if ( keyColumName.equalscolumnName ) ) {
				return true;
			}
		}
		return false;
	}

Whether this key meta-data represents the inverse side of a bi-directional association.

Returns:
true if this key meta-data represents the inverse side of a bi-directional association, false otherwise.
	public boolean isInverse() {
		return ;
	}

Returns the association role.
	}

Returns the type of association
	}
	public boolean isOneToOne() {
		return ;
	}
	public boolean equals(Object o) {
		if ( this == o ) {
			return true;
		}
		if ( o == null || DefaultAssociationKeyMetadata.class != o.getClass() ) {
			return false;
		}
		// order of comparison matters on performance:
		if ( !.equalsthat.table ) ) {
			return false;
		}
		if ( !Arrays.equalsthat.columnNames ) ) {
			return false;
		}
		return true;
	}
	public int hashCode() {
		return ;
	}
	public String toString() {
		return "DefaultAssociationKeyMetadata [table=" +  + ", columnNames=" + Arrays.toString ) + ", isInverse=" +  + ", collectionRole="
 + ", associationKind=" +  + ", rowKeyColumnNames=" + Arrays.toString )
", rowKeyIndexColumnNames=" + Arrays.toString ) + ", associatedEntityKeyMetadata=" + 
"]";
	}
New to GrepCode? Check out our FAQ X