/**
* 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.olongid.LongIdPBinder;
import org.objectweb.jorm.facility.naming.olongid.LongIdPNC;
import org.objectweb.jorm.facility.naming.olongid.LongIdManager;
import org.objectweb.jorm.facility.naming.olongid.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 java.lang.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 NULL value.The java.lang.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.olongid.LongIdManager
* @author S.Chassande-Barrioz
*/
public class OLongIdNamingManager
extends CommonLongIdNamingManager {
private final static String LONG_ID_NAME
= "org.objectweb.jorm.facility.naming.olongid.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";
private LongIdManager lidm = new LongIdManager();
protected String getLongIdName() {
return LONG_ID_NAME;
}
protected String getLongIdLid() {
return LONG_ID_LID;
}
protected PType getFieldType() {
return PTypeSpace.OBJLONG;
}
protected BasicOperand getBasicOperand() {
return new BasicOperand(new Long(1l << 44), PTypeSpace.OBJLONG);
}
protected boolean checkFieldType(String type) {
return "Long".equals(type) || "java.lang.Long".equals(type);
}
protected String getBinderForClass() {
return BINDER_FOR_CLASS;
}
protected String getBinderForGenClass() {
return BINDER_FOR_GENCLASS;
}
protected PName decodeLong(PNameCoder pnc, String idStr) throws PException {
return pnc.decodeOlong(Long.valueOf(idStr));
}
protected String getHiddenLidFieldName() {
return HIDDEN_LID_FIELD_NAME;
}
protected Class getJavaFieldType() {
return Long.class;
}
public PMapper getMapper() {
return lidm.getMapper();
}
protected String getName() {
return "olid";
}
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 LongIdPBinder.class;
}
public java.lang.Class getPNameClass() {
return LongIdPName.class;
}
public java.lang.Class getPNamingContextClass() {
return LongIdPNC.class;
}
// IMPLEMENTATION OF THE METHOD FROM THE NamingManager INTERFACE //
//---------------------------------------------------------------//
public boolean canManage(SpeedoClass sc) {
return sc.identity.strategy == SpeedoIdentity.DATASTORE_OLONG;
}
public Object encode(PName pn) throws PException {
if (pn instanceof LongIdPName) {
return pn.getPNameManager().getPType().getJormName()
+ SEP + pn.encodeOlong();
}
return null;
}
public String getGCPNameHints(SpeedoClass sc, NameDef nd) {
return "speedoPO.getPName().encodeOlong()";
}
}