use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.
the class JarUtil method add.
/**
* Add a jar file to the current connection's database.
*
* <P> The reason for adding the jar file in this private instance
* method is that it allows us to share set up logic with drop and
* replace.
* @param is A stream for reading the content of the file to add.
* @exception StandardException Opps
*/
private long add(final InputStream is) throws StandardException {
//
// Like create table we say we are writing before we read the dd
dd.startWriting(lcc);
FileInfoDescriptor fid = getInfo();
if (fid != null)
throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, fid.getDescriptorType(), sqlName, fid.getSchemaDescriptor().getDescriptorType(), schemaName);
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
try {
notifyLoader(false);
dd.invalidateAllSPSPlans();
UUID id = BaseActivation.getMonitor().getUUIDFactory().createUUID();
final String jarExternalName = JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar());
long generationId = setJar(jarExternalName, is, true, 0L);
fid = ddg.newFileInfoDescriptor(id, sd, sqlName, generationId);
dd.addDescriptor(fid, sd, DataDictionary.SYSFILES_CATALOG_NUM, false, lcc.getTransactionExecute());
return generationId;
} finally {
notifyLoader(true);
}
}
use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.
the class JarUtil method drop.
/**
* Drop a jar file from the current connection's database.
*
* <P> The reason for dropping the jar file in this private instance
* method is that it allows us to share set up logic with add and
* replace.
*
* @exception StandardException Opps
*/
private void drop() throws StandardException {
//
// Like create table we say we are writing before we read the dd
dd.startWriting(lcc);
FileInfoDescriptor fid = getInfo();
if (fid == null)
throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
String dbcp_s = PropertyUtil.getServiceProperty(lcc.getTransactionExecute(), Property.DATABASE_CLASSPATH);
if (dbcp_s != null) {
String[][] dbcp = IdUtil.parseDbClassPath(dbcp_s);
boolean found = false;
// a database classpath that is stored in the propert congomerate.
for (int ix = 0; ix < dbcp.length; ix++) if (dbcp.length == 2 && dbcp[ix][0].equals(schemaName) && dbcp[ix][1].equals(sqlName))
found = true;
if (found)
throw StandardException.newException(SQLState.LANG_CANT_DROP_JAR_ON_DB_CLASS_PATH_DURING_EXECUTION, IdUtil.mkQualifiedName(schemaName, sqlName), dbcp_s);
}
try {
notifyLoader(false);
dd.invalidateAllSPSPlans();
DependencyManager dm = dd.getDependencyManager();
dm.invalidateFor(fid, DependencyManager.DROP_JAR, lcc);
UUID id = fid.getUUID();
dd.dropFileInfoDescriptor(fid);
fr.remove(JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar()), fid.getGenerationId());
} finally {
notifyLoader(true);
}
}
use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.
the class SYSFILESRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSFILES row
*
* @return Row suitable for inserting into SYSFILES
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
String id_S = null;
String schemaId_S = null;
String SQLname = null;
long generationId = 0;
ExecRow row;
if (td != null) {
FileInfoDescriptor descriptor = (FileInfoDescriptor) td;
id_S = descriptor.getUUID().toString();
schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString();
SQLname = descriptor.getName();
generationId = descriptor.getGenerationId();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);
/* 1st column is ID (UUID - char(36)) */
row.setColumn(ID_COL_NUM, new SQLChar(id_S));
/* 2nd column is SCHEMAID (UUID - char(36)) */
row.setColumn(SCHEMA_ID_COL_NUM, new SQLChar(schemaId_S));
/* 3rd column is NAME (varchar(30)) */
row.setColumn(NAME_COL_NUM, new SQLVarchar(SQLname));
/* 4th column is GENERATIONID (long) */
row.setColumn(GENERATION_ID_COL_NUM, new SQLLongint(generationId));
return row;
}
use of org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor in project derby by apache.
the class JarUtil method replace.
/**
* Replace a jar file in the current connection's database with the
* content of an external file.
*
* <P> The reason for adding the jar file in this private instance
* method is that it allows us to share set up logic with add and
* drop.
* @param is An input stream for reading the new content of the jar file.
* @exception StandardException Opps
*/
private long replace(InputStream is) throws StandardException {
//
// Like create table we say we are writing before we read the dd
dd.startWriting(lcc);
//
// Temporarily drop the FileInfoDescriptor from the data dictionary.
FileInfoDescriptor fid = getInfo();
if (fid == null)
throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
try {
// disable loads from this jar
notifyLoader(false);
dd.invalidateAllSPSPlans();
dd.dropFileInfoDescriptor(fid);
final String jarExternalName = JarUtil.mkExternalName(fid.getUUID(), schemaName, sqlName, fr.getSeparatorChar());
//
// Replace the file.
long generationId = setJar(jarExternalName, is, false, fid.getGenerationId());
//
// Re-add the descriptor to the data dictionary.
FileInfoDescriptor fid2 = ddg.newFileInfoDescriptor(fid.getUUID(), fid.getSchemaDescriptor(), sqlName, generationId);
dd.addDescriptor(fid2, fid.getSchemaDescriptor(), DataDictionary.SYSFILES_CATALOG_NUM, false, lcc.getTransactionExecute());
return generationId;
} finally {
// reenable class loading from this jar
notifyLoader(true);
}
}
Aggregations