Exemple #1
0
  public synchronized void init() {
    if (init) {
      return;
    }

    schemaMap = new HashMap<String, Schema>();

    if (schemaFactory instanceof SubSchemaFactory) {
      ((SubSchemaFactory) schemaFactory).init();
    }

    List<SchemaImpl> result = new ArrayList<SchemaImpl>();

    for (Schema schema : schemaFactory.listSchemas()) {
      if (schema instanceof SchemaImpl) {
        /* Copy */
        SchemaImpl impl = new SchemaImpl((SchemaImpl) schema);

        for (SchemaPostProcessor post : postProcessors) {
          impl = post.postProcessRegister(impl, this);
          if (impl == null) {
            break;
          }
        }

        if (impl != null) {
          result.add(impl);
          schemaMap.put(impl.getId(), impl);
        }
      }
    }

    schemaList = result;

    for (SchemaImpl schema : schemaList) {
      for (SchemaPostProcessor post : postProcessors) {
        schema = post.postProcess(schema, this);
      }
    }

    for (SchemaImpl schema : schemaList) {
      prune(schema);
    }

    if (SERIALIZE.get()) {
      serializeSchema(listSchemas(), getId());
      synchronized (schemaFactory) {
        serializeSchema(schemaFactory.listSchemas(), schemaFactory.getId());
      }
    }

    init = true;
  }
  @SuppressWarnings("unchecked")
  @Override
  public <T> List<? extends T> findToRemove(
      Class<T> mapType, Class<?> resourceType, long resourceId) {
    String type = schemaFactory.getSchemaName(mapType);

    Table<?> table = getTable(mapType);

    Relationship reference = getRelationship(mapType, resourceType);
    TableField<?, Object> removed =
        JooqUtils.getTableField(metaDataManager, type, ObjectMetaDataManager.REMOVED_FIELD);
    TableField<?, Object> referenceField =
        JooqUtils.getTableField(metaDataManager, type, reference.getPropertyName());
    TableField<?, Object> state =
        JooqUtils.getTableField(metaDataManager, type, ObjectMetaDataManager.STATE_FIELD);

    if (removed == null || referenceField == null || state == null) {
      throw new IllegalArgumentException(
          "Type [" + mapType + "] is missing required removed, reference, or state column");
    }

    return (List<? extends T>)
        create()
            .selectFrom(table)
            .where(
                referenceField
                    .eq(resourceId)
                    .and(removed.isNull().or(state.eq(CommonStatesConstants.REMOVING))))
            .fetch();
  }
Exemple #3
0
  @SuppressWarnings("unchecked")
  public static Class<UpdatableRecord<?>> getRecordClass(SchemaFactory factory, Class<?> clz) {
    if (UpdatableRecord.class.isAssignableFrom(clz)) {
      return (Class<UpdatableRecord<?>>) clz;
    }

    if (factory != null) {
      Schema schema = factory.getSchema(clz);
      Class<?> testClz = factory.getSchemaClass(schema.getId());
      if (clz.isAssignableFrom(testClz)) {
        if (!UpdatableRecord.class.isAssignableFrom(testClz)) {
          throw new IllegalArgumentException(
              "Class [" + testClz + "] is not an instanceof UpdatableRecord");
        }
        return (Class<UpdatableRecord<?>>) testClz;
      }
    }

    throw new IllegalArgumentException("Failed to find UpdatableRecord class for [" + clz + "]");
  }
  protected Relationship getRelationship(Class<?> mapType, Class<?> resourceType) {
    Map<String, Relationship> rels =
        metaDataManager.getLinkRelationships(schemaFactory, schemaFactory.getSchemaName(mapType));
    Relationship reference = null;
    for (Map.Entry<String, Relationship> entry : rels.entrySet()) {
      Relationship rel = entry.getValue();
      if (rel.getRelationshipType() == Relationship.RelationshipType.REFERENCE
          && resourceType.isAssignableFrom(rel.getObjectType())) {
        reference = rel;
        break;
      }
    }

    if (reference == null) {
      throw new IllegalArgumentException(
          "Failed to find reference relationship from [" + mapType + "] to [" + resourceType + "]");
    }

    return reference;
  }
  @SuppressWarnings("unchecked")
  @Override
  public <T> T findNonRemoved(
      Class<T> mapType,
      Class<?> leftResourceType,
      long leftResourceId,
      Class<?> rightResourceType,
      long rightResourceId) {
    String type = schemaFactory.getSchemaName(mapType);

    Table<?> table = getTable(mapType);

    Relationship leftReference = getRelationship(mapType, leftResourceType);
    Relationship rightReference = getRelationship(mapType, rightResourceType);
    TableField<?, Object> removed =
        JooqUtils.getTableField(metaDataManager, type, ObjectMetaDataManager.REMOVED_FIELD);
    TableField<?, Object> leftReferenceField =
        JooqUtils.getTableField(metaDataManager, type, leftReference.getPropertyName());
    TableField<?, Object> rightReferenceField =
        JooqUtils.getTableField(metaDataManager, type, rightReference.getPropertyName());

    if (removed == null || leftReferenceField == null || rightReferenceField == null) {
      throw new IllegalArgumentException(
          "Type [" + mapType + "] is missing required removed or references column");
    }

    return (T)
        create()
            .selectFrom(table)
            .where(
                removed
                    .isNull()
                    .and(leftReferenceField.eq(leftResourceId))
                    .and(rightReferenceField.eq(rightResourceId)))
            .fetchOne();
  }
Exemple #6
0
 @Override
 public Class<?> getSchemaClass(String type) {
   Schema schema = getSchema(type);
   return schema == null ? null : schemaFactory.getSchemaClass(type);
 }
Exemple #7
0
 @Override
 public Schema getSchema(String type) {
   Schema parentSchema = schemaFactory.getSchema(type);
   return parentSchema == null ? null : schemaMap.get(parentSchema.getId());
 }
Exemple #8
0
 @Override
 public Schema getSchema(Class<?> clz) {
   return getSchema(schemaFactory.getSchemaName(clz));
 }