I am trying to flush the mondrian dimension cache by following code -
org.olap4j.metadata.Schema OlapSchema = olapConnection.getOlapSchema();
NamedList<org.olap4j.metadata.Cube> cubeList = OlapSchema.getCubes();
org.olap4j.metadata.Member m = null;
for(org.olap4j.metadata.Cube cube: cubeList) {
m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList());
final CacheControl cacheControl = olapConnection.getCacheControl(null);
CacheControl.MemberSet regionTime = cacheControl.createMemberSet(mondrian.olap.Member)m, false);
cacheControl.flush(regionTime);
}
But this code is throwing a runtime error "MondrianOlap4jMember and mondrian.olap.member are incompatible"
Looks like you need to do the following to flush the cache -
unwrap the member object returned by lookupMember function using Olap wrapper class like so -
m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList());
OlapWrapper wrapper = (OlapWrapper)m;
mondrian.olap.Member MondrianMember = wrapper.unwrap(mondrian.olap.Member.class);
And now call the flush method -
cacheControl.flush(MondrianMember);
Related
Need help in creating cross region standby database via python have tried creating with
oci.database.models.CreateCrossRegionAutonomousDatabaseDataGuardDetails
I am unable to find an example for the same so i tried with whatever i can find through sdk documentation
response = oci_client.get_autonomous_database(autonomous_database_id=primary_db_id)
primary_db_details = response.data
def create_cross_region_standby_db(db_client, primary_db_details: oci.database.models.AutonomousDatabase):
adw_request = oci.database.models.CreateCrossRegionAutonomousDatabaseDataGuardDetails()
adw_request.compartment_id = primary_db_details.compartment_id
adw_request.db_name = primary_db_details.db_name
adw_request.data_storage_size_in_tbs = primary_db_details.data_storage_size_in_tbs
adw_request.data_storage_size_in_gbs = primary_db_details.data_storage_size_in_gbs
adw_request.cpu_core_count = primary_db_details.cpu_core_count
adw_request.db_version = primary_db_details.db_version
adw_request.db_workload = primary_db_details.db_workload
adw_request.license_model = primary_db_details.license_model
adw_request.is_mtls_connection_required = primary_db_details.is_mtls_connection_required
adw_request.is_auto_scaling_enabled = primary_db_details.is_auto_scaling_enabled
adw_request.source_id = primary_db_details.id
adw_request.subnet_id = <standby subnet id>
adw_response = db_client.create_autonomous_database(create_autonomous_database_details=adw_request)
print(adw_response.data)
adw_id = adw_response.data.id
oci.wait_until(db_client, db_client.get_autonomous_database(adw_id), 'lifecycle_state', 'AVAILABLE')
print("Created ADW {}".format(adw_id))
return adw_id
create_cross_region_standby_db is done using standby region credentials. Creation of primary db in the same region works fine.
In my ASP.NET Web API project, I am trying to use the generic repositories with the List objects under one of the methods. But it is throwing exception
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
System.Data.Entity.Core.EntityCommandExecutionException: Calling 'Read' when the data reader is closed is not a valid operation. --->
System.Data.SqlClient.SqlException: Execution Timeout Expired. The
timeout period elapsed prior to completion of the operation or the
server is not responding. ---> System.ComponentModel.Win32Exception:
The wait operation timed out
lstFinalResult object contains few rows. partnerRepo is a generic repo and will have data at the later stage, i suppose.
Please advise, where am i making the mistake. Can we mix the List with generic repository objects in the linq query ?
Here is the linq code :-
List<UserDocumentResult> lstFinalResult = new List<UserDocumentResult>();
foreach (DocumentMapping dm in lstMappings)
{
lstFinalResult.Add(new UserDocumentResult { PID = dm.PartnerID,
DocMappingID = dm.DocumentMappingID,
EntityType = "",
Name = ""
});
}
var partnerRepo = _docRepository.PtGenericRepo.Get();
var entityCodesRepo = _docRepository.EntityCodeGenericRepo.Get();
---While debugging, I am getting error in the below code only.
var qualifiedPartnerSet = (from tmp in lstFinalResult
join px in partnerRepo on tmp.PID equals px.PartnerID
join ecx in entityCodesRepo on px.EntityCodeID equals ecx.EntityCodeID
select new UserDocumentResult
{
PID = px.PartnerID,
MappingID = tmp.MappingID,
EntityType = ecx.DisLabel.Trim(),
Name = px.NameLine1.Trim() + px.NameLine2.Trim(),
}).ToList();
The information in the MVStore docs on backing up a database is a little vague, and I'm not familiar with all the concepts and terminology, so I wanted to see if the approach I came up with makes sense.
I'm a Clojure programmer, so please forgive my Java here:
// db is an MVStore instance
FileStore fs = db.getFileStore();
FileOutputStream fos = java.io.FileOutputStream(pathToBackupFile);
FileChannel outChannel = fos.getChannel();
try {
db.commit();
db.setReuseSpace(false);
ByteBuffer bb = fs.readFully(0, fs.size());
outChannel.write(bb);
}
finally {
outChannel.close();
db.setReuseSpace(true);
}
Here's what it looks like in Clojure in case my Java is bad:
(defn backup-db
[db path-to-backup-file]
(let [fs (.getFileStore db)
backup-file (java.io.FileOutputStream. path-to-backup-file)
out-channel (.getChannel backup-file)]
(try
(.commit db)
(.setReuseSpace db false)
(let [file-contents (.readFully fs 0 (.size fs))]
(.write out-channel file-contents))
(finally
(.close out-channel)
(.setReuseSpace db true)))))
My approach seems to work, but I wanted to make sure I'm not missing anything or see if there's a better way. Thanks!
P.S. I used the H2 tag because MVStore doesn't exist and I don't have enough reputation to create it.
The docs currently say:
The persisted data can be backed up at any time, even during write
operations (online backup). To do that, automatic disk space reuse
needs to be first disabled, so that new data is always appended at the
end of the file. Then, the file can be copied. The file handle is
available to the application. It is recommended to use the utility
class FileChannelInputStream to do this.
The classes FileChannelInputStream and FileChannelOutputStream convert a java.nio.FileChannel into a standard InputStream and OutputStream. There is existing H2 code in BackupCommand.java that shows how to use them. We can improve upon it using Java 9 input.transferTo(output); to copy the data:
public void backup(MVStore s, File backupFile) throws Exception {
try {
s.commit();
s.setReuseSpace(false);
try(RandomAccessFile outFile = new java.io.RandomAccessFile(backupFile, "rw");
FileChannelOutputStream output = new FileChannelOutputStream(outFile.getChannel(), false)){
try(FileChannelInputStream input = new FileChannelInputStream(s.getFileStore().getFile(), false)){
input.transferTo(output);
}
}
} finally {
s.setReuseSpace(true);
}
}
Note that when you create the FileChannelInputStream you have to pass false to tell it to not close the underlying file channel when the stream is closed. If you don't do that it will close the file that your FileStore is trying to use. That code uses try-with-resource syntax to make sure that the output file is properly closed.
In order to try this, I checked out the mvstore code then modified the TestMVStore to add a testBackup() method which is similar to the existing testSimple() code:
private void testBackup() throws Exception {
// write some records like testSimple
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
MVMap<Integer, String> m = s.openMap("data");
for (int i = 0; i < 3; i++) {
m.put(i, "hello " + i);
}
// create a backup
String fileNameBackup = getBaseDir() + "/" + getTestName() + ".backup";
FileUtils.delete(fileNameBackup);
backup(s, new File(fileNameBackup));
// this throws if you accidentally close the input channel you get from the store
s.close();
// open the backup and verify
s = openStore(fileNameBackup);
m = s.openMap("data");
for (int i = 0; i < 3; i++) {
assertEquals("hello " + i, m.get(i));
}
s.close();
}
With your example, you are reading into a ByteBuffer which must fit into memory. Using the stream transferTo method uses an internal buffer that is currently (as at Java11) set to 8192 bytes.
I have some demo code as follwing.
Class<?> myClass = cl.loadClass("com.hp.ac.scriptengine.test." + generateClassName);
Object my_obj = myClass.newInstance();
MethodType mt;
MethodHandle mh;
MethodHandles.Lookup lookup = MethodHandles.lookup();
mt = MethodType.methodType(void.class, int.class);
mh = lookup.findVirtual(my_obj.getClass(), "ToDoit", mt);
mh.invokeExact(my_obj,1);
here '"com.hp.ac.scriptengine.test." + generateClassName' is a generated class.
I got the message as follows.
java.lang.invoke.WrongMethodTypeException: (I)V cannot be called as (Ljava/lang/Object;I)V
at com.hp.ac.scriptengine.test.compliebyCommandline.main(compliebyCommandline.java:138)
Here line 138 is mh.invokeExact(my_obj,1);'
I tried that demo code(such as ... mh.invokeExact("daddy",'d','n')...) in Java 7 API document. It works fine. Such call(mh.invokeExact("daddy",'d','n'))just invoke (CC)Ljava/lang/String other than (Ljava/lang/String;CC)Ljava/lang/String.
But why, in my code, mh.invokeExact(my_obj,1) invoke (Ljava/lang/Object;I)V other than (I)V ?
I think the problem is with int.class. Try Integeer.class or Integer.TYPE instead.
I'm using Joomla 2.5 to build a medium-sized website, and I've decided to ease maintenance and content management headaches through creating menus automatically.
I've looked for extensions which did this, but only found Joomla 1.5 extensions. I ended up trying to upgrade a GPL extension called Auto Menu Magic.
It was easy to deal with the basic issues like the XML tags in the extension file, since there's a page in the Joomla which helps you migrate from Joomla 1.5 to 1.6.
The extension I mentioned has a function named onContentAfterSave which is called by joomla when an article is saved. I've been debugging through creating rubbish articles in the admin interface and changing the code to throw exceptions in several places, which I can see as error messages on the admin frontend.
This is where I got stuck:
$db = &JFactory::getDBO();
$menu = JTable::getInstance( 'menu');
$menu->menutype = $menutype;
$menu->name = $name;
$menu->link = $link;
$menu->type = $linktype;
$menu->published = $published;
$menu->componentid = $componentid;
$menu->parent = $menuparentid;
$menu->sublevel = $menusublevel;
$menu->checked_out = 0;
$menu->checked_out_time = 0;
$menu->pollid = 0;
$menu->browserNav = 0;
$menu->access = 0;
$menu->utaccess = 0;
$menu->lft = 0;
$menu->rgt = 0;
$menu->home = 0;
$menu->params = $params;
// Figure out the order (Just pop this article at the end of the list):
$menu->ordering = $menu->getNextOrder(
"menutype = ".$db->Quote($menu->menutype).
" AND published >= 0 AND parent = ".(int) $menu->parent
);
// Validate:
if (!$menu->check())
return NULL;
// DEBUG 2 -- Integrity check
throw new Exception ("menutype: $menutype, name: $name, link: $link published: $published, componentid: $componentid menuparentid: $menuparentid menusublevel: $menusublevel");
// Save:
if (!$menu->store())
return NULL;
// DEBUG 1
throw new Exception(" Could save! ");
As you can see above, I tried to throw an exception (DEBUG 1) when the menu was saved to the database. This exception was never reached, but the upper exception (DEBUG 2) is reached. This means that $menu->check() returns true, but not $menu->store(). I assume that the database is returning an error because some of the Joomla database structure might have changed after 1.5.
I have read the source a lot these past hours, but I can't find one thing. How can I look at the columns that a Joomla table uses, so I can debug this error properly?
Thanks in advance!
PS: I've looked at the SQL database too, but it doesn't help much. The variables seem to have different naming conventions from the column names.
I think it should look like this because I have been trying to convert auto menu as well!
$db = &JFactory::getDBO();
$menu = JTable::getInstance('menu');
$menu->menutype = $menutype;
$menu->title = $title;
$menu->alias = strtolower($title) ;
$menu->note = "Created by automenu";
$menu->path = $link;
$menu->link = $link;
$menu->type = $linktype;
$menu->published = $published;
$menu->parent_id = $menuparentid
$menu->level = $menusublevel;
$menu->componentid = $componentid;
$menu->ordering = 0;
$menu->checked_out = 0;
$menu->checked_out_time = 0;
$menu->browserNav = 0;
$menu->access = 1;
$menu->img = '';
$menu->templat_style_id = 0;
$menu->params = $params;
$menu->lft = 0;
$menu->rgt = 0;
$menu->home = 0;
$menu->language = '*';
$menu->client_id = 0;
I would be interseted to know if you ever got it working!
I'd suggest turning on Joomla debugging in the System Configuration. At the bottom of each page it shows all the queries it has executed, and this (depending on the plugin) might show you what SQL is being executed, and presumably, failing. There's likely to be a big list, so you may have to search through it a bit to find the statement you're interested in.
Fabio,
Many thanks! I will try it out and see if I can improve it further.
Mike
You're forgetting the first rule of Exceptions Club, if you throw something... you have to catch it.
I don't see a try/catch pair in your code so PHP would be stopping with a "Fatal Error..." for the uncaught exception so it would never get to the DEBUG 1. e.g.
Fatal error: Uncaught exception 'Exception' with message ...
Try wrapping your code in a try/catch pair and allowing the execution to continue after DEBUG 2 have a look at the PHP doc's for exceptions