could not find driver error in Laravel 5.5 - driver

I am facing below error while I am trying to run php artisan db:seed
. I ran composer update and composer dump-autoload before.
User.php
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use Notifiable, HasApiTokens;
protected $fillable = ['name', 'email', 'password',];
protected $hidden = ['password', 'remember_token',];
}
Address.php
use Illuminate\Database\Eloquent\Model;
class Address extends Model
{
protected $fillable = ['user_id', 'name', 'address','mobile_no','image','email'];
public function users() {
return $this->hasOne(User::class);
}
}
DatabaseSeeder.php
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(UsersTableSeeder::class);
$this->call(AddressessTableSeeder::class);
}
}
UsersTableSeeder.php
class UsersTableSeeder extends Seeder
{
public function run()
{
factory(App\User::class,10)->create();
}
}
AddressessTableSeeder.php
class AddressessTableSeeder extends Seeder
{
public function run()
{
factory(\App\Address::class, 50)->create()->each(function ($u) {
$u->users()->save(factory(App\Post::class)->make());
});
}
}
Here is my model and seeder files.I could not find out why the error is coming out.

Related

Dagger generated code compilation failed when using #Singleton annotation

I am using Dagger - 2.6 and i have the following classes.
public class Trigger {
public static JSONObject triggerLambda(JSONObject jsonObject) {
DataTransformerComponent daggerDataTransformerComponent = DaggerDataTransformerComponent.create();
return daggerDataTransformerComponent.getHandler().handle(jsonObject);
}
}
Data Handler class:
public class DataHandler {
private static final Logger LOGGER = Logger.getLogger(DataHandler.class.getName());
private A a;
#Inject
public DataHandler(A a) {
this.a = a;
}
public JSONObject handle(JSONObject input) {
LOGGER.info("Json input received - " + input.toString());
return a.executeTransformation(input);
}
}
And a dependency:
public class A {
#Inject
public A() {
}
public JSONObject executeTransformation(JSONObject jsonObject) {
System.out.println("a");
return null;
}
}
My component class looks like:
#Component
public interface DataTransformerComponent {
DataHandler getHandler();
}
When i compile the above code it runs absolutely fine.
Now i want to make my A dependency #Singleton.
So i change my dependency class and component class as follows:
#Singleton
#Component
public interface DataTransformerComponent {
DataHandler getHandler();
}
Dependency class:
#Singleton
public class A {
#Inject
public A() {
}
public JSONObject executeTransformation(JSONObject jsonObject) {
System.out.println("a");
return null;
}
}
But now the generated component shows compilation errors saying:
A_Factory not found and it fails in the initialize() method.
DaggerDataTransformerComponent :
#Generated(
value = "dagger.internal.codegen.ComponentProcessor",
comments = "https://google.github.io/dagger"
)
public final class DaggerDataTransformerComponent implements DataTransformerComponent {
private Provider<A> aProvider;
private Provider<DataHandler> dataHandlerProvider;
private DaggerDataTransformerComponent(Builder builder) {
assert builder != null;
initialize(builder);
}
public static Builder builder() {
return new Builder();
}
public static DataTransformerComponent create() {
return builder().build();
}
#SuppressWarnings("unchecked")
private void initialize(final Builder builder) {
this.aProvider = DoubleCheck.provider(A_Factory.create());
this.dataHandlerProvider = DataHandler_Factory.create(aProvider);
}
#Override
public DataHandler getHandler() {
return dataHandlerProvider.get();
}
public static final class Builder {
private Builder() {}
public DataTransformerComponent build() {
return new DaggerDataTransformerComponent(this);
}
}
}
I am unable to figure out why it does not create _factory class when i use #Singleton annotation.?.
Just use regular JavaScript + node.js, its a lot simpler

Grails 2.5.4: Get all logged in users with HttpSessionListener

