예제 #1
0
파일: Checks.java 프로젝트: doo/jclouds
  public static void checkEntityType(EntityType<?> entity) {
    // Check required fields
    assertNotNull(entity.getName(), String.format(NOT_NULL_OBJECT_FMT, "Name", "EntityType"));

    // Check optional fields
    // NOTE description cannot be checked
    Set<Task> tasks = entity.getTasks();
    if (tasks != null && tasks != null && !tasks.isEmpty()) {
      for (Task task : tasks) checkTask(task);
    }

    // Check parent type
    checkResourceType(entity);
  }
  /** Introspects. */
  public BeanType introspect(Class type) throws ConfigException, SQLException {
    BeanType beanType = null;

    try {
      EntityType entityType = null;

      EntityType parentType = introspectParent(type.getSuperclass());

      entityType = introspectEntityType(type, parentType);

      if (entityType == null) entityType = introspectMappedType(type, parentType);

      if (entityType == null) return introspectEmbeddableType(type);

      beanType = entityType;

      // jpa/0ge2
      entityType.setInstanceClassName(type.getName() + "__ResinExt");
      entityType.setEnhanced(true);

      MappedSuperclassConfig mappedSuperOrEntityConfig = introspectEntityConfig(type);

      entityType.setParentType(parentType);

      introspectTable(type, entityType, parentType);

      // inheritance must be after table since it adds columns
      introspectInheritance(type, entityType, parentType);

      introspectTableCache(entityType, type);

      getInternalIdClassConfig(type, _annotationCfg);
      IdClass idClassAnn = (IdClass) _annotationCfg.getAnnotation();
      IdClassConfig idClassConfig = _annotationCfg.getIdClassConfig();

      Class idClass = null;
      if (!_annotationCfg.isNull()) {
        if (idClassAnn != null) idClass = idClassAnn.value();
        else {
          String s = idClassConfig.getClassName();
          idClass = _persistenceUnit.loadTempClass(s);
        }

        // XXX: temp. introspects idClass as an embeddable type.
        _persistenceUnit.addEntityClass(idClass.getName(), idClass);

        // jpa/0i49 vs jpa/0i40
        // embeddable.setFieldAccess(isField);
      }

      if (entityType.getId() != null) {
      } else if (entityType.isFieldAccess())
        introspectIdField(
            _persistenceUnit, entityType, parentType, type, idClass, mappedSuperOrEntityConfig);
      else {
        introspectIdMethod(
            _persistenceUnit, entityType, parentType, type, idClass, mappedSuperOrEntityConfig);
      }

      HashMap<String, IdConfig> idMap = null;

      AttributesConfig attributes = null;

      if (mappedSuperOrEntityConfig != null) {
        attributes = mappedSuperOrEntityConfig.getAttributes();

        if (attributes != null) idMap = attributes.getIdMap();
      }

      // if ((idMap == null) || (idMap.size() == 0)) {
      //   idMap = entityType.getSuperClass();
      // }

      if (entityType.isEntity()
          && (entityType.getId() == null)
          && ((idMap == null) || (idMap.size() == 0)))
        throw new ConfigException(
            L.l(
                "{0} does not have any primary keys.  Entities must have at least one @Id or exactly one @EmbeddedId field.",
                entityType.getName()));

      // Introspect overridden attributes. (jpa/0ge2)
      introspectAttributeOverrides(entityType, type);

      introspectSecondaryTable(entityType, type);

      if (entityType.isFieldAccess())
        introspectFields(
            _persistenceUnit, entityType, parentType, type, mappedSuperOrEntityConfig, false);
      else
        introspectMethods(
            _persistenceUnit, entityType, parentType, type, mappedSuperOrEntityConfig);

      introspectCallbacks(type, entityType);

      // Adds entity listeners, if any.
      introspectEntityListeners(type, entityType, _persistenceUnit);

      // Adds sql result set mappings, if any.
      introspectSqlResultSetMappings(type, entityType, entityType.getName());

      // Adds named queries, if any.
      introspectNamedQueries(type, entityType.getName());
      introspectNamedNativeQueries(type, entityType.getName());
    } catch (ConfigException e) {
      if (beanType != null) beanType.setConfigException(e);

      throw e;
    } catch (SQLException e) {
      if (beanType != null) beanType.setConfigException(e);

      throw e;
    } catch (RuntimeException e) {
      if (beanType != null) beanType.setConfigException(e);

      throw e;
    }

    return beanType;
  }
  private void introspectTable(Class type, EntityType entityType, EntityType parentType) {
    // XXX: need better test
    boolean isEntity = !(entityType instanceof MappedSuperclassType);

    AmberTable table = null;

    getInternalTableConfig(type, _annotationCfg);
    Table tableAnn = (Table) _annotationCfg.getAnnotation();
    TableConfig tableConfig = _annotationCfg.getTableConfig();

    String tableName = null;

    if (tableAnn != null) tableName = tableAnn.name();
    else if (tableConfig != null) tableName = tableConfig.getName();

    // jpa/0gg0, jpa/0gg2
    if (isEntity) { // && ! type.isAbstract()) {

      boolean hasTableConfig = true;

      if (tableName == null || tableName.equals("")) {
        hasTableConfig = false;
        tableName = toSqlName(entityType.getName());
      }

      /*
           InheritanceType strategy = null;

           if (parentType != null)
             strategy = parentType.getInheritanceStrategy();

           if (inheritanceAnn != null)
      strategy = (InheritanceType) inheritanceAnn.get("strategy");
           else if (inheritanceConfig != null)
      strategy = inheritanceConfig.getStrategy();
            */

      // jpa/0gg2
      if (!entityType.isEntity()) return;
      /*
           if (type.isAbstract()
        && strategy != InheritanceType.JOINED
        && ! hasTableConfig) {
      // jpa/0gg0
           }
            */
      else if (parentType == null || parentType.getTable() == null) {
        entityType.setTable(_persistenceUnit.createTable(tableName));
      } else if (parentType.isJoinedSubClass()) {
        entityType.setTable(_persistenceUnit.createTable(tableName));

        EntityType rootType = parentType.getRootType();

        Class rootClass = rootType.getBeanClass();
        getInternalTableConfig(rootClass, _annotationCfg);
        Table rootTableAnn = (Table) _annotationCfg.getAnnotation();
        TableConfig rootTableConfig = _annotationCfg.getTableConfig();

        String rootTableName = null;

        if (rootTableAnn != null) rootTableName = rootTableAnn.name();
        else if (rootTableConfig != null) rootTableName = rootTableConfig.getName();

        if (rootTableName == null || rootTableName.equals("")) {
          String rootEntityName = rootType.getName();

          rootTableName = toSqlName(rootEntityName);
        }

        entityType.setRootTableName(rootTableName);
      } else entityType.setTable(parentType.getTable());
    }
  }
