📄 tablemap.java
字号:
Iterator it = columns.values().iterator(); int i = 0; while (it.hasNext()) { tableColumns[i++] = (ColumnMap) it.next(); } return tableColumns; } /** * Get a ColumnMap for the named table. * * @param name A String with the name of the table. * @return A ColumnMap. */ public ColumnMap getColumn(String name) { try { return (ColumnMap) columns.get(name); } catch (Exception e) { return null; } } /** * Add a pre-created column to this table. It will replace any * existing column. * * @param cmap A ColumnMap. */ public void addColumn (ColumnMap cmap) { columns.put (cmap.getColumnName(), cmap); } /** * Add a column to this table of a certain type. * * @param columnName A String with the column name. * @param type An Object specifying the type. */ public void addColumn(String columnName, Object type) { addColumn(columnName, type, false, null, null, 0); } /** * Add a column to this table of a certain type and size. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param size An int specifying the size. */ public void addColumn(String columnName, Object type, int size) { addColumn(columnName, type, false, null, null, size); } /** * Add a primary key column to this Table. * * @param columnName A String with the column name. * @param type An Object specifying the type. */ public void addPrimaryKey(String columnName, Object type) { addColumn(columnName, type, true, null, null, 0); } /** * Add a primary key column to this Table. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param size An int specifying the size. */ public void addPrimaryKey(String columnName, Object type, int size) { addColumn(columnName, type, true, null, null, size); } /** * Add a foreign key column to the table. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param fkTable A String with the foreign key table name. * @param fkColumn A String with the foreign key column name. */ public void addForeignKey(String columnName, Object type, String fkTable, String fkColumn) { addColumn(columnName, type, false, fkTable, fkColumn, 0); } /** * Add a foreign key column to the table. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param fkTable A String with the foreign key table name. * @param fkColumn A String with the foreign key column name. * @param size An int specifying the size. */ public void addForeignKey(String columnName, Object type, String fkTable, String fkColumn, int size) { addColumn(columnName, type, false, fkTable, fkColumn, size); } /** * Add a foreign primary key column to the table. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param fkTable A String with the foreign key table name. * @param fkColumn A String with the foreign key column name. */ public void addForeignPrimaryKey(String columnName, Object type, String fkTable, String fkColumn) { addColumn(columnName, type, true, fkTable, fkColumn, 0); } /** * Add a foreign primary key column to the table. * * @param columnName A String with the column name. * @param type An Object specifying the type. * @param fkTable A String with the foreign key table name. * @param fkColumn A String with the foreign key column name. * @param size An int specifying the size. */ public void addForeignPrimaryKey(String columnName, Object type, String fkTable, String fkColumn, int size) { addColumn(columnName, type, true, fkTable, fkColumn, size); } /** * Add a column to the table. * * @param name A String with the column name. * @param type An Object specifying the type. * @param pk True if column is a primary key. * @param fkTable A String with the foreign key table name. * @param fkColumn A String with the foreign key column name. * @param size An int specifying the size. */ private void addColumn(String name, Object type, boolean pk, String fkTable, String fkColumn, int size) { // If the tablename is prefixed with the name of the column, // remove it ie: SCARAB_PROJECT.PROJECT_ID remove the // SCARAB_PROJECT. if (name.indexOf('.') > 0 && name.indexOf(getName()) != -1) { name = name.substring(getName().length() + 1); } if (fkTable != null && fkTable.length() > 0 && fkColumn != null && fkColumn.length() > 0) { if (fkColumn.indexOf('.') > 0 && fkColumn.indexOf(fkTable) != -1) { fkColumn = fkColumn.substring(fkTable.length() + 1); } } ColumnMap col = new ColumnMap(name, this); col.setType(type); col.setPrimaryKey(pk); col.setForeignKey(fkTable, fkColumn); col.setSize(size); columns.put(name, col); } /** * Sets the method used to generate a key for this table. Valid * values are as specified in the {@link * org.apache.torque.adapter.IDMethod} interface. * * @param method The ID generation method type name. */ public void setPrimaryKeyMethod(String method) { primaryKeyMethod = NO_ID_METHOD; // Validate ID generation method. for (int i = 0; i < VALID_ID_METHODS.length; i++) { if (VALID_ID_METHODS[i].equalsIgnoreCase(method)) { primaryKeyMethod = method; break; } } } /** * Sets the pk information needed to generate a key * * @param pkInfo information needed to generate a key */ public void setPrimaryKeyMethodInfo(Object pkInfo) { this.pkInfo = pkInfo; } //---Utility methods for doing intelligent lookup of table names /** * Tell me if i have PREFIX in my string. * * @param data A String. * @return True if prefix is contained in data. */ private final boolean hasPrefix(String data) { return (data.indexOf(getPrefix()) != -1); } /** * Removes the PREFIX. * * @param data A String. * @return A String with data, but with prefix removed. */ private final String removePrefix(String data) { return data.substring(getPrefix().length()); } /** * Removes the PREFIX, removes the underscores and makes * first letter caps. * * SCARAB_FOO_BAR becomes FooBar. * * @param data A String. * @return A String with data processed. */ public final String removeUnderScores(String data) { String tmp = null; StringBuffer out = new StringBuffer(); if (hasPrefix(data)) { tmp = removePrefix(data); } else { tmp = data; } StringTokenizer st = new StringTokenizer(tmp, "_"); while (st.hasMoreTokens()) { String element = ((String) st.nextElement()).toLowerCase(); out.append (StringUtils.capitalise(element)); } return out.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -