Search in sources :

Example 11 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class News method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("provider", Types.VARCHAR)).add(new JDBCColumn("item_id", Types.INTEGER)).add(new JDBCColumn("_owner_", "people")).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("last_update", Types.TIMESTAMP));
    for (JDBCColumn column : m_additional_columns) table_def.add(column);
    db.getTable("news", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 12 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class NewsFeed method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("_owner_", "people")).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
    addColumns(table_def);
    db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 13 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Discussions method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("title", Types.VARCHAR, 60)).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("_owner_", "people"));
    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");
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 14 with JDBCColumn

use of db.JDBCColumn 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 15 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class ColumnBase method writeInput.

// --------------------------------------------------------------------------
public static void writeInput(String column_name, String default_value, View view, Request request) throws IOException {
    JDBCColumn jdbc_column = request.db.getTable(view.getViewDef().getFrom()).getColumn(column_name);
    if (jdbc_column == null)
        throw new RuntimeException("column " + column_name + " not found in table " + view.getViewDef().getFrom());
    String value = getValue(jdbc_column, default_value, view, request);
    HTMLWriter writer = request.writer;
    if (jdbc_column.isBinary())
        TextAreaColumn.writeTextArea(column_name, DBConnection.decodeBinary(value), 40, 5, view, writer);
    else if (jdbc_column.isBoolean()) {
        writer.checkbox(column_name, column_name.replace('_', ' '), null, value != null && (value.equals("yes") || value.equals("t")), false);
        writer.hiddenInput("db_boolean" + writer.newID(), column_name);
    } else if (jdbc_column.isDate())
        writer.dateInput(column_name, value);
    else if (jdbc_column.isInteger())
        writer.numberInput(column_name, null, null, value);
    else if (jdbc_column.isText())
        writer.textAreaExpanding(column_name, "min-width:100px", value);
    else if (jdbc_column.isTime()) {
        Calendar time = null;
        if (view.getMode() == View.Mode.EDIT_FORM) {
            Time t = view.data().getTime(column_name);
            if (t != null) {
                time = Calendar.getInstance();
                time.setTime(t);
            }
        } else if (value != null)
            try {
                time = Calendar.getInstance();
                time.setTime(new SimpleDateFormat("hh:mm a").parse(value));
            } catch (ParseException e) {
            }
        writer.timeInput(column_name, time);
    } else
        writer.textInput(column_name, Integer.toString(jdbc_column.size), value);
}
Also used : HTMLWriter(web.HTMLWriter) Calendar(java.util.Calendar) JDBCColumn(db.JDBCColumn) Time(java.sql.Time) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

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