Ejemplo n.º 1
0
  @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();
  }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
  @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();
  }
Ejemplo n.º 4
0
 @Override
 public Schema getSchema(Class<?> clz) {
   return getSchema(schemaFactory.getSchemaName(clz));
 }