I'm trying to get all the current user sessions using the app-info plugin but it doesn't compile in Grails 2.5.4. Is there another way to get this information? I'm new to Grails.
This link has some information including a reference to the app-info plugin but it's old and I wasn't able to get anything to compile.
UPDATE
I've added this custom class in src\groovy\UserSessions:
package usersessions
import javax.servlet.http.HttpSessionEvent
import javax.servlet.http.HttpSessionListener
//import org.apache.shiro.subject.PrincipalCollection
//import org.apache.shiro.subject.SimplePrincipalCollection;
//import org.apache.shiro.subject.support.DefaultSubjectContext
class MyHttpSessionListener implements HttpSessionListener {
private static List activeUsers = Collections.synchronizedList(new ArrayList());
#Override
public void sessionCreated(HttpSessionEvent event) { }
#Override
public void sessionDestroyed(HttpSessionEvent event) {
String userName = getCurrentUserName(event)
if (userName == null) {
return
}
MyHttpSessionListener.userLoggedOut(userName)
}
public static void userLoggedIn(String userName) {
if (!activeUsers.contains(userName)) {
activeUsers.add(userName)
}
}
public static void userLoggedOut(String userName) {
activeUsers.remove(userName)
}
public static List getCurrentUserNames() {
return Collections.unmodifiableList(activeUsers);
}
/*
private String getCurrentUserName(HttpSessionEvent event) {
PrincipalCollection currentUser = (PrincipalCollection) event.getSession().getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
if (currentUser == null) {
return null
}
return (String) currentUser.getPrimaryPrincipal();
}
*/
}
Added this to /scripts/_Events.groovy
import groovy.xml.StreamingMarkupBuilder
eventWebXmlEnd = {String tmpfile ->
def root = new XmlSlurper().parse(webXmlFile)
root.appendNode {
'listener' {
'listener-class' (
'usersessions.MyHttpSessionListener'
)
}
}
webXmlFile.text = new StreamingMarkupBuilder().bind {
mkp.declareNamespace(
"": "http://java.sun.com/xml/ns/javaee")
mkp.yield(root)
}
}
Added this to resources.groovy
myHttpSessionListener(usersessions.MyHttpSessionListener)
/* shiroAuthenticator(ModularRealmAuthenticator) {
authenticationStrategy = ref("shiroAuthenticationStrategy")
authenticationListeners = [ ref("authListener") ]
}
*/
Added this to my controller:
package usersessions
class NewController extends MyHttpSessionListener {
def index() {
myHttpSessionListener.userLoggedIn("user1")
render "Users "+ getCurrentUserNames()
}
}
It compiles and the app runs but I don't see how to get sessions in the listener? The controller gives an error when I load it:
No such property: myHttpSessionListener for class: usersessions.NewController
UPDATE 2
I changed the controller to use this code to test creating a sessions and it works:
def index() {
String randomString = org.apache.commons.lang.RandomStringUtils.random(3, true, true)
userLoggedIn(randomString)
render "Users "+ getCurrentUserNames()
}

Jersy2 inject slf4j Logger

I'm trying to understand Jersey 2 development and context-dependency injection.
I don't understand how to inject into a resource an object that needs initialization parameters in the constructor.
For example: I'd like to #Inject slf4j Logger, built using LoggerFactory.
My resource class is:
#Path("/myresource")
public class MyResource {
#Inject
private Logger log;
#GET
#Produces(MediaType.APPLICATION_JSON)
public Answer status() {
log.info("STATUS");
return new Answer(200, "Server up and running # "+ ZonedDateTime.now());
}
}
My Resource config is:
public class MyAppextends ResourceConfig {
public MyApp() {
register(new MyBinder());
packages(true, "my.packages");
}
}
public class MyBinder extends AbstractBinder {
#Override
protected void configure() {
bindFactory(MyLoggerFactory.class).to(org.slf4j.Logger.class);
}
}
Finally, the Factory is:
public class MyLoggerFactory implements Factory<Logger> {
#Override
public Logger provide() {
return LoggerFactory.getLogger(TYPE_FOR_LOGGING.class);
}
#Override
public void dispose(Logger logger) {
}
}
How can I specify TYPE_FOR_LOGGING as argument, in order to Inject the correctly initialized Logger in every resource I want?
Thanks
What you are looking for is called the InstantiationService. You can inject it into Factories to find out who is calling the factory inside of the provide method.
Below find a code sample from the hk2 tests that illustrate the use of the InstantiationService.
#Singleton
public class CorrelationFactory implements Factory<PerLookupServiceWithName> {
private final static PerLookupServiceWithName NULL_SERVICE = new PerLookupServiceWithName() {
#Override
public String getName() {
return null;
}
};
#Inject
private InstantiationService instantiationService;
/* (non-Javadoc)
* #see org.glassfish.hk2.api.Factory#provide()
*/
#Override #PerLookup
public PerLookupServiceWithName provide() {
InstantiationData data = instantiationService.getInstantiationData();
if (data == null) {
return NULL_SERVICE;
}
Injectee parent = data.getParentInjectee();
if (parent == null) {
return NULL_SERVICE;
}
Class<?> parentClass = parent.getInjecteeClass();
if (parentClass == null) {
return NULL_SERVICE;
}
Correlator correlator = parentClass.getAnnotation(Correlator.class);
if (correlator == null) {
return NULL_SERVICE;
}
final String fName = correlator.value();
return new PerLookupServiceWithName() {
#Override
public String getName() {
return fName;
}
};
}
/* (non-Javadoc)
* #see org.glassfish.hk2.api.Factory#dispose(java.lang.Object)
*/
#Override
public void dispose(PerLookupServiceWithName instance) {
// DO nothing
}
}

How to explicitly access the Connector from Widget Side into Vaadin 7?