예제 #4
0
 public static void load() {
   final FileConfiguration config = UDSPlugin.getPlugin().getConfig();
   BLOCK_CREEPERS = config.getBoolean("block.creeper");
   BLOCK_ENDERMEN = config.getBoolean("block.endermen");
   BLOCK_SILVERFISH = config.getBoolean("block.silverfish");
   BLOCK_TNT = config.getBoolean("block.tnt");
   BLOCK_WITHER = config.getBoolean("block.wither");
   MAP_DATA = (byte) config.getInt("map-data");
   BASE_COST = config.getInt("cost.base");
   BUILD_COST = config.getInt("cost.build");
   CITY_COST = config.getInt("cost.city");
   CLAN_COST = config.getInt("cost.clan");
   EXPAND_COST = config.getInt("cost.expand");
   HOME_COST = config.getInt("cost.home");
   MAP_COST = config.getInt("cost.map");
   SHOP_COST = config.getInt("cost.shop");
   VIP_COST = config.getInt("cost.vip");
   UNDO_COUNT = config.getInt("range.undo");
   DRAIN_RANGE = config.getInt("range.drain");
   MOVE_RANGE = config.getInt("range.move");
   EDIT_RANGE = config.getInt("range.edit");
   COMPASS_RANGE = config.getInt("range.compass");
   BUTCHER_RANGE = config.getInt("range.butcher");
   VIP_SPAWNS = config.getInt("vip.spawns");
   WORLD_BORDER = config.getInt("range.world");
   WORLD_BORDER_SQRD = WORLD_BORDER * WORLD_BORDER;
   SPAWNER_EXP = config.getInt("exp.spawner");
   REQUEST_TTL = config.getLong("request-timeout") * TimeUtils.SECOND;
   MINECART_TTL = config.getLong("minecart.life") * TimeUtils.SECOND;
   PVP_TIME = config.getLong("pvp-time") * TimeUtils.SECOND;
   SLOW_TIME = config.getLong("auto-save") * TimeUtils.MINUTE;
   DRAGON_RESPAWN = config.getLong("respawn-dragon") * TimeUtils.MINUTE;
   VIP_TIME = config.getLong("vip.time") * TimeUtils.DAY;
   CURRENCIES = config.getString("currency.plural");
   WELCOME_MSG = config.getString("welcome.message");
   WELCOME_ADMIN = config.getString("welcome.admin");
   SERVER_OWNER = config.getString("server-owner");
   CURRENCY = config.getString("currency.singular");
   MAIN_WORLD = config.getString("world-name");
   WELCOME_GIFT = Material.getMaterial(config.getString("welcome.gift"));
   if (WELCOME_GIFT == null) WELCOME_GIFT = Material.EMERALD;
   SERVER_RULES = config.getStringList("server-rules");
   PISTON_POWER = config.getDouble("piston-power");
   SHARES = config.getStringList("inventory-shares");
   GMAIL_ADDRESS = config.getString("gmail.email");
   SKULL = config.getDouble("head-drop-chance");
   GMAIL_PASSWORD = config.getString("gmail.password");
   VIP_WHITELIST.clear();
   for (int typeId : config.getIntegerList("item-whitelist")) {
     VIP_WHITELIST.add(Material.getMaterial(typeId));
   }
   KITS.clear();
   for (String kit : config.getStringList("kits")) {
     final String[] kitSplit = kit.split(",");
     final List<ItemStack> items =
         new ArrayList<ItemStack>(ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1).length);
     for (Object item : ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1)) {
       items.add(new ItemStack(Material.getMaterial(Integer.parseInt((String) item))));
     }
     KITS.add(
         new Kit(
             kitSplit[0],
             Integer.parseInt(kitSplit[1]),
             items,
             PlayerRank.getByName(kitSplit[2])));
   }
   MOB_REWARDS.clear();
   for (EntityType entityType : EntityType.values()) {
     String entityName = "mob-rewards." + entityType.getName();
     if (entityName != null) {
       entityName = entityName.toLowerCase();
       MOB_REWARDS.put(entityType, config.getInt(entityName));
     }
   }
   GLOBAL_FLAGS.clear();
   for (RegionFlag flag : RegionFlag.values()) {
     final String flagname = "global-flags." + flag.toString().toLowerCase();
     GLOBAL_FLAGS.put(flag, config.getBoolean(flagname));
   }
 }
예제 #5
0
 public static CreatureType fromEntityType(EntityType creatureType) {
   return fromName(creatureType.getName());
 }