Java Code Examples for org.hibernate.cfg.Configuration#setNamingStrategy()

The following examples show how to use org.hibernate.cfg.Configuration#setNamingStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaExportTask.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 2
Source File: SchemaUpdateTask.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 3
Source File: SchemaValidatorTask.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 4
Source File: SchemaValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
	}
}
 
Example 5
Source File: SchemaUpdate.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
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();
	}
}
 
Example 6
Source File: SchemaExport.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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();
	}
}
 
Example 7
Source File: SchemaUpdate.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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();
	}
}