Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] DynamicClass Name containing a dot

Hi Dennis
AFAIK when you create a DynamicType you specify a type name which is the like the fully qualified (package + class name) name of a java class. So typically you will give a type name like "p1.c1" where c1 is treated as the class name or the alias for the type.
Thanks
Rohit

----- Original Message -----
From: dennis.fuglsang@xxxxxxxxxx
To: rohit.banga@xxxxxxxxxx, eclipselink-users@xxxxxxxxxxx
Cc: jamesssss@xxxxxxxxx
Sent: Saturday, April 16, 2011 6:12:34 AM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi
Subject: RE: [eclipselink-users] DynamicClass Name containing a dot

For an alias to a Java class name what are the set of invalid characters that cannot be used?   I tried to use a ‘:’ character in my alias and encountered a parser exception.

 

From: Rohit Banga
Sent: Wednesday, April 13, 2011 10:33 AM
To: EclipseLink User Discussions
Cc: James Sutherland
Subject: Re: [eclipselink-users] DynamicClass Name containing a dot

 

Thanks James for the clarification. I missed the fact that I was using the alias.
Instead of getAlias() I should use getJavaClassName().
Better still I will consider having different type names across the packages.

Thanks
Rohit

On 4/13/2011 8:18 PM, James Sutherland wrote:

 
The issue is that the alias defaults to the simple class name.
 
If you use the full packaged name it will get the correct class.
 
ReadAllQuery query2 = new DynamicHelper(session).newReadAllQuery("p2.type"); 
 
or,
 
ReadAllQuery query2 = new DynamicHelper(session).newReadAllQuery(
                               
type2Builder.getType().getDescriptor().getJavaClass().getName()); 
 
or just,
 
ReadAllQuery query2 = new
ReadAllQuery(type2Builder.getType().getDescriptor().getJavaClass());
 
You should set the alias on one (or both) or your descriptors to be
different, as having two descriptors with the same alias is a bad idea.
 
type2Builder.getType().getDescriptor().setAlias("p2.type");
 
 
 
Rohit Banga-2 wrote:
 
Hi All
 
When we create a DynamicClass using 
DynamicClassLoader.createDynamicClass(className), then how is the class 
name expected to be interpreted if it contains a dot character.
Lets say if the className be "p.c".
Is "p" treated as the package and "c" as the class within the package?
 
The attached program throws the following exception:
 
Exception [EclipseLink-51000] (Eclipse Persistence Services - 
2.3.0.v20110324-r9156):
org.eclipse.persistence.exceptions.DynamicException
Exception Description: Invalid DynamicEntity[DynamicEntityType(type) - 
RelationalDescriptor(p1.type --> [DatabaseTable(addrinfo)])] property 
name: addrline2
     at 
org.eclipse.persistence.exceptions.DynamicException.invalidPropertyName(DynamicException.java:66)
     at 
org.eclipse.persistence.internal.dynamic.DynamicEntityImpl.get(DynamicEntityImpl.java:145)
     at jpatest.UniqueTypeName.main(UniqueTypeName.java:79)
 
Ideally I would expect p1.type and p2.type to be treated as separated 
classes. Is the above behavior expected or is it a bug in Eclipselink?
 
-- 
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
 
import java.util.List;
import java.util.Vector;
 
import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicHelper;
import org.eclipse.persistence.dynamic.DynamicTypeBuilder;
import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl;
import org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder;
import org.eclipse.persistence.queries.ReadAllQuery;
import org.eclipse.persistence.sessions.DatabaseLogin;
import org.eclipse.persistence.sessions.DatabaseRecord;
import org.eclipse.persistence.sessions.DatabaseSession;
 
public class UniqueTypeName
{
  public static void main(String[] args)
  {
         DatabaseLogin login = new DatabaseLogin();
         login.setUserName("*****");
         login.setPassword("*****");
         login.setDriverURLHeader("jdbc:oracle:thin:@");
         login.setDriverClassName("oracle.jdbc.OracleDriver");
         login.setDatabaseURL("***************");
         DatabaseSession session = new DatabaseSessionImpl(login);
 
         session.login();
 
         DynamicHelper helper = new DynamicHelper(session);
         DynamicClassLoader dcl = helper.getDynamicClassLoader();
 
         Class<?> type1 = dcl.createDynamicClass("p1.type");
         Class<?> type2 = dcl.createDynamicClass("p2.type");
 
         DynamicTypeBuilder type1Builder = new JPADynamicTypeBuilder(type1, null,
"addrinfo");
 
         DynamicTypeBuilder type2Builder = new JPADynamicTypeBuilder(type2, null,
"addrinfo");
 
         type1Builder.setPrimaryKeyFields("addrid");
         type1Builder.addDirectMapping("addrid", String.class, "addrid");
         type1Builder.addDirectMapping("addrline1", String.class, "addr1");
 
         type2Builder.setPrimaryKeyFields("addrid");
         type2Builder.addDirectMapping("addrid", String.class, "addrid");
         type2Builder.addDirectMapping("addrline1", String.class, "addr1");
         type2Builder.addDirectMapping("addrline2", String.class, "addr2");
 
         helper.addTypes(false, true, type2Builder.getType(),
type1Builder.getType());
 
         ReadAllQuery query = new DynamicHelper(session).newReadAllQuery(
                         type1Builder.getType().getDescriptor().getAlias());
         
         query.prepareCall(session, new DatabaseRecord());
         System.out.println("query: " + query.getSQLString());
 
         List<DynamicEntity> emps = (List<DynamicEntity>)
session.executeQuery(query);
 
         for (DynamicEntity entity : emps)
         {
                 System.out.println(entity.get("addrid"));
                 System.out.println(entity.get("addrline1"));
                 System.out.println();
         }
 
         ReadAllQuery query1 = new DynamicHelper(session).newReadAllQuery(
                         type2Builder.getType().getDescriptor().getAlias());
 
         query1.prepareCall(session, new DatabaseRecord());
         System.out.println("query: " + query1.getSQLString());
 
         emps = (List<DynamicEntity>) session.executeQuery(query1);
         for (DynamicEntity entity : emps)
         {
                 System.out.println(entity.get("addrid"));
                 System.out.println(entity.get("addrline1"));
                 System.out.println(entity.get("addrline2"));
                 System.out.println();
         }
 
  }
}
 
 
 
 
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 

 

--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies


Back to the top