Package org.hibernate.ogm.grid.impl

Source Code of org.hibernate.ogm.grid.impl.RowKeyBuilder

/*
* 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.grid.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.ogm.datastore.spi.Tuple;
import org.hibernate.ogm.grid.EntityKey;
import org.hibernate.ogm.grid.RowKey;

/**
* @author Emmanuel Bernard &lt;emmanuel@hibernate.org&gt;
*/
public class RowKeyBuilder {
  private final List<String> columnNames = new ArrayList<String>();
  private final List<String> indexColumnNames = new ArrayList<String>( 3 );
  private String tableName;
  private Tuple tuple;
  private EntityKey entityKey;

  public RowKeyBuilder addColumns(String... columns) {
    for ( String columnName : columns ) {
      columnNames.add( columnName );
    }
    return this;
  }

  public RowKeyBuilder addIndexColumns(String... columns) {
    for ( String columnName : columns ) {
      columnNames.add( columnName );
      indexColumnNames.add( columnName );
    }
    return this;
  }

  public RowKeyBuilder tableName(String tableName) {
    this.tableName = tableName;
    return this;
  }

  public RowKeyBuilder entityKey(EntityKey entityKey) {
    this.entityKey = entityKey;
    return this;
  }

  public RowKey build() {
    final String[] columnNamesArray = columnNames.toArray( new String[columnNames.size()] );
    final int length = columnNamesArray.length;
    Object[] columnValuesArray = new Object[length];

    for (int index = 0 ; index < length ; index++ ) {
      columnValuesArray[index] = tuple.get( columnNamesArray[index] );
    }

    return new RowKey( tableName, columnNamesArray, columnValuesArray, entityKey );
  }

  public RowKeyBuilder values(Tuple tuple) {
    this.tuple = tuple;
    return this;
  }

  public String[] getColumnNames() {
    return columnNames.toArray( new String[ columnNames.size() ] );
  }

  public String[] getIndexColumnNames() {
    return indexColumnNames.toArray( new String[ indexColumnNames.size() ] );
  }
}
TOP

Related Classes of org.hibernate.ogm.grid.impl.RowKeyBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.