Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2013 Ning, Inc.
   *
   * Ning licenses this file to you under the Apache License, version 2.0
   * (the "License"); you may not use this file except in compliance with the
   * License.  You may obtain a copy of the License at:
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  * License for the specific language governing permissions and limitations
  * under the License.
  */
 
 package com.ning.billing.subscription.engine.dao;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
 
 
 
     private static final String NOT_IMPLEMENTED = "Not implemented";
 
 
     private static final class SubscriptionEventWithOrderingId {
 
         private final SubscriptionBaseEvent event;
         private final long orderingId;
 
         public SubscriptionEventWithOrderingId(final SubscriptionBaseEvent eventfinal long orderingId) {
             this. = event;
             this. = orderingId;
         }
 
         public SubscriptionBaseEvent getEvent() {
             return ;
         }
 
         public long getOrderingId() {
             return ;
         }
 
         @Override
         public String toString() {
             final StringBuilder tmp = new StringBuilder();
             tmp.append("[");
             tmp.append(.getType());
             tmp.append(": effDate=");
             tmp.append(.getEffectiveDate());
             tmp.append(", subId=");
             tmp.append(.getSubscriptionId());
             tmp.append(", ordering=");
             tmp.append(.getTotalOrdering());
             tmp.append("]");
             return tmp.toString();
         }
     }
 
     private static final class SubscriptionRepairEvent {
 
         private final Set<SubscriptionEventWithOrderingIdevents;
         private long curOrderingId;
 
         public SubscriptionRepairEvent(final List<SubscriptionBaseEventinitialEvents) {
                 @Override
                 public int compare(final SubscriptionEventWithOrderingId o1final SubscriptionEventWithOrderingId o2) {
                     // Work around jdk7 change: compare(o1, o1) is now invoked when inserting the first element
                     // See:
                     // - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147
                     // - http://hg.openjdk.java.net/jdk7/tl/jdk/rev/bf37edb38fbb
                    if (o1 == o2) {
                        return 0;
                    }
                    final int result = o1.getEvent().getEffectiveDate().compareTo(o2.getEvent().getEffectiveDate());
                    if (result == 0) {
                        if (o1.getOrderingId() < o2.getOrderingId()) {
                            return -1;
                        } else if (o1.getOrderingId() > o2.getOrderingId()) {
                            return 1;
                        } else {
                            throw new RuntimeException(String.format(" Repair subscription events should not have the same orderingId %s, %s "o1o2));
                        }
                    }
                    return result;
                }
            });
            this. = 0;
            if (initialEvents != null) {
                addEvents(initialEvents);
            }
        }
        public List<SubscriptionBaseEventgetEvents() {
            return new ArrayList<SubscriptionBaseEvent>(Collections2.transform(new Function<SubscriptionEventWithOrderingIdSubscriptionBaseEvent>() {
                @Override
                public SubscriptionBaseEvent apply(SubscriptionEventWithOrderingId in) {
                    return in.getEvent();
                }
            }));
        }
        public void addEvents(final List<SubscriptionBaseEventnewEvents) {
            for (final SubscriptionBaseEvent cur : newEvents) {
                .add(new SubscriptionEventWithOrderingId(cur++));
            }
        }
    }
        if (.get() == null) {
        }
        return .get();
    }
    private SubscriptionRepairEvent getRepairSubscriptionEvents(final UUID subscriptionId) {
        final Map<UUIDSubscriptionRepairEventmap = getRepairMap();
        return map.get(subscriptionId);
    }
    @Override
    public List<SubscriptionBaseEventgetEventsForSubscription(final UUID subscriptionIdfinal InternalTenantContext context) {
        final SubscriptionRepairEvent target = getRepairSubscriptionEvents(subscriptionId);
        return new LinkedList<SubscriptionBaseEvent>(target.getEvents());
    }
    @Override
    public void createSubscription(final DefaultSubscriptionBase subscriptionfinal List<SubscriptionBaseEventcreateEventsfinal InternalCallContext context) {
        addEvents(subscription.getId(), createEvents);
    }
    @Override
    public void recreateSubscription(final DefaultSubscriptionBase subscriptionfinal List<SubscriptionBaseEventrecreateEventsfinal InternalCallContext context) {
        addEvents(subscription.getId(), recreateEvents);
    }
    @Override
    public void cancelSubscription(final DefaultSubscriptionBase subscriptionfinal SubscriptionBaseEvent cancelEventfinal InternalCallContext contextfinal int cancelSeq) {
        final UUID subscriptionId = subscription.getId();
        final long activeVersion = cancelEvent.getActiveVersion();
        addEvents(subscriptionId, Collections.singletonList(cancelEvent));
        final SubscriptionRepairEvent target = getRepairSubscriptionEvents(subscriptionId);
        boolean foundCancelEvent = false;
        for (final SubscriptionBaseEvent cur : target.getEvents()) {
            if (cur.getId().equals(cancelEvent.getId())) {
                foundCancelEvent = true;
            } else if (foundCancelEvent) {
                cur.setActiveVersion(activeVersion - 1);
            }
        }
    }
    @Override
    public void cancelSubscriptions(final List<DefaultSubscriptionBasesubscriptionsfinal List<SubscriptionBaseEventcancelEventsfinal InternalCallContext context) {
    }
    @Override
    public void changePlan(final DefaultSubscriptionBase subscriptionfinal List<SubscriptionBaseEventchangeEventsfinal InternalCallContext context) {
        addEvents(subscription.getId(), changeEvents);
    }
    @Override
    public void initializeRepair(final UUID subscriptionIdfinal List<SubscriptionBaseEventinitialEventsfinal InternalTenantContext context) {
        final Map<UUIDSubscriptionRepairEventmap = getRepairMap();
        if (map.get(subscriptionId) == null) {
            final SubscriptionRepairEvent value = new SubscriptionRepairEvent(initialEvents);
            map.put(subscriptionIdvalue);
        } else {
            throw new SubscriptionBaseError(String.format("Unexpected SubscriptionRepairEvent %s for thread %s"subscriptionId, Thread.currentThread().getName()));
        }
    }
    @Override
    public void cleanup(final InternalTenantContext context) {
        final Map<UUIDSubscriptionRepairEventmap = getRepairMap();
        map.clear();
    }
    private void addEvents(final UUID subscriptionIdfinal List<SubscriptionBaseEventevents) {
        final SubscriptionRepairEvent target = getRepairSubscriptionEvents(subscriptionId);
        target.addEvents(events);
    }
    @Override
    public void uncancelSubscription(final DefaultSubscriptionBase subscriptionfinal List<SubscriptionBaseEventuncancelEventsfinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<SubscriptionBaseBundlegetSubscriptionBundleForAccount(final UUID accountIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public SubscriptionBaseBundle getSubscriptionBundleFromId(final UUID bundleIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
        throw new SubscriptionBaseError();
    }
    @Override
    public SubscriptionBase getSubscriptionFromId(final UUID subscriptionIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public UUID getAccountIdFromSubscriptionId(final UUID subscriptionIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public SubscriptionBase getBaseSubscription(final UUID bundleIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<SubscriptionBasegetSubscriptions(final UUID bundleIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void updateChargedThroughDate(final DefaultSubscriptionBase subscriptionfinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void createNextPhaseEvent(final DefaultSubscriptionBase subscriptionfinal SubscriptionBaseEvent nextPhasefinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public SubscriptionBaseEvent getEventById(final UUID eventIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
        throw new SubscriptionBaseError();
    }
    @Override
    public Map<UUIDList<SubscriptionBaseEvent>> getEventsForBundle(final UUID bundleIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<SubscriptionBaseEventgetPendingEventsForSubscription(final UUID subscriptionIdfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void migrate(final UUID accountIdfinal AccountMigrationData datafinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void repair(final UUID accountIdfinal UUID bundleIdfinal List<SubscriptionDataRepairinRepairfinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void transfer(final UUID srcAccountIdfinal UUID destAccountIdfinal BundleMigrationData data,
                         final List<TransferCancelDatatransferCancelDatafinal InternalCallContext fromContext,
                         final InternalCallContext toContext) {
        throw new SubscriptionBaseError();
    }
    @Override
    public void updateBundleExternalKey(final UUID bundleIdfinal String externalKeyfinal InternalCallContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<SubscriptionBaseBundlegetSubscriptionBundlesForKey(final String bundleKeyfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<UUIDgetNonAOSubscriptionIdsForKey(final String bundleKeyfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
    @Override
    public List<SubscriptionBaseBundlegetSubscriptionBundlesForAccountAndKey(final UUID accountIdfinal String bundleKeyfinal InternalTenantContext context) {
        throw new SubscriptionBaseError();
    }
New to GrepCode? Check out our FAQ X