use of org.hibernate.mapping.PrimaryKey in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHQLQueryPlan.
@Test
public void testCreateHQLQueryPlan() {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
Mappings mappings = configuration.createMappings();
Table t = new Table("FOO");
Column c = new Column("foo");
t.addColumn(c);
PrimaryKey key = new PrimaryKey();
key.addColumn(c);
t.setPrimaryKey(key);
Mappings m = configuration.createMappings();
SimpleValue sv = new SimpleValue(m);
sv.setNullValue("null");
sv.setTypeName(Integer.class.getName());
sv.setTable(t);
sv.addColumn(c);
RootClass rc = new RootClass();
rc.setEntityName("foo");
rc.setJpaEntityName("foo");
rc.setIdentifier(sv);
rc.setTable(t);
mappings.addClass(rc);
ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
Map<String, Filter> filters = Collections.emptyMap();
HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
use of org.hibernate.mapping.PrimaryKey in project jbosstools-hibernate by jbosstools.
the class PrimaryKeyFacadeTest method beforeEach.
@BeforeEach
public void beforeEach() {
primaryKeyTarget = new PrimaryKey();
primaryKeyTarget.setTable(new Table());
primaryKeyFacade = new AbstractPrimaryKeyFacade(FACADE_FACTORY, primaryKeyTarget) {
};
}
use of org.hibernate.mapping.PrimaryKey in project jbosstools-hibernate by jbosstools.
the class TableFacadeTest method testGetPrimaryKey.
@Test
public void testGetPrimaryKey() {
Table table = new Table();
PrimaryKey primaryKey = new PrimaryKey();
ITable tableFacade = FACADE_FACTORY.createTable(table);
assertNull(tableFacade.getPrimaryKey());
table.setPrimaryKey(primaryKey);
IPrimaryKey primaryKeyFacade = tableFacade.getPrimaryKey();
assertSame(primaryKey, ((IFacade) primaryKeyFacade).getTarget());
}
use of org.hibernate.mapping.PrimaryKey in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHQLQueryPlan.
@Test
public void testCreateHQLQueryPlan() {
final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
standardServiceRegistryBuilder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
standardServiceRegistryBuilder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
Table t = new Table("FOO");
Column c = new Column("foo");
t.addColumn(c);
PrimaryKey key = new PrimaryKey(t);
key.addColumn(c);
t.setPrimaryKey(key);
@SuppressWarnings("deprecation") SimpleValue sv = new SimpleValue(metadata);
sv.setNullValue("null");
sv.setTypeName(Integer.class.getName());
sv.setTable(t);
sv.addColumn(c);
final RootClass rc = new RootClass(null);
rc.setEntityName("foo");
rc.setJpaEntityName("foo");
rc.setIdentifier(sv);
rc.setTable(t);
rc.setOptimisticLockStyle(OptimisticLockStyle.NONE);
entityBindings.add(rc);
MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
return rc;
} else if ("getEntityBindings".equals(method.getName())) {
return entityBindings;
}
return method.invoke(metadata, args);
}
});
MetadataBuildingOptions mbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry);
BootstrapContext bc = new BootstrapContextImpl(serviceRegistry, mbo);
SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, new SessionFactoryOptionsBuilder(serviceRegistry, bc), HQLQueryPlan::new);
Map<String, Filter> filters = Collections.emptyMap();
HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
use of org.hibernate.mapping.PrimaryKey in project hibernate-orm by hibernate.
the class TableGenerator method registerExportables.
@Override
public void registerExportables(Database database) {
final Dialect dialect = database.getJdbcEnvironment().getDialect();
final Namespace namespace = database.locateNamespace(qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName());
Table table = namespace.locateTable(qualifiedTableName.getObjectName());
if (table == null) {
table = namespace.createTable(qualifiedTableName.getObjectName(), false);
// todo : note sure the best solution here. do we add the columns if missing? other?
final Column segmentColumn = new ExportableColumn(database, table, segmentColumnName, StringType.INSTANCE, dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0));
segmentColumn.setNullable(false);
table.addColumn(segmentColumn);
// lol
table.setPrimaryKey(new PrimaryKey(table));
table.getPrimaryKey().addColumn(segmentColumn);
final Column valueColumn = new ExportableColumn(database, table, valueColumnName, LongType.INSTANCE);
table.addColumn(valueColumn);
}
// allow physical naming strategies a chance to kick in
this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(table.getQualifiedTableName(), dialect);
table.addInitCommand(generateInsertInitCommand());
this.selectQuery = buildSelectQuery(dialect);
this.updateQuery = buildUpdateQuery();
this.insertQuery = buildInsertQuery();
}
Aggregations