📄 dboperator.java
字号:
} catch (SQLException ex ) {
getLogger().warn("Category patch failed. Trying HDBSQL Syntax");
connection.prepareStatement("ALTER TABLE CATEGORY ADD COLUMN DEFINITION VARCHAR").execute();
connection.commit();
}
getLogger().warn("CATEGORY patched!");
}
if ( categoryTable.getMetaData().getColumnCount() == 5)
{
getLogger().warn("Patching Database for table CATEGORY (Category Order)");
connection.prepareStatement("ALTER TABLE CATEGORY ADD COLUMN PARENT_ORDER INTEGER").execute();
getLogger().warn("CATEGORY patched!");
}
ResultSet eventTable = connection.prepareStatement("select * from EVENT" ).executeQuery();
if ( eventTable.getMetaData().getColumnCount() == 5) {
getLogger().warn("Patching Database for table EVENT");
connection.prepareStatement("ALTER TABLE EVENT ADD COLUMN LAST_CHANGED_BY INTEGER").execute();
connection.commit();
getLogger().warn("EVENT patched");
}
checkForOldResourceTableName( connection );
}
ResultSet set = connection.prepareStatement("select * from DYNAMIC_TYPE").executeQuery();
if ( !set.next() ) {
getLogger().warn("No content in database! Creating new database");
CachableStorageOperator sourceOperator = ( CachableStorageOperator) serviceManager.lookup(CachableStorageOperator.ROLE + "/file");
sourceOperator.connect();
setCache( sourceOperator.getCache());
saveData();
getLogger().warn("Database created!");
} else {
cache.clearAll();
idTable.setCache(cache);
readEverythingIntoCache( connection );
idTable.setCache(cache);
if ( getLogger().isDebugEnabled())
getLogger().debug("Entities contextualized");
if ( getLogger().isDebugEnabled())
getLogger().debug("All ConfigurationReferences resolved");
}
}
catch (RaplaException ex)
{
throw ex;
}
catch (Exception ex)
{
throw new RaplaException( ex);
}
finally
{
close ( connection );
}
}
private void checkForOldResourceTableName( Connection connection )
{
try
{
ResultSet oldResourceTable = connection.getMetaData().getTables(null, null,"RESOURCE" , null);
while ( oldResourceTable.next())
{
oldResourceTableName = true;
}
}
catch (SQLException ex)
{
oldResourceTableName = false;
}
if ( oldResourceTableName )
{
getLogger().warn("Using old resource table name RESOURCE. Please rename to RAPLA_RESOURCE");
}
}
public Object createIdentifier(RaplaType raplaType) throws RaplaException {
return idTable.createId(raplaType);
}
public void dispatch(UpdateEvent evt) throws RaplaException {
evt = createClosure( evt );
check(evt);
Connection connection = createConnection();
try {
executeEvent(connection,evt);
if (bSupportsTransactions) {
getLogger().debug("Commiting");
connection.commit();
}
UpdateResult result = super.update(evt, true);
fireStorageUpdated(result);
} catch (Exception ex) {
try {
if (bSupportsTransactions) {
connection.rollback();
getLogger().error("Doing rollback");
throw new RaplaDBException(getI18n().getString("error.rollback"),ex);
} else {
String message = getI18n().getString("error.no_rollback");
getLogger().fatalError(message);
forceDisconnect();
throw new RaplaDBException(message,ex);
}
} catch (SQLException sqlEx) {
String message = "Unrecoverable error while storing";
getLogger().fatalError(message, sqlEx);
forceDisconnect();
throw new RaplaDBException(message,sqlEx);
}
} finally {
close( connection );
}
}
/**
* @param evt
* @throws RaplaException
*/
protected void executeEvent(Connection connection,UpdateEvent evt) throws RaplaException, SQLException {
// create the writer
RaplaSQL raplaSQL = new RaplaSQL(createOutputContext(), oldResourceTableName);
// execute updates
Iterator it = evt.getStoreObjects().iterator();
while (it.hasNext()) {
RefEntity entity = (RefEntity) it.next();
raplaSQL.store( connection, entity);
}
// execute removes
it = evt.getRemoveObjects().iterator();
while (it.hasNext()) {
Object id = ((RefEntity) it.next()).getId();
RefEntity entity = (RefEntity)cache.get(id);
if (entity != null)
raplaSQL.remove( connection, entity);
}
}
public void removeAll() throws RaplaException {
Connection connection = createConnection();
try {
checkForOldResourceTableName( connection );
RaplaSQL raplaSQL = new RaplaSQL(createOutputContext(), oldResourceTableName);
if (!isConnected())
createConnection();
raplaSQL.removeAll( connection );
connection.commit();
// do something here
getLogger().info("DB cleared");
}
catch (SQLException ex)
{
throw new RaplaException(ex);
}
finally
{
close( connection );
}
}
public void saveData() throws RaplaException {
Connection connection = createConnection();
try {
checkForOldResourceTableName( connection );
RaplaSQL raplaSQL = new RaplaSQL(createOutputContext(), oldResourceTableName);
getLogger().info("Creation of DB started");
if (!isConnected())
createConnection();
raplaSQL.removeAll( connection );
raplaSQL.createAll( connection );
connection.commit();
// do something here
getLogger().info("DB Creation complete");
}
catch (SQLException ex)
{
throw new RaplaException(ex);
}
finally
{
close( connection );
}
}
static private void close(Connection connection) throws RaplaException
{
try
{
connection.close();
}
catch (SQLException e)
{
throw new RaplaException("Can't close connection to database ", e);
}
}
protected boolean readEverythingIntoCache(Connection connection) throws RaplaException, IOException, SQLException {
EntityStore entityStore = new EntityStore(null, cache.getSuperCategory());
RaplaSQL raplaSQL = new RaplaSQL(createInputContext(entityStore), oldResourceTableName);
raplaSQL.loadAll( connection );
resolveEntities( entityStore.getList().iterator(), entityStore );
cache.putAll( entityStore.getList());
for (Iterator it = cache.getIterator(User.TYPE);it.hasNext();)
{
RefEntity user = ((RefEntity)it.next());
String password = entityStore.getPassword( user.getId());
cache.putPassword(user.getId(), password);
}
return false;
}
protected RaplaDefaultContext createInputContext( EntityStore store) throws RaplaException {
RaplaDefaultContext inputContext = new IOContext().createInputContext(serviceManager, store,idTable);
RaplaInput xmlAdapter = new RaplaInput(getLogger().getChildLogger("reading"));
inputContext.put(RaplaInput.class.getName(),xmlAdapter);
return inputContext;
}
protected RaplaDefaultContext createOutputContext() throws RaplaException {
RaplaDefaultContext outputContext = new IOContext().createOutputContext(serviceManager, cache,true,false);
return outputContext;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -