Package org.objectweb.speedo.naming.lib

Source Code of org.objectweb.speedo.naming.lib.LongIdNamingManager

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.naming.lib;

import org.objectweb.jorm.api.PException;
import org.objectweb.jorm.api.PMapper;
import org.objectweb.jorm.facility.naming.longid.LongIdBinder;
import org.objectweb.jorm.facility.naming.longid.LongIdManager;
import org.objectweb.jorm.facility.naming.longid.LongIdPNC;
import org.objectweb.jorm.facility.naming.longid.LongIdPName;
import org.objectweb.jorm.metainfo.api.NameDef;
import org.objectweb.jorm.naming.api.PBinder;
import org.objectweb.jorm.naming.api.PName;
import org.objectweb.jorm.naming.api.PNameCoder;
import org.objectweb.jorm.naming.api.PNamingContext;
import org.objectweb.jorm.type.api.PType;
import org.objectweb.jorm.type.api.PTypeSpace;
import org.objectweb.medor.expression.lib.BasicOperand;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.metadata.SpeedoIdentity;

/**
* This is naming manager manages identifier based on a long value
* generated by Speedo, using a persistent generator (Speedo structure in
* database). The long value is composed of two parts. Some bits are used for
* the class identifier, and the rest is used to identify the object instance
* in the class.  This identifier format supports very well the polymorphism.
* The null reference  is represented by the -1 value. The long field can be a
* visible persistent field, otherwise it is hidden by Speedo/JORM
* implementation.
*
* @see org.objectweb.speedo.naming.api.NamingManager
* @see org.objectweb.jorm.facility.naming.longid.LongIdManager
* @author S.Chassande-Barrioz
*/
public class LongIdNamingManager
  extends CommonLongIdNamingManager {

  private final static String LONG_ID_NAME
    = "org.objectweb.jorm.facility.naming.longid.LongId";
  private final static String LONG_ID_LID = "lid";
  private final static String BINDER_FOR_CLASS = "c";
  private final static String BINDER_FOR_GENCLASS = "gc";
  private final static String HIDDEN_LID_FIELD_NAME = "jdolid";

  LongIdManager lidm = new LongIdManager();
  protected String getLongIdName() {
      return LONG_ID_NAME;
  }
  protected String getLongIdLid() {
      return LONG_ID_LID;
  }
  protected PType getFieldType() {
      return PTypeSpace.LONG;
  }
  protected java.lang.Class getJavaFieldType() {
      return Long.TYPE;
  }
  protected BasicOperand getBasicOperand() {
    return new BasicOperand(1l << 44);
  }
  protected boolean checkFieldType(String type) {
      return "long".equals(type);
  }

    public PMapper getMapper() {
        return lidm.getMapper();
    }
    protected String getName() {
        return "lid";
    }
    public PBinder newClassPBinder(String className, Object conn) throws PException {
        return lidm.newClassPBinder(className, conn);
    }
    public PNamingContext newClassPNamingContext() throws PException {
        return lidm.newClassPNamingContext();
    }
    public PBinder newGenClassPBinder() throws PException {
        return lidm.newGenClassPBinder();
    }
    public void setPMapper(PMapper mapper) {
        super.setPMapper(mapper);
        try {
            lidm.setPMapper(mapper);
        } catch (PException e) {
            e.printStackTrace();
        }
    }
 
    public java.lang.Class getLongIdManagerClass() {
        return LongIdManager.class;
    }
    public java.lang.Class getPBinderClass() {
        return LongIdBinder.class;
    }
    public java.lang.Class getPNameClass() {
        return LongIdPName.class;
    }
    public java.lang.Class getPNamingContextClass() {
        return LongIdPNC.class;
    }
  protected String getBinderForGenClass() {
        return BINDER_FOR_GENCLASS;
    }
  protected String getBinderForClass() {
        return BINDER_FOR_CLASS;
    }
    protected String getHiddenLidFieldName() {
        return HIDDEN_LID_FIELD_NAME;
    }
  public boolean canManage(SpeedoClass sc) {
    return sc.identity.strategy ==  SpeedoIdentity.DATASTORE_LONG;
  }
  public Object encode(PName pn) throws PException {
    if (pn instanceof LongIdPName) {
      return pn.getPNameManager().getPType().getJormName()
          + SEP + pn.encodeLong();
    }
    return null;
  }
  protected PName decodeLong(PNameCoder pnc, String idStr) throws PException {
    return pnc.decodeLong(Long.parseLong(idStr));
  }
    public String getGCPNameHints(SpeedoClass sc, NameDef nd) {
    return "new Long(speedoPO.getPName().encodeLong())";
  }
}
TOP

Related Classes of org.objectweb.speedo.naming.lib.LongIdNamingManager

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.