List of usage examples for org.hibernate.mapping Table getName
public String getName()
From source file:com.github.gekoh.yagen.hibernate.PatchGlue.java
License:Apache License
public static String afterTableSqlCreateString(Table table, Dialect dialect, String returnValue) { StringBuffer buf = new StringBuffer(returnValue); Map<String, Column> allColumns = new LinkedHashMap<String, Column>(); Iterator<Column> colIt = table.getColumnIterator(); while (colIt.hasNext()) { Column column = colIt.next();/*from w w w . ja v a2 s.c o m*/ allColumns.put(column.getName().toLowerCase(), column); } CreateDDL ddlEnhancer = getDDLEnhancerFromDialect(dialect); if (ddlEnhancer == null) { return returnValue; } return ddlEnhancer.updateCreateTable(dialect, buf.append(dialect.getTableTypeString()), table.getName(), allColumns); }
From source file:com.github.gekoh.yagen.hibernate.PatchGlue.java
License:Apache License
public static String afterTableSqlDropString(Table table, Dialect dialect, String returnValue) { StringBuffer buf = new StringBuffer(returnValue); CreateDDL ddlEnhancer = getDDLEnhancerFromDialect(dialect); if (ddlEnhancer == null) { return returnValue; }/* ww w . j av a 2s . c om*/ return ddlEnhancer.updateDropTable(dialect, buf, table.getName()); }
From source file:com.github.shyiko.rook.target.hibernate4.cache.PrimaryKey.java
License:Apache License
private PrimaryKey(KeyValue keyValue, Table table, Map<String, Integer> columnIndexByNameMap) { KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()]; int index = 0; if (keyValue instanceof Component) { Iterator propertyIterator = ((Component) keyValue).getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); String columnName = ((Column) property.getColumnIterator().next()).getName(); positionWithinRow[index++] = new KeyColumn(property.getName(), columnIndexByNameMap.get(columnName)); }/* w w w . j a v a 2 s. co m*/ } else { Iterator columnIterator = keyValue.getColumnIterator(); while (columnIterator.hasNext()) { String columnName = ((Column) columnIterator.next()).getName(); positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName)); } } if (positionWithinRow.length == 0) { throw new IllegalStateException("Unable to determine PK for " + table.getName()); } this.positionWithinRow = positionWithinRow; }
From source file:com.github.shyiko.rook.target.hibernate4.cache.SynchronizationContext.java
License:Apache License
private Map<String, Integer> getColumnIndexByNameMap(Table table) throws SQLException { String tableName = table.getName(); if (!columnMappingsByTable.containsKey(tableName)) { Map<String, Integer> columnIndexByName = extractColumnMapping(table); columnMappingsByTable.put(tableName, Collections.unmodifiableMap(columnIndexByName)); }//from w ww.j av a 2 s. c om return columnMappingsByTable.get(tableName); }
From source file:com.github.shyiko.rook.target.hibernate4.cache.SynchronizationContext.java
License:Apache License
private Map<String, Integer> extractColumnMapping(Table table) throws SQLException { Map<String, Integer> result = new HashMap<String, Integer>(); Connection connection = null; ConnectionProvider connectionProvider = getSessionFactory().getServiceRegistry() .getService(ConnectionProvider.class); try {// ww w .j a va 2 s .c o m connection = connectionProvider.getConnection(); DatabaseMetaData meta = connection.getMetaData(); ResultSet rs = meta.getColumns(table.getCatalog(), table.getSchema(), table.getName(), "%"); try { int index = 0; while (rs.next()) { String column = rs.getString("COLUMN_NAME"); if (column != null) { result.put(column, index++); } } } finally { rs.close(); } } finally { connectionProvider.closeConnection(connection); } return result; }
From source file:com.github.shyiko.rook.target.hibernate4.cache.SynchronizationContext.java
License:Apache License
private Collection<EvictionTarget> evictionTargetsOf(Table table) { String key = schema + "." + table.getName().toLowerCase(); Collection<EvictionTarget> evictionTargets = targetsByTable.get(key); if (evictionTargets == null) { targetsByTable.put(key, evictionTargets = new LinkedList<EvictionTarget>()); }/*from w w w.j a va 2 s . co m*/ return evictionTargets; }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.PrimaryKey.java
License:Apache License
public PrimaryKey(PersistentClass persistentClass) { this.entityClass = persistentClass.getMappedClass(); KeyValue keyValue = persistentClass.getKey(); Table table = persistentClass.getTable(); Map<String, Integer> columnIndexByNameMap = getColumnIndexByNameMap(table); KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()]; int index = 0; if (keyValue instanceof Component) { Iterator propertyIterator = ((Component) keyValue).getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); String columnName = ((Column) property.getColumnIterator().next()).getName(); positionWithinRow[index++] = new KeyColumn(property.getName(), columnIndexByNameMap.get(columnName)); }//from w w w. j a va2 s .co m } else { Iterator columnIterator = keyValue.getColumnIterator(); while (columnIterator.hasNext()) { String columnName = ((Column) columnIterator.next()).getName(); positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName)); } } if (positionWithinRow.length == 0) { throw new IllegalStateException("Unable to determine PK for " + table.getName()); } Property identifierProperty = persistentClass.getIdentifierProperty(); this.getter = identifierProperty.getGetter(this.entityClass); this.positionWithinRow = positionWithinRow; }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java
License:Apache License
@SuppressWarnings("unchecked") private void loadIndexingDirectives(Configuration configuration) { Map<String, IndexingDirective> directivesByEntityNameMap = new HashMap<String, IndexingDirective>(); Collection<Property> allContainedInProperties = new ArrayList<Property>(); for (Iterator<PersistentClass> classIterator = configuration.getClassMappings(); classIterator.hasNext();) { PersistentClass persistentClass = classIterator.next(); boolean suppressSelfIndexing = true; Class mappedClass = persistentClass.getMappedClass(); Indexed indexed = (Indexed) mappedClass.getAnnotation(Indexed.class); EntityIndexingInterceptor indexingInterceptor = null; if (indexed != null) { suppressSelfIndexing = false; Class<? extends EntityIndexingInterceptor> interceptorClass = indexed.interceptor(); if (interceptorClass != DefaultEntityInterceptor.class) { try { indexingInterceptor = interceptorClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); }/*from w w w . j a va2 s . c o m*/ } } Collection<Property> containedInProperties = extractAnnotatedProperties(persistentClass, ContainedIn.class); if (suppressSelfIndexing && containedInProperties.isEmpty()) { continue; } allContainedInProperties.addAll(containedInProperties); PrimaryKey primaryKey = new PrimaryKey(persistentClass); Collection<Reference> containers = new ArrayList<Reference>(); for (Property property : containedInProperties) { containers.add(new Reference(property.getGetter(mappedClass))); } IndexingDirective indexingDirective = new IndexingDirective(primaryKey, suppressSelfIndexing, indexingInterceptor, containers); Table table = persistentClass.getTable(); directivesByTable.put(schema + "." + table.getName().toLowerCase(), indexingDirective); directivesByEntityClass.put(mappedClass, indexingDirective); directivesByEntityNameMap.put(persistentClass.getEntityName(), indexingDirective); } loadIndexingDirectivesForJoinTables(allContainedInProperties, directivesByEntityNameMap); }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java
License:Apache License
private void loadIndexingDirectivesForJoinTables(Collection<Property> allContainedInProperties, Map<String, IndexingDirective> directivesByEntityNameMap) { for (Property property : allContainedInProperties) { Value value = property.getValue(); if (value instanceof org.hibernate.mapping.Collection) { org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value; Table collectionTable = collection.getCollectionTable(); String tableName = schema + "." + collectionTable.getName().toLowerCase(); if (directivesByTable.containsKey(tableName)) { continue; }//from w w w .ja v a 2 s . com PrimaryKey primaryKey = resolveForeignPrimaryKey(collection, directivesByEntityNameMap); if (primaryKey == null) { continue; } IndexingDirective containerIndexingDirective = directivesByEntityClass .get(primaryKey.getEntityClass()); directivesByTable.put(tableName, new IndexingDirective(primaryKey, containerIndexingDirective.isSuppressSelfIndexing(), containerIndexingDirective.getEntityIndexingInterceptor(), containerIndexingDirective.getContainerReferences())); } } }
From source file:com.krawler.esp.hibernate.impl.HibernateUtil.java
License:Open Source License
public static String getPrimaryColName(String tableName) throws ServiceException { String colName = ""; Configuration cfg = HibernateUtil.getConfig(); java.util.Iterator itr = cfg.getTableMappings(); while (itr.hasNext()) { Table table = (Table) itr.next(); if (tableName.equals(table.getName())) { colName = getPrimaryColName(table); break; }/*from w ww. java 2 s . c o m*/ } return colName; }