Search in sources :

Example 1 with Options

use of db.Options in project common by zenlunatics.

the class Documents method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("filename", Types.VARCHAR, 60)).add(new JDBCColumn("title", Types.VARCHAR, 60)).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("url", Types.BOOLEAN)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
    if (m_extra_columns != null)
        for (JDBCColumn column : m_extra_columns) table_def.add(column);
    addColumns(table_def);
    db.getTable("documents", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createTable("documents_types", "text VARCHAR");
    m_site.addObjects(new Options(new Select("text").from("documents_types").orderBy("text"), true, m_site).setAllowEditing(true));
    Roles.add("docs", m_site, db);
    m_site.addUserDropdownItem(new Page("Edit Documents", m_site) {

        @Override
        public void write(Request request) throws IOException {
            request.site.writePageOpen("Edit Documents", request);
            request.site.newView("edit documents", request).writeComponent();
            request.writer.br();
            request.close();
        }
    }.setRole("docs"), db);
}
Also used : Options(db.Options) JDBCTable(db.JDBCTable) Select(db.Select) Request(app.Request) JDBCColumn(db.JDBCColumn) Page(app.Page)

Example 2 with Options

use of db.Options in project common by zenlunatics.

the class Event method load.

// --------------------------------------------------------------------------
protected void load(ResultSet rs, Site site) {
    try {
        ResultSetMetaData rsmd = rs.getMetaData();
        for (int i = 1, n = rsmd.getColumnCount(); i <= n; i++) {
            String column = rsmd.getColumnName(i);
            switch(column) {
                case "color":
                    setColor(rs.getString(i));
                    break;
                case "date":
                    {
                        LocalDate localDate = rs.getDate(i).toLocalDate();
                        m_start.set(localDate.getYear(), localDate.getMonthValue() - 1, localDate.getDayOfMonth(), 0, 0, 0);
                    }
                    break;
                case "end_date":
                    Date end_date = rs.getDate(i);
                    if (end_date != null) {
                        LocalDate localDate = end_date.toLocalDate();
                        m_end_date = site.newCalendar();
                        m_end_date.set(localDate.getYear(), localDate.getMonthValue() - 1, localDate.getDayOfMonth(), 0, 0, 0);
                    }
                    break;
                case "end_time":
                    setEndTime(rs.getTime(i));
                    break;
                case "event":
                    m_event_text = rs.getString("event");
                    break;
                case "id":
                    m_id = rs.getInt(i);
                    break;
                case "notes":
                    m_notes = rs.getString(i);
                    break;
                case "_owner_":
                    m_owner = rs.getInt(i);
                    break;
                case "repeat":
                    m_repeat = rs.getString(i);
                    break;
                case "start_time":
                    setStartTime(rs.getTime(i));
                    break;
                default:
                    if (m_event_provider != null)
                        if (column.equals(m_event_provider.getCategoriesTable() + "_id")) {
                            Options categories = m_event_provider.getCategories();
                            if (categories != null) {
                                String categories_id = rs.getString(i);
                                if (categories_id != null)
                                    m_category = (Category) categories.getOptionByValue(categories_id);
                            }
                        } else if (column.equals(m_event_provider.getLocationsTable() + "_id")) {
                            Options locations = m_event_provider.getLocations();
                            if (locations != null) {
                                String location_id = rs.getString(i);
                                if (location_id != null)
                                    m_location = locations.getOptionByValue(location_id);
                            }
                        }
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Options(db.Options) SQLException(java.sql.SQLException) LocalDate(java.time.LocalDate) Date(java.sql.Date) LocalDate(java.time.LocalDate)

Example 3 with Options

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

Aggregations

Options (db.Options)3 JDBCColumn (db.JDBCColumn)2 JDBCTable (db.JDBCTable)2 Select (db.Select)2 Page (app.Page)1 Request (app.Request)1 RoleAccessPolicy (db.access.RoleAccessPolicy)1 Date (java.sql.Date)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1