Search in sources :

Example 16 with JDBCTable

use of db.JDBCTable 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 17 with JDBCTable

use of db.JDBCTable 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

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