I create a Widget with his Server Side Class and the Client Side (Connector Class, ServerRPC Class, State Class and Widget Class).
Connector :
#Connect(Custom.class)
public class CustomConnector extends ButtonConnector {
...
public void myFunc() {
// DO Something
}
}
Widget :
public class CustomWidget extends VButton {
...
private CustomConnector conn = new CustomConnector();
public CustomWidget () {
conn.myFunc();
}
...
}
Now from the Widget Class i want to explicitly call/access the Connector Object, which are not a Singleton, so that i can access a function too. How can i solve it?
In my opinion you should not access connector directly from GWT widget. It is against Vaadin 7 architecture where GWT widgets are objects independent from vaadin at all.
However if we are talking about dirty migration from Vaadin 6 to 7 solution could be:
ComponentConnector connector = ConnectorMap.get(client).getConnector(CustomWidget.this); // client is taken from updateFromUIDL method (Vaadin6)
Better solution will be to add "state" listener to the widget
public interface CustomWidgetStateListener {
public void stateChanged();
}
public class CustomWidget extends VButton {
...
CustomWidgetStateListener listener;
public void addStateListener(CustomWidgetStateListener listener) {
this.listener = listener;
}
public void notifyStateChanged() { // You can call notifyStateChanged() whenever you want to notify connector
listener.stateChanged();
}
...
}
public class CustomConnector extends ButtonConnector {
public CustomConnector() {
getWidget().addStateListener(new CustomWidgetStateListener() {
public void stateChanged() {
myFunc();
}
});
}
...
public void myFunc() {
// DO Something
}
}

Flex MultiCore PureMVC Notifier initialization error

I am trying to write a simple multicore PureMVC helloword. I am getting Error: multitonKey for this Notifier not yet initialized!
at org.puremvc.as3.multicore.patterns.observer::Notifier/get facade()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3_MultiCore\src\org\puremvc\as3\multicore\patterns\observer\Notifier.as:89]
at com.jacksutest.view::ApplicationMediator()[C:\myworkspace\MyPureMVC\src\com\jacksutest\view\ApplicationMediator.as:15]
Here is the main mxml:
public static const APP_NAME : String = "MyPureMVC";
private var facade : ApplicationFacade = ApplicationFacade.getInstance(APP_NAME);
public function init() : void
{
facade.startup(this);
}
...
<components:WordForm id="theWordForm"/>
This is the ApplicationFacade.
public class ApplicationFacade extends Facade implements IFacade
{
public static const STARTUP : String = "Startup";
public static const VERIFY_WORD : String = "VerifyWord";
public function ApplicationFacade(key:String)
{
super(key);
}
public static function removeInstance(key:String):void
{
if( null != instanceMap )
{
if( null != instanceMap[key] )
{
delete instanceMap[key];
}
}
}
/**
* Singleton ApplicationFacade Factory Method
*/
public static function getInstance(key:String):ApplicationFacade
{
if ( null == instanceMap[key] )
{
instanceMap[key] = new ApplicationFacade(key);
}
return instanceMap[key] as ApplicationFacade;
}
/**
* Register Commands with the Controller
*/
override protected function initializeController():void
{
super.initializeController();
registerCommand(STARTUP, StartupCommand);
registerCommand(VERIFY_WORD, VerifyWordCommand);
}
public function startup(app : MyPureMVC):void
{
trace("In facade startup");
sendNotification(STARTUP, app);
}
public function verifyWord(wordDTO : WordDTO) : void
{
sendNotification(VERIFY_WORD, wordDTO);
}
}
}
This is startup command
public class StartupCommand extends MacroCommand
{
public function StartupCommand()
{
trace("Startup command created");
addSubCommand(ModelPrepCommand);
addSubCommand(ViewPrepCommand);
}
}
This is ViewPrepCommand
public class ViewPrepCommand extends SimpleCommand
{
override public function execute( note : INotification ) : void
{
var app : MyPureMVC = note.getBody() as MyPureMVC;
facade.registerMediator(new ApplicationMediator(app));
}
}
And this is ApplicationMediator:
public class ApplicationMediator extends Mediator implements IMediator
{
public static const NAME : String = "MyPureMVCApplicationMediator";
public function ApplicationMediator(mainApp : MyPureMVC)
{
facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
}
Error happens when facade.registerMediator.
Find the problem. I should not reference facade in the constructor of ApplicationMediator.
Instead, I should call the facade.registerMediator in onRegister method.
public static const NAME : String = "MyPureMVCApplicationMediator";
public function ApplicationMediator(viewComponent : MyPureMVC)
{
super( NAME, viewComponent );
}
override public function onRegister():void
{
// Retrieve reference to frequently consulted Proxies
facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
}
public function get mainApp() : MyPureMVC
{
return viewComponent as MyPureMVC;
}

Resources