List of usage examples for org.hibernate.mapping Table getName
public String getName()
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void createUniqueKeyForColumns(Table table, String columnName, List<Column> keyList) { Collections.reverse(keyList); UniqueKey key = table.getOrCreateUniqueKey("unique-" + columnName); List<?> columns = key.getColumns(); if (columns.isEmpty()) { LOG.debug("create unique key for " + table.getName() + " columns = " + keyList); key.addColumns(keyList.iterator()); }/*from w w w. j av a2 s . co m*/ }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private Table getTableMapping(String tablename, DefaultGrailsDomainConfiguration config) { Table result = null;/*from w w w . ja va 2s .co m*/ for (Iterator tableMappings = config.getTableMappings(); tableMappings.hasNext();) { Table table = (Table) tableMappings.next(); if (tablename.equals(table.getName())) { result = table; } } return result; }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private void assertColumnNotNullable(String tablename, String columnName, DefaultGrailsDomainConfiguration config) { Table table = getTableMapping(tablename, config); assertTrue(table.getName() + "." + columnName + " is not nullable", !table.getColumn(new Column(columnName)).isNullable()); }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
/** * Extra lazy mapping for lists needs a real property for the list index and * a real inverse for the other side as well. * /*ww w .j av a2 s .co m*/ * This method iterates over all associations and adds an inverse for the * list and set mappings. */ protected void addExtraLazyInverseProperties() { final Map<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>(); for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) { final PersistentClass pc = (PersistentClass) pcs.next(); if (isClassOrSuperClassEAVMapped(pc)) { continue; } persistentClasses.put(pc.getEntityName(), pc); } for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) { final PersistentClass pc = (PersistentClass) pcs.next(); // copy to prevent concurrent modification final Iterator<?> propIt = pc.getPropertyIterator(); final List<Property> props = new ArrayList<Property>(); while (propIt.hasNext()) { final Property prop = (Property) propIt.next(); props.add(prop); } for (Property prop : props) { EClass eClass = null; if (pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) == null) { if (pc.getEntityName() != null) { eClass = getEntityNameStrategy().toEClass(pc.getEntityName()); } else { eClass = EModelResolver.instance().getEClass(pc.getMappedClass()); } } final EStructuralFeature ef = eClass == null ? null : StoreUtil.getEStructuralFeature(eClass, prop.getName()); if (ef != null && ef instanceof EReference && prop.getValue() instanceof Collection) { final Collection collection = (Collection) prop.getValue(); final EReference eReference = (EReference) ef; // only work for extra lazy if (!collection.isExtraLazy()) { continue; } final Value elementValue = collection.getElement(); final PersistentClass elementPC; if (elementValue instanceof OneToMany) { final OneToMany oneToMany = (OneToMany) elementValue; elementPC = oneToMany.getAssociatedClass(); } else if (elementValue instanceof ManyToOne) { final ManyToOne mto = (ManyToOne) elementValue; elementPC = persistentClasses.get(mto.getReferencedEntityName()); } else { continue; } if (isClassOrSuperClassEAVMapped(elementPC)) { continue; } collection.setInverse(true); // and add an eopposite if (eReference.getEOpposite() == null) { final Table collectionTable = collection.getCollectionTable(); if (isClassOrSuperClassEAVMapped(elementPC)) { continue; } final Property inverseRefProperty = new Property(); inverseRefProperty.setName(StoreUtil.getExtraLazyInversePropertyName(ef)); final Map<Object, Object> metas = new HashMap<Object, Object>(); final MetaAttribute metaAttribute = new MetaAttribute( HbConstants.SYNTHETIC_PROPERTY_INDICATOR); metaAttribute.addValue("true"); metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute); inverseRefProperty.setMetaAttributes(metas); inverseRefProperty.setNodeName(inverseRefProperty.getName()); inverseRefProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName()); inverseRefProperty.setLazy(false); final ManyToOne mto = new ManyToOne(getMappings(), collectionTable); mto.setReferencedEntityName(pc.getEntityName()); mto.setLazy(false); mto.setFetchMode(FetchMode.SELECT); inverseRefProperty.setValue(mto); final Iterator<?> it = collection.getKey().getColumnIterator(); while (it.hasNext()) { final Column originalColumn = (Column) it.next(); // final Column newColumn = new // Column(originalColumn.getName()); mto.addColumn(originalColumn); } mto.createForeignKey(); // now determine if a join should be created if (collectionTable.getName().equalsIgnoreCase(elementPC.getTable().getName())) { elementPC.addProperty(inverseRefProperty); } else { // create a join final Join join = new Join(); join.setPersistentClass(elementPC); join.setTable(collectionTable); join.addProperty(inverseRefProperty); final ManyToOne keyValue = new ManyToOne(getMappings(), collectionTable); join.setKey(keyValue); @SuppressWarnings("unchecked") final Iterator<Column> keyColumns = collection.getElement().getColumnIterator(); while (keyColumns.hasNext()) { keyValue.addColumn(keyColumns.next()); } keyValue.setReferencedEntityName(elementPC.getEntityName()); keyValue.setTable(collectionTable); keyValue.createForeignKey(); elementPC.addJoin(join); } } // add an opposite index if (collection.isIndexed() && !collection.isMap()) { Table collectionTable = collection.getCollectionTable(); IndexedCollection indexedCollection = (IndexedCollection) collection; final Column column = (Column) indexedCollection.getIndex().getColumnIterator().next(); final Property indexProperty = new Property(); indexProperty.setName(StoreUtil.getExtraLazyInverseIndexPropertyName(ef)); final Map<Object, Object> metas = new HashMap<Object, Object>(); final MetaAttribute metaAttribute = new MetaAttribute( HbConstants.SYNTHETIC_PROPERTY_INDICATOR); metaAttribute.addValue("true"); metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute); indexProperty.setMetaAttributes(metas); indexProperty.setNodeName(indexProperty.getName()); indexProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName()); // always make this nullable, nullability is controlled // by the main property indexProperty.setOptional(true); Join join = null; @SuppressWarnings("unchecked") final Iterator<Join> it = (Iterator<Join>) elementPC.getJoinIterator(); while (it.hasNext()) { final Join foundJoin = it.next(); if (foundJoin.getTable().getName().equalsIgnoreCase(collectionTable.getName())) { join = foundJoin; collectionTable = join.getTable(); break; } } final SimpleValue sv = new SimpleValue(getMappings(), indexedCollection.getIndex().getTable()); sv.setTypeName("integer"); // final Column svColumn = new Column(column.getName()); sv.addColumn(column); // checkColumnExists(collectionTable, // svColumn)); indexProperty.setValue(sv); if (join != null) { join.addProperty(indexProperty); } else { elementPC.addProperty(indexProperty); } } } } } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a Column instance to the Hibernate meta model * * @param property The Grails domain class property * @param parentProperty/*from w ww .j a v a2 s.c o m*/ * @param column The column to bind * @param path * @param table The table name * @param sessionFactoryBeanName the session factory bean name */ protected void bindColumn(PersistentProperty property, PersistentProperty parentProperty, Column column, ColumnConfig cc, String path, Table table, String sessionFactoryBeanName) { if (cc != null) { column.setComment(cc.getComment()); column.setDefaultValue(cc.getDefaultValue()); column.setCustomRead(cc.getRead()); column.setCustomWrite(cc.getWrite()); } Class<?> userType = getUserType(property); String columnName = getColumnNameForPropertyAndPath(property, path, cc, sessionFactoryBeanName); if ((property instanceof Association) && userType == null) { Association association = (Association) property; // Only use conventional naming when the column has not been explicitly mapped. if (column.getName() == null) { column.setName(columnName); } if (property instanceof ManyToMany) { column.setNullable(false); } else if (property instanceof org.grails.datastore.mapping.model.types.OneToOne && association.isBidirectional() && !association.isOwningSide()) { if (isHasOne(((Association) property).getInverseSide())) { column.setNullable(false); } else { column.setNullable(true); } } else if ((property instanceof ToOne) && association.isCircular()) { column.setNullable(true); } else { column.setNullable(property.isNullable()); } } else { column.setName(columnName); column.setNullable(property.isNullable() || (parentProperty != null && parentProperty.isNullable())); // Use the constraints for this property to more accurately define // the column's length, precision, and scale if (String.class.isAssignableFrom(property.getType()) || byte[].class.isAssignableFrom(property.getType())) { bindStringColumnConstraints(column, property); } if (Number.class.isAssignableFrom(property.getType())) { bindNumericColumnConstraints(column, property, cc); } } handleUniqueConstraint(property, column, path, table, columnName, sessionFactoryBeanName); bindIndex(columnName, column, cc, table); final PersistentEntity owner = property.getOwner(); if (!owner.isRoot()) { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); column.setNullable(true); } else { column.setNullable(property.isNullable()); } } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] bound property [" + property.getName() + "] to column name [" + column.getName() + "] in table [" + table.getName() + "]"); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void createUniqueKeyForColumns(Table table, String columnName, List<Column> columns) { Collections.reverse(columns); UniqueKey uk = new UniqueKey(); uk.setTable(table);//from w ww . j a v a2 s.com uk.addColumns(columns.iterator()); if (LOG.isDebugEnabled()) { LOG.debug("create unique key for " + table.getName() + " columns = " + columns); } setGeneratedUniqueName(uk); table.addUniqueKey(uk); }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindIndex(String columnName, Column column, ColumnConfig cc, Table table) { if (cc == null) { return;//from w w w. j a va 2 s. com } Object indexObj = cc.getIndex(); String indexDefinition = null; if (indexObj instanceof Boolean) { Boolean b = (Boolean) indexObj; if (b) { indexDefinition = table.getName() + '_' + columnName + "_idx"; } } else if (indexObj != null) { indexDefinition = indexObj.toString(); } if (indexDefinition == null) { return; } String[] tokens = indexDefinition.split(","); for (int i = 0; i < tokens.length; i++) { String index = tokens[i]; table.getOrCreateIndex(index).addColumn(column); } }
From source file:org.hiberframe.HibUtils.java
License:Open Source License
public static void dumpTableInfo(Class<?> c) { PersistentClass pc = config.getClassMapping(c.getName()); Table t = pc.getTable(); System.out.println(c.getName()); System.out.println("t name: " + t.getName()); System.out.println("t id: " + t.getPrimaryKey().getName()); }
From source file:org.hyperic.hq.common.server.session.ServerConfigManagerImpl.java
License:Open Source License
/** * Run an analyze command on all non metric tables. The metric tables are * handled seperately using analyzeHqMetricTables() so that only the tables * that have been modified are analyzed. * //from w w w . j a v a 2s . c om * @return The time taken in milliseconds to run the command. * */ @Transactional public long analyzeNonMetricTables() { HQDialect dialect = (HQDialect) ((SessionFactoryImplementor) Bootstrap.getBean(SessionFactory.class)) .getDialect(); long duration = 0; Connection conn = null; try { conn = dbUtil.getConnection(); for (Iterator i = Bootstrap.getBean(LocalSessionFactoryBean.class).getConfiguration() .getTableMappings(); i.hasNext();) { Table t = (Table) i.next(); if (t.getName().toUpperCase().startsWith("EAM_MEASUREMENT_DATA") || t.getName().toUpperCase().startsWith("HQ_METRIC_DATA")) { continue; } String sql = dialect.getOptimizeStmt(t.getName(), 0); duration += doCommand(conn, sql, null); } } catch (SQLException e) { log.error("Error analyzing table", e); } finally { DBUtil.closeConnection(LOG_CTX, conn); } return duration; }
From source file:org.jboss.forge.addon.database.tools.generate.DatabaseTableSelectionStep.java
License:Open Source License
private boolean isSelected(Collection<String> selection, POJOClass element) { boolean result = false; if (element instanceof ComponentPOJOClass) { ComponentPOJOClass cpc = (ComponentPOJOClass) element; Iterator<?> iterator = cpc.getAllPropertiesIterator(); result = true;//from ww w.j av a2 s . co m while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof Property) { Property property = (Property) object; String tableName = property.getValue().getTable().getName(); if (!selection.contains(tableName)) { result = false; break; } } } } else if (element instanceof EntityPOJOClass) { EntityPOJOClass epc = (EntityPOJOClass) element; Object object = epc.getDecoratedObject(); if (object instanceof PersistentClass) { PersistentClass pc = (PersistentClass) object; Table table = pc.getTable(); if (selection.contains(table.getName())) { result = true; } } } return result; }