/** * createIndexDDL has been added for Symfoware support. Returns DDL in String form * to create index. The returned string has the format: * <pre> * CREATE INDEX table_name.table_name KEY(id, name) * </pre> * @param table Table for which DDL is to be created. * @return DDL to create index. */ private static String createIndexDDL(TableElement table) { String[] twoParam = { table.getName().getName() , getColumnNames(table.getPrimaryKey().getColumns()) }; return DDLTemplateFormatter.formatCreateIndex(twoParam); }
/** * Create primary key and add to table. * @param table TableElement for adding primary key. * @return UniqueKeyElement that represents the primary key. * @throws DBException */ static UniqueKeyElement createAndAttachPrimaryKey(TableElement table, String pKeyName) throws DBException { String tableName = table.getName().getName(); String fullName = NameUtil.getAbsoluteMemberName(tableName, pKeyName); // create index for primary key TableElementImpl tableImpl = (TableElementImpl)table.getElementImpl(); IndexElementImpl indexImpl = new IndexElementImpl(tableImpl, fullName, true); IndexElement index = new IndexElement(indexImpl, table); index.setUnique(true); UniqueKeyElementImpl pKeyImpl = new UniqueKeyElementImpl(); UniqueKeyElement pKey = new UniqueKeyElement(pKeyImpl, table, index); pKey.setName(DBIdentifier.create(fullName)); pKey.setPrimaryKey(true); table.addKey(pKey); table.addIndex(pKey.getAssociatedIndex()); return pKey; }
if (uk.isPrimaryKey() && Arrays.asList( uk.getColumns()).contains(column))
/** * Returns DDL in String form to create a primary key constraint. The * string has the format: * <pre> * CONSTRAINT pk_name PRIMARY KEY(id, name) * </pre> * @param table Table for which constraint DDL is returned. * @return DDL to create a PK constraint or null if there is no PK. */ private static String createPrimaryKeyConstraint(TableElement table) { String rc = null; UniqueKeyElement pk = table.getPrimaryKey(); if (pk != null) { String[] twoParams = new String[2]; twoParams[0] = pk.getName().getName(); twoParams[1] = getColumnNames(pk.getColumns()); rc = DDLTemplateFormatter.formatPKConstraint(twoParams); } return rc; }
retVal.setDeclaringSchema(schema); org.netbeans.modules.dbschema.UniqueKeyElement tkey = new org.netbeans.modules.dbschema.UniqueKeyElement(); ColumnElement fakeKeyCol = new ColumnElement(); fakeKeyCol.setName(DBIdentifier.create(retVal.getName().getName()+ "."+"fookeyng")); //NOI18N tkey.setPrimaryKey(true); tkey.addColumn(fakeKeyCol); retVal.addColumn(fakeKeyCol); retVal.addKey(tkey);
pKey.addColumn(column); pKey.getAssociatedIndex().addColumn(column); mappingClass.getTable(tableName).addKeyColumn( column);
/** * Checks, if the column <code>ce</code> is part of the * primary key <code>pk</code>. * RESOLVE: Method isPrimaryKeyColumn in ModelValidator * implements similar functionality. * * @param ce Column element for the column to be tested. * @param pk Primary key element. The column to be tested * <b>must</b> be defined in the same table. * @return True, if the column is part of the primary key, * false otherwise. * @see com.sun.jdo.api.persistence.model.util.ModelValidator */ private boolean isPartOfPrimaryKey(ColumnElement ce, UniqueKeyElement pk) { return null != pk && ce.equals(pk.getColumn(ce.getName())); }
ColumnElement cols[] = uke.getColumns(); if (null != cols && 1 == cols.length) { candidatePK = cols[0];
if (uk.isPrimaryKey() && Arrays.asList( uk.getColumns()).contains(column))
ColumnElement[] columns = key.getColumns(); int i, count = ((columns != null) ? columns.length : 0);
ColumnElement[] columns = key.getColumns(); int i, count = ((columns != null) ? columns.length : 0);
if (primaryTableColumns.size() < pk.getColumns().length) {
ColumnElement [] pkColumns = pk.getColumns(); String refTblName = refTbl.getName().getName();