Package com.alvazan.orm.impl.meta.data.collections

Source Code of com.alvazan.orm.impl.meta.data.collections.ToOneProviderProxy

package com.alvazan.orm.impl.meta.data.collections;

import com.alvazan.orm.api.base.ToOneProvider;
import com.alvazan.orm.api.z5api.NoSqlSession;
import com.alvazan.orm.api.z8spi.Row;
import com.alvazan.orm.impl.meta.data.MetaAbstractClass;
import com.alvazan.orm.impl.meta.data.Tuple;

public class ToOneProviderProxy<T> extends ToOneProvider<T> {

  private MetaAbstractClass<T> classMeta;
  private byte[] value;
  private NoSqlSession session;

  public ToOneProviderProxy(MetaAbstractClass<T> classMeta, byte[] value,
      NoSqlSession session) {
    this.classMeta = classMeta;
    this.value = value;
    this.session = session;
  }

  @Override
  public T get() {
    if(inst == null) {
      byte[] virtualKey = classMeta.getIdField().getMetaIdDbo().formVirtRowKey(value);
      Row row = session.find(classMeta.getMetaDbo(), virtualKey);
      if(row == null)
        throw new RuntimeException("corrupt databuse? as we could not find the row corresponding this this key");
      Tuple<T> tuple = classMeta.convertIdToProxy(row, session, value, null);
      inst = tuple.getProxy();
    }
    return inst;
  }

}
TOP

Related Classes of com.alvazan.orm.impl.meta.data.collections.ToOneProviderProxy

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.