static void initializeClassInfos(DomainModel model, int serverId) {
    serverOidBase =
        (long) serverId << 48; // the server id provides de 16 most significant bits of the OID

    int maxId = 0;
    Map<Class, DomainClassInfo> map = new IdentityHashMap<Class, DomainClassInfo>();
    ArrayList<DomainClassInfo> array = new ArrayList<DomainClassInfo>();

    // special case: create record for DomainRoot (must get class id = 0)
    addNewInfo(map, array, new DomainClassInfo(DomainRoot.class, 0));

    // create all other records, skipping DomainRoot of course
    for (DomainClass domClass : model.getDomainClasses()) {
      Class javaClass;
      try {
        javaClass = Class.forName(domClass.getFullName());
      } catch (ClassNotFoundException e) {
        throw new ExceptionInInitializerError(e);
      }

      if (javaClass != DomainRoot.class && !map.containsKey(javaClass)) {
        DomainClassInfo classInfo = new DomainClassInfo(javaClass, ++maxId);
        addNewInfo(map, array, classInfo);
      }
    }

    // finish the initialization by assigning to the static variables
    classInfoMap = Collections.unmodifiableMap(map);
    classInfoById = new DomainClassInfo[maxId + 1];
    array.toArray(classInfoById);
  }
Ejemplo n.º 2
0
  public static String getJdbcTypeFor(DomainModel model, String valueType) {
    ValueType vt = model.findValueType(valueType);

    String jdbcType = null;

    if (vt.isEnum()) {
      jdbcType = "VARCHAR";
    } else if (vt.isBuiltin()) {
      jdbcType = BUILT_IN_JDBC_MAP.get(valueType);
    } else {
      List<ExternalizationElement> extElems = vt.getExternalizationElements();
      if (extElems.size() != 1) {
        throw new Error("Can't handle ValueTypes with more than one externalization element, yet!");
      }
      jdbcType = getJdbcTypeFor(model, extElems.get(0).getType().getDomainName());
    }

    if (jdbcType == null) {
      throw new Error("Couldn't find a JDBC type for the value type " + valueType);
    }

    return jdbcType;
  }