package com.sangdol.experiment.portableDb;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hugh
 */
public class ViewTable {
    public static final String TABLE_PREFIX = "true_view";
    private static final int TABLE_COUNT = 100;
    private static final List<String> names = new ArrayList<>();

    static {
        for (int i = 0; i < TABLE_COUNT; i++) {
            names.add(TABLE_PREFIX + i);
        }
    }

    public List<String> getAll() {
        return names;
    }

    // TODO throw exception when trying to get a not existing table
    public String get(int userId) {
        final int HOST_COUNT_IN_TABLE = 100;
        int tableNumber = (userId - 1) / HOST_COUNT_IN_TABLE;
        return TABLE_PREFIX + tableNumber;
    }
}

@@ -52,51 +52,140 @@
 java
-.util.ArrayList;%0Aimport java.util.List;%0A%0A/*
+x.ws.rs.WebApplicationException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Manage horizontally split table names.%0A 
 *%0A *
@@ -527,135 +527,305 @@
     
-public List%3CString%3E getAll() %7B%0A        return names;%0A    %7D%0A%0A    // TODO throw exception when trying to get a not existing table
+/**%0A     * Returns all table names with designated TABLE_PREFIX and TABLE_COUNT.%0A     */%0A    public List%3CString%3E getAll() %7B%0A        return names;%0A    %7D%0A%0A    /**%0A     * Returns the allocated table name to the userId.%0A     * The index of table name is 0-based, e.g. true_view0, true_view1...%0A     */
 %0A   
@@ -964,16 +964,110 @@
 _TABLE;%0A
+%0A        if (tableNumber %3E= TABLE_COUNT)%0A            throw new WebApplicationException(404);%0A%0A
         

Add docs / Throw exception for wrong userId