类org.hibernate.cfg.NamingStrategy源码实例Demo

下面列出了怎么用org.hibernate.cfg.NamingStrategy的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
@SuppressWarnings("serial")
public void testLocalSessionFactoryBeanWithNamingStrategy() throws Exception {
	LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
		@Override
		protected Configuration newConfiguration() {
			return new Configuration() {
				@Override
				public Configuration setNamingStrategy(NamingStrategy namingStrategy) {
					throw new IllegalArgumentException(namingStrategy.toString());
				}
			};
		}
	};
	sfb.setMappingResources(new String[0]);
	sfb.setDataSource(new DriverManagerDataSource());
	sfb.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);
	try {
		sfb.afterPropertiesSet();
		fail("Should have thrown IllegalArgumentException");
	}
	catch (IllegalArgumentException ex) {
		// expected
		assertTrue("Correct exception", ex.getMessage().equals(ImprovedNamingStrategy.INSTANCE.toString()));
	}
}
 
源代码2 项目: cacheonix-core   文件: SchemaExportTask.java
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
			);
	}
	if (configurationFile != null) {
		cfg.configure( 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;
}
 
源代码3 项目: cacheonix-core   文件: SchemaUpdateTask.java
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
			);
	}
	if (configurationFile!=null) {
		cfg.configure( 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;
}
 
源代码4 项目: cacheonix-core   文件: SchemaValidatorTask.java
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
			);
	}
	if (configurationFile!=null) {
		cfg.configure( 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;
}
 
源代码5 项目: cacheonix-core   文件: SchemaValidator.java
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();

		String propFile = null;

		for ( int i = 0; i < args.length; i++ ) {
			if ( args[i].startsWith( "--" ) ) {
				if ( args[i].startsWith( "--properties=" ) ) {
					propFile = args[i].substring( 13 );
				}
				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 {
				cfg.addFile( args[i] );
			}

		}

		if ( propFile != null ) {
			Properties props = new Properties();
			props.putAll( cfg.getProperties() );
			props.load( new FileInputStream( propFile ) );
			cfg.setProperties( props );
		}

		new SchemaValidator( cfg ).validate();
	}
	catch ( Exception e ) {
		log.error( "Error running schema update", e );
		e.printStackTrace();
	}
}
 
源代码6 项目: document-management-system   文件: SchemaUpdate.java
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();
		String outFile = null;

		boolean script = true;
		// If true then execute db updates, otherwise just generate and
		// display updates
		boolean doUpdate = true;
		String propFile = null;

		for (int i = 0; i < args.length; i++) {
			if (args[i].startsWith("--")) {
				if (args[i].equals("--quiet")) {
					script = false;
				} else if (args[i].startsWith("--properties=")) {
					propFile = args[i].substring(13);
				} else if (args[i].startsWith("--config=")) {
					cfg.configure(args[i].substring(9));
				} else if (args[i].startsWith("--text")) {
					doUpdate = false;
				} else if (args[i].startsWith("--naming=")) {
					cfg.setNamingStrategy((NamingStrategy) ReflectHelper.classForName(
							args[i].substring(9)).newInstance());
				} else if (args[i].startsWith("--output=")) {
					outFile = args[i].substring(9);
				}
			} else {
				cfg.addFile(args[i]);
			}

		}

		if (propFile != null) {
			Properties props = new Properties();
			props.putAll(cfg.getProperties());
			props.load(new FileInputStream(propFile));
			cfg.setProperties(props);
		}

		new SchemaUpdate(cfg).setOutputFile(outFile).execute(script, doUpdate);
	} catch (Exception e) {
		log.error("Error running schema update", e);
		e.printStackTrace();
	}
}
 
public NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
 
源代码8 项目: cacheonix-core   文件: SchemaExport.java
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();

		boolean script = true;
		boolean drop = false;
		boolean create = false;
		boolean halt = false;
		boolean export = true;
		String outFile = null;
		String importFile = "/import.sql";
		String propFile = null;
		boolean format = 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( "--create" ) ) {
					create = true;
				}
				else if ( args[i].equals( "--haltonerror" ) ) {
					halt = 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( "--import=" ) ) {
					importFile = args[i].substring( 9 );
				}
				else if ( args[i].startsWith( "--properties=" ) ) {
					propFile = args[i].substring( 13 );
				}
				else if ( args[i].equals( "--format" ) ) {
					format = 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( new File( filename ) );
				}
				else {
					cfg.addFile( filename );
				}
			}

		}

		if ( propFile != null ) {
			Properties props = new Properties();
			props.putAll( cfg.getProperties() );
			props.load( new FileInputStream( propFile ) );
			cfg.setProperties( props );
		}

		SchemaExport se = new SchemaExport( cfg )
				.setHaltOnError( halt )
				.setOutputFile( outFile )
				.setImportFile( importFile )
				.setDelimiter( delim );
		if ( format ) {
			se.setFormat( true );
		}
		se.execute( script, export, drop, create );

	}
	catch ( Exception e ) {
		log.error( "Error creating schema ", e );
		e.printStackTrace();
	}
}
 
源代码9 项目: cacheonix-core   文件: SchemaUpdate.java
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();

		boolean script = true;
		// If true then execute db updates, otherwise just generate and display updates
		boolean doUpdate = true;
		String propFile = null;

		for ( int i = 0; i < args.length; i++ ) {
			if ( args[i].startsWith( "--" ) ) {
				if ( args[i].equals( "--quiet" ) ) {
					script = false;
				}
				else if ( args[i].startsWith( "--properties=" ) ) {
					propFile = args[i].substring( 13 );
				}
				else if ( args[i].startsWith( "--config=" ) ) {
					cfg.configure( args[i].substring( 9 ) );
				}
				else if ( args[i].startsWith( "--text" ) ) {
					doUpdate = false;
				}
				else if ( args[i].startsWith( "--naming=" ) ) {
					cfg.setNamingStrategy(
							( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
					);
				}
			}
			else {
				cfg.addFile( args[i] );
			}

		}

		if ( propFile != null ) {
			Properties props = new Properties();
			props.putAll( cfg.getProperties() );
			props.load( new FileInputStream( propFile ) );
			cfg.setProperties( props );
		}

		new SchemaUpdate( cfg ).execute( script, doUpdate );
	}
	catch ( Exception e ) {
		log.error( "Error running schema update", e );
		e.printStackTrace();
	}
}
 
源代码10 项目: lams   文件: LocalSessionFactoryBean.java
/**
 * Set a Hibernate NamingStrategy for the SessionFactory, determining the
 * physical column and table names given the info in the mapping document.
 * @see org.hibernate.cfg.Configuration#setNamingStrategy
 */
public void setNamingStrategy(NamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}
 
/**
 * Set a Hibernate NamingStrategy for the SessionFactory, determining the
 * physical column and table names given the info in the mapping document.
 * @see org.hibernate.cfg.Configuration#setNamingStrategy
 */
public void setNamingStrategy(NamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}
 
/**
 * Set a Hibernate NamingStrategy for the SessionFactory, determining the
 * physical column and table names given the info in the mapping document.
 */
public void setNamingStrategy(NamingStrategy namingStrategy) {
    this.namingStrategy = namingStrategy;
}
 
 类所在包
 类方法
 同包方法