@Override public Column[] getColumns(DatabaseMetaData meta, String catalog, String schemaName, String tableName, String columnName, Connection conn) throws SQLException { return getColumns(meta, DBIdentifier.newCatalog(catalog), DBIdentifier.newSchema(schemaName), DBIdentifier.newTable(tableName), DBIdentifier.newColumn(columnName), conn); }
/** * Returns a new DBIdentifier with the given string combined using * delimiting rules and appropriate separators. * @param name * @param length */ public static DBIdentifier combine(DBIdentifier name, String str) { DBIdentifier sName = name.clone(); String strName = sName.getNameInternal(); strName = Normalizer.combine(strName, str); sName.setNameInternal(strName); return sName; }
public DBIdentifier getGeneratedKeySequenceName(Column col, int maxLen) { DBIdentifier tname = col.getTableIdentifier(); DBIdentifier cname = col.getIdentifier(); int max = maxLen; int extraChars = -max + tname.getName().length() + 1 // <tname> + '_' + cname.getName().length() + 4; // <cname> + '_SEQ' String tsname = tname.getName(); if (extraChars > 0) { // this assumes that tname is longer than extraChars tsname = tsname.substring(0, tsname.length() - extraChars); } return DBIdentifier.combine(DBIdentifierType.SEQUENCE, tsname, cname.getName(), "SEQ"); }
@Override public void populateJoinColumn(FieldMapping fm, Table local, Table foreign, Column col, Object target, int pos, int cols) { // only use spec defaults with column targets if (!(target instanceof Column)) return; // if this is a bidi relation, prefix with inverse field name, else // prefix with owning entity name FieldMapping[] inverses = fm.getInverseMappings(); DBIdentifier sName = DBIdentifier.NULL; if (inverses.length > 0) sName = DBIdentifier.newColumn(inverses[0].getName()); else sName = DBIdentifier.newColumn(fm.getDefiningMapping().getTypeAlias()); DBIdentifier targetName = ((Column) target).getIdentifier(); DBIdentifier tempName = DBIdentifier.NULL; if ((sName.length() + targetName.length()) >= dict.maxColumnNameLength) tempName = DBIdentifier.truncate(sName, dict.maxColumnNameLength - targetName.length() - 1); // suffix with '_' + target column if (DBIdentifier.isNull(tempName)) tempName = sName; sName = DBIdentifier.combine(tempName, targetName.getName()); sName = dict.getValidColumnName(sName, foreign); col.setIdentifier(sName); }
public void populateForeignKeyColumn(ValueMapping vm, DBIdentifier sName, Table local, Table foreign, Column col, Object target, boolean inverse, int pos, int cols) { boolean elem = vm == vm.getFieldMapping().getElement() && vm.getFieldMapping().getTypeCode() != JavaTypes.MAP; // if this is a non-inverse collection element key, it must be in // a join table: if we're not prepending the field name, leave the // default if (!_prependFieldNameToJoinTableInverseJoinColumns && !inverse && elem) return; // otherwise jpa always uses <field>_<pkcol> for column name, even // when only one col if (target instanceof Column) { if (DBIdentifier.isNull(sName)) { sName = col.getIdentifier(); } else { if (elem) sName = DBIdentifier.newColumn(vm.getFieldMapping().getName()); if (isRemoveHungarianNotation()) sName = DBIdentifier.newColumn(Normalizer.removeHungarianNotation(sName.getName())); sName = sName.combine(sName, ((Column)target).getIdentifier().getName()); // No need to check for uniqueness. sName = dict.getValidColumnName(sName, local, false); } col.setIdentifier(sName); } }
if (_seconds == null || DBIdentifier.isNull(tableName) || _seconds.containsKey(tableName) || !DBIdentifier.isNull(path.getSchemaName())) return tableName; if (joinPath.isUnqualifiedObject() && pts < 2 && fullJoin.equalsIgnoreCase(tableName)) { best = fullJoin; pts = 2; if (join.equals(tableName)) return fullJoin; if (pts < 1 && join.equalsIgnoreCase(tableName)) { best = fullJoin; pts = 1;
/** * Reflect on the schema to find tables matching the given name pattern. * @deprecated */ public Table[] getTables(DatabaseMetaData meta, String catalog, String schemaName, String tableName, Connection conn) throws SQLException { return getTables(meta, DBIdentifier.newCatalog(catalog), DBIdentifier.newSchema(schemaName), DBIdentifier.newTable(tableName), conn); }
/** * Form a qualified table name from a schema and table name. */ private DBIdentifier toTableIdentifier(String schema, String table) { DBIdentifier sName = DBIdentifier.newSchema(schema, delimit()); DBIdentifier tName = DBIdentifier.newTable(table, delimit()); if (DBIdentifier.isEmpty(tName) || DBIdentifier.isEmpty(sName)) { return tName; } return QualifiedDBIdentifier.newPath(sName, tName); }
/** * Returns a copy of an identifier with name trimmed to null. * @param name */ public static DBIdentifier trimToNull(DBIdentifier name) { if (DBIdentifier.isNull(name)) { return name; } DBIdentifier sName = name.clone(); sName.setNameInternal(StringUtil.trimToNull(sName.getNameInternal())); return sName; }
/** * Reflect on the schema to find sequences matching the given name pattern. * Returns an empty array by default, as there is no standard way to * retrieve a list of sequences. * @deprecated */ public Sequence[] getSequences(DatabaseMetaData meta, String catalog, String schemaName, String sequenceName, Connection conn) throws SQLException { return getSequences(meta, DBIdentifier.newCatalog(catalog), DBIdentifier.newSchema(schemaName), DBIdentifier.newSequence(sequenceName), conn); }
/** * Creates a clone of this identifier. */ public QualifiedDBIdentifier clone() { QualifiedDBIdentifier sPath = new QualifiedDBIdentifier(); sPath.setObjectTableName(getObjectTableName().clone()); sPath.setSchemaName(getSchemaName().clone()); sPath.setBaseName(super.getName()); sPath.setType(getType()); sPath.setIgnoreCase(getIgnoreCase()); return sPath; }
return null; if (!DBIdentifier.isNull(path.getSchemaName())) { Schema schema = getSchema(path.getSchemaName()); if (schema != null) boolean isDefaultSchema = DBIdentifier.isNull(inSchema.getIdentifier()) && !DBIdentifier.isNull(defaultSchemaName) && DBIdentifier.equalsIgnoreCase(defaultSchemaName, schemas[i].getIdentifier()); boolean hasNoDefaultSchema = DBIdentifier.isNull(inSchema.getIdentifier()) && DBIdentifier.isNull(defaultSchemaName);
/** * Create a new schema column with information from the given annotation. */ private Column newColumn(PrimaryKeyJoinColumn join) { Column col = new Column(); col.setFlag(Column.FLAG_PK_JOIN, true); if (!StringUtil.isEmpty(join.name())) col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit())); if (!StringUtil.isEmpty(join.columnDefinition())) col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); if (!StringUtil.isEmpty(join.referencedColumnName())) setTargetIdentifier(col, join.referencedColumnName()); return col; }
/** * Helper to track the secondary table for a set of columns. * * @param secondary secondary table for last column * @param colSecondary secondary table for current column * @return secondary table for field */ private DBIdentifier trackSecondaryTable(FieldMapping fm, DBIdentifier secondary, DBIdentifier colSecondary, int col) { if (DBIdentifier.isEmpty(colSecondary)) colSecondary = DBIdentifier.NULL; if (col == 0) return colSecondary; if (!DBIdentifier.equalsIgnoreCase(secondary, colSecondary)) throw new MetaDataException(_loc.get("second-inconsist", fm)); return secondary; }
/** * The database-specific SQL type of this column. * @deprecated */ public void setTypeName(String typeName) { setTypeIdentifier(DBIdentifier.newColumnDefinition(typeName)); }
public void populateDataStoreIdColumns(ClassMapping cls, Table table, Column[] cols) { for (int i = 0; i < cols.length; i++) { if (!DBIdentifier.isNull(_dsIdName) && cols.length == 1) cols[i].setIdentifier(_dsIdName); else if (!DBIdentifier.isNull(_dsIdName)) cols[i].setIdentifier(DBIdentifier.append(_dsIdName, Integer.toString(i))); correctName(table, cols[i]); } }