Search in sources :

Example 16 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Pictures method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("file", Types.VARCHAR, 30)).add(new JDBCColumn("caption", Types.VARCHAR, 60)).add(new JDBCColumn("_owner_", "people").setOnDeleteSetNull(true)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("width", Types.INTEGER)).add(new JDBCColumn("height", Types.INTEGER));
    for (JDBCColumn column : m_additional_columns) table_def.add(column);
    addColumns(table_def);
    db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createTable(m_table + "_tags", "tag VARCHAR");
    db.createManyToManyLinkTable(m_table, m_table + "_tags");
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 17 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Admin method writeColumns.

// --------------------------------------------------------------------------
private void writeColumns(String table, Request request) throws IOException {
    JDBCTable jdbc_table = request.db.getTable(table);
    String[] column_names = jdbc_table.getColumnNamesAll();
    HTMLWriter writer = request.writer;
    writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>name</th><th>type</th><th>default</th><th>nullable</th><th>references</th><th>actions</th></tr>");
    for (String column : column_names) {
        writer.write("<tr><td onclick=\"column_rename('").write(table).write("','").write(column).write("',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))\" style=\"cursor:pointer;\">");
        writer.write(column);
        writer.write("</td><td onclick=\"new Dialog({url:'admin?action=get_column_form&table=").write(table).write("&column=").write(column).write("',title:'Edit Column',owner:this.ancestorWithClass('tab-pane'),ok:true,cancel:true})\" style=\"cursor:pointer;\">");
        JDBCColumn jdbc_column = jdbc_table.getColumn(column);
        int size = jdbc_column.size;
        String type_name = jdbc_column.type_name;
        writer.write(type_name);
        if (type_name.endsWith("CHAR") && size > 0) {
            writer.write('(');
            writer.write(Integer.toString(size));
            writer.write(')');
        }
        if (column.equals("id"))
            writer.write("</td><td>");
        else {
            writer.write("</td><td onclick=\"new Dialog({url:'admin?action=get default form&table=").write(table).write("&column=").write(column).write("',title:'Set Default',owner:this.ancestorWithClass('tab-pane'),ok:true,cancel:true})\" style=\"cursor:pointer;\">");
            writer.write(jdbc_column.getDefaultValue());
        }
        writer.write("</td><td>");
        writer.setAttribute("onchange", "XHR_post('admin','action='+(this.checked?'drop':'set')+'_not_null&table=" + table + "&column=" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.checkbox(null, null, null, jdbc_column.isNullable(), true);
        writer.write("</td><td>");
        if (jdbc_column.getPrimaryTable() != null)
            writer.write(jdbc_column.getPrimaryTable());
        else
            writer.nbsp();
        writer.write("</td><td>");
        writer.aOnClick("drop", "column_drop('" + table + "','" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.write(",&nbsp;");
        writer.aOnClick("index", "XHR_post('admin','action=column_index&table=" + table + "&column=" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.write("</td></tr>");
    }
    writer.write("</table>");
}
Also used : HTMLWriter(web.HTMLWriter) JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 18 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class EventProvider method adjustTables.

// --------------------------------------------------------------------------
protected void adjustTables(DBConnection db) {
    if (m_events_table != null) {
        JDBCTable table_def = new JDBCTable().add(new JDBCColumn("date", Types.DATE)).add(new JDBCColumn("notes", Types.VARCHAR)).add(new JDBCColumn("uuid", Types.VARCHAR));
        if (m_events_are_owned)
            table_def.add(new JDBCColumn("_owner_", "people").setOnDeleteSetNull(true));
        if (m_events_can_repeat) {
            table_def.add(new JDBCColumn("repeat", Types.VARCHAR));
            table_def.add(new JDBCColumn("end_date", Types.DATE));
        }
        if (m_events_have_category) {
            String categories_table = m_events_table + "_categories";
            table_def.add(new JDBCColumn(categories_table).setOnDeleteSetNull(true));
            JDBCTable table_def2 = new JDBCTable().add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("color", Types.VARCHAR));
            if (db.tableExists(categories_table))
                db.getTable(categories_table).createMissingColumns(table_def2, db).dropExtraColumns(table_def2, db);
            else
                db.createTable(categories_table, "text VARCHAR,color VARCHAR");
            m_categories = (Options) m_site.getObjects(categories_table);
            if (m_categories == null) {
                m_categories = new Options(new Select("*").from(categories_table).orderBy("lower(text)"), true, m_site).setAllowEditing(true);
                m_categories.setObjectClass(Category.class);
                m_site.addObjects(m_categories);
            }
        }
        if (m_events_have_color)
            table_def.add(new JDBCColumn("color", Types.VARCHAR));
        if (m_events_have_event)
            table_def.add(new JDBCColumn("event", Types.VARCHAR));
        if (m_events_have_location) {
            String locations_table = getLocationsTable();
            table_def.add(new JDBCColumn(locations_table).setOnDeleteSetNull(true));
            db.createTable(locations_table, "text VARCHAR");
            m_locations = (Options) m_site.getObjects(locations_table);
            if (m_locations == null) {
                m_locations = new Options(new Select("*").from(locations_table).orderBy("lower(text)"), true, m_site).setAllowEditing(true);
                m_site.addObjects(m_locations);
            }
        }
        if (m_events_have_start_time) {
            table_def.add(new JDBCColumn("start_time", Types.TIME));
            table_def.add(new JDBCColumn("end_time", Types.TIME));
        }
        if (m_one_table != null)
            table_def.add(new JDBCColumn(m_one_table));
        if (m_support_registrations)
            table_def.add(new JDBCColumn("register_people", Types.BOOLEAN));
        table_def.add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
        for (JDBCColumn column : m_additional_columns) table_def.add(column);
        db.getTable(m_events_table, true).matchColumns(table_def, db);
        db.createIndex(m_events_table, "date");
        if (m_support_registrations) {
            table_def = new JDBCTable().add(new JDBCColumn(m_events_table)).add(new JDBCColumn("person", Types.INTEGER)).add(new JDBCColumn("note", Types.VARCHAR));
            db.getTable(m_events_table + "_registrations", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
        }
        adjustRemindersTables(db);
    }
    if (m_role != null) {
        Roles.add(m_role, m_site, db);
        setAccessPolicy(new RoleAccessPolicy(m_role).add().delete().edit());
    } else
        setAccessPolicy(null);
}
Also used : Options(db.Options) JDBCTable(db.JDBCTable) Select(db.Select) JDBCColumn(db.JDBCColumn) RoleAccessPolicy(db.access.RoleAccessPolicy)

Example 19 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Pages method init.

// --------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("name", Types.VARCHAR));
    db.getTable("designs", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    table_def = new JDBCTable().add(new JDBCColumn("designs")).add(new JDBCColumn("description", Types.VARCHAR)).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("data", Types.VARCHAR)).add(new JDBCColumn("_order_", Types.INTEGER));
    db.getTable("designs_items", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    table_def = new JDBCTable().add(new JDBCColumn("designs")).add(new JDBCColumn("filename", Types.VARCHAR));
    db.getTable("designs_css_files", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    table_def = new JDBCTable().add(new JDBCColumn("designs")).add(new JDBCColumn("filename", Types.VARCHAR));
    db.getTable("designs_js_files", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    DBObject.init("pages", Page.class, db);
    table_def = new JDBCTable().add(new JDBCColumn("pages")).add(new JDBCColumn("description", Types.VARCHAR)).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("data", Types.VARCHAR)).add(new JDBCColumn("_order_", Types.INTEGER));
    db.getTable("pages_items", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    try {
        ResultSet rs = db.select(new Select("*").from("pages"));
        while (rs.next()) {
            Page page = new Page();
            DBObject.load(page, rs);
            m_pages.put(page.getName().toLowerCase(), page);
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        m_site.log(e);
    }
}
Also used : SQLException(java.sql.SQLException) JDBCTable(db.JDBCTable) ResultSet(java.sql.ResultSet) Select(db.Select) JDBCColumn(db.JDBCColumn)

Example 20 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class People method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("data", Types.VARCHAR)).add(new JDBCColumn("data_keys", Types.VARCHAR)).add(new JDBCColumn("email", Types.VARCHAR)).add(new JDBCColumn("first", Types.VARCHAR)).add(new JDBCColumn("last", Types.VARCHAR)).add(new JDBCColumn("last_login", Types.TIMESTAMP)).add(new JDBCColumn("password", Types.VARCHAR)).add(new JDBCColumn("user_name", Types.VARCHAR).setUnique(true));
    for (JDBCColumn column : m_additional_columns) table_def.add(column);
    db.getTable("people", true).matchColumns(table_def, db);
    db.createManyTable("people", "user_roles", "user_name VARCHAR REFERENCES people(user_name) ON UPDATE CASCADE, role VARCHAR");
    if (!db.exists("people", null)) {
        int id = db.insert("people", "first,user_name,password", "'Administrator','admin','admin'");
        db.insert("user_roles", "people_id,user_name,role", id + ",'admin','administrator'");
        if (m_site.getDefaultRole() != null)
            db.insert("user_roles", "people_id,user_name,role", id + ",'admin','" + m_site.getDefaultRole() + "'");
    }
    Roles.add("people", m_site, db);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Aggregations

JDBCColumn (db.JDBCColumn)20 JDBCTable (db.JDBCTable)14 Select (db.Select)5 HTMLWriter (web.HTMLWriter)4 Page (app.Page)3 Request (app.Request)3 ViewDef (db.ViewDef)3 NameValuePairs (db.NameValuePairs)2 Options (db.Options)2 RoleAccessPolicy (db.access.RoleAccessPolicy)2 Column (db.column.Column)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Pages (app.Pages)1 LinkValueRenderer (db.LinkValueRenderer)1 ManyToMany (db.ManyToMany)1 AccessPolicy (db.access.AccessPolicy)1 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)1 FileColumn (db.column.FileColumn)1