本文整理汇总了Java中net.sf.hibernate.cfg.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于net.sf.hibernate.cfg包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConfiguration
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private Configuration getConfiguration() throws Exception {
Configuration cfg = new Configuration();
if (namingStrategy!=null) cfg.setNamingStrategy(
(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
);
if (configurationFile != null) cfg.configure( new File(configurationFile) );
String[] files = getFiles();
for (int i = 0; i < files.length; i++) {
String filename = files[i];
if ( filename.endsWith(".jar") ) {
cfg.addJar( new File(filename) );
}
else {
cfg.addFile(filename);
}
}
return cfg;
}
示例2: open
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
/**
* Specify the underlying <tt>SessionFactory</tt>, by passing a JNDI name.
* The <tt>accessMode</tt> is ignored by Hibernate.
* @see org.odmg.Database#open(String, int)
*/
public void open(String name, int accessMode) throws ODMGException {
try {
new Configuration().configure();
}
catch (HibernateException he) {
throw new ODMGException( he.getMessage() );
}
sessionFactory = (SessionFactory) SessionFactoryObjectFactory.getNamedInstance(name);
if (sessionFactory==null) throw new ODMGException("No SessionFactory was associated with the given JDNI name");
/*try {
sessionFactory = (SessionFactory) NamingHelper.getInitialContext( Environment.getProperties() ).lookup(name);
}
catch (NamingException ne) {
throw new ODMGException( ne.getMessage() );
}*/
}
示例3: hibernateInit
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
@Ignore
@Test
public void hibernateInit() throws Exception
{
Database.init();
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
// Filter-time code (H3SessionAjaxFilter)
transaction.commit();
// Shutdown code, when do we need to do this?
sessionFactory.close();
}
示例4: PersonalBlogService
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
/**
* Constructor for PersonalBlogService.
*/
protected PersonalBlogService(Properties conn)
throws InitializationException {
log.debug("initialization - constructor");
try {
cfg = new Configuration().addClass(Post.class)
.addClass(Comment.class)
.addClass(Referrer.class)
.addClass(BlogProperty.class);
if (conn != null) {
cfg.setProperties(conn);
pm = new PropertyManager(conn);
} else {
pm = new PropertyManager();
}
//I want to take it out of here, for these
sf = cfg.buildSessionFactory();
} catch (Exception e) {
log.error("Error initializing PersonalBlog Service", e);
throw new InitializationException(e);
}
}
示例5: initSessionFactory
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
//URL url = ClassLoader.getSystemResource(fileName);
//String file_name = url.getFile();
//File f = new File(file_name);
//File f = new File("config/myfile.cfg.xml");
//sf = new Configuration().configure(f).buildSessionFactory();
sf = new Configuration().configure().buildSessionFactory();
if(sf!=null){
System.out.println("Message from ApplicationSessionFactory: Got Session !");
}else{
System.out.println("Message from ApplicationSessionFactory: could not get Session !");
}
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例6: initSessionFactory
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
File f = new File(fileName);
//File f = new File("config/myfile.cfg.xml");
sf = new Configuration().configure(f).buildSessionFactory();
//sf = new Configuration().configure().buildSessionFactory();
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例7: initSessionFactory
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
File f = new File(fileName);
//File f = new File("config/myfile.cfg.xml");
sf = new Configuration().configure(f).buildSessionFactory();
//sf = new Configuration().configure().buildSessionFactory();
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例8: createCollectionPersister
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
public static CollectionPersister createCollectionPersister(Configuration cfg, Collection model, SessionFactoryImplementor factory) throws HibernateException {
Class persisterClass = model.getCollectionPersisterClass();
if(persisterClass==null) { // default behavior
return model.isOneToMany() ?
(CollectionPersister) new OneToManyPersister(model, cfg, factory) :
(CollectionPersister) new BasicCollectionPersister(model, cfg, factory);
}
else {
return create(persisterClass, cfg, model, factory);
}
}
示例9: getSchemaExport
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private SchemaExport getSchemaExport(Configuration cfg) throws HibernateException, IOException {
SchemaExport schemaExport;
if (propertiesFile == null) {
schemaExport = new SchemaExport(cfg);
}
else {
Properties properties = new Properties();
properties.load( new FileInputStream(propertiesFile) );
schemaExport = new SchemaExport(cfg, properties);
}
schemaExport.setOutputFile(outputFile);
schemaExport.setDelimiter(delimiter);
return schemaExport;
}
示例10: SchemaExport
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
/**
* Create a schema exporter for the given Configuration, with the given
* database connection properties.
*/
public SchemaExport(Configuration cfg, Properties connectionProperties) throws HibernateException {
this.connectionProperties = connectionProperties;
dialect = Dialect.getDialect(connectionProperties);
dropSQL = cfg.generateDropSchemaScript(dialect);
createSQL = cfg.generateSchemaCreationScript(dialect);
}
示例11: getConfiguration
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
private Configuration getConfiguration() throws HibernateException {
Configuration cfg = new Configuration().addProperties( getProperties() );
String[] mappingFiles = parseResourceList( getMapResources() );
for ( int i=0; i<mappingFiles.length; i++ ) {
cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() );
}
return cfg;
}
示例12: OneToManyPersister
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
public OneToManyPersister(
Collection collection,
Configuration cfg,
SessionFactoryImplementor factory)
throws MappingException, CacheException {
super(collection, cfg, factory);
}
示例13: main
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final Main test = new Main();
Configuration cfg = new Configuration()
.addClass(AuctionItem.class)
.addClass(Bid.class)
.addClass(User.class)
.setProperty(Environment.HBM2DDL_AUTO, "create");
//cfg.setProperty("hibernate.show_sql", "true");
test.factory = cfg.buildSessionFactory();
test.createTestAuctions();
test.viewAllAuctionsSlow();
test.viewAllAuctionsFast();
test.bidOnAuction(mainBidder, mainItem, 5.5f);
test.viewAllAuctionsFast();
test.viewUserAuctions( mainSeller.getId() );
mainSeller.setEmail("[email protected]");
test.changeUserDetails(mainSeller);
test.changeItemDescription(mainItem.getId(), "new description");
test.viewUserAuctions( mainSeller.getId() );
test.viewAuctionsByDescription("It", 0);
test.viewAuctionsByDescription("DESC", 3);
test.viewAuctionsByDescription("DESC", 8);
test.factory.close();
}
示例14: main
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
public static void main(String[] args) throws HibernateException , IOException, Exception
{
boolean isToPrintOnConsole = false;
boolean isToExecuteOnDB = false;
if(args.length!=0)
{
String arg = args[0];
if(arg.equalsIgnoreCase("true"))
{
isToPrintOnConsole = true;
isToExecuteOnDB = true;
}
if(arg.equalsIgnoreCase("false"))
{
isToPrintOnConsole = false;
isToExecuteOnDB = false;
}
}
File file = new File("db.properties");
BufferedInputStream stram = new BufferedInputStream(new FileInputStream(file));
Properties p = new Properties();
p.load(stram);
stram.close();
Configuration cfg = new Configuration();
cfg.setProperties(p);
cfg.addDirectory(new File("./WEB-INF/src"));
new SchemaExport(cfg).setOutputFile("catissuecore.sql").create(isToPrintOnConsole, isToExecuteOnDB);
// if(isToExecuteOnDB)
// new GenerateUser();
}
示例15: main
import net.sf.hibernate.cfg.Configuration; //导入依赖的package包/类
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
boolean script = true;
boolean drop = false;
boolean export = true;
String outFile = null;
String propFile = null;
boolean formatSQL = false;
String delim = null;
for ( int i=0; i<args.length; i++ ) {
if( args[i].startsWith("--") ) {
if( args[i].equals("--quiet") ) {
script = false;
}
else if( args[i].equals("--drop") ) {
drop = true;
}
else if( args[i].equals("--text") ) {
export = false;
}
else if( args[i].startsWith("--output=") ) {
outFile = args[i].substring(9);
}
else if( args[i].startsWith("--properties=") ) {
propFile = args[i].substring(13);
}
else if( args[i].equals("--format") ) {
formatSQL = true;
}
else if ( args[i].startsWith("--delimiter=") ) {
delim = args[i].substring(12);
}
else if ( args[i].startsWith("--config=") ) {
cfg.configure( args[i].substring(9) );
}
else if ( args[i].startsWith("--naming=") ) {
cfg.setNamingStrategy(
(NamingStrategy) ReflectHelper.classForName( args[i].substring(9) ).newInstance()
);
}
}
else {
String filename = args[i];
if ( filename.endsWith( ".jar" ) ) {
cfg.addJar(filename);
}
else {
cfg.addFile(filename);
}
}
}
if(propFile!=null) {
Properties props = new Properties();
props.load( new FileInputStream(propFile) );
new SchemaExport(cfg, props)
.setOutputFile(outFile)
.setDelimiter(delim)
.execute(script, export, drop, formatSQL);
}
else {
new SchemaExport(cfg)
.setOutputFile(outFile)
.setDelimiter(delim)
.execute(script, export, drop, formatSQL);
}
}
catch(Exception e) {
log.error( "Error creating schema ", e );
e.printStackTrace();
}
}