Search in sources :

Example 1 with JDBCTable

use of db.JDBCTable in project common by zenlunatics.

the class EventProvider method adjustRemindersTables.

// --------------------------------------------------------------------------
protected void adjustRemindersTables(DBConnection db) {
    if (m_support_reminders) {
        JDBCTable table_def = new JDBCTable().add(new JDBCColumn(m_events_table)).add(new JDBCColumn("before", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("email", Types.VARCHAR)).add(new JDBCColumn("last_sent", Types.DATE)).add(new JDBCColumn("note", Types.VARCHAR)).add(new JDBCColumn("num", Types.INTEGER)).add(new JDBCColumn("_owner_", "people")).add(new JDBCColumn("repeat_days", Types.VARCHAR).setDefaultValue("each event")).add(new JDBCColumn("unit", Types.VARCHAR));
        db.getTable(m_events_table + "_reminders", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    }
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 2 with JDBCTable

use of db.JDBCTable in project common by zenlunatics.

the class Admin method doGet.

// --------------------------------------------------------------------------
@Override
public boolean doGet(Request request) throws IOException {
    if (!request.userIsAdministrator())
        return false;
    String action = request.getParameter("action");
    if (action != null)
        try {
            if (action.equals("edit settings"))
                request.site.newView("_settings_", request).writeComponent();
            else if (action.equals("edit_table"))
                request.site.newView("admin__" + request.getParameter("table"), request).writeComponent();
            else if (action.equals("exportCSV"))
                exportCSV(request.getParameter("table"), request.getParameter("filename"), request);
            else if (action.equals("generate jdbctable")) {
                request.writer.write("<p><b>JDBCTable</b></p>");
                request.writer.write(request.db.getTable(request.getParameter("table")).getCode());
            } else if (action.equals("generate sql")) {
                request.writer.write("<p><b>SQL</b></p>");
                request.writer.write(request.db.getTable(request.getParameter("table")).getSQL());
            } else // writeAddModuleForm(request);
            if (action.equals("get_column_form")) {
                String table = request.getParameter("table");
                String column = request.getParameter("column");
                writeColumnForm(table, column == null ? null : request.db.getTable(table).getColumn(column), request);
            } else if (action.equals("get default form")) {
                String table = request.getParameter("table");
                writeDefaultForm(table, request.db.getTable(table).getColumn(request.getParameter("column")), request);
            } else if (action.equals("get file manager"))
                ((FileManager) request.site.getModule("FileManager")).write(request);
            else if (action.equals("get log")) {
                request.writer.write("<pre>");
                BufferedReader br = new BufferedReader(new FileReader(request.site.getSettings().getString("log path") + "/" + request.getParameter("log")));
                String l = br.readLine();
                while (l != null) {
                    request.writer.write(l).write("\n");
                    l = br.readLine();
                }
                br.close();
                request.writer.write("</pre>");
            } else if (action.equals("get logs")) {
                request.writer.write("<table border=\"1\"><tr><td valign=\"top\">");
                String[] logs = new File(request.site.getSettings().getString("log path")).list();
                if (logs == null || logs.length == 0)
                    request.writer.write("no logs found in " + request.site.getSettings().getString("log path"));
                else {
                    for (String log : logs) {
                        request.writer.aOnClick(log, "$('log').replace('admin?action=get log&log=" + log + "')");
                        request.writer.br();
                    }
                    request.writer.write("</td><td id=\"log\" valign=\"top\"></td></tr></table>");
                }
            } else if (action.equals("get_many_to_many_link_table_create_form"))
                writeManyToManyLinkTableCreateForm(request);
            else if (action.equals("get_method_form")) {
                String class_name = request.getParameter("class");
                String site_class = request.site.getClass().getName();
                if (class_name == null)
                    new MethodForm(request.site.getModule(request.getParameter("module"))).write(request.getParameter("method"), request);
                else if (class_name.equals("Admin"))
                    new MethodForm(Admin.class).write(request.getParameter("method"), request);
                else if (class_name.equals(site_class.substring(site_class.indexOf('.') + 1)))
                    new MethodForm(request.site.getClass()).write(request.getParameter("method"), request);
                else {
                    Class<?>[] classes = request.site.getClasses();
                    for (Class<?> c : classes) if (c.getSimpleName().equals(class_name)) {
                        new MethodForm(c).write(request.getParameter("method"), request);
                        break;
                    }
                }
            } else if (action.equals("get_module")) {
                String module_name = request.getParameter("module");
                Module module = request.site.getModule(module_name);
                if (module == null)
                    request.writer.write("module " + module_name + " not found");
                module.writeAdminPane(null, true, true, request);
            } else if (action.equals("get_object"))
                request.site.newView(request.getParameter("object"), request).writeComponent();
            else if (action.equals("get_nav_list"))
                writeAccordion(request);
            else if (action.equals("get_schema_diff_form"))
                writeSchemaDiffForm(request);
            else if (action.equals("get_session_attributes"))
                writeSessionAttributes(request);
            else if (action.equals("get sql form"))
                writeSQLForm(request);
            else if (action.equals("get state")) {
                Table table = new Table(request.writer).addClass("table").addStyle("width", "auto");
                Td td = new Td(request.writer).addStyle("vertical-align", "top");
                table.td(td);
                request.writer.h3("Tomcat");
                writeTomcatState(request);
                table.td(td);
                request.writer.h3("Session Attributes");
                writeSessionAttributes(request);
                table.td(td);
                request.writer.h3("Threads");
                writeThreads(request);
                table.td(td);
                request.writer.h3("ViewDef Cache");
                componentOpen(null, request);
                writeViewDefCache(request);
                table.close();
            } else if (action.equals("get_table"))
                writeTablePane(request.getParameter("table"), request);
            else if (action.equals("get_table_create_form"))
                writeTableCreateForm(request);
            else if (action.equals("get_table_def")) {
                ViewState.setShowReturnLink("_tables_", false, request);
                request.site.newView("_tables_", request).writeEditForm();
            } else if (action.equals("get_view")) {
                ViewState.setShowReturnLink("_views_", false, request);
                request.site.newView("_views_", request).writeEditForm();
            } else if (action.equals("get_view_def_cache"))
                writeViewDefCache(request);
            else if (action.equals("schema_diff"))
                new Schema().diff(request.getParameter("url"), request);
            else if (action.equals("search"))
                writeSearchPanel(request);
            else if (action.equals("sql")) {
                List<String> tables = request.db.readValues(new db.Select("table_name").from("information_schema.tables").where("table_name ilike '" + request.getParameter("tables") + "'"));
                for (String table : tables) {
                    request.writer.h4(table);
                    writeResultSet(request.db.select(new db.Select(request.getParameter("columns")).from(table).where(request.getParameter("where"))), request);
                }
            } else if (action.equals("tables with column")) {
                String column = request.getParameter("column");
                String where = request.getParameter("where");
                List<String> tables = request.db.findTablesWithColumn(column);
                if (where.length() > 0) {
                    request.writer.h4("Tables with column " + column + " where " + where);
                    for (String table : tables) {
                        int num_rows = request.db.countRows(table, column + where);
                        if (num_rows > 0)
                            request.writer.write(table).write("(").write(num_rows).write(")").br();
                    }
                } else {
                    request.writer.h4("Tables with column " + column);
                    for (String table : tables) request.writer.write(table).br();
                }
            } else {
                request.writer.write("unknown action: " + action);
                return false;
            }
            return true;
        } catch (SQLException e) {
            request.abort(e);
        }
    writeAdminPage(request);
    return true;
}
Also used : Table(web.Table) JDBCTable(db.JDBCTable) SQLException(java.sql.SQLException) Schema(db.Schema) Td(web.Td) BufferedReader(java.io.BufferedReader) Select(web.Select) FileReader(java.io.FileReader) List(java.util.List) ArrayList(java.util.ArrayList) Module(app.Module) File(java.io.File)

Example 3 with JDBCTable

use of db.JDBCTable in project common by zenlunatics.

the class MailLists method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("active", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("allow_from_outside", Types.BOOLEAN).setDefaultValue(false)).add(new JDBCColumn("allow_from_outside_subscribers", Types.BOOLEAN).setDefaultValue(false)).add(new JDBCColumn("announce_only", Types.BOOLEAN)).add(new JDBCColumn("archive", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("archives_public", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("footer", Types.VARCHAR)).add(new JDBCColumn("host", Types.VARCHAR)).add(new JDBCColumn("name", Types.VARCHAR)).add(new JDBCColumn("password", Types.VARCHAR)).add(new JDBCColumn("send_to", Types.VARCHAR)).add(new JDBCColumn("store_on_disk", Types.BOOLEAN)).add(new JDBCColumn("username", Types.VARCHAR));
    db.getTable("mail_lists", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createManyToManyLinkTable("mail_lists", "people");
    db.createTable("mail_lists_digest", false, "mail_lists_id INTEGER REFERENCES mail_lists ON DELETE CASCADE,people_id INTEGER REFERENCES people ON DELETE CASCADE", null, false);
    db.createManyTable("mail_lists", "subscribers", "email VARCHAR(60)");
    table_def = new JDBCTable().add(new JDBCColumn("people")).add(new JDBCColumn("email", Types.VARCHAR, 60));
    db.getTable("additional_emails", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    Roles.add("mail", m_site, db);
    m_site.addUserDropdownItem(new Page("Edit Mail Lists", m_site) {

        @Override
        public void write(Request request) throws IOException {
            request.site.writePageOpen("Edit Mail Lists", request);
            request.site.newView("mail_lists", request).writeComponent();
            request.close();
        }
    }.setRole("mail"), db);
}
Also used : JDBCTable(db.JDBCTable) Request(app.Request) JDBCColumn(db.JDBCColumn) Page(app.Page)

Example 4 with JDBCTable

use of db.JDBCTable in project common by zenlunatics.

the class ColumnBase method _init_.

// --------------------------------------------------------------------------
public static void _init_(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("_views_")).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("type_args", Types.VARCHAR));
    DBObject.addColumns(table_def, ColumnBase.class);
    db.getTable("_columns_", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 5 with JDBCTable

use of db.JDBCTable in project common by zenlunatics.

the class Minutes method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("date", Types.DATE)).add(new JDBCColumn("summary", Types.VARCHAR)).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("_owner_", "people"));
    for (JDBCColumn column : m_columns) table_def.add(column);
    addColumns(table_def);
    db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createManyTable(m_table, m_table + "_attachments", "filename VARCHAR");
    m_site.addModule(new Comments(m_table, m_site, db), db);
}
Also used : JDBCTable(db.JDBCTable) Comments(social.Comments) JDBCColumn(db.JDBCColumn)

Aggregations

JDBCTable (db.JDBCTable)17 JDBCColumn (db.JDBCColumn)14 Select (db.Select)4 Page (app.Page)3 Request (app.Request)3 SQLException (java.sql.SQLException)3 Options (db.Options)2 ViewDef (db.ViewDef)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 HTMLWriter (web.HTMLWriter)2 Module (app.Module)1 Pages (app.Pages)1 DBConnection (db.DBConnection)1 OneToMany (db.OneToMany)1 Reorderable (db.Reorderable)1 Schema (db.Schema)1 RoleAccessPolicy (db.access.RoleAccessPolicy)1 LookupColumn (db.column.LookupColumn)1 BufferedReader (java.io.BufferedReader)1