public static Attribute getAttribute(Entity entidad, String atributo) { for (Attribute attr : getAllDirectAttributes(entidad)) { if (attr.getName().equals(atributo)) { return attr; } } return null; }
public static String getSimpleTipo(Attribute attr) { if (attr.getType().getSimple() != null) { return attr.getType().getSimple().getType(); } if (attr.getType().getSpecial() != null) { return attr.getType().getSpecial().getType(); } return null; }
public static boolean esColeccion(Attribute attr) { if (attr.getType().getCompound() == null) { return false; } if (attr.getType().getCompound().getCollectionType() != null) { return true; } return false; }
public static boolean esLista(Attribute attr) { if (attr.getType().getCompound() == null) { return false; } if (attr.getType().getCompound().getLista() != null) { return true; } return false; }
/** * En el caso de que el atributo sea una referencia, devuelve el tipo de la referencia(OneToOne, * OneToMany, ManyToOne, ManyToMany) El tipo por defecto es OneToOne * * @param attr * @return */ public static String getTipoReferencia(Attribute attr) { if (!isReferencia(attr)) return null; CompoundType c = attr.getType().getCompound(); if (c.getTipoReferencia() == null) { return "OneToOne"; } return c.getTipoReferencia().getType(); }
public static void addId(Entity entidad) { if (entidad.getExtends() != null) { return; } for (Attribute attr : entidad.getAttributes()) { if (attr.getName().equals("id")) { return; } } LedFactory factory = new LedFactoryImpl(); Attribute id = factory.createAttribute(); id.setName("id"); id.setType(factory.createType()); id.getType().setSimple(new LedFactoryImpl().createSimpleType()); id.getType().getSimple().setType("Long"); entidad.getAttributes().add(id); }
public static boolean isReferencia(Attribute attr) { return attr != null && attr.getType().getCompound() != null && attr.getType().getCompound().getEntidad() != null; }
public static Entity getEntidad(Attribute attr) { if (attr == null || attr.getType().getCompound() == null) { return null; } return attr.getType().getCompound().getEntidad(); }
public static boolean esSimple(Attribute attr) { return attr.getType().getSimple() != null || attr.getType().getSpecial() != null